From 04666b19c3d812c41eed182975cf65c01591ddd3 Mon Sep 17 00:00:00 2001 From: Nick Chan Date: Sun, 22 Jan 2023 19:18:35 +0800 Subject: [PATCH] add -k option, fix -s description --- src/common.h | 1 + src/exec_checkra1n.c | 8 +++++++- src/main.c | 21 +++++++++++++++------ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/common.h b/src/common.h index 93113f7..7e100cd 100644 --- a/src/common.h +++ b/src/common.h @@ -55,6 +55,7 @@ typedef struct { extern int spin; extern unsigned int verbose; extern int demote; +extern char* pongo_path; extern bool dfuhelper_only; extern bool pongo_exit; diff --git a/src/exec_checkra1n.c b/src/exec_checkra1n.c index ee65271..269dbdc 100644 --- a/src/exec_checkra1n.c +++ b/src/exec_checkra1n.c @@ -9,6 +9,7 @@ #include #include #include +#include #include @@ -16,6 +17,7 @@ extern char **environ; #include "common.h" #include "checkra1n.h" +char* pongo_path = NULL; void exec_checkra1n() { LOG(LOG_INFO, "About to execute checkra1n"); @@ -42,19 +44,23 @@ void exec_checkra1n() { char args[0x10] = "-pE"; if (demote) strcat(args, "d"); if (verbose >= 2) strcat(args, "v"); + if (pongo_path != NULL) strcat(args, "k"); // keep this at last pid_t pid; char* checkra1n_argv[] = { checkra1n_path, args, + pongo_path, NULL }; ret = posix_spawn(&pid, checkra1n_path, NULL, NULL, checkra1n_argv, environ); + if (pongo_path != NULL) free(pongo_path); + pongo_path = NULL; if (ret) { LOG(LOG_FATAL, "Cannot posix spawn %s: %d (%s)", checkra1n_path, errno, strerror(errno)); unlink(checkra1n_path); return; } - LOG(LOG_VERBOSE2, "%s %s spawned successfully", checkra1n_path, args); + LOG(LOG_VERBOSE2, "%s spawned successfully", checkra1n_path); sleep(2); unlink(checkra1n_path); waitpid(pid, NULL, 0); diff --git a/src/main.c b/src/main.c index 975fe9b..84321e7 100644 --- a/src/main.c +++ b/src/main.c @@ -159,6 +159,7 @@ static struct option longopts[] = { {"force-revert", no_argument, NULL, checkrain_option_force_revert}, {"safe-mode", no_argument, NULL, 's'}, {"version", no_argument, NULL, palerain_option_version}, + {"override-pongo", required_argument, NULL, 'k'}, {"override-overlay", required_argument, NULL, 'o'}, {"override-ramdisk", required_argument, NULL, 'r'}, {"override-kpf", required_argument, NULL, 'K'}, @@ -167,7 +168,7 @@ static struct option longopts[] = { int usage(int e, char* prog_name) { fprintf(stderr, - "Usage: %s [-DhpPvlds] [-e boot arguments] [-f root device] [-o overlay file] [-r ramdisk file] [-K KPF file]\n" + "Usage: %s [-DhpPvlds] [-e boot arguments] [-f root device] [-k Pongo image] [-o overlay file] [-r ramdisk file] [-K KPF file]\n" "Copyright (C) 2023, palera1n team, All Rights Reserved.\n\n" "iOS/iPadOS 15+ arm64 jailbreaking tool\n\n" "\t--version\t\t\t\tPrint version\n" @@ -181,8 +182,9 @@ int usage(int e, char* prog_name) "\t-e, --boot-args \tXNU boot arguments\n" "\t-f, --rootfs \t\tBoots rootful setup on \n" "\t-l, --rootless\t\t\t\tBoots rootless. This is the default\n" - "\t-s, --safe-mode\t\t\t\tEnter safe mode (on rootless)\n" + "\t-s, --safe-mode\t\t\t\tEnter safe mode\n" "\t-d, --demote\t\t\t\tDemote\n" + "\t-k, --override-pongo \t\tOverride Pongo image\n" "\t-o, --override-overlay \t\tOverride overlay\n" "\t-r, --override-ramdisk \t\tOverride ramdisk\n" "\t-K, --override-kpf \t\tOverride kernel patchfinder\n", @@ -258,7 +260,7 @@ int main(int argc, char *argv[]) if (build_checks()) return -1; int opt; int index; - while ((opt = getopt_long(argc, argv, "DhpPvldse:f:o:r:K:", longopts, NULL)) != -1) + while ((opt = getopt_long(argc, argv, "DhpPvldse:f:o:r:K:k:", longopts, NULL)) != -1) { switch (opt) { @@ -294,6 +296,13 @@ int main(int argc, char *argv[]) case 's': checkrain_flags |= checkrain_option_safemode; break; + case 'k': + if (access(optarg, F_OK) != 0) { + LOG(LOG_FATAL, "Cannot access pongo file at %s: %d (%s)\n", optarg, errno, strerror(errno)); + return -1; + } + pongo_path = malloc(strlen(optarg) + 1); + strcpy(pongo_path, optarg); case 'o': if (override_file(&override_overlay, binpack_dmg, &binpack_dmg_len, optarg)) return 1; @@ -307,13 +316,13 @@ int main(int argc, char *argv[]) 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) { - LOG(LOG_ERROR, "Invalid kernel patchfinder: Not thin 64-bit Mach-O"); + LOG(LOG_FATAL, "Invalid kernel patchfinder: Not thin 64-bit Mach-O"); goto cleanup; } else if (hdr->filetype != MH_KEXT_BUNDLE) { - LOG(LOG_ERROR, "Invalid kernel patchfinder: Not a kext bundle"); + LOG(LOG_FATAL, "Invalid kernel patchfinder: Not a kext bundle"); goto cleanup; } else if (hdr->cputype != CPU_TYPE_ARM64) { - LOG(LOG_ERROR, "Invalid kernel patchfinder: CPU type is not arm64"); + LOG(LOG_FATAL, "Invalid kernel patchfinder: CPU type is not arm64"); goto cleanup; } break;