diff --git a/src/exec_checkra1n.c b/src/exec_checkra1n.c index aeaf940..233b3c9 100644 --- a/src/exec_checkra1n.c +++ b/src/exec_checkra1n.c @@ -185,6 +185,15 @@ setenv_ra1n: return -1; } LOG(LOG_VERBOSE2, "%s spawned successfully", checkra1n_path); +#if defined(__APPLE__) +#if TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR + waitpid(pid, NULL, WUNTRACED); + ret = ptrace(PT_DETACH, pid, NULL, 0); + + if (ret) + LOG(LOG_WARNING, "Cannot ptrace(PT_DETACH): %d (%s)", errno, strerror(errno)); +#endif +#endif sleep(2); if (ext_checkra1n == NULL) { unlink(checkra1n_path); @@ -192,7 +201,7 @@ setenv_ra1n: checkra1n_path = NULL; } waitpid(pid, NULL, 0); - if (!external_pongo && pongo_path != NULL) { + if (!external_pongo && pongo_path != NULL) { unlink(pongo_path); } if (pongo_path != NULL) free(pongo_path); diff --git a/src/helper/helper.c b/src/helper/helper.c index 84cbee0..3ad58c3 100644 --- a/src/helper/helper.c +++ b/src/helper/helper.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -16,6 +17,11 @@ extern char **environ; extern char ***_NSGetArgv(void); extern int *_NSGetArgc(void); +#define CS_OPS_STATUS 0 +#define CS_DEBUGGED 0x10000000 + +int csops(pid_t pid, unsigned int ops, void *useraddr, size_t usersize); + __attribute__((constructor)) void ctor(void) { char ***argvp = _NSGetArgv(); @@ -28,17 +34,12 @@ __attribute__((constructor)) void ctor(void) char **argv = *argvp; #if TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR - if (argc == 2 && strcmp(argv[1], "__CHECKRA1N_JIT_PLEASE__") == 0) { - assert(ptrace(PT_TRACE_ME, 0, 0, 0) == 0); - exit(0); - } else { - char exe_path[PATH_MAX]; - uint32_t exe_path_size = PATH_MAX; - assert(_NSGetExecutablePath(exe_path, &exe_path_size) == 0); - pid_t pid; - assert(posix_spawnp(&pid, exe_path, NULL, NULL, (char*[]){"__CHECKRA1N_JIT_PLEASE__",NULL}, environ) == 0); - assert(waitpid(pid, NULL, 0) == pid); - } + assert(ptrace(PT_TRACE_ME, 0, 0, 0) == 0); + uint32_t csflags; + assert(csops(getpid(), CS_OPS_STATUS, &csflags, sizeof(csflags)) == 0); + + if (!(csflags & CS_DEBUGGED)) + printf("WARNING: CS_DEBUGGED is not set (0x%x)\n", csflags); #endif char *c1_path = getenv("LIBCHECKRA1NHELPER_CHECKRA1N_PATH");