Files
palera1n/src/main.c
T

490 lines
15 KiB
C
Raw Normal View History

2023-01-16 16:17:41 +08:00
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <fcntl.h>
#include <stddef.h>
#include <unistd.h>
#include <stdarg.h>
#include <ctype.h>
#include <assert.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/ioctl.h>
#include <signal.h>
#include <pthread.h>
#include <inttypes.h>
2023-01-17 13:46:42 +08:00
#include <getopt.h>
#include <errno.h>
2023-01-22 20:47:52 +08:00
#include <spawn.h>
2023-01-18 17:58:20 +08:00
#include <sys/mman.h>
2023-01-24 03:32:29 +08:00
#include <time.h>
2023-01-16 16:17:41 +08:00
2023-01-17 19:26:37 +08:00
#include <libimobiledevice/libimobiledevice.h>
2023-01-18 17:58:20 +08:00
#if defined(__APPLE__)
#include <mach-o/loader.h>
2023-01-18 22:35:22 +08:00
#include <mach-o/ldsyms.h>
2023-01-18 17:58:20 +08:00
#else
2023-01-21 18:27:07 +08:00
#define MH_MAGIC_64 0xfeedfacf
#define MH_CIGAM_64 0xcffaedfe
2023-01-18 17:58:20 +08:00
#define MH_KEXT_BUNDLE 0xb
typedef int cpu_type_t;
typedef int cpu_subtype_t;
#define CPU_ARCH_ABI64 0x01000000
#define CPU_TYPE_ARM ((cpu_type_t) 12)
#define CPU_TYPE_ARM64 (CPU_TYPE_ARM | CPU_ARCH_ABI64)
struct mach_header_64
{
uint32_t magic; /* mach magic number identifier */
cpu_type_t cputype; /* cpu specifier */
cpu_subtype_t cpusubtype; /* machine specifier */
uint32_t filetype; /* type of file */
uint32_t ncmds; /* number of load commands */
uint32_t sizeofcmds; /* the size of all the load commands */
uint32_t flags; /* flags */
uint32_t reserved; /* reserved */
};
2023-01-21 18:27:07 +08:00
2023-01-18 17:58:20 +08:00
#endif
2023-01-16 16:17:41 +08:00
#include "ANSI-color-codes.h"
#include "common.h"
2023-01-17 13:46:42 +08:00
#include "checkra1n.h"
2023-01-18 16:02:43 +08:00
#include "kerninfo.h"
2023-01-16 16:17:41 +08:00
2023-01-17 13:46:42 +08:00
#define CMD_LEN_MAX 512
2023-01-18 17:58:20 +08:00
#define OVERRIDE_MAGIC 0xd803b376
2023-01-17 13:46:42 +08:00
2023-01-25 15:42:40 +08:00
unsigned int verbose = 0U;
2023-01-22 17:38:47 +08:00
int enable_rootful = 0;
2023-01-17 19:26:37 +08:00
int do_pongo_sleep = 0;
2023-01-25 15:42:40 +08:00
int device_has_booted = 0;
int demote = 0;
2023-01-25 15:42:40 +08:00
int pongo_thr_running = 0, dfuhelper_thr_running = 0;
2023-01-22 20:47:52 +08:00
bool ohio = true;
2023-01-22 23:42:22 +08:00
char xargs_cmd[0x270] = "xargs wdt=-1";
2023-01-18 16:02:43 +08:00
char checkrain_flags_cmd[0x20] = "checkra1n_flags 0x0";
2023-01-22 23:20:46 +08:00
char palerain_flags_cmd[0x20] = "palera1n_flags 0x0";
char kpf_flags_cmd[0x20] = "kpf_flags 0x0";
2023-01-22 17:38:47 +08:00
char dtpatch_cmd[0x20] = "dtpatch md0";
char rootfs_cmd[512];
2023-01-22 20:47:52 +08:00
extern char** environ;
2023-01-17 13:46:42 +08:00
2023-01-25 15:42:40 +08:00
bool dfuhelper_only = false;
bool pongo_exit = false;
bool start_from_pongo = false;
bool palerain_version = false;
2023-01-23 01:24:22 +08:00
typedef unsigned char niarelap_file_t[];
niarelap_file_t* kpf_to_upload_1 = &checkra1n_kpf_pongo;
niarelap_file_t* ramdisk_to_upload_1 = &ramdisk_dmg;
2023-01-22 14:02:20 -05:00
niarelap_file_t* overlay_to_upload_1 = &binpack_dmg;
2023-01-23 01:24:22 +08:00
niarelap_file_t** kpf_to_upload = &kpf_to_upload_1;
niarelap_file_t** ramdisk_to_upload = &ramdisk_to_upload_1;
niarelap_file_t** overlay_to_upload = &overlay_to_upload_1;
2023-01-18 17:58:20 +08:00
override_file_t override_ramdisk;
override_file_t override_kpf;
override_file_t override_overlay;
2023-01-18 16:02:43 +08:00
uint32_t checkrain_flags = 0;
2023-01-22 17:38:47 +08:00
uint32_t palerain_flags = 0;
2023-01-22 23:20:46 +08:00
uint32_t kpf_flags = 0;
2023-01-18 16:02:43 +08:00
2023-01-25 15:42:40 +08:00
pthread_t dfuhelper_thread, pongo_thread;
pthread_mutex_t log_mutex;
2023-01-16 16:17:41 +08:00
2023-01-17 13:46:42 +08:00
int found_pongo = 0;
2023-01-25 15:42:40 +08:00
void *pongo_usb_callback(void *arg) {
2023-01-18 00:44:47 +08:00
if (found_pongo)
return NULL;
2023-01-17 13:46:42 +08:00
found_pongo = 1;
2023-01-18 00:44:47 +08:00
LOG(LOG_INFO, "Found PongoOS USB Device");
2023-01-17 13:46:42 +08:00
usb_device_handle_t handle = *(usb_device_handle_t *)arg;
2023-01-24 02:01:29 +08:00
issue_pongo_command(handle, NULL);
2023-01-17 13:46:42 +08:00
issue_pongo_command(handle, "fuse lock");
issue_pongo_command(handle, "sep auto");
2023-01-23 01:24:22 +08:00
upload_pongo_file(handle, **kpf_to_upload, checkra1n_kpf_pongo_len);
2023-01-17 13:46:42 +08:00
issue_pongo_command(handle, "modload");
2023-01-22 23:20:46 +08:00
issue_pongo_command(handle, kpf_flags_cmd);
2023-01-18 16:02:43 +08:00
issue_pongo_command(handle, checkrain_flags_cmd);
2023-01-22 17:38:47 +08:00
issue_pongo_command(handle, palerain_flags_cmd);
if (enable_rootful)
2023-01-18 17:58:20 +08:00
{
2023-01-22 17:38:47 +08:00
issue_pongo_command(handle, rootfs_cmd);
issue_pongo_command(handle, dtpatch_cmd);
2023-01-17 19:26:37 +08:00
}
2023-01-22 17:38:47 +08:00
strcat(xargs_cmd, " rootdev=md0");
2023-01-23 01:24:22 +08:00
upload_pongo_file(handle, **ramdisk_to_upload, ramdisk_dmg_len);
2023-01-22 17:38:47 +08:00
issue_pongo_command(handle, "ramdisk");
2023-01-23 01:24:22 +08:00
upload_pongo_file(handle, **overlay_to_upload, binpack_dmg_len);
2023-01-22 17:38:47 +08:00
issue_pongo_command(handle, "overlay");
2023-01-17 13:59:44 +08:00
issue_pongo_command(handle, xargs_cmd);
2023-01-18 00:44:47 +08:00
issue_pongo_command(handle, "kpf");
issue_pongo_command(handle, "bootux");
2023-01-17 13:46:42 +08:00
LOG(LOG_INFO, "Booting Kernel...");
2023-01-25 15:42:40 +08:00
device_has_booted = 1;
if (dfuhelper_thr_running) {
pthread_cancel(dfuhelper_thread);
}
2023-01-17 13:46:42 +08:00
spin = false;
return NULL;
}
static struct option longopts[] = {
{"dfuhelper", no_argument, NULL, 'D'},
{"help", no_argument, NULL, 'h'},
{"pongo-shell", no_argument, NULL, 'p'},
2023-01-22 23:20:46 +08:00
{"debug-logging", no_argument, NULL, 'v'},
{"verbose-boot", no_argument, NULL, 'V'},
2023-01-17 13:59:44 +08:00
{"boot-args", required_argument, NULL, 'e'},
2023-01-17 20:48:54 +08:00
{"rootfs", required_argument, NULL, 'f'},
2023-01-18 16:02:43 +08:00
{"rootless", no_argument, NULL, 'l'},
2023-01-23 13:59:07 +08:00
{"jbinit-log-to-file", no_argument, NULL, 'L'},
2023-01-18 16:02:43 +08:00
{"demote", no_argument, NULL, 'd'},
{"force-revert", no_argument, NULL, checkrain_option_force_revert},
{"safe-mode", no_argument, NULL, 's'},
{"version", no_argument, NULL, palerain_option_version},
2023-01-22 19:18:35 +08:00
{"override-pongo", required_argument, NULL, 'k'},
2023-01-18 17:58:20 +08:00
{"override-overlay", required_argument, NULL, 'o'},
{"override-ramdisk", required_argument, NULL, 'r'},
{"override-kpf", required_argument, NULL, 'K'},
2023-01-22 20:47:52 +08:00
{"disable-ohio", no_argument, NULL, 'O'},
2023-01-25 15:42:40 +08:00
{NULL, 0, NULL, 0}
};
2023-01-17 13:46:42 +08:00
2023-01-25 15:42:40 +08:00
int usage(int e, char* prog_name) {
2023-01-17 13:46:42 +08:00
fprintf(stderr,
2023-01-23 13:59:07 +08:00
"Usage: %s [-DhpPvVldsOL] [-e boot arguments] [-f root device] [-k Pongo image] [-o overlay file] [-r ramdisk file] [-K KPF file]\n"
2023-01-17 13:46:42 +08:00
"Copyright (C) 2023, palera1n team, All Rights Reserved.\n\n"
"iOS/iPadOS 15+ arm64 jailbreaking tool\n\n"
2023-01-18 16:02:43 +08:00
"\t--version\t\t\t\tPrint version\n"
"\t--force-revert\t\t\t\tRemove jailbreak (on rootless)\n"
2023-01-17 14:06:08 +08:00
"\t-D, --dfuhelper-only\t\t\tExit after entering DFU\n"
"\t-h, --help\t\t\t\tShow this help\n"
"\t-p, --pongo-shell\t\t\tBoots to PongoOS shell\n"
2023-01-17 19:26:37 +08:00
"\t-v, --debug-logging\t\t\tEnable debug logging\n"
2023-01-17 14:06:27 +08:00
"\t\tThis option can be repeated for extra verbosity.\n"
2023-01-22 23:20:46 +08:00
"\t-V, --verbose-boot\t\t\tVerbose boot\n"
2023-01-23 13:59:07 +08:00
"\t-L, --jbinit-log-to-file\t\tMake jbinit log to /cores/jbinit.log (can be read from sandbox while jailbroken)\n"
2023-01-17 19:26:37 +08:00
"\t-e, --boot-args <boot arguments>\tXNU boot arguments\n"
"\t-f, --rootfs <root device>\t\tBoots rootful setup on <root device>\n"
"\t-l, --rootless\t\t\t\tBoots rootless. This is the default\n"
2023-01-22 19:18:35 +08:00
"\t-s, --safe-mode\t\t\t\tEnter safe mode\n"
2023-01-18 17:58:20 +08:00
"\t-d, --demote\t\t\t\tDemote\n"
2023-01-22 19:18:35 +08:00
"\t-k, --override-pongo <file>\t\tOverride Pongo image\n"
2023-01-18 17:58:20 +08:00
"\t-o, --override-overlay <file>\t\tOverride overlay\n"
"\t-r, --override-ramdisk <file>\t\tOverride ramdisk\n"
2023-01-22 20:47:52 +08:00
"\t-K, --override-kpf <file>\t\tOverride kernel patchfinder\n"
"\t-O, --disable-ohio\t\t\tDisable Ohio\n",
2023-01-21 18:27:07 +08:00
prog_name);
2023-01-17 13:46:42 +08:00
exit(e);
2023-01-25 15:42:40 +08:00
};
2023-01-17 13:46:42 +08:00
2023-01-25 15:42:40 +08:00
int override_file(override_file_t *finfo, niarelap_file_t** orig, unsigned int *orig_len, char *filename) {
2023-01-18 17:58:20 +08:00
int ret = 0;
int fd = open(filename, O_RDONLY);
2023-01-25 15:42:40 +08:00
LOG(LOG_VERBOSE5, "override_file() called!");
if (fd == -1) {
2023-01-24 03:32:29 +08:00
LOG(LOG_ERROR, "Cannot open file %s: %d (%s)", filename, errno, strerror(errno));
2023-01-18 17:58:20 +08:00
return errno;
}
2023-01-25 15:42:40 +08:00
LOG(LOG_VERBOSE5, "override_file: opened %s!", filename);
2023-01-18 17:58:20 +08:00
struct stat st;
ret = fstat(fd, &st);
2023-01-25 15:42:40 +08:00
if (ret) {
2023-01-24 03:32:29 +08:00
LOG(LOG_ERROR, "Cannot fstat fd from file %s: %d (%s)", filename, errno, strerror(errno));
2023-01-18 17:58:20 +08:00
return errno;
}
2023-01-25 15:42:40 +08:00
LOG(LOG_VERBOSE5, "override_file: fstat fd %d succeeded!", fd);
2023-01-18 17:58:20 +08:00
void *addr = mmap(NULL, st.st_size, PROT_READ, MAP_FILE | MAP_PRIVATE, fd, 0);
if (addr == MAP_FAILED) {
LOG(LOG_ERROR, "Failed to map file %s: %d (%s)", filename, errno, strerror(errno));
return errno;
}
2023-01-25 15:42:40 +08:00
LOG(LOG_VERBOSE5, "override_file: Override file mapped successfully");
2023-01-18 17:58:20 +08:00
finfo->magic = OVERRIDE_MAGIC;
finfo->fd = fd;
finfo->len = (unsigned int)st.st_size;;
2023-01-23 01:24:22 +08:00
finfo->ptr = *(niarelap_file_t*)addr;
2023-01-18 17:58:20 +08:00
finfo->orig_len = *orig_len;
2023-01-23 01:24:22 +08:00
finfo->orig_ptr = **orig;
*orig = (niarelap_file_t*)addr;
2023-01-18 17:58:20 +08:00
*orig_len = (unsigned int)st.st_size;
2023-01-25 15:42:40 +08:00
LOG(LOG_VERBOSE5, "override_file() finished!");
2023-01-18 17:58:20 +08:00
return 0;
2023-01-25 15:42:40 +08:00
};
2023-01-18 17:58:20 +08:00
2023-01-18 22:35:22 +08:00
int build_checks() {
#if defined(__APPLE__)
struct mach_header_64* c1_header = (struct mach_header_64*)&checkra1n[0];
if (c1_header->magic != MH_MAGIC_64 && c1_header->magic != MH_CIGAM_64) {
LOG(LOG_FATAL, "Broken build: checkra1n is not a thin Mach-O");
return -1;
}
if (c1_header->cputype != _mh_execute_header.cputype) {
LOG(LOG_FATAL, "Broken build: checkra1n CPU type is not the same as %s CPU type", getprogname());
return -1;
}
#endif
struct mach_header_64 *kpf_hdr = (struct mach_header_64 *)checkra1n_kpf_pongo;
if (kpf_hdr->magic != MH_MAGIC_64 && kpf_hdr->magic != MH_CIGAM_64) {
LOG(LOG_FATAL, "Broken build: Invalid kernel patchfinder: Not thin 64-bit Mach-O");
return -1;
} else if (kpf_hdr->filetype != MH_KEXT_BUNDLE) {
LOG(LOG_FATAL, "Broken build: Invalid kernel patchfinder: Not a kext bundle");
return -1;
} else if (kpf_hdr->cputype != CPU_TYPE_ARM64) {
LOG(LOG_FATAL, "Broken build: Invalid kernel patchfinder: CPU type is not arm64");
return -1;
}
return 0;
}
2023-01-25 15:42:40 +08:00
void thr_cleanup(void* ptr) {
*(int*)ptr = 0;
return;
}
2023-01-17 13:46:42 +08:00
2023-01-25 15:42:40 +08:00
void* pongo_helper(void* ptr) {
pongo_thr_running = 1;
pthread_cleanup_push(thr_cleanup, &pongo_thr_running);
wait_for_pongo();
while (spin) {
sleep(1);
}
pthread_cleanup_pop(1);
return NULL;
}
int palera1n(int argc, char *argv[]) {
int mutex_err = pthread_mutex_init(&log_mutex, NULL);
if (mutex_err) {
fprintf(stderr, "palera1n_init: cannot create mutex: %d (%s)\n", errno, strerror(errno));
return -1;
}
2023-01-18 22:35:22 +08:00
if (build_checks()) return -1;
2023-01-17 13:46:42 +08:00
int opt;
int index;
2023-01-25 15:42:40 +08:00
while ((opt = getopt_long(argc, argv, "DhpvVldsOLe:f:o:r:K:k:", longopts, NULL)) != -1)
2023-01-17 13:46:42 +08:00
{
switch (opt)
{
case 'P':
start_from_pongo = true;
break;
case 'p':
pongo_exit = true;
break;
case 'D':
dfuhelper_only = true;
break;
case 'h':
2023-01-21 18:27:07 +08:00
usage(0, argv[0]);
2023-01-17 13:46:42 +08:00
assert(0);
2023-01-17 19:26:37 +08:00
case 'v':
2023-01-17 13:46:42 +08:00
verbose++;
break;
2023-01-22 23:20:46 +08:00
case 'V':
kpf_flags |= checkrain_option_verbose_boot;
break;
2023-01-17 13:59:44 +08:00
case 'e':
2023-01-24 02:01:29 +08:00
if (strstr(optarg, "rootdev=") != NULL) {
LOG(LOG_FATAL, "The boot arg rootdev= is already used by palera1n and cannot be overriden");
return -1;
}
2023-01-17 13:59:44 +08:00
snprintf(xargs_cmd, sizeof(xargs_cmd), "xargs %s", optarg);
break;
2023-01-17 19:26:37 +08:00
case 'f':
2023-01-22 17:38:47 +08:00
snprintf(rootfs_cmd, sizeof(rootfs_cmd), "rootfs %s", optarg);
snprintf(dtpatch_cmd, 0x20, "dtpatch %s", optarg);
enable_rootful = 1;
2023-01-17 19:26:37 +08:00
break;
case 'l':
2023-01-22 17:38:47 +08:00
enable_rootful = 0;
break;
2023-01-23 13:59:07 +08:00
case 'L':
palerain_flags |= palerain_option_jbinit_log_to_file;
break;
case 'd':
demote = 1;
break;
2023-01-18 16:02:43 +08:00
case 's':
checkrain_flags |= checkrain_option_safemode;
break;
2023-01-22 19:18:35 +08:00
case 'k':
if (access(optarg, F_OK) != 0) {
2023-01-24 03:32:29 +08:00
LOG(LOG_FATAL, "Cannot access pongo file at %s: %d (%s)", optarg, errno, strerror(errno));
2023-01-22 19:18:35 +08:00
return -1;
}
pongo_path = malloc(strlen(optarg) + 1);
strcpy(pongo_path, optarg);
2023-01-24 14:36:49 +08:00
break;
2023-01-18 17:58:20 +08:00
case 'o':
2023-01-23 01:24:22 +08:00
if (override_file(&override_overlay, overlay_to_upload, &binpack_dmg_len, optarg))
2023-01-18 17:58:20 +08:00
return 1;
break;
case 'r':
2023-01-23 01:24:22 +08:00
if (override_file(&override_ramdisk, ramdisk_to_upload, &ramdisk_dmg_len, optarg))
2023-01-18 17:58:20 +08:00
return 1;
break;
case 'K':
2023-01-23 01:24:22 +08:00
if (override_file(&override_kpf, kpf_to_upload, &checkra1n_kpf_pongo_len, optarg))
2023-01-18 17:58:20 +08:00
return 1;
struct mach_header_64* hdr = (struct mach_header_64*)override_kpf.ptr;
if (hdr->magic != MH_MAGIC_64 && hdr->magic != MH_CIGAM_64) {
2023-01-22 19:18:35 +08:00
LOG(LOG_FATAL, "Invalid kernel patchfinder: Not thin 64-bit Mach-O");
2023-01-18 17:58:20 +08:00
goto cleanup;
} else if (hdr->filetype != MH_KEXT_BUNDLE) {
2023-01-22 19:18:35 +08:00
LOG(LOG_FATAL, "Invalid kernel patchfinder: Not a kext bundle");
2023-01-18 17:58:20 +08:00
goto cleanup;
} else if (hdr->cputype != CPU_TYPE_ARM64) {
2023-01-22 19:18:35 +08:00
LOG(LOG_FATAL, "Invalid kernel patchfinder: CPU type is not arm64");
2023-01-18 17:58:20 +08:00
goto cleanup;
}
break;
2023-01-22 20:47:52 +08:00
case 'O':
ohio = false;
2023-01-22 23:20:46 +08:00
break;
2023-01-18 16:02:43 +08:00
case checkrain_option_force_revert:
checkrain_flags |= checkrain_option_force_revert;
break;
case palerain_option_version:
palerain_version = true;
break;
2023-01-17 13:46:42 +08:00
default:
2023-01-21 18:27:07 +08:00
usage(1, argv[0]);
2023-01-17 13:46:42 +08:00
break;
}
}
2023-01-25 15:42:40 +08:00
if (palerain_version) {
2023-01-18 16:02:43 +08:00
printf("palera1n %s\n", PALERAIN_VERSION);
return 0;
}
2023-01-22 17:38:47 +08:00
if (enable_rootful) {
palerain_flags |= palerain_option_rootful;
}
2023-01-18 16:02:43 +08:00
snprintf(checkrain_flags_cmd, 0x20, "checkra1n_flags 0x%x", checkrain_flags);
2023-01-22 17:38:47 +08:00
snprintf(palerain_flags_cmd, 0x20, "palera1n_flags 0x%x", palerain_flags);
2023-01-22 23:20:46 +08:00
snprintf(kpf_flags_cmd, 0x20, "kpf_flags 0x%x", kpf_flags);
2023-01-24 03:32:29 +08:00
LOG(LOG_VERBOSE3, "checkrain_flags: %s", checkrain_flags_cmd);
LOG(LOG_VERBOSE3, "palerain_flags: %s", palerain_flags_cmd);
LOG(LOG_VERBOSE3, "kpf_flags: %s", kpf_flags_cmd);
2023-01-23 01:24:22 +08:00
if (override_kpf.magic == OVERRIDE_MAGIC) {
2023-01-24 03:32:29 +08:00
LOG(LOG_VERBOSE4, "kpf override length %u -> %u", override_kpf.orig_len, checkra1n_kpf_pongo_len);
LOG(LOG_VERBOSE4, "kpf override ptr %p -> %p", override_kpf.orig_ptr, **kpf_to_upload);
2023-01-23 01:24:22 +08:00
}
if (override_ramdisk.magic == OVERRIDE_MAGIC) {
2023-01-24 03:32:29 +08:00
LOG(LOG_VERBOSE4, "ramdisk override length %u -> %u", override_ramdisk.orig_len, ramdisk_dmg_len);
LOG(LOG_VERBOSE4, "ramdisk override ptr %p -> %p", override_ramdisk.orig_ptr, **ramdisk_to_upload);
2023-01-23 01:24:22 +08:00
}
if (override_overlay.magic == OVERRIDE_MAGIC) {
2023-01-24 03:32:29 +08:00
LOG(LOG_VERBOSE4, "overlay override length %u -> %u", override_overlay.orig_len, binpack_dmg_len);
LOG(LOG_VERBOSE4, "overlay override ptr %p -> %p", override_overlay.orig_ptr, **overlay_to_upload);
2023-01-23 01:24:22 +08:00
}
2023-01-18 17:58:20 +08:00
2023-01-17 13:46:42 +08:00
for (index = optind; index < argc; index++)
{
if (!strcmp("windows", argv[index]))
{
fprintf(stderr,
"Windows not really using for manipulating OSX images,\n"
"compiled in mingw tool for this working unstable and incorrectly\n");
2023-01-17 21:43:46 +08:00
return -2;
2023-01-17 13:46:42 +08:00
}
else
{
2023-01-21 18:27:07 +08:00
fprintf(stderr, "%s: unknown argument: %s\n", argv[0], argv[index]);
usage(1, argv[0]);
2023-01-17 13:46:42 +08:00
}
}
2023-01-22 23:20:46 +08:00
if (verbose >= 2) putenv("LIBUSB_DEBUG=1");
2023-01-18 00:44:47 +08:00
if (verbose >= 3)
{
2023-01-17 19:26:37 +08:00
irecv_set_debug_level(1);
2023-01-22 23:20:46 +08:00
putenv("LIBUSB_DEBUG=2");
}
if (verbose >= 4) {
2023-01-17 19:26:37 +08:00
idevice_set_debug_level(1);
2023-01-18 00:44:47 +08:00
putenv("LIBUSB_DEBUG=3");
2023-01-17 19:26:37 +08:00
}
2023-01-22 23:20:46 +08:00
if (verbose >= 5)
2023-01-18 00:44:47 +08:00
putenv("LIBUSB_DEBUG=4");
LOG(LOG_INFO, "Waiting for devices");
2023-01-25 15:42:40 +08:00
2023-01-17 19:26:37 +08:00
do_pongo_sleep = 1;
2023-01-16 16:17:41 +08:00
pthread_create(&dfuhelper_thread, NULL, dfuhelper, NULL);
2023-01-25 15:42:40 +08:00
pthread_create(&pongo_thread, NULL, pongo_helper, NULL);
2023-01-16 16:17:41 +08:00
pthread_join(dfuhelper_thread, NULL);
2023-01-25 15:42:40 +08:00
if (device_has_booted) goto done;
2023-01-17 13:46:42 +08:00
if (dfuhelper_only)
return 0;
2023-01-25 15:42:40 +08:00
if (pongo_thr_running) {
pthread_cancel(pongo_thread);
}
2023-01-16 17:33:12 +08:00
exec_checkra1n();
2023-01-17 13:46:42 +08:00
if (pongo_exit)
return 0;
2023-01-18 00:44:47 +08:00
else
LOG(LOG_INFO, "Waiting for PongoOS devices...");
2023-01-25 15:42:40 +08:00
spin = true;
sleep(2);
pthread_create(&pongo_thread, NULL, pongo_helper, NULL);
pthread_join(pongo_thread, NULL);
2023-01-18 00:44:47 +08:00
while (spin)
{
2023-01-17 13:46:42 +08:00
sleep(1);
}
2023-01-25 15:42:40 +08:00
done:
2023-01-22 20:47:52 +08:00
if (access("/usr/bin/curl", F_OK) == 0 && ohio) {
LOG(LOG_VERBOSE4, "Ohio");
char* ohio_argv[] = {
"/usr/bin/curl",
"-sX",
"POST",
"-d",
"{\"app_name\": \"palera1n_c-rewrite\"}",
"-H",
"Content-Type: application/json",
"-H",
"User-Agent: python-requests/99 palera1n-c-rewrite/0",
2023-01-23 01:24:22 +08:00
"-o",
"/dev/null",
2023-01-22 20:47:52 +08:00
"https://ohio.itsnebula.net/hit",
NULL
};
pid_t pid;
posix_spawn(&pid, ohio_argv[0], NULL, NULL, ohio_argv, environ);
}
2023-01-18 17:58:20 +08:00
cleanup:
if (override_kpf.magic == OVERRIDE_MAGIC) {
munmap(override_kpf.ptr, (size_t)override_kpf.len);
close(override_kpf.fd);
}
if (override_ramdisk.magic == OVERRIDE_MAGIC) {
munmap(override_ramdisk.ptr, (size_t)override_ramdisk.len);
close(override_ramdisk.fd);
}
if (override_overlay.magic == OVERRIDE_MAGIC) {
munmap(override_overlay.ptr, (size_t)override_overlay.len);
close(override_overlay.fd);
}
2023-01-25 15:42:40 +08:00
pthread_mutex_destroy(&log_mutex);
2023-01-16 16:17:41 +08:00
return 0;
}
2023-01-25 15:42:40 +08:00
int main (int argc, char* argv[]) {
return palera1n(argc, argv);
}