Run a virtual iPhone on an Apple Silicon Mac.
Swift
Merge branch 'pr-807' into merge-pr-807
Jackyf4ecfebb6d79
diff --cc Research/0_binary_patch_comparison.mdindex 9f178ffe,ce6ec539..bad5e920--- a/Research/0_binary_patch_comparison.md+++ b/Research/0_binary_patch_comparison.md@@@ -6106,135 -6049,161 +6184,294 @@@ layout the completion does not produceservice. With primitive restart no longer sent, an OpenGL ES 2 strip that drawsvertex 65535 is cut there.+ ## The stock launchd_cache_loader takes a re-signed launchd.plist (2026-11-01)++ `minimal` used to keep one userland security patch,+ `filesystem-boot-launchd_cache_loader_unsecure_cache_gate`, because vphoned's+ entry in `/System/Library/xpc/launchd.plist` made the stock loader refuse the+ file. It no longer needs it: `filesystem-boot-vphoned` signs the edited file+ the way Apple signs it, and the static trust cache the restore image already+ rebuilds (and TSS signs) carries the new cdhashes. The patch is now+ `filesystem-exp-launchd_cache_loader_unsecure_cache_gate`, not boot-essential,+ left out of `minimal` and `watchos`; `renamedPatches` migrates a VM's old+ record. A Watch7,18 watchOS 26.4 (23T240) guest on cloudOS 26.4 (23E244),+ restored with the gate blocked, booted to the pairing screen with vphoned up:+ its stock loader logged "cdhash: … 0xeacd92f9… is trusted" for the re-signed+ `launchd.plist.sig` and "Cache sent to launchd successfully" (2026-11-02).++ What the loader checks (`/usr/libexec/launchd_cache_loader`, libxpc-2894.140.12,+ iOS 18.6 22G86, read from the disassembly):++ 1. `0x100000a44`: the default paths, `/System/Library/xpc/launchd.plist` and+ `/System/Library/xpc/launchd.plist.sig` ("Code: %s Sig: %s").+ 2. `0x100000b2c`: `kern.bootargs`; with `launchd_unsecure_cache=` the+ `cbz x0` at `0x100000b58` falls into "Using unsecure cache" and skips 3-6.+ That `cbz` is what the old patch NOPs.+ 3. `SecStaticCodeCreateWithPath(plist)`, `SecCodeSetDetachedSignature(sig)`,+ `SecStaticCodeCheckValidity(code, 6)` (no executable or resource+ validation; errSecCSSignatureNotVerifiable, -67060, is let through).+ 4. `SecCodeCopySigningInformation` → `kSecCodeInfoUnique` (the cdhash) →+ `IOConnectCallMethod` selector 6 on `AppleMobileFileIntegrity`+ (`AppleMobileFileIntegrityUserClient::isCdhashInTrustCache` in the kernel+ log). Not found (`0xe00002f0`) logs "cdhash: %s is not in trust cache" and+ aborts (`abort_with_reason`).+ 5. `SecCodeMapMemory` attaches the signature to the vnode ("Failed to push+ signature to kernel" otherwise), so the pages read next are checked against+ the code directory.+ 6. `open`/`mmap` the plist, copy it into memory mapped into launchd ("Sending+ validated cache to launchd").++ `launchd.plist.sig` is a detached ad hoc signature: a SuperBlob with a SHA-1+ code directory, empty requirements, a SHA-256 alternate code directory, an+ empty CMS wrapper and an identification wrapper (slot 0x10001) holding the+ file's SHA-1. Both directories are version 0x20500, flags 0x10002 (ad hoc,+ runtime), runtime version 11.0.0, 4 KiB pages, identifier+ `launchd-<sha1 of the file>`. The stock static trust cache+ (`043-19071-100.dmg.aea.trustcache`) lists both cdhashes of Apple's file+ (`72c3cf9a…` SHA-256, `2e45eca3…` SHA-1), as it does those of+ `extensions.plist.sig`. `cryptexctl generate-trust-cache` hashes Mach-O code+ directories only, so the edited plist's new signature has to be added by hand.++ `CustomFirmwareDetachedSignature` writes that signature: for 22G86's+ `extensions.plist` it reproduces Apple's `extensions.plist.sig` byte for byte+ (`codesign -s - -o runtime --pagesize 4096 --detached` differs only in its+ 0x20100 header). `resignLaunchdCache` replaces `launchd.plist.sig` (root:admin+ 0644) after vphoned's entry is merged; `createTrustcache` reads it back from the+ image and hands `cryptexctl` a second `--base-trust-cache`, a raw version 1+ trust cache with its two cdhashes. Apple's stale entries stay; nothing has+ their bytes any more.++ Checked on 2026-11-01: `vm create lcl-186 --preset minimal --device iPhone11,6`+ (18.6 22G86 on cloudOS 22G86, bundle 2.12.2-local.442efa84) signed the plist+ (`c6a34260…` SHA-1, `b4ace6ca…` SHA-256), the rebuilt `new.trustcache` held+ both, the patch log listed the gate under "Turned off", and the boot log shows+ the secure path:++ ```+ Code: /System/Library/xpc/launchd.plist Sig: /System/Library/xpc/launchd.plist.sig+ …isCdhashInTrustCache…: Returning IOReturn 0x0 to process 28+ cdhash: {length = 20, bytes = 0xb4ace6cacd1e77cf9b8546e7c9bed89a0914462e} is trusted+ Attached signature to file, checking ...+ Sending validated cache to launchd+ Cache sent to launchd successfully+ ```++ with no "Using unsecure cache". SpringBoard came up and `guest rpc+ processes.list` answered from `/usr/bin/vphoned`.++ ## Launch-constraint categories in the rebuilt static trust cache (2026-11-02)++ `filesystem-boot-cryptex_merge` rebuilds the static trust cache with+ `cryptexctl generate-trust-cache`, which writes a version 1 cache: entries of+ cdhash, hash type and flags, no launch-constraint category. Apple's iOS trust+ caches (the OS's `StaticTrustCache`, `Cryptex1,SystemTrustCache` and+ `Cryptex1,AppTrustCache`) are version 2 and give each cdhash a category, so on+ a `minimal` guest every system service ran with category 0 and the kernel+ logged `Launch Constraint Violation (not enforcing) … launched as a system+ service unexpectedly but met System Service constraints` for each: 212 lines+ (355 distinct programs) in lcl-186's serial log of one 18.6 Minimal boot,+ 303 lines (898 occurrences) in `iphone-265.log`, a 26.5 Minimal boot.++ `createTrustcache` now rewrites cryptexctl's output as version 2+ (`TrustCache.withConstraintCategories`): each entry gets the category its+ cdhash has in Apple's three caches; a file the merge signs again gets the+ category its IPSW cdhashes had (`resignedCDHashes`: `launchd_cache_loader`+ where it is still patched, mobileactivationd, and the detached+ `launchd.plist.sig` of "The stock launchd_cache_loader takes a re-signed+ launchd.plist"); what Apple's caches do not list (vphoned, its Swift library,+ the GPU driver bundle, kexts Apple left out) keeps 0. Entries, order, flags,+ UUID and the IM4P's type and description stay as cryptexctl wrote them.++ The detached signature's cdhashes reach cryptexctl through the second base+ trust cache and are in none of Apple's caches. Apple's 22G86 static trust+ cache (`043-19071-100.dmg.aea.trustcache`) gives both cdhashes of its own+ `launchd.plist.sig` (`72c3cf9a…` SHA-256, `2e45eca3…` SHA-1) category 2, and+ `resignLaunchdCache` maps the new cdhashes to those. Apple's 26.5 static+ trust cache (`094-54920-099.dmg.aea.trustcache`) does the same for its+ `launchd.plist.sig` (`b2f662df…` SHA-1, `cb7da9ce…` SHA-256).++ Checked on 2026-11-02 with two `minimal` guests that also carried the other+ Minimal changes of that week (a stock LLB with only iBEC's image-4 callback+ patched, vphoned's paravirtual user-client entitlements, the restore tree+ published as clones). int-186 (iPhone11,6 18.6 22G86 on cloudOS 22G86, bundle+ 2.12.2-local.c632b261), patch log:++ ```+ [+] Apple's launchd.plist.sig: cdhash 2e45eca3ba25f02a7166775802481dfadaa2757c+ [+] Apple's launchd.plist.sig: cdhash 72c3cf9a1de7d4eb05fe0da99889cbb47ab41afc+ [+] Signed launchd.plist: cdhash c6a34260… (hash type 1)+ [+] Signed launchd.plist: cdhash b4ace6ca… (hash type 2)+ [+] Constraint categories for 6228 of 6693 trust cache entries+ [+] Re-signed cdhash 5c5eb26e… (hash type 2): category 3 (mobileactivationd)+ [+] Re-signed cdhash b4ace6ca… (hash type 2): category 2+ [+] Re-signed cdhash c6a34260… (hash type 1): category 2+ ```++ The installed `new.trustcache` is version 2, 3428 CDHashes, with both new+ cdhashes at category 2. A reboot's unified log (Persist tracev3 pulled with+ `guest pull` and read with `log show` over a hand-built archive, since the+ stock LLB passes no serial boot-args) shows:++ - `isCdhashInTrustCache … Process 28 is checking if a cdhash is in the trust+ cache` / `Returning IOReturn 0x0 to process 28`, the same pid and pair+ lcl-186's serial log shows just before `cdhash: … b4ace6ca… is trusted`.+ The loader's own lines are not in the persisted log (it runs before logd).+ - Two `Launch Constraint Violation (not enforcing) … met System Service+ constraints` lines, for `/usr/libexec/init_exclavekit` and+ `/usr/bin/vphoned`, both at category 0 because Apple's caches do not list+ them.+ - No `Launch Constraint Violation (enforcing)`, no CODESIGNING exit, no crash+ report (`idevicecrashreport -k`: only `restore_perform.txt`);+ launchd_cache_loader, mobileactivationd and vphoned ran.++ int-265 (iPhone17,3 26.5 23F77 on cloudOS 23F75) was built with `minimal`+ plus `--allow llb-boot-boot_args --allow ibec-boot-boot_args`, so that the+ host serial log has the boot. Its patch log gives 6729 of 7277 entries a+ category, the new `launchd.plist.sig` cdhashes (`4230469c…`, `20f70244…`)+ category 2 and mobileactivationd's category 3, and the serial log shows the+ secure path:++ ```+ Code: /System/Library/xpc/launchd.plist Sig: /System/Library/xpc/launchd.plist.sig+ cdhash: {length = 20, bytes = 0x20f702440c87a4d86aa49deca652100424c19381} is trusted+ Attached signature to file, checking ...+ Sending validated cache to launchd+ Cache sent to launchd successfully+ ```++ with three `Launch Constraint Violation (not enforcing)` lines+ (`MobileAssetEarlyBootTask`, `init_exclavekit`, `vphoned`), no enforcing+ violation and no crash report.+++## Always On display (2026-11-02)++No new patch identifier and no new bytes in an Apple binary.+`preboot-cfw-devicetree_iphone_product` (the iPhone product repair, which `cfw+install` and `cfw update-environment` run) also adds+`/product/vphone-always-on-display = 1` when the board's own tree has+`/arm-io/disp0` `always-on-time`. MobileGestalt reads nothing by that name.+vphoned reads it at startup and answers DeviceSupportsAlwaysOnDisplay+(`2OOJf1VhaM7NxfRok3HbWQ`) and DeviceSupportsAlwaysOnTime+(`j8/Omm6s1lsmTDFsXjsBfA`) yes in the MobileGestalt cache's `CacheExtra`+(`GuestMobileGestaltAnswers`, `GuestMobileGestaltCache.presentAlwaysOnDisplayOnStartup`).+Settings then offers Always On Display and SpringBoard dims the Lock Screen+instead of turning it off. Issue #650.++**Why not the tree.** libMobileGestalt (24A446) answers the three questions from+one node:++| Answer | Source |+| --- | --- |+| DeviceSupportsAlwaysOnTime | `IODeviceTree:/arm-io/disp0` `always-on-time` |+| DeviceSupportsAlwaysOnDisplay | AlwaysOnTime, else `disp0` `always-on-device` |+| DeviceSupportsAlwaysOnDisplayFlipbook | AlwaysOnTime, else `disp0` `always-on-device-flipbook` |++Settings shows the row only with AlwaysOnTime (DisplayAndBrightnessSettings+asks for it; with AlwaysOnDisplay alone there is no row, measured). The board's+`always-on-time` therefore answers the flipbook yes too. CoreBrightness reads it+in backboardd (`-[CBAODState initializeAODSupportConfiguration]`) and drives the+flipbook through the panel controller (DCP), which the paravirtual panel does+not have. An iPhone18,1 27.0.1 guest with an `/arm-io/disp0` stub carrying the+board's `always-on-time` lost backboardd at every boot (`rebooting due to+critical process crashes: backboardd`) and launchd restarted it into the device+recovery environment. A second guest made without the stub booted, and+answering all three yes in its `CacheExtra` crashed it the same way. Without+the flipbook, `-[BLSHBacklightOSInterfaceProvider initWithPlatformProvider:]`+gives SpringBoard BacklightServices' own renderer (`BLSHPseudoFlipbook`), which+works on a guest. Answering the first two in the cache leaves the flipbook+unanswered there and so no. Keeping `always-on-time` in the tree and answering+the flipbook no in the cache would not do: the tree decides whenever the cache+is missing, at a guest's first boot and after every drop, and one boot with the+flipbook is enough to lose backboardd.++A guest that went through that crash loop kept losing backboardd after the+answers and the whole cache were removed; the cause was not found. Do not+test the flipbook answer on a VM you want to keep.++**When the answers land.** libMobileGestalt writes the cache when a process+first asks after it is gone: at a guest's first boot, and after vphoned drops a+cache older than the tree. vphoned waits for it (up to 10 minutes), adds the+answers once, and sets `mobilegestalt_restart_pending`; the cache keeps them+across boots, and a rebuilt cache gets them again at the next start. A new+machine's creation boots more than once, so it is offered from its first use.++**The window.** On a foldable guest the VM window covers the panel while+`display.orientation` says `screen_off`, so a waking panel does not show its+frame from before (`bde6440c`). SpringBoard posts `hasBlankedScreen` for the+always-on Lock Screen too, so the window covered it. FoldDisplay now publishes+whether the panel went off since SpringBoard last lit the screen+(`com.vphone.folddisplay.panel-dark`: 1 stayed on, 2 went off), and+`screen_off` is SpringBoard's blank and that.++**Verified.**+- New machine: iPhone18,1 27.0.1, cloudOS 26.4, bundle from this branch on+ 2.14.2. `cfw install` logged `product/vphone-always-on-display: 'absent' ->+ '01000000'`; with nothing done by hand, the cache had both answers yes and the+ flipbook unanswered, Settings showed Always On Display On, and the locked+ screen stayed dimmed with the clock moving (9:34 to 9:36). No backboardd crash.+- Existing machine: iPhone19,4 27.1 (24A94425), `vm set-bundle+ --update-environment`. The repair added the marker; the next boot dropped the+ cache, the rebuilt one got the answers and the restart was reported pending;+ after the restart the Lock Screen went always-on, the panel state stayed 1,+ `screen_off` false, and the VM window showed it. With Always On Display+ switched off in Settings the panel went off (state 2), `screen_off` was true+ and the window covered it, then uncovered it on wake.++**Not covered.** Other iPhones with the display were not run. Apple Watch:+N227b's tree has `always-on-time` too, but on a Watch7,18 26.4 guest the same two+answers left the screen fully dark after the timeout (Carousel decides; not+investigated), so the repair stays iPhone-only. No iPad board has the property.+The VM keeps rendering while dimmed: there is no low-power display.++## Experimental iOS 16.6.1 desktop bring-up++Measured pairing: iPhone15,2 (iPhone 14 Pro), iOS 16.6.1/20G81 userland,+cloudOS 26.1/23B85 vphone600 boot chain. All additions below are manual opt-ins;+shipped presets and the no-plan path leave them disabled. See+`Research/Guest/ios16_bringup.md` for procedure, evidence and limitations.++- `system-launchd-exp-ios16_mach_ports` bridges the old out-of-line self-task+ Mach-port API to the newer fixed-three-port RPCs in the native launch hooks.+ `dyld-exp-ios16_mach_ports_lookup` updates the old libxpc client's pre-constructor+ lookup through a symbol-derived, bounded cache patch with undo capture.+- `system-backboard-exp-ios16_migration` skips the fresh lab's measured migration+ wait and releases its local shell sentinel/PreBoard re-block. It does not+ migrate existing user data or persist completion. `system-springboard-exp-ios16_desktop`+ avoids unavailable startup media, widget and flashlight services and uses the+ native local setup-state setter. These services remain unavailable.+- `system-systemhook-exp-ios16_surface` converts capability replies 0x28 ->+ 0x18 and allocation/lookup replies 0xC68 -> 0xA68, including narrowed fields+ and the changed plane stride. Offline metadata derives the framework-private+ transport stub, verifies its instruction pattern and records its Mach-O UUID.+ The runtime detour checks UUID/expected bytes, suspends peer threads, uses+ private COW memory without writable executable pages, and restores protection.+- `system-systemhook-exp-ios16_framebuffer` translates the measured old 0x46C+ SwapEnd payload into the modern 0x560 layout. It inserts the new event/port+ slots, retaining frame token, surfaces, rectangles and measured flags. Native+ create/lock/write/read/unlock and surface lookup probes pass; submitted color+ bars and the real SpringBoard desktop are visible.+- `preboot-exp-ios16_ephemeral_storage` changes only the existing chosen/product+ ephemeral-storage fields, preserving their widths and tree size. Native+ `hw.ephemeral_storage` and `os_variant_uses_ephemeral_storage` then report 1;+ PreBoard no longer owns the shell. Restore pre-ephemeral snapshots to undo+ guest data effects; restoring device-tree bits alone is insufficient.+- `system-vphoned-exp-ios16_touchscreen` registers a built-in HID touchscreen+ only when none exists. With desktop startup selected, native backlight-state+ changes also publish the legacy HID factor. Real mouse swipes and clicks now+ reach the guest rather than being dropped as missing-digitizer/display-off.+- `system-springboard-exp-ios16_keybagless_ui` is restricted to a fresh ephemeral+ lab. The root daemon requires explicit markers and a strict session/persona+ keybag-directory allowlist before publishing a single-link, root-owned,+ magic-checked lease. Three signature-checked UI getters honor that lease for+ at most three seconds and otherwise forward to native. MKB/AKS and encrypted+ data remain unchanged; this is not working credentials or protected storage.+- The existing battery helper weak-imports the unavailable newer precise-power+ API and falls back to its existing ByType API. This resolves the measured+ Preferences pre-main dyld crash without synthesizing an IOKit export.++The real guest displays Home Screen, accepts mouse input and opens Settings >+General > About (16.6.1, iPhone 14 Pro, 64 GB). Initial About lookup can wait for+IOKit/SystemConfiguration quiescence; a proposed fallback was never deployed and+is excluded. Wallpaper preview fails without Metal; its cancelled, unvalidated+prototype is excluded as well. No general iOS 16/15, Metal, full audio, camera,+networking or persistent protected-data compatibility is claimed.diff --cc VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwarePatchSetCatalog.swiftindex 49175fd4,b9af425e..da458522--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwarePatchSetCatalog.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwarePatchSetCatalog.swift@@@ -411,9 -422,11 +413,10 @@@ public enum FirmwarePatchSetCatalog.bundled(FirmwareRestoreImagePatchSet.identifier),],selection: .allow(- minimalBootChainPatches- .union(minimalDeviceTreePatches)+ minimalDeviceTreePatches.union(FirmwareResearchBoardPatchSet.manifest.patches.map(\.identifier))- .union(FirmwareRestoreImagePatchSet.manifest.patches.map(\.identifier)),+ .union(FirmwareRestoreImagePatchSet.manifest.patches.map(\.identifier))+ .subtracting([FirmwareRestoreImagePatchSet.launchdCacheLoader]),),)@@@ -443,9 -453,11 +446,10 @@@summary: "Minimal for an Apple Watch guest: the watch board's device tree, and a resealed system with vphoned, the GPU driver, speaker audio and activation restored onto a stock kernel and TXM.",patchSets: minimalPreset.patchSets,selection: .allow(- minimalBootChainPatches- .union(watchOSDeviceTreePatches)+ watchOSDeviceTreePatches.union(FirmwareResearchBoardPatchSet.manifest.patches.map(\.identifier))- .union(FirmwareRestoreImagePatchSet.manifest.patches.map(\.identifier)),+ .union(FirmwareRestoreImagePatchSet.manifest.patches.map(\.identifier))+ .subtracting([FirmwareRestoreImagePatchSet.launchdCacheLoader]),),)diff --cc VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/PatchSets/FirmwarePatchSetCatalogTests.swiftindex 0b3dae58,3ce665a7..47881d8d--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/PatchSets/FirmwarePatchSetCatalogTests.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/PatchSets/FirmwarePatchSetCatalogTests.swift@@@ -260,18 -233,14 +260,22 @@@ struct FirmwarePatchSetCatalogTestscloudOS: VPhoneVersion("26.4"),)let restoreImage = Set(FirmwareRestoreImagePatchSet.manifest.patches.map(\.identifier))- let bootChain = FirmwarePatchSetCatalog.minimalBootChainPatcheslet researchBoard = Set(FirmwareResearchBoardPatchSet.manifest.patches.map(\.identifier))- #expect(plan.enabled == restoreImage.union(FirmwarePatchSetCatalog.minimalDeviceTreePatches).union(researchBoard))+ // The unsecure-cache gate stays out: the launchd.plist minimal edits is+ // signed and in the trust cache, so the stock launchd_cache_loader takes it.+ #expect(!plan.isEnabled(FirmwareRestoreImagePatchSet.launchdCacheLoader))+ #expect(plan.enabled == restoreImage.subtracting([FirmwareRestoreImagePatchSet.launchdCacheLoader])- .union(FirmwarePatchSetCatalog.minimalDeviceTreePatches).union(bootChain).union(researchBoard))- #expect(plan.droppedBootEssentials.allSatisfy { !$0.hasPrefix("ibec-") && !$0.hasPrefix("llb-") })++ .union(FirmwarePatchSetCatalog.minimalDeviceTreePatches).union(researchBoard))+ #expect(plan.enabled.isDisjoint(with: FirmwareBootChainPatchSet.manifest.patches.map(\.identifier)))+ // The set stays named, so `--allow` can turn a boot chain patch back on.+ let verbose = try VPhonePatchPlan.resolve(+ preset: FirmwarePatchSetCatalog.minimalPreset,+ patchSets: FirmwarePatchSetCatalog.bundled,+ iOSBase: VPhoneVersion("26.4"),+ cloudOS: VPhoneVersion("26.4"),+ allowed: ["llb-boot-boot_args"],+ )+ #expect(verbose.enabled.contains("llb-boot-boot_args"))let watch = try VPhonePatchPlan.resolve(preset: FirmwarePatchSetCatalog.watchOSPreset,@@@ -279,10 -248,9 +283,10 @@@iOSBase: VPhoneVersion("26.4"),cloudOS: VPhoneVersion("26.4"),)- #expect(watch.enabled == restoreImage- .union(FirmwarePatchSetCatalog.watchOSDeviceTreePatches)- .union(researchBoard))+ #expect(!watch.isEnabled(FirmwareRestoreImagePatchSet.launchdCacheLoader))+ #expect(watch.enabled == restoreImage.subtracting([FirmwareRestoreImagePatchSet.launchdCacheLoader])- .union(FirmwarePatchSetCatalog.watchOSDeviceTreePatches).union(bootChain).union(researchBoard))++ .union(FirmwarePatchSetCatalog.watchOSDeviceTreePatches).union(researchBoard))+ #expect(watch.enabled.isDisjoint(with: FirmwareBootChainPatchSet.manifest.patches.map(\.identifier)))}@Test