From ccaa9416f182dad0bc26832cbec85b799ae47dad Mon Sep 17 00:00:00 2001 From: khanhduytran0 Date: Mon, 12 Sep 2022 18:54:46 +0700 Subject: [PATCH] Changes for TrollStore self-JIT enabler Special thanks to @asdfugil for testing (arm64), not yet tested on arm64e --- Natives/main.m | 29 ++++++++++++++++------------- entitlements_ipa.xml | 6 +++++- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/Natives/main.m b/Natives/main.m index aeb24eb6..c6a5abf1 100644 --- a/Natives/main.m +++ b/Natives/main.m @@ -1,6 +1,7 @@ #import #import #import +#import #import #import @@ -24,11 +25,10 @@ #include "codesign.h" #define CS_PLATFORM_BINARY 0x4000000 - #define PT_TRACE_ME 0 int ptrace(int, pid_t, caddr_t, int); - #define fm NSFileManager.defaultManager +extern char** environ; void printEntitlementAvailability(NSString *key) { NSLog(@"[Pre-Init] - %@: %@", key, getEntitlementValue(key) ? @"YES" : @"NO"); @@ -278,6 +278,15 @@ void init_setupResolvConf() { } int main(int argc, char * argv[]) { + if (getppid() != 1) { + NSLog(@"parent pid is not launchd, calling ptrace(PT_TRACE_ME)"); + // Child process can call to PT_TRACE_ME + // then both parent and child processes get CS_DEBUGGED + int ret = ptrace(PT_TRACE_ME, 0, 0, 0); + return ret; + // FIXME: how to kill the child process? + } + if (pJLI_Launch) { return pJLI_Launch(argc, argv, 0, NULL, // sizeof(const_jargs) / sizeof(char *), const_jargs, @@ -334,24 +343,18 @@ int main(int argc, char * argv[]) { // If sandbox is disabled, W^X JIT can be enabled by PojavLauncher itself if (getEntitlementValue(@"com.apple.private.security.no-container")) { NSLog(@"[Pre-init] Sandbox is disabled, trying to enable JIT"); - pid_t pid = fork(); - if (pid == 0) { - // Forked process can call to PT_TRACE_ME - // then both parent and child processes get CS_DEBUGGED - int ret = ptrace(PT_TRACE_ME, 0, 0, 0); - // If ptrace is successful, it will not continue - assert(ret == 0); - } else if (pid > 0) { - // Fork is successful, let's check if JIT is enabled + int pid; + int ret = posix_spawnp(&pid, argv[0], NULL, NULL, argv, environ); + if (ret == 0) { + // posix_spawn is successful, let's check if JIT is enabled usleep(10000); if (isJITEnabled()) { NSLog(@"[Pre-init] JIT has heen enabled with PT_TRACE_ME"); } else { NSLog(@"[Pre-init] Failed to enable JIT: unknown reason"); } - kill(pid, SIGKILL); } else { - NSLog(@"[Pre-init] Failed to enable JIT: fork() failed errno %d", errno); + NSLog(@"[Pre-init] Failed to enable JIT: posix_spawn() failed errno %d", errno); } } diff --git a/entitlements_ipa.xml b/entitlements_ipa.xml index d0fcea7c..66e11cbd 100644 --- a/entitlements_ipa.xml +++ b/entitlements_ipa.xml @@ -17,7 +17,9 @@ com.apple.private.security.no-container - + + com.apple.private.security.storage.AppDataContainers + com.apple.security.iokit-user-client-class IOSurfaceRootUserClient @@ -26,5 +28,7 @@ AGXCommandQueue AGXDevice + platform-application +