Run a virtual iPhone on an Apple Silicon Mac.
Swift
Load the bootstrap's LaunchDaemons from vphoned, as RootHide does
Lakr9d3551cfa25e
diff --git a/Research/0_binary_patch_comparison.md b/Research/0_binary_patch_comparison.mdindex 98be0dbf..740d6fed 100644--- a/Research/0_binary_patch_comparison.md+++ b/Research/0_binary_patch_comparison.md@@ -166,21 +166,20 @@> `cfw install` now places `launchdhook-vphone.dylib` and a diagnostic> `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-> the in-memory XPC plist. The hook also tries to remove PID 1's existing+> launchd hook after `patch-launchd-jetsam`, and re-signs launchd. Until+> 2026-09-29 the hook also extended launchd's `Paths` and `LaunchDaemons`+> cache values with the bootstrap's `Library/LaunchDaemons`, under distinct+> `/System/Library/LaunchDaemons/vphone.*.plist` keys (the tested iOS 26.6.2+> cache loader ignored `/var/jb/...` and `/Library/...` keys). Those jobs did+> not match the plist path a package script boots out, so the hook no longer+> touches `xpc_dictionary_get_value`: vphoned loads the bootstrap's daemons+> after boot, as RootHide's `jbctl startup` does (`Research/roothide_loader_links.md`).+> 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. The bootstrap root is `/var/jb` or the one RootHide root vphoned+> installs, `.jbroot-000114514191980C`; spawns look for it until it appears.+> The hook also tries to remove PID 1's existing> jetsam limit and suppresses future fatal task-limit assignments for PID 1.> The launchd hook interposes PID 1's `posix_spawn` without loading ElleKit,> so process injection remains available before a package manager installs it. It addsdiff --git a/VPhoneDaemon/Daemon/Bootstrap/GuestIrisinInstaller+LaunchDaemons.swift b/VPhoneDaemon/Daemon/Bootstrap/GuestIrisinInstaller+LaunchDaemons.swiftnew file mode 100644index 00000000..7de82cd4--- /dev/null+++ b/VPhoneDaemon/Daemon/Bootstrap/GuestIrisinInstaller+LaunchDaemons.swift@@ -0,0 +1,49 @@+import Foundation+import IcliKit++// MARK: - Bootstrap LaunchDaemons++extension GuestIrisinInstaller {+ /// The launchd hook does not import the bootstrap's daemons. As RootHide's+ /// `jbctl startup` does, vphoned loads `Library/LaunchDaemons` into the+ /// system domain once the root is repaired, under each plist's own path,+ /// so a package script's `launchctl bootout` of that path finds the job.+ /// No launchctl is needed: RootHide plists are rewritten here, and a job+ /// that is already loaded answers EEXIST, which IcliKit accepts.+ static func loadBootstrapDaemons(layout: String, root: String) {+ let directory = root + "/Library/LaunchDaemons"+ guard let names = try? FileManager.default.contentsOfDirectory(atPath: directory) else { return }+ for name in names.sorted() where name.hasSuffix(".plist") {+ let plist = directory + "/" + name+ do {+ if layout == "roothide" {+ try patchRootHideDaemon(at: plist, root: root)+ }+ _ = try loadServices([plist], load: true, override: false)+ } catch {+ NSLog("vphoned: could not load bootstrap daemon %@: %@", plist, String(describing: error))+ }+ }+ }++ /// `services.load` of a plist, or a directory of them, inside the RootHide+ /// root rewrites each before launchd reads it.+ static func prepareBootstrapDaemons(_ paths: [String]) throws {+ guard let installation = try completedBootstrap(), installation.layout == "roothide" else { return }+ let root = installation.root+ // standardizingPath drops the /private of /private/var, so compare+ // each path with the root spelled the same way.+ let prefix = (root as NSString).standardizingPath + "/"+ for path in paths.map({ ($0 as NSString).standardizingPath }) where path.hasPrefix(prefix) {+ if isDirectory(path) {+ for name in try FileManager.default.contentsOfDirectory(atPath: path).sorted()+ where name.hasSuffix(".plist")+ {+ try patchRootHideDaemon(at: path + "/" + name, root: root)+ }+ } else if path.hasSuffix(".plist") {+ try patchRootHideDaemon(at: path, root: root)+ }+ }+ }+}diff --git a/VPhoneDaemon/Daemon/Bootstrap/GuestIrisinInstaller.swift b/VPhoneDaemon/Daemon/Bootstrap/GuestIrisinInstaller.swiftindex b344c9ea..1ab24153 100644--- a/VPhoneDaemon/Daemon/Bootstrap/GuestIrisinInstaller.swift+++ b/VPhoneDaemon/Daemon/Bootstrap/GuestIrisinInstaller.swift@@ -84,9 +84,10 @@ enum GuestIrisinInstaller {}static func refreshBootstrapOnStartup() {+ var installation: (layout: String, root: String)?do {- guard let installation = try completedBootstrap() else { return }- if installation.layout == "roothide" {+ installation = try completedBootstrap()+ if let installation, installation.layout == "roothide" {let base = try repairRootHide(root: installation.root)if base["created"] as? [String] != [] || base["deferred"] as? [String] != [] {NSLog("vphoned: RootHide bootstrap base: %@", String(describing: base))@@ -96,6 +97,12 @@ enum GuestIrisinInstaller {} catch {NSLog("vphoned: could not repair RootHide bootstrap: %@", String(describing: error))}+ if let installation {+ // Off the startup path: the server should not wait for launchd.+ DispatchQueue.global().async {+ loadBootstrapDaemons(layout: installation.layout, root: installation.root)+ }+ }do {_ = try repairFirmwareRecord()} catch {@@ -173,7 +180,7 @@ enum GuestIrisinInstaller {guard layout == "rootless", info.st_mode & mode_t(S_IFMT) == mode_t(S_IFLNK) else {throw GuestAPIError.operationFailed("Bootstrap root is not a directory: \(root)")}- return (try rootlessLinkTarget(root), true)+ return try (rootlessLinkTarget(root), true)}static func completedBootstrap() throws -> (layout: String, root: String)? {@@ -187,8 +194,10 @@ enum GuestIrisinInstaller {}guard let layout = marker["layout"] as? String,let root = marker["jbroot"] as? String,- (layout == "rootless" && root == rootlessRoot) || (layout == "roothide" && isRootHideRoot(root))+ layout == "rootless" || layout == "roothide"else { throw GuestAPIError.operationFailed("Completed bootstrap marker has an invalid root") }+ // A RootHide root under another name is left for uninstall to find.+ guard root == (layout == "rootless" ? rootlessRoot : roothideRoot) else { return nil }return (layout, root)}@@ -297,7 +306,7 @@ enum GuestIrisinInstaller {version: version, architecture: architecture, layout: layout)if layout == "roothide" {- try prepareRootHidePlist(plist, executable: root + "/usr/libexec/irisind")+ _ = try patchRootHideDaemon(at: plist.path, root: root)}try prepareAppData()diff --git a/VPhoneDaemon/Daemon/Bootstrap/RootHide/GuestIrisinInstaller+RootHide.swift b/VPhoneDaemon/Daemon/Bootstrap/RootHide/GuestIrisinInstaller+RootHide.swiftindex 4dda46ea..25c59abd 100644--- a/VPhoneDaemon/Daemon/Bootstrap/RootHide/GuestIrisinInstaller+RootHide.swift+++ b/VPhoneDaemon/Daemon/Bootstrap/RootHide/GuestIrisinInstaller+RootHide.swift@@ -5,6 +5,10 @@ import Foundationextension GuestIrisinInstaller {static let roothideParent = "/private/var/containers/Bundle/Application"+ /// The one RootHide root vphone installs and loads: a user-selected stem,+ /// zero-padded to 16 hex digits with RootHide's XOR checksum in the final+ /// byte (0C instead of the proposed 10). The launchd hook names it too.+ static let roothideRoot = roothideParent + "/.jbroot-000114514191980C"static func roothideName(_ name: String) -> Bool {guard name.range(of: "^\\.jbroot-[0-9a-fA-F]{16}$", options: .regularExpression) != nil,@@ -16,11 +20,8 @@ extension GuestIrisinInstaller {return check == UInt8(truncatingIfNeeded: value)}- static func isRootHideRoot(_ root: String) -> Bool {- root.hasPrefix(roothideParent + "/") && roothideName(String(root.dropFirst(roothideParent.count + 1)))- }-- /// Every valid `.jbroot-<16 hex>` directory entry, sorted.+ /// Every valid `.jbroot-<16 hex>` directory entry, sorted. Only+ /// `roothideRoot` is used; the others are listed so they can be removed.static func roothideRoots() throws -> [String] {try FileManager.default.contentsOfDirectory(atPath: roothideParent).sorted()@@ -28,36 +29,13 @@ extension GuestIrisinInstaller {.map { roothideParent + "/" + $0 }}+ /// A RootHide bootstrap under any other name has to be uninstalled first.static func roothideBootstrapRoot(detected: String?) throws -> String {- if let detected {- return detected- }- let roots = try roothideRoots().filter(isDirectory)- guard roots.count <= 1 else {- throw GuestAPIError.operationFailed("Multiple RootHide bootstrap roots exist")- }- if let root = roots.first {- return root- }-- // User-selected stem, zero-padded to 16 hex digits with RootHide's- // XOR checksum in the final byte (0C instead of the proposed 10).- let name = ".jbroot-000114514191980C"- guard roothideName(name) else {- throw GuestAPIError.operationFailed("Configured RootHide bootstrap name is invalid")+ let others = try roothideRoots().filter { $0 != roothideRoot && isDirectory($0) }+ guard detected == nil || detected == roothideRoot, others.isEmpty else {+ throw GuestAPIError.operationFailed("Another RootHide bootstrap exists; uninstall it first")}- return roothideParent + "/" + name- }-- static func prepareRootHidePlist(_ url: URL, executable: String) throws {- let data = try Data(contentsOf: url)- guard var plist = try PropertyListSerialization.propertyList(from: data, format: nil) as? [String: Any] else {- throw GuestAPIError.operationFailed("Irisin launchd plist is invalid")- }- plist["ProgramArguments"] = [executable]- plist["__Patched"] = true- let updated = try PropertyListSerialization.data(fromPropertyList: plist, format: .xml, options: 0)- try updated.write(to: url, options: .atomic)+ return roothideRoot}/// Runs at install and on every vphoned start: the loader links, then the@@ -124,7 +102,7 @@ extension GuestIrisinInstaller {/// program's dependencies before it starts; this pass covers the rest.static func ensureRootHideMachOLinks(root: String) -> [String] {let files = FileManager.default- let skipped: Set<String> = ["usr/share", "usr/include"]+ let skipped: Set = ["usr/share", "usr/include"]var linked: Set<String> = []var created: [String] = []for top in ["bin", "sbin", "usr", "Library"] {@@ -135,7 +113,9 @@ extension GuestIrisinInstaller {let relative = top + "/" + entryswitch walk.fileAttributes?[.type] as? FileAttributeType {case .typeDirectory?:- if skipped.contains(relative) { walk.skipDescendants() }+ if skipped.contains(relative) {+ walk.skipDescendants()+ }continuecase .typeRegular?:breakdiff --git a/VPhoneDaemon/Daemon/Bootstrap/RootHide/GuestIrisinInstaller+RootHideDaemons.swift b/VPhoneDaemon/Daemon/Bootstrap/RootHide/GuestIrisinInstaller+RootHideDaemons.swiftnew file mode 100644index 00000000..04d294f9--- /dev/null+++ b/VPhoneDaemon/Daemon/Bootstrap/RootHide/GuestIrisinInstaller+RootHideDaemons.swift@@ -0,0 +1,100 @@+import Foundation++// MARK: - RootHide LaunchDaemon plists++extension GuestIrisinInstaller {+ /// Rewrites a bootstrap LaunchDaemon plist in place the way RootHide's+ /// launchctl does (`plistpatch.m`), because launchd runs outside vroot and+ /// needs kernel paths. RootHide renames its root at every jailbreak, so its+ /// launchctl takes the old root off a `__Patched` plist before putting the+ /// new one on. vphone's root never changes, so a `__Patched` plist is+ /// already right, and that launchctl turns one written here back into the+ /// same file. A plist whose program is under `/rootfs/` is a system job and+ /// is left alone. Returns whether the file changed.+ @discardableResult+ static func patchRootHideDaemon(at path: String, root: String) throws -> Bool {+ let url = URL(fileURLWithPath: path)+ let data = try Data(contentsOf: url)+ guard var plist = try PropertyListSerialization.propertyList(from: data, format: nil) as? [String: Any] else {+ throw GuestAPIError.operationFailed("LaunchDaemon plist is invalid: \(path)")+ }+ if plist["__Patched"] as? Bool == true {+ return false+ }+ func physical(_ value: String) -> String {+ guard value.hasPrefix("/") else { return value }+ if value.hasPrefix("/rootfs/") {+ return String(value.dropFirst("/rootfs".count))+ }+ let aliased = "/var" + root.dropFirst("/private/var".count)+ if value.hasPrefix(root + "/") || value.hasPrefix(aliased + "/") {+ return value+ }+ return root + value+ }+ func physicalList(_ value: Any?) -> [Any]? {+ (value as? [Any])?.map { ($0 as? String).map(physical) ?? $0 }+ }++ var arguments = plist["ProgramArguments"] as? [Any]+ let program = plist["Program"] as? String ?? arguments?.first as? String+ if program?.hasPrefix("/rootfs/") == true {+ return false+ }+ // Only the executable moves, as RootHide's launchctl does: the other+ // arguments are read by the program itself, inside vroot.+ if let value = plist["Program"] as? String {+ plist["Program"] = physical(value)+ } else if let first = arguments?.first as? String {+ arguments![0] = physical(first)+ plist["ProgramArguments"] = arguments+ }+ for key in ["RootDirectory", "WorkingDirectory", "StandardInPath", "StandardOutPath", "StandardErrorPath"] {+ if let value = plist[key] as? String {+ plist[key] = physical(value)+ }+ }+ for key in ["WatchPaths", "QueueDirectories"] {+ if let value = physicalList(plist[key]) {+ plist[key] = value+ }+ }+ if var environment = plist["EnvironmentVariables"] as? [String: Any] {+ for key in ["CFFIXED_USER_HOME", "HOME", "TMPDIR"] {+ if let value = environment[key] as? String {+ environment[key] = physical(value)+ }+ }+ plist["EnvironmentVariables"] = environment+ }+ if var keepAlive = plist["KeepAlive"] as? [String: Any],+ let states = keepAlive["PathState"] as? [String: Any]+ {+ keepAlive["PathState"] = Dictionary(states.map { (physical($0.key), $0.value) }) { first, _ in first }+ plist["KeepAlive"] = keepAlive+ }+ if let sockets = plist["Sockets"] as? [String: Any] {+ plist["Sockets"] = sockets.mapValues { value -> Any in+ guard var socket = value as? [String: Any], let name = socket["SockPathName"] as? String else {+ return value+ }+ socket["SockPathName"] = physical(name)+ return socket+ }+ }+ if var events = plist["LaunchEvents"] as? [String: Any],+ let matching = events["com.apple.fsevents.matching"] as? [String: Any]+ {+ events["com.apple.fsevents.matching"] = matching.mapValues { value -> Any in+ guard var event = value as? [String: Any], let path = event["Path"] as? String else { return value }+ event["Path"] = physical(path)+ return event+ }+ plist["LaunchEvents"] = events+ }+ plist["__Patched"] = true+ let updated = try PropertyListSerialization.data(fromPropertyList: plist, format: .xml, options: 0)+ try updated.write(to: url, options: .atomic)+ return true+ }+}diff --git a/VPhoneDaemon/Daemon/GuestAPI+Service.swift b/VPhoneDaemon/Daemon/GuestAPI+Service.swiftindex 5a0a947d..74625c89 100644--- a/VPhoneDaemon/Daemon/GuestAPI+Service.swift+++ b/VPhoneDaemon/Daemon/GuestAPI+Service.swift@@ -54,7 +54,9 @@ extension GuestAPI {throw GuestAPIError.invalidRequest("paths must list plist files or directories")}let load = method == "services.load"- if !load {+ if load {+ try GuestIrisinInstaller.prepareBootstrapDaemons(paths)+ } else {try requireForce(params, "unload services")}return try loadServices(paths, load: load, override: bool(params, "override"))diff --git a/VPhoneGuestComponents/LaunchHook/launchdhook-vphone.c b/VPhoneGuestComponents/LaunchHook/launchdhook-vphone.cindex cfe66178..2cc03dcb 100644--- a/VPhoneGuestComponents/LaunchHook/launchdhook-vphone.c+++ b/VPhoneGuestComponents/LaunchHook/launchdhook-vphone.c@@ -1,21 +1,18 @@#include "../Shared/InjectionEnvironment.h"#include "../Shared/RootHideLoaderLinks.h"-#include <ctype.h>-#include <dirent.h>-#include <dlfcn.h>#include <fcntl.h>#include <limits.h>#include <spawn.h>#include <stdio.h>#include <stdlib.h>#include <string.h>-#include <sys/mman.h>#include <sys/stat.h>#include <unistd.h>-#include <xpc/xpc.h>++// vphoned installs RootHide under this one name (`roothideRoot`).+#define VP_ROOTHIDE_ROOT "/private/var/containers/Bundle/Application/.jbroot-000114514191980C"static char vpBootRoot[PATH_MAX];-static int vpFindJBRoot(char root[PATH_MAX]);static void vpLogInjection(const char *event, const char *path, int status) {int fd = open("/var/mobile/Library/Caches/vphone-launchdhook-injection.log",@@ -59,14 +56,29 @@ static int vpIsBootstrapProgram(const char *path) {return length && strncmp(path, root, length) == 0 && path[length] == '/';}+// Neither bootstrap exists on the first boot, and one may be installed while+// launchd runs, so spawns look again until a root appears.+static int vpFindJBRoot(char root[PATH_MAX]) {+ static const char *const roots[] = {"/var/jb", VP_ROOTHIDE_ROOT};+ for (size_t index = 0; index < sizeof(roots) / sizeof(roots[0]); index++) {+ char library[PATH_MAX];+ struct stat info;+ snprintf(library, sizeof(library), "%s/usr/lib", roots[index]);+ if (stat(library, &info) == 0 && S_ISDIR(info.st_mode) && realpath(roots[index], root))+ return 1;+ }+ root[0] = '\0';+ return 0;+}+typedef int (*VPSpawnFunction)(pid_t *restrict, const char *restrict, const posix_spawn_file_actions_t *restrict,const posix_spawnattr_t *restrict, char *const[restrict], char *const[restrict]);static int vpSpawnWith(VPSpawnFunction spawn, pid_t *restrict pid, const char *restrict path,const posix_spawn_file_actions_t *restrict actions, const posix_spawnattr_t *restrict attributes,char *const argv[restrict], char *const envp[restrict]) {- if (!vpBootRoot[0] && path && (vpIsAppProgram(path) || strstr(path, "/.jbroot-")))- vpFindJBRoot(vpBootRoot);+ if (!vpBootRoot[0] && vpFindJBRoot(vpBootRoot))+ vpLogInjection("bootstrap-root", vpBootRoot, 0);int bootstrapProgram = vpIsBootstrapProgram(path);int appProgram = vpIsAppProgram(path);if (bootstrapProgram || appProgram) {@@ -106,174 +118,12 @@ static int vpSpawnP(pid_t *restrict pid, const char *restrict path, const posix_return vpSpawnWith(posix_spawnp, pid, path, actions, attributes, argv, envp);}-// 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]) {- struct stat info;- if (stat("/var/jb/usr/lib", &info) == 0 && S_ISDIR(info.st_mode)) {- return realpath("/var/jb", root) != NULL;- }- const char *parent = "/private/var/containers/Bundle/Application";- DIR *directory = opendir(parent);- if (!directory)- return 0;- int matches = 0;- struct dirent *entry;- while ((entry = readdir(directory))) {- if (strncmp(entry->d_name, ".jbroot-", 8) != 0 || strlen(entry->d_name) != 24)- continue;- int valid = 1;- for (unsigned index = 8; index < 24; index++) {- if (!isxdigit((unsigned char)entry->d_name[index]))- valid = 0;- }- if (!valid)- continue;- char candidate[PATH_MAX];- int length = snprintf(candidate, sizeof(candidate), "%s/%s", parent, entry->d_name);- if (length < 0 || (size_t)length >= sizeof(candidate))- continue;- char library[PATH_MAX];- length = snprintf(library, sizeof(library), "%s/usr/lib", candidate);- if (length < 0 || (size_t)length >= sizeof(library) || stat(library, &info) != 0 || !S_ISDIR(info.st_mode))- continue;- if (!realpath(candidate, root))- continue;- matches++;- }- closedir(directory);- if (matches != 1)- root[0] = '\0';- return matches == 1;-}--// 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 (*VPPlistDecoder)(const void *, size_t);+// The bootstrap's LaunchDaemons are not imported here: vphoned loads them+// after boot under their own paths, as RootHide's jbctl does.extern int memorystatus_control(uint32_t, int32_t, uint32_t, void *, size_t);enum { VPSetJetsamHighWaterMark = 5, VPSetJetsamTaskLimit = 6 };-static int vpPhysicalProgram(const char *program, const char *root, char physical[PATH_MAX]) {- if (!program || program[0] != '/')- return 0;- size_t rootLength = strlen(root);- if (strncmp(program, root, rootLength) == 0 && program[rootLength] == '/')- return 0;- char canonical[PATH_MAX];- if (realpath(program, canonical) && strncmp(canonical, root, rootLength) == 0 && canonical[rootLength] == '/')- return 0;- int used = strncmp(program, "/rootfs/", 8) == 0 ? snprintf(physical, PATH_MAX, "%s", program + 7)- : snprintf(physical, PATH_MAX, "%s%s", root, program);- return used > 0 && used < PATH_MAX;-}--static void vpPatchProgram(xpc_object_t plist, const char *root) {- // RootHide's bootstrap paths are relative to jbroot. launchd is outside- // vroot, so its executable must be passed as a physical kernel path.- if (!strstr(root, "/.jbroot-") || xpc_dictionary_get_bool(plist, "__Patched"))- return;- xpc_object_t args = xpc_dictionary_get_value(plist, "ProgramArguments");- if (args && xpc_get_type(args) == XPC_TYPE_ARRAY && xpc_array_get_count(args) > 0) {- const char *program = xpc_array_get_string(args, 0);- char physical[PATH_MAX];- if (vpPhysicalProgram(program, root, physical))- xpc_array_set_string(args, 0, physical);- }- const char *program = xpc_dictionary_get_string(plist, "Program");- char physical[PATH_MAX];- if (vpPhysicalProgram(program, root, physical))- xpc_dictionary_set_string(plist, "Program", physical);-}--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);- if (fd < 0)- return;- struct stat info;- if (fstat(fd, &info) != 0 || !S_ISREG(info.st_mode) || info.st_size <= 0 || info.st_size >= 1024 * 1024) {- close(fd);- return;- }- void *bytes = mmap(NULL, (size_t)info.st_size, PROT_READ, MAP_PRIVATE, fd, 0);- close(fd);- if (bytes == MAP_FAILED)- return;- xpc_object_t plist = decode(bytes, (size_t)info.st_size);- munmap(bytes, (size_t)info.st_size);- if (!plist)- return;- if (xpc_get_type(plist) == XPC_TYPE_DICTIONARY) {- vpPatchProgram(plist, root);- xpc_dictionary_set_value(dictionary, key, plist);- vpLogInjection("daemon-plist", path, 0);- }- xpc_release(plist);-}--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;- while ((entry = readdir(stream))) {- size_t length = strlen(entry->d_name);- 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))- 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) {- 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;- }- vpLogInjection("cache-key", key, 0);- char root[PATH_MAX];- if (!vpFindJBRoot(root)) {- vpLogInjection("bootstrap-unavailable", key, 0);- return value;- }- 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))- return value;- if (strcmp(key, "Paths") == 0 && xpc_get_type(value) == XPC_TYPE_ARRAY) {- xpc_array_set_string(value, XPC_ARRAY_APPEND, path);- used = snprintf(path, sizeof(path), "%s/basebin/LaunchDaemons", root);- if (used > 0 && (size_t)used < sizeof(path) && access(path, F_OK) == 0) {- xpc_array_set_string(value, XPC_ARRAY_APPEND, path);- }- } else if (strcmp(key, "LaunchDaemons") == 0 && xpc_get_type(value) == XPC_TYPE_DICTIONARY) {- 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, "basebin", root);- }- return value;-}-static int vpMemoryStatus(uint32_t command, int32_t pid, uint32_t flags, void *buffer, size_t size) {if (getpid() == 1 && command == VPSetJetsamTaskLimit && (pid == 1 || pid == 0)) {return 0;@@ -296,7 +146,6 @@ __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 *)vpSpawnP, (const void *)posix_spawnp},{(const void *)vpMemoryStatus, (const void *)memorystatus_control},