From 625af2739f0d699aee968d9dbcfd360887be044c Mon Sep 17 00:00:00 2001 From: opa334 Date: Sun, 28 Apr 2024 15:11:49 +0200 Subject: [PATCH] Centralize primitive retrieval logic --- BaseBin/boomerang/src/main.c | 26 ++-------------- BaseBin/launchdhook/src/boomerang.c | 41 ++++--------------------- BaseBin/libjailbreak/src/libjailbreak.h | 1 + BaseBin/libjailbreak/src/main.c | 18 +++++++++-- 4 files changed, 24 insertions(+), 62 deletions(-) diff --git a/BaseBin/boomerang/src/main.c b/BaseBin/boomerang/src/main.c index d3492288c..7ed27c3fd 100644 --- a/BaseBin/boomerang/src/main.c +++ b/BaseBin/boomerang/src/main.c @@ -50,30 +50,8 @@ int main(int argc, char* argv[]) if (kr != KERN_SUCCESS) return -1; mach_port_deallocate(mach_task_self(), launchdTaskPort); - // Retrieve system info - xpc_object_t xSystemInfoDict = NULL; - if (jbclient_root_get_sysinfo(&xSystemInfoDict) != 0) return -1; - SYSTEM_INFO_DESERIALIZE(xSystemInfoDict); - - // Retrieve physrw - jbclient_root_get_physrw(false, NULL); - libjailbreak_physrw_init(true); - - libjailbreak_translation_init(); - - libjailbreak_IOSurface_primitives_init(); - if (!gPrimitives.kalloc_global) { - libjailbreak_kalloc_pt_init(); - } - - // Retrieve kcall if available -#ifdef __arm64e__ - if (jbinfo(usesPACBypass)) { - jbclient_get_fugu14_kcall(); - } -#else - arm64_kcall_init(); -#endif + // Retrieve primitives + jbclient_initialize_primitives_internal(false); // Send done message to launchd jbclient_boomerang_done(); diff --git a/BaseBin/launchdhook/src/boomerang.c b/BaseBin/launchdhook/src/boomerang.c index dbc4c8542..837a075e5 100644 --- a/BaseBin/launchdhook/src/boomerang.c +++ b/BaseBin/launchdhook/src/boomerang.c @@ -81,41 +81,12 @@ int boomerang_recoverPrimitives(bool firstRetrieval, bool shouldEndBoomerang) unsetenv("BOOMERANG_PID"); } - // Retrieve system info - xpc_object_t xSystemInfoDict = NULL; - if (jbclient_root_get_sysinfo(&xSystemInfoDict) != 0) return -4; - SYSTEM_INFO_DESERIALIZE(xSystemInfoDict); - - // Retrieve physrw - bool usePhysrwPTE = firstRetrieval && !is_kcall_available(); - uint64_t asidPtr = 0; - int physrwRet = jbclient_root_get_physrw(usePhysrwPTE, &asidPtr); - if (physrwRet != 0) return -20 + physrwRet; - if (usePhysrwPTE) { - // For performance reasons we only use physrw_pte until the first userspace reboot - // Handing off full physrw from the app is really slow and causes watchdog timeouts - // But from launchd it's generally fine, no clue why - libjailbreak_physrw_pte_init(true, asidPtr); - } - else { - libjailbreak_physrw_init(true); - } - - libjailbreak_translation_init(); - - libjailbreak_IOSurface_primitives_init(); - if (!gPrimitives.kalloc_global) { - libjailbreak_kalloc_pt_init(); - } - - // Retrieve kcall if available -#ifdef __arm64e__ - if (jbinfo(usesPACBypass)) { - jbclient_get_fugu14_kcall(); - } -#else - arm64_kcall_init(); -#endif + // Retrieve primitives + // For performance reasons we only use physrw_pte until the first userspace reboot + // Handing off full physrw from the app is really slow and causes watchdog timeouts + // But from launchd it's generally fine, no clue why + bool physrwPTE = firstRetrieval && !is_kcall_available(); + jbclient_initialize_primitives_internal(physrwPTE); if (shouldEndBoomerang) { // Send done message to boomerang diff --git a/BaseBin/libjailbreak/src/libjailbreak.h b/BaseBin/libjailbreak/src/libjailbreak.h index b10bfccfd..27885a8ee 100644 --- a/BaseBin/libjailbreak/src/libjailbreak.h +++ b/BaseBin/libjailbreak/src/libjailbreak.h @@ -6,4 +6,5 @@ #include "trustcache.h" #include "jbclient_xpc.h" +int jbclient_initialize_primitives_internal(bool physrwPTE); int jbclient_initialize_primitives(void); \ No newline at end of file diff --git a/BaseBin/libjailbreak/src/main.c b/BaseBin/libjailbreak/src/main.c index 000eb6d0e..3a6673533 100644 --- a/BaseBin/libjailbreak/src/main.c +++ b/BaseBin/libjailbreak/src/main.c @@ -1,6 +1,7 @@ #include "jbclient_xpc.h" #include #include "physrw.h" +#include "physrw_pte.h" #include "kalloc_pt.h" #include "primitives_IOSurface.h" #include "info.h" @@ -9,7 +10,7 @@ #include "kcall_arm64.h" #include -int jbclient_initialize_primitives(void) +int jbclient_initialize_primitives_internal(bool physrwPTE) { if (getuid() != 0) return -1; @@ -17,8 +18,14 @@ int jbclient_initialize_primitives(void) if (jbclient_root_get_sysinfo(&xSystemInfo) == 0) { SYSTEM_INFO_DESERIALIZE(xSystemInfo); xpc_release(xSystemInfo); - if (jbclient_root_get_physrw(false, NULL) == 0) { - libjailbreak_physrw_init(true); + uint64_t asidPtr = 0; + if (jbclient_root_get_physrw(physrwPTE, &asidPtr) == 0) { + if (physrwPTE) { + libjailbreak_physrw_pte_init(true, asidPtr); + } + else { + libjailbreak_physrw_init(true); + } libjailbreak_translation_init(); libjailbreak_IOSurface_primitives_init(); if (__builtin_available(iOS 16.0, *)) { @@ -41,6 +48,11 @@ int jbclient_initialize_primitives(void) return -1; } +int jbclient_initialize_primitives(void) +{ + return jbclient_initialize_primitives_internal(false); +} + // Used for supporting third party legacy software that still calls this function int jbdInitPPLRW(void) {