Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Make launchd daemon discovery work on iOS 26

Lakr415caff4becd
diff --git a/Research/0_binary_patch_comparison.md b/Research/0_binary_patch_comparison.md
index dbf1608e..b10dac12 100644
--- a/Research/0_binary_patch_comparison.md
+++ b/Research/0_binary_patch_comparison.md
@@ -9,13 +9,21 @@
> below. Old variant rows are research history,
> not available install modes.
-> **Current launchd hook (2026-09-24; source/build verification only):**
+> **Current launchd hook (2026-09-25; isolated VM verification):**
> `cfw install` now places `launchdhook-vphone.dylib` and an inert
> `SystemHook-vphone.dylib` in `/usr/lib`, links `/vh` to the launchd hook,
> inserts a weak `/vh` load command for the
> launchd hook after `patch-launchd-jetsam`, and re-signs launchd. The hook
> extends launchd's `Paths` and `LaunchDaemons` values with the selected
> bootstrap's `Library/LaunchDaemons` (plus `basebin/LaunchDaemons` when present).
+> It reads each real plist from the bootstrap root but inserts it under a
+> distinct `/System/Library/LaunchDaemons/vphone.*.plist` cache key. On the
+> tested iOS 26.6.2 cache loader, otherwise identical entries keyed by
+> `/var/jb/Library/LaunchDaemons/...` or `/Library/LaunchDaemons/...` were
+> ignored; a System key was imported and its executable ran. The old binary
+> in `zqxwce/vphone-cli-storage` at `2ef6b06` uses the real `/var/jb` key
+> and `MSHookFunction` to intercept `xpc_dictionary_get_value`; it also
+> requires `/cores/systemhook.dylib` and `/cores/libellekit.dylib` at startup.
> A single `.jbroot-<16 hex>` under the RootHide application container is
> accepted; ambiguous roots are ignored. RootHide bootstrap-relative `Program`
> and `ProgramArguments[0]` paths are translated to physical kernel paths in
@@ -23,11 +31,16 @@
> jetsam limit and suppresses future fatal task-limit assignments for PID 1.
> `SystemHook-vphone.dylib` is not injected into processes in this phase; ElleKit
> chain loading, `DISABLE_TWEAKS`, and tweak filters remain a later step.
-> **Validation needed on a disposable VM before relying on this at boot:**
-> confirm launchd loads the weak dylib and dyld interposition fires; install
-> one RootHide and one rootless daemon on separate VM copies, reboot each, and
-> inspect their `launchctl print` executable paths; verify PID 1's effective
-> jetsam limit separately from the existing panic-guard patch.
+> The cloned `vphone-launchdhook-lab-26.6.2` booted with the weak dylib and
+> retained a healthy vphoned API. Rootless and RootHide probes, each tested
+> after reboot, were imported and spawned by launchd. The RootHide probe's
+> plist named `/usr/bin/vphone-hook-daemon-probe`, which does not exist outside
+> its randomized root; successful spawn confirms the in-memory physical-path
+> translation. A read-only `MEMORYSTATUS_CMD_GET_MEMLIMIT_PROPERTIES` probe
+> returned active/inactive `-1/-1` for PID 1 with this hook. With `/vh`
+> 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.
> **`scripts/patchers/*.py` no longer exists.** The tables below cite those
> filenames throughout, because that is where each patch was first written and
diff --git a/VPhoneGuestComponents/LaunchHook/launchdhook-vphone.c b/VPhoneGuestComponents/LaunchHook/launchdhook-vphone.c
index 9aed777a..8db604e3 100644
--- a/VPhoneGuestComponents/LaunchHook/launchdhook-vphone.c
+++ b/VPhoneGuestComponents/LaunchHook/launchdhook-vphone.c
@@ -47,21 +47,11 @@ static int vpFindJBRoot(char root[PATH_MAX]) {
// launchd itself uses kernel paths. Bootstrap tools may use vroot paths, but
// plist discovery and ProgramArguments handed to launchd must be physical.
-typedef xpc_object_t (*VPGetValue)(xpc_object_t, const char *);
typedef xpc_object_t (*VPPlistDecoder)(const void *, size_t);
-typedef int (*VPMemoryStatus)(uint32_t, int32_t, uint32_t, void *, size_t);
extern int memorystatus_control(uint32_t, int32_t, uint32_t, void *, size_t);
enum { VPSetJetsamHighWaterMark = 5, VPSetJetsamTaskLimit = 6 };
-static VPGetValue vpOriginalGetValue(void) {
- return (VPGetValue)dlsym(RTLD_NEXT, "xpc_dictionary_get_value");
-}
-
-static VPMemoryStatus vpOriginalMemoryStatus(void) {
- return (VPMemoryStatus)dlsym(RTLD_NEXT, "memorystatus_control");
-}
-
static int vpPhysicalProgram(const char *program, const char *root, char physical[PATH_MAX]) {
if (!program || program[0] != '/') return 0;
size_t rootLength = strlen(root);
@@ -90,7 +80,8 @@ static void vpPatchProgram(xpc_object_t plist, const char *root) {
if (vpPhysicalProgram(program, root, physical)) xpc_dictionary_set_string(plist, "Program", physical);
}
-static void vpAddPlist(xpc_object_t dictionary, const char *path, const char *root) {
+static void vpAddPlist(xpc_object_t dictionary, const char *path,
+ const char *key, const char *root) {
VPPlistDecoder decode = (VPPlistDecoder)dlsym(RTLD_DEFAULT, "xpc_create_from_plist");
if (!decode) return;
int fd = open(path, O_RDONLY | O_CLOEXEC | O_NOFOLLOW);
@@ -109,12 +100,13 @@ static void vpAddPlist(xpc_object_t dictionary, const char *path, const char *ro
if (!plist) return;
if (xpc_get_type(plist) == XPC_TYPE_DICTIONARY) {
vpPatchProgram(plist, root);
- xpc_dictionary_set_value(dictionary, path, plist);
+ xpc_dictionary_set_value(dictionary, key, plist);
}
xpc_release(plist);
}
-static void vpAddDaemons(xpc_object_t dictionary, const char *directory, const char *root) {
+static void vpAddDaemons(xpc_object_t dictionary, const char *directory,
+ const char *source, const char *root) {
DIR *stream = opendir(directory);
if (!stream) return;
struct dirent *entry;
@@ -123,15 +115,22 @@ static void vpAddDaemons(xpc_object_t dictionary, const char *directory, const c
if (length < 6 || strcmp(entry->d_name + length - 6, ".plist") != 0) continue;
char path[PATH_MAX];
int used = snprintf(path, sizeof(path), "%s/%s", directory, entry->d_name);
- if (used > 0 && (size_t)used < sizeof(path)) vpAddPlist(dictionary, path, root);
+ if (used <= 0 || (size_t)used >= sizeof(path)) continue;
+ // On the tested iOS 26 cache loader, /var/jb and /Library keys are
+ // ignored, while a System LaunchDaemon key is imported. Keep the
+ // real plist on the bootstrap volume and use a distinct cache key.
+ char key[PATH_MAX];
+ used = snprintf(key, sizeof(key), "/System/Library/LaunchDaemons/vphone.%s.%s",
+ source, entry->d_name);
+ if (used > 0 && (size_t)used < sizeof(key)) vpAddPlist(dictionary, path, key, root);
}
closedir(stream);
}
+// dyld leaves this image's own bindings on the original symbols when it
+// interposes other images. dlsym would return the replacement and recurse.
static xpc_object_t vpGetValue(xpc_object_t dictionary, const char *key) {
- VPGetValue original = vpOriginalGetValue();
- if (!original) return NULL;
- xpc_object_t value = original(dictionary, key);
+ xpc_object_t value = xpc_dictionary_get_value(dictionary, key);
if (getpid() != 1 || !value || !key ||
(strcmp(key, "Paths") != 0 && strcmp(key, "LaunchDaemons") != 0)) {
return value;
@@ -149,9 +148,9 @@ static xpc_object_t vpGetValue(xpc_object_t dictionary, const char *key) {
}
} else if (strcmp(key, "LaunchDaemons") == 0 &&
xpc_get_type(value) == XPC_TYPE_DICTIONARY) {
- vpAddDaemons(value, path, root);
+ vpAddDaemons(value, path, "jb", root);
used = snprintf(path, sizeof(path), "%s/basebin/LaunchDaemons", root);
- if (used > 0 && (size_t)used < sizeof(path)) vpAddDaemons(value, path, root);
+ if (used > 0 && (size_t)used < sizeof(path)) vpAddDaemons(value, path, "basebin", root);
}
return value;
}
@@ -161,18 +160,15 @@ static int vpMemoryStatus(uint32_t command, int32_t pid, uint32_t flags,
if (getpid() == 1 && command == VPSetJetsamTaskLimit && (pid == 1 || pid == 0)) {
return 0;
}
- VPMemoryStatus original = vpOriginalMemoryStatus();
- return original ? original(command, pid, flags, buffer, size) : -1;
+ return memorystatus_control(command, pid, flags, buffer, size);
}
__attribute__((constructor))
static void vpLaunchHookInit(void) {
if (getpid() != 1) return;
- VPMemoryStatus original = vpOriginalMemoryStatus();
- if (!original) return;
// The firmware panic-guard patch does not remove a limit already on PID 1.
- original(VPSetJetsamTaskLimit, 1, (uint32_t)-1, NULL, 0);
- original(VPSetJetsamHighWaterMark, 1, (uint32_t)-1, NULL, 0);
+ memorystatus_control(VPSetJetsamTaskLimit, 1, (uint32_t)-1, NULL, 0);
+ memorystatus_control(VPSetJetsamHighWaterMark, 1, (uint32_t)-1, NULL, 0);
}
// This image is loaded by launchd's LC_LOAD_WEAK_DYLIB. Child injection is