Skip to content

Commit

Permalink
Centralize primitive retrieval logic
Browse files Browse the repository at this point in the history
  • Loading branch information
opa334 committed Apr 28, 2024
1 parent a4e998d commit 625af27
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 62 deletions.
26 changes: 2 additions & 24 deletions BaseBin/boomerang/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
41 changes: 6 additions & 35 deletions BaseBin/launchdhook/src/boomerang.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions BaseBin/libjailbreak/src/libjailbreak.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
#include "trustcache.h"
#include "jbclient_xpc.h"

int jbclient_initialize_primitives_internal(bool physrwPTE);
int jbclient_initialize_primitives(void);
18 changes: 15 additions & 3 deletions BaseBin/libjailbreak/src/main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "jbclient_xpc.h"
#include <stdlib.h>
#include "physrw.h"
#include "physrw_pte.h"
#include "kalloc_pt.h"
#include "primitives_IOSurface.h"
#include "info.h"
Expand All @@ -9,16 +10,22 @@
#include "kcall_arm64.h"
#include <xpc/xpc.h>

int jbclient_initialize_primitives(void)
int jbclient_initialize_primitives_internal(bool physrwPTE)
{
if (getuid() != 0) return -1;

xpc_object_t xSystemInfo = NULL;
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, *)) {
Expand All @@ -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)
{
Expand Down

0 comments on commit 625af27

Please sign in to comment.