Run a virtual iPhone on an Apple Silicon Mac.
Swift
Keep launchd process injection independent of ElleKit
Lakr25041f4a2ad9
diff --git a/Research/0_binary_patch_comparison.md b/Research/0_binary_patch_comparison.mdindex 4b6020ba..dddb2f29 100644--- a/Research/0_binary_patch_comparison.md+++ b/Research/0_binary_patch_comparison.md@@ -29,8 +29,8 @@> and `ProgramArguments[0]` paths are translated to physical kernel paths in> the in-memory XPC plist. The hook also tries to remove PID 1's existing> jetsam limit and suppresses future fatal task-limit assignments for PID 1.-> When a bootstrap and its ElleKit library exist, the launchd hook uses-> `MSHookFunction` on PID 1's `posix_spawn` to add+> The launchd hook interposes PID 1's `posix_spawn` without loading ElleKit,+> so process injection remains available before a package manager installs it. It adds> `DYLD_INSERT_LIBRARIES=/usr/lib/SystemHook-vphone.dylib` to `xpcproxy`,> directly spawned bootstrap programs, and app executables under the system> or application bundle paths. `SystemHook-vphone.dylib` interposes@@ -94,6 +94,15 @@> removed but the existing `patch-launchd-jetsam` left in place, the same> probe returned `50/50` MB with fatal attributes. These tests used a cloned> VM disk and separate host API port; the original VM was not modified.+> On 2026-09-25, the new interposed spawn hook was installed on the existing+> `vphone-launchdhook-lab-26.6.2` rootless VM and read back byte-for-byte.+> After a cold boot, launchd imported `wiki.qaq.ighostvtd.plist`; the service+> and its `wiki.qaq.ighostvt.service` Mach endpoint were running. The daemon's+> `DISABLE_TWEAKS=1` kept TweakLoader out of that process. Launchd logged a+> successful Calculator spawn; Calculator reached the foreground and its own+> sandbox log recorded `SystemHook-vphone.dylib` and a successful load of the+> installed ElleKit `TweakLoader.dylib`. This checks the injection chain, but+> does not prove that a particular tweak took effect.> **`scripts/patchers/*.py` no longer exists.** The tables below cite those> filenames throughout, because that is where each patch was first written anddiff --git a/VPhoneGuestComponents/LaunchHook/launchdhook-vphone.c b/VPhoneGuestComponents/LaunchHook/launchdhook-vphone.cindex 85869741..1b2a003b 100644--- a/VPhoneGuestComponents/LaunchHook/launchdhook-vphone.c+++ b/VPhoneGuestComponents/LaunchHook/launchdhook-vphone.c@@ -13,9 +13,6 @@#include <unistd.h>#include <xpc/xpc.h>-static int (*vpOriginalSpawn)(pid_t *restrict, const char *restrict, const posix_spawn_file_actions_t *restrict,- const posix_spawnattr_t *restrict, char *const argv[restrict],- char *const envp[restrict]);static char vpBootRoot[PATH_MAX];static void vpLogInjection(const char *event, const char *path, int status) {@@ -57,13 +54,13 @@ static int vpSpawn(pid_t *restrict pid, const char *restrict path, const posix_sint appProgram = vpIsAppProgram(path);if (!path || (strcmp(path, "/usr/libexec/xpcproxy") != 0 && !bootstrapProgram && !appProgram) ||vpInjectionDisabled(envp)) {- int status = vpOriginalSpawn(pid, path, actions, attributes, argv, envp);+ int status = posix_spawn(pid, path, actions, attributes, argv, envp);if (appProgram)vpLogSpawn("app-disabled", path, status == 0 && pid ? *pid : -1, status);return status;}VPInjectionEnvironment injected = vpInsertHook(envp, vpBootRoot);- int status = vpOriginalSpawn(pid, path, actions, attributes, argv, injected.values ? injected.values : envp);+ int status = posix_spawn(pid, path, actions, attributes, argv, injected.values ? injected.values : envp);vpLogInjection(injected.values ? "inserted" : "unchanged", path, status);vpLogSpawn(injected.values ? "inserted" : "unchanged", path, status == 0 && pid ? *pid : -1,status);@@ -71,31 +68,6 @@ static int vpSpawn(pid_t *restrict pid, const char *restrict path, const posix_sreturn status;}-static void vpInstallSpawnHook(const char *root) {- static int installed;- if (installed || access(VP_SYSTEM_HOOK, R_OK) != 0)- return;- char path[PATH_MAX];- int used = snprintf(path, sizeof(path), "%s/usr/lib/libellekit.dylib", root);- if (used <= 0 || (size_t)used >= sizeof(path) || access(path, R_OK) != 0)- return;- void *ellekit = dlopen(path, RTLD_NOW | RTLD_LOCAL);- if (!ellekit) {- vpLogInjection("ellekit-dlopen-failed", path, 0);- return;- }- void (*hook)(void *, void *, void **) = dlsym(ellekit, "MSHookFunction");- if (!hook) {- vpLogInjection("ellekit-symbol-missing", path, 0);- return;- }- snprintf(vpBootRoot, sizeof(vpBootRoot), "%s", root);- hook((void *)posix_spawn, (void *)vpSpawn, (void **)&vpOriginalSpawn);- installed = vpOriginalSpawn != NULL;- vpLogInjection("bootstrap-root", vpBootRoot, 0);- vpLogInjection(installed ? "installed" : "install-failed", path, 0);-}-// Neither bootstrap exists on the first boot. RootHide is chosen once and// keeps one randomized root across later boots; ambiguity disables discovery.static int vpFindJBRoot(char root[PATH_MAX]) {@@ -241,7 +213,10 @@ static xpc_object_t vpGetValue(xpc_object_t dictionary, const char *key) {vpLogInjection("bootstrap-unavailable", key, 0);return value;}- vpInstallSpawnHook(root);+ if (!vpBootRoot[0]) {+ snprintf(vpBootRoot, sizeof(vpBootRoot), "%s", root);+ vpLogInjection("bootstrap-root", vpBootRoot, 0);+ }char path[PATH_MAX];int used = snprintf(path, sizeof(path), "%s/Library/LaunchDaemons", root);if (used < 0 || (size_t)used >= sizeof(path))@@ -276,12 +251,14 @@ __attribute__((constructor)) static void vpLaunchHookInit(void) {memorystatus_control(VPSetJetsamHighWaterMark, 1, (uint32_t)-1, NULL, 0);}-// This image is loaded by launchd's LC_LOAD_WEAK_DYLIB. The spawn hook handles-// xpcproxy, direct bootstrap executables, and apps; SystemHook owns xpcproxy's exec.+// This image is loaded by launchd's LC_LOAD_WEAK_DYLIB. Interposing spawn here+// keeps the injection chain available before ElleKit is installed. SystemHook+// owns xpcproxy's exec and loads ElleKit's TweakLoader when it appears.__attribute__((used, section("__DATA,__interpose"))) static const struct {const void *replacement;const void *replacee;} vpInterpose[] = {{(const void *)vpGetValue, (const void *)xpc_dictionary_get_value},+ {(const void *)vpSpawn, (const void *)posix_spawn},{(const void *)vpMemoryStatus, (const void *)memorystatus_control},};