From 96cadc41059dc0ae700e4596fbb079567ff57223 Mon Sep 17 00:00:00 2001 From: Nick Chan Date: Fri, 10 Feb 2023 22:34:29 +0800 Subject: [PATCH] allow not embedding resources --- src/Makefile | 29 +++++++++++++++++++++++++---- src/fake_embedded.c | 21 +++++++++++++++++++++ src/main.c | 8 +++++++- src/optparse.c | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 91 insertions(+), 5 deletions(-) create mode 100644 src/fake_embedded.c diff --git a/src/Makefile b/src/Makefile index 4ec6580..b1f4a02 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,9 +1,30 @@ all: palera1n -OBJECTS = main.o dfuhelper.o devhelper.o lockdown_helper.o exec_checkra1n.o -OBJECTS += optparse.o override_file.o pongo_helper.o log.o -OBJECTS += xxd-checkra1n.o xxd-checkra1n-kpf-pongo.o xxd-ramdisk.dmg.o -OBJECTS += xxd-binpack.dmg.o lock_vars.o +OBJECTS = main.o dfuhelper.o devhelper.o lockdown_helper.o +OBJECTS += optparse.o override_file.o log.o lock_vars.o +OBJECTS += fake_embedded.o exec_checkra1n.o pongo_helper.o + +ifneq ($(NO_RAMDISK),1) +OBJECTS += xxd-ramdisk.dmg.o +else +CFLAGS += -DNO_RAMDISK +endif +ifneq ($(NO_KPF),1) +OBJECTS += xxd-checkra1n-kpf-pongo.o +else +CFLAGS += -DNO_KPF +endif +ifneq ($(NO_BINPACK),1) +OBJECTS += xxd-binpack.dmg.o +else +CFLAGS += -DNO_BINPACK +endif +ifneq ($(NO_CHECKRAIN),1) +OBJECTS += xxd-checkra1n.o +else +CFLAGS += -DNO_CHECKRAIN +endif + ifeq ($(DEV_BUILD),1) OBJECTS += tui_screen_enter_recovery.o tui_screen_enter_dfu.o tui_main.o OBJECTS += tui_screen_jailbreak.o tui_screen_main.o tui_screen_options.o diff --git a/src/fake_embedded.c b/src/fake_embedded.c new file mode 100644 index 0000000..3b673df --- /dev/null +++ b/src/fake_embedded.c @@ -0,0 +1,21 @@ +#include + +#ifdef NO_KPF +unsigned char* checkra1n_kpf_pongo = NULL; +unsigned int checkra1n_kpf_pongo_len = 0; +#endif + +#ifdef NO_RAMDISK +unsigned char* ramdisk_dmg = NULL; +unsigned int ramdisk_dmg_len = 0; +#endif + +#ifdef NO_CHECKRAIN +unsigned char* checkra1n = NULL; +unsigned int checkra1n_len = 0; +#endif + +#ifdef NO_BINPACK +unsigned char* binpack_dmg = NULL; +unsigned int binpack_dmg_len = 0; +#endif diff --git a/src/main.c b/src/main.c index 64ec829..a3820c0 100644 --- a/src/main.c +++ b/src/main.c @@ -58,6 +58,7 @@ void thr_cleanup(void* ptr) { int build_checks() { #if defined(__APPLE__) +#ifndef NO_CHECKRAIN 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"); @@ -68,17 +69,21 @@ int build_checks() { return -1; } #endif +#endif +#ifndef NO_KPF 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) { + } 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; } +#endif return 0; } @@ -114,6 +119,7 @@ int palera1n(int argc, char *argv[]) { device_has_booted) goto normal_exit; if (exec_checkra1n()) goto cleanup; + if (checkrain_option_enabled(host_flags, host_option_pongo_exit) || checkrain_option_enabled(host_flags, host_option_demote)) goto normal_exit; set_spin(1); diff --git a/src/optparse.c b/src/optparse.c index e30ac5e..5cd131e 100644 --- a/src/optparse.c +++ b/src/optparse.c @@ -279,6 +279,44 @@ int optparse(int argc, char* argv[]) { return -1; } } + if (!( + checkrain_option_enabled(host_flags, host_option_dfuhelper_only) || + checkrain_option_enabled(host_flags, host_option_enter_recovery) || + checkrain_option_enabled(host_flags, host_option_exit_recovery) || + checkrain_option_enabled(host_flags, host_option_reboot_device))) + { +#ifdef NO_CHECKRAIN + if (checkra1n_len == 0 && ext_checkra1n == NULL) + { + LOG(LOG_FATAL, "checkra1n omitted in build but no override specified"); + return -1; + } + if (!(checkrain_option_enabled(host_flags, host_option_pongo_exit) || checkrain_option_enabled(host_flags, host_option_pongo_exit))) + { +#ifdef NO_BINPACK + if (binpack_dmg_len == 0) + { + LOG(LOG_FATAL, "binpack omitted in build but no override specified"); + return -1; + } +#endif +#ifdef NO_RAMDISK + if (ramdisk_dmg_len == 0) + { + LOG(LOG_FATAL, "ramdisk omitted in build but no override specified"); + return -1; + } +#endif +#ifdef NO_KPF + if (checkra1n_kpf_pongo_len == 0) + { + LOG(LOG_FATAL, "kernel patchfinder omitted in build but no override specified"); + return -1; + } +#endif + } +#endif + } for (index = optind; index < argc; index++) {