Run a virtual iPhone on an Apple Silicon Mac.
Swift
Validate userspace debugging on iPhone, watch and HomePod guests
Maximilian Paß29d6110a8c33
diff --git a/Research/0_binary_patch_comparison.md b/Research/0_binary_patch_comparison.mdindex 41f7bca6..c9a3394d 100644--- a/Research/0_binary_patch_comparison.md+++ b/Research/0_binary_patch_comparison.md@@ -6289,7 +6289,7 @@ with three `Launch Constraint Violation (not enforcing)` lines(`MobileAssetEarlyBootTask`, `init_exclavekit`, `vphoned`), no enforcingviolation and no crash report.-## Userspace debugging on `minimal` (2026-11-02)+## Userspace debugging on `minimal`, watchOS and HomePod (2026-11-02)`system-debugserver-cfw-install` re-signs the guest's `/usr/libexec/debugserver`(strips `seatbelt-profiles`, sets `task_for_pid-allow`, ad hoc) in `cfw install`,@@ -6297,49 +6297,73 @@ which `minimal` never runs. `filesystem-exp-debugserver` makes the same change ithe restore-image merge, before the reseal, so the new hash lands in theregenerated static trust cache. Both stages share the entitlement transform(`CustomFirmwareDebugserver.attachEntitlements`) and are a logged no-op when the-system ships no debugserver: a stock userland carries it only in the Developer-disk image, so it is present to re-sign on a research/cloudOS build. The patch is-opt-in (`FirmwareRestoreImagePatchSet.optInPatches`); plain `minimal` and-`watchos` leave it off.+system ships no debugserver. The merged iPhone17,3 26.5, Watch7,18 26.4 and+HomePod Software 27.0 systems all ship one. A watch's debugserver also carries an+arm64_32 slice the signer cannot rewrite, so the merge thins it to arm64e first.The entitlement alone does not let debugserver run or attach on `minimal`'s stockkernel and TXM: AMFI asks TXM for developer mode and kills it ("Developer mode isdisabled, task_for_pid-allow is disallowed"), and an enrolment from the guest doesnot survive a forced reboot. The `userspace-debugging` feature-(`FirmwarePatchSetCatalog.userspaceDebugging`) groups the re-sign with the-smallest kernel and TXM set that lets it attach to any process and read its-memory:+(`FirmwarePatchSetCatalog.userspaceDebugging`) is the smallest set found to attach+to a system daemon and read its memory:-| Patch | Why |-| --- | --- |-| `filesystem-exp-debugserver` | The re-signed debugserver, in the image's trust cache. |-| `kernel-cfw-task_for_pid` | Return a task port for a process the caller does not own. |-| `kernel-boot-task_conversion_eval` | Let that task port be converted. |-| `kernel-cfw-debugger` | Report the kernel debuggable; `task_for_pid` is gated on it. |-| `kernel-boot-port_to_map` | No panic when debugserver converts the target's task port to a vm_map. |-| `kernel-boot-proc_security_policy` | Let the per-process security policy check pass. |-| `kernel-boot-cred_label_update_execve` + `kernel-boot-hook_cred_label` | Grant the platform label and retarget the MACF hook to that handler; the handler is dead code without the hook. |-| `kernel-boot-amfi_trustcache` + `kernel-boot-amfi_execve` | Admit the re-signed debugserver should it run outside the image's trust cache. |-| `txm-boot-developer_mode_bypass` | Report developer mode on, without enrolment. |-| `txm-cfw-debugger_entitlement` | Pass selector 42's (debug memory mapping) debugger entitlement check. |-| `txm-boot-sel42_29` + `txm-cfw-get_task_allow` | Set the target's get-task-allow byte where selectors 42 and 41 read it. |--The rest of `kernel.base`/`kernel.cfw` and TXM's signature-admission patches stay-off: the resealed image's trust cache admits everything it runs. `standard`-already turns on every kernel and TXM patch above and installs its debugserver-with `cfw install`, so the feature is not offered there.--To make this selectable without a preset of its own, `minimal` now names the two-kernel sets and selects nothing from them. The pipeline builds a kernel patcher-only when the plan turns on a patch from those sets (the research board's kext-mix targets the kernelcache too, so the target alone does not say), so a plain-`minimal` kernel stays stock. `watchos` does not name them: the feature is untried-on a watch kernel. A feature is only a list of patch identifiers: turning it on is-`--allow` for each, and `fw patches` reports it (`features` in `--json`, with-`available` for the active preset) so Launchpad's patch sheet offers one box-without declaring a patch itself. On an installed `minimal` VM a kernel patch is-reported as delivered by a restore, not by `cfw update-kernel`, which refuses a-VM whose system was customised before its restore.+| Part | `minimal` / `watchos` | HomePod (`cfw install`) | Why |+| --- | --- | --- | --- |+| debugserver | `filesystem-exp-debugserver` | `system-debugserver-cfw-install` | The re-signed debugserver. |+| launchd | `filesystem-exp-launchd_jetsam_panic_guard` | `system-launchd-boot-jetsam_panic_guard_bypass` | See below. |+| kernel | `kernel-cfw-task_for_pid`, `kernel-boot-task_conversion_eval`, `kernel-cfw-debugger`, `kernel-boot-port_to_map`, `kernel-boot-proc_security_policy`, `kernel-boot-cred_label_update_execve` + `kernel-boot-hook_cred_label` | already in the preset | Task port for a process the caller does not own, and its conversion; the debugger gate `task_for_pid` checks; no panic converting the port to a vm_map; the per-process policy; the platform label and the MACF hook that reaches it. |+| TXM | `txm-boot-developer_mode_bypass`, `txm-cfw-debugger_entitlement`, `txm-boot-sel42_29` + `txm-cfw-get_task_allow` | already in the preset | Developer mode on without enrolment; selector 42's debugger entitlement check; the target's get-task-allow byte where selectors 42 and 41 read it. |++A part names one patch per delivery, and a preset takes the first its sets+declare. `standard` already has every part, so Launchpad offers no box there. The+Apple TV presets get none either: `cfw install` refuses debugserver and launchd+patches not validated for tvOS (`FirmwareGuestPatchResolution`), and the feature+checks that list. HomePod's list now admits the two, as validated below.++**AMFI patches are not needed.** `kernel-boot-amfi_trustcache` and+`kernel-boot-amfi_execve` were in the first cut "should debugserver run outside+the image's trust cache". It doesn't: the re-sign is in the resealed trust cache.+An iPhone17,3 26.5 `minimal` guest without them launches the re-signed+debugserver from launchd and attaches.++**launchd's jetsam guard.** With developer mode on, the host's CoreDevice (a+`minimal` guest pairs with the Mac over the NAT) mounts Xcode's personalized+Developer disk image whenever a developer service needs it, for example+`xcrun devicectl device info processes`. `MobileStorageMounter` mounts+`Xcode_iOS_DDI`, launchd loads its daemons, and launchd kills init:+`initproc exited -- ... jetsam property category (Daemon) is not initialized`.+Observed on the first boots of an iPhone guest without the patch (and in an+earlier `minimal-ctf` machine's log). `standard` avoids it with+`system-launchd-boot-jetsam_panic_guard_bypass`; on `minimal` launchd is in the+sealed system, so `filesystem-exp-launchd_jetsam_panic_guard` applies the same+`CustomFirmwareJetsamPatcher` change in the merge. With it, the same+`devicectl` call mounts the DDI, `dtappserviced` starts, and the guest stays up.+On HomePod, launchd is patched for the persona adapter, which returned before+the jetsam verb; `cfw install` now applies both to the one copy.++To make the feature selectable without a preset of its own, `minimal` and+`watchos` name the two kernel sets and select nothing from them. The pipeline+builds a kernel patcher only when the plan turns on a patch from those sets (the+research board's kext mix targets the kernelcache too, so the target alone does+not say), so a plain `minimal` kernel stays stock. A feature is only a list of+patch identifiers: turning it on is `--allow` for each, and `fw patches` reports+it (`features` in `--json`, with `available` and the patches for the active+preset) so Launchpad's patch sheet offers one box without declaring a patch+itself. On an installed `minimal` VM a kernel patch is reported as delivered by+a restore, not by `cfw update-kernel`, which refuses a VM whose system was+customised before its restore.++Validation (Launchpad `vm create` with the feature's patches allowed, then a+launchd job running `/usr/libexec/debugserver 0.0.0.0:<port> --attach=<configd>`+and LLDB over gdb-remote: attach, `(int)getpid()` evaluated in the target, 16+bytes of its code read):++| Guest | Preset | Kernel and TXM | Result |+| --- | --- | --- | --- |+| iPhone17,3 26.5 (23F77) / cloudOS 26.5 (23F75) | `minimal` | 22 kernelcache (2 base + 20 cfw) and 9 TXM records | developer mode `enabled`; attach to configd in 6.8 s; DDI mounted by `devicectl`, no panic |+| Watch7,18 26.4 (23T240) / cloudOS 26.4 (23E244) | `watchos` | 22 kernelcache (2 base + 20 cfw) and 9 TXM records on the watch mix | developer mode `enabled`; attach to configd in 10.3 s; the watch is not paired with the Mac, so no host DDI mount |+| AudioAccessory5,1 27.0 (24J361) / cloudOS 26.4 (23E5207q) | `homepod-mini` | preset's own | attach to configd in 4.3 s; Xcode has no DDI for its board |On an iOS 18 guest several of these patches are found only by the iOS 18 kernel-and TXM finders (`feature/ios18-standard`).+and TXM finders (`feature/ios18-standard`); not run here.diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcher.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcher.swiftindex 50c3852d..e2e0844b 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcher.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcher.swift@@ -108,6 +108,7 @@ public final class CryptexFilesystemPatcher: BufferedPatcher {(FirmwareRestoreImagePatchSet.virtualBluetooth, "Enable LE connections over the virtual Bluetooth controller"),(FirmwareRestoreImagePatchSet.watchAudio, "Install the virtio sound HAL plugin for a watch"),(FirmwareRestoreImagePatchSet.debugserver, "Re-sign debugserver so it can attach in the guest"),+ (FirmwareRestoreImagePatchSet.launchdJetsam, "Patch launchd's jetsam panic guard"),]@discardableResult@@ -228,6 +229,10 @@ public final class CryptexFilesystemPatcher: BufferedPatcher {print("- Re-signing debugserver for in-guest attach…")try patchDebugserver(targetMount: targetMount)}+ if gate.isEnabled(FirmwareRestoreImagePatchSet.launchdJetsam) {+ print("- Patching launchd's jetsam panic guard…")+ try patchLaunchdJetsam(targetMount: targetMount)+ }try removeHostEventLog(mount: targetMount)}diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcherGuestPayload.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcherGuestPayload.swiftindex 3e349030..e8689df6 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcherGuestPayload.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcherGuestPayload.swift@@ -49,6 +49,24 @@ extension CryptexFilesystemPatcher {}}+ /// The launchd change `cfw install` makes for+ /// `system-launchd-boot-jetsam_panic_guard_bypass` (``CustomFirmwareJetsamPatcher``),+ /// in the pre-reseal merge. Re-signed ad hoc over its own entitlements, so+ /// the new hash lands in the regenerated trust cache.+ func patchLaunchdJetsam(targetMount: String) throws {+ try editGuestFile("sbin/launchd", targetMount: targetMount, mode: 0o755) { file in+ try thinToArm64e(file)+ try CustomFirmwareJetsamPatcher.patch(fileAt: file, log: { print(" \($0)") })+ try setMode(0o755, at: file)++ try VPhoneSigner.sign(+ fileAt: file,+ options: guestSigningOptions(identifier: "com.apple.xpc.launchd"),+ )+ }+ print(" [+] Patched launchd's jetsam panic guard")+ }+func injectLaunchDaemons(targetMount: String) throws {let target = try VPhoneConfinedDirectory.pin(absolutePath: targetMount)let source = resources.guestResources.appendingPathComponent("vphoned.plist")@@ -266,6 +284,9 @@ extension CryptexFilesystemPatcher {return}try editGuestFile(relative, targetMount: targetMount, mode: 0o755) { file in+ // A watch's debugserver also carries an arm64_32 slice, which the+ // signer cannot rewrite; the guest runs the arm64e one.+ try thinToArm64e(file)guard let source = try VPhoneSigner.entitlements(ofFileAt: file).first(where: { !$0.isEmpty }) else {throw VPhonePatchKit.PatcherError.patchVerificationFailed("debugserver has no readable entitlements; cannot grant task_for_pid",diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestPatchResolution.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestPatchResolution.swiftindex 8e9cd3bf..ac6a980f 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestPatchResolution.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestPatchResolution.swift@@ -69,6 +69,8 @@ public enum FirmwareGuestPatchResolution {FirmwareGuestSystemPatchSet.installCoordinationPersona,FirmwareGuestSystemPatchSet.homePodAdHocInstall,FirmwareGuestSystemPatchSet.virtioSoundDriver])+ // Userspace debugging: debugserver attached on a HomePod Software 27.0 guest.+ .union(["system-debugserver-cfw-install", "system-launchd-boot-jetsam_panic_guard_bypass"]).union(FirmwarePatchSetCatalog.tvOS27UserlandPatches)public static func unvalidatedHomePodGuestPatches(enabled: Set<String>) -> [String] {diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwarePatchFeature.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwarePatchFeature.swiftindex 141979eb..474792e6 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwarePatchFeature.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwarePatchFeature.swift@@ -14,23 +14,48 @@ public struct FirmwarePatchFeature: Sendable, Hashable, Identifiable {public let identifier: Stringpublic let title: Stringpublic let summary: String- /// The patches the feature turns on, by identifier.- public let patches: Set<String>+ /// What the feature turns on, one entry per part. Most parts are one patch;+ /// a part that presets deliver in different ways lists each patch that does+ /// it, and a preset takes the first one its sets declare.+ public let parts: [[String]]public var id: String {identifier}- /// Whether `preset` can carry this feature: it names every set that- /// declares one of its patches, so `--allow` for each resolves. A preset- /// without one of those sets cannot turn the feature on at all.- public func isAvailable(in preset: VPhonePatchPreset) -> Bool {+ /// Every patch any preset could take for the feature.+ public var allPatches: Set<String> {+ Set(parts.flatMap(\.self))+ }++ /// The patches `preset` turns on for the feature, or nil when it cannot+ /// carry it: some part has no patch in a set the preset names, so `--allow`+ /// would not resolve, or `cfw install` would refuse one of them on the+ /// preset's tvOS-family guest (``FirmwareGuestPatchResolution``).+ public func patches(in preset: VPhonePatchPreset) -> Set<String>? {let named = Set(preset.patchSets.map(\.identifier))- return patches.allSatisfy { patch in- FirmwarePatchSetCatalog.bundled.contains { set in- named.contains(set.identifier) && set.patches.contains { $0.identifier == patch }- }+ let declared = Set(FirmwarePatchSetCatalog.bundled.filter { named.contains($0.identifier) }+ .flatMap(\.patches).map(\.identifier))+ var result: Set<String> = []+ for part in parts {+ guard let patch = part.first(where: declared.contains) else { return nil }+ result.insert(patch)+ }+ let refused: [String] = switch preset.identifier {+ case VPhonePatchPreset.homePodMiniIdentifier:+ FirmwareGuestPatchResolution.unvalidatedHomePodGuestPatches(enabled: result)+ case VPhonePatchPreset.tvOSIdentifier:+ FirmwareGuestPatchResolution.unvalidatedTVGuestPatches(enabled: result)+ case VPhonePatchPreset.tvOS4KIdentifier:+ FirmwareGuestPatchResolution.unvalidatedTVGuestPatches(enabled: result, arm64eUserland: true)+ default:+ []}+ return refused.isEmpty ? result : nil+ }++ public func isAvailable(in preset: VPhonePatchPreset) -> Bool {+ patches(in: preset) != nil}}@@ -39,9 +64,17 @@ extension FirmwarePatchSetCatalog {/// guest and read its memory, and no more. `minimal` restores a resealed/// system onto a stock kernel and TXM; this adds:///- /// - `filesystem-exp-debugserver`: re-signs the guest's debugserver with- /// `task_for_pid-allow` and no sandbox profile, before the reseal, so its- /// new hash lands in the regenerated trust cache.+ /// - A debugserver re-signed with `task_for_pid-allow` and no sandbox+ /// profile: `filesystem-exp-debugserver` re-signs it before the reseal,+ /// so its new hash lands in the regenerated trust cache; a preset that+ /// installs the guest with `cfw install` takes+ /// `system-debugserver-cfw-install` instead (HomePod and the Apple TV+ /// presets leave it off).+ /// - launchd's jetsam panic guard, bypassed (`filesystem-exp-launchd_jetsam_panic_guard`+ /// before the reseal, `system-launchd-boot-jetsam_panic_guard_bypass` with+ /// `cfw install`). With developer mode on, MobileStorageMounter mounts the+ /// Developer disk image, and launchd kills init over its daemons+ /// ("jetsam property category (Daemon) is not initialized")./// - `kernel-cfw-task_for_pid` returns a task port for a process the caller/// does not own, and `kernel-boot-task_conversion_eval` lets that port be/// converted.@@ -53,8 +86,6 @@ extension FirmwarePatchSetCatalog {/// - `kernel-boot-cred_label_update_execve` grants the platform label and/// `kernel-boot-hook_cred_label` retargets the MACF hook to that handler;/// the handler is dead code without the hook.- /// - `kernel-boot-amfi_trustcache` and `kernel-boot-amfi_execve` admit the- /// re-signed debugserver should it run outside the image's trust cache./// - `txm-boot-developer_mode_bypass` reports developer mode on. On a TXM/// device AMFI asks TXM, and kills the re-signed debugserver without it/// ("Developer mode is disabled, task_for_pid-allow is disallowed");@@ -66,28 +97,29 @@ extension FirmwarePatchSetCatalog {/// debugged (Research/Firmware/txm_jb_patches.md).////// The rest of the kernel sets, and TXM's signature-admission patches, stay- /// off: the resealed image's own trust cache admits everything it runs.- /// `standard` and its relatives install their debugserver with- /// `cfw install` instead and already carry these kernel and TXM patches.+ /// off: the resealed image's own trust cache admits everything it runs,+ /// the re-signed debugserver included, so AMFI's trust cache and execve+ /// patches are not needed (an iPhone17,3 26.5 guest attached without them).+ /// `standard` and its relatives turn every part on already, so the editor+ /// offers no box there.public static let userspaceDebugging = FirmwarePatchFeature(identifier: "userspace-debugging",title: "Userspace debugging",summary: "A re-signed debugserver, and the kernel and TXM patches it needs to attach to any process in the guest and read its memory. The kernel and TXM stay otherwise stock.",- patches: [- FirmwareRestoreImagePatchSet.debugserver,- "kernel-cfw-task_for_pid",- "kernel-boot-task_conversion_eval",- "kernel-cfw-debugger",- "kernel-boot-port_to_map",- "kernel-boot-proc_security_policy",- "kernel-boot-cred_label_update_execve",- "kernel-boot-hook_cred_label",- "kernel-boot-amfi_trustcache",- "kernel-boot-amfi_execve",- "txm-boot-developer_mode_bypass",- "txm-cfw-debugger_entitlement",- "txm-boot-sel42_29",- "txm-cfw-get_task_allow",+ parts: [+ [FirmwareRestoreImagePatchSet.debugserver, "system-debugserver-cfw-install"],+ [FirmwareRestoreImagePatchSet.launchdJetsam, "system-launchd-boot-jetsam_panic_guard_bypass"],+ ["kernel-cfw-task_for_pid"],+ ["kernel-boot-task_conversion_eval"],+ ["kernel-cfw-debugger"],+ ["kernel-boot-port_to_map"],+ ["kernel-boot-proc_security_policy"],+ ["kernel-boot-cred_label_update_execve"],+ ["kernel-boot-hook_cred_label"],+ ["txm-boot-developer_mode_bypass"],+ ["txm-cfw-debugger_entitlement"],+ ["txm-boot-sel42_29"],+ ["txm-cfw-get_task_allow"],],)diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwarePatchSetCatalog.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwarePatchSetCatalog.swiftindex 61eaa2b8..719cb323 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwarePatchSetCatalog.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwarePatchSetCatalog.swift@@ -442,19 +442,13 @@ public enum FirmwarePatchSetCatalog {/// ``minimalPreset`` for an Apple Watch: its device tree presents the watch/// board. Its boot chain is stock too: a stock iBEC restores the guest and a/// stock LLB boots it to the pairing screen and vphoned (watchOS 26.4 23T240- /// on cloudOS 26.4 23E244, 2026-11-02). It does not name the kernel sets, so- /// ``userspaceDebugging``, untried on a watch kernel, is not offered.- /// The shipped `watchos.plist` must match this.+ /// on cloudOS 26.4 23E244, 2026-11-02). The shipped `watchos.plist` must+ /// match this.public static let watchOSPreset = VPhonePatchPreset(identifier: VPhonePatchPreset.watchOSIdentifier,title: "Apple Watch",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: [- .bundled(FirmwareBootChainPatchSet.identifier),- .bundled(FirmwareResearchBoardPatchSet.identifier),- .bundled(FirmwareDeviceTreePatchSet.identifier),- .bundled(FirmwareRestoreImagePatchSet.identifier),- ],+ patchSets: minimalPreset.patchSets,selection: .allow(watchOSDeviceTreePatches.union(FirmwareResearchBoardPatchSet.manifest.patches.map(\.identifier))diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareRestoreImagePatchSet.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareRestoreImagePatchSet.swiftindex 1df49780..8d97cb2d 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareRestoreImagePatchSet.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareRestoreImagePatchSet.swift@@ -35,12 +35,13 @@ public enum FirmwareRestoreImagePatchSet {public static let virtualBluetooth = "filesystem-exp-btvc_le_connection"public static let watchAudio = "filesystem-exp-watch_audio"public static let debugserver = "filesystem-exp-debugserver"+ public static let launchdJetsam = "filesystem-exp-launchd_jetsam_panic_guard"public static let digestRehash = "manifest-boot-digest_rehash"/// Patches a machine asks for by name (`--allow`, or a preset that lists them);/// `minimal` and `watchos` leave them off, so the plain presets stay a lifelike/// stock guest.- public static let optInPatches: Set = [debugserver]+ public static let optInPatches: Set = [debugserver, launchdJetsam]/// What `minimal` and `watchos` select from this set: everything but the/// opt-in patches.public static var presetPatches: Set<String> {@@ -111,6 +112,12 @@ public enum FirmwareRestoreImagePatchSet {summary: "Re-signs the guest's debugserver with task_for_pid-allow and no sandbox profile, before the reseal, so it can attach to a process in the guest. Off by default — a lifelike guest ships no debugger, and a stock userland carries debugserver only in the Developer disk image, where this is a no-op. On its own it does not run on minimal's stock kernel and TXM: turn on Userspace debugging, which adds the kernel and TXM patches it needs.",target: .firmware(.filesystem),),+ VPhonePatchDeclaration(+ identifier: launchdJetsam,+ title: "launchd jetsam panic guard",+ summary: "Patches launchd, before the reseal, so a daemon without jetsam properties does not panic the guest. Off by default. With developer mode on, MobileStorageMounter mounts the Developer disk image, and launchd's guard against its daemons kills init (\"jetsam property category (Daemon) is not initialized\"). The same change cfw install makes with system-launchd-boot-jetsam_panic_guard_bypass.",+ target: .firmware(.filesystem),+ ),VPhonePatchDeclaration(identifier: digestRehash,title: "Manifest digests",diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/PatchSets/FirmwarePatchSetCatalogTests.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/PatchSets/FirmwarePatchSetCatalogTests.swiftindex df499e17..3df96123 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/PatchSets/FirmwarePatchSetCatalogTests.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/PatchSets/FirmwarePatchSetCatalogTests.swift@@ -184,8 +184,8 @@ struct FirmwarePatchSetCatalogTests {// presets drop exactly the iOS ones an Apple TV has no port of.let tvPresets = [VPhonePatchPreset.homeViewIdentifier, VPhonePatchPreset.tvOSIdentifier, VPhonePatchPreset.tvOS4KIdentifier, VPhonePatchPreset.homePodMiniIdentifier]// `minimal` and `watchos` drop every boot chain patch, and- // `minimal` every kernel patch of the two sets it names only- // so a machine can turn some on: their system is customised+ // every kernel patch of the two sets they name only so a+ // machine can turn some on: their system is customised// before the restore instead, onto a stock kernel.let restoreImagePresets = [VPhonePatchPreset.minimalIdentifier, VPhonePatchPreset.watchOSIdentifier]let droppable = Set(@@ -307,52 +307,67 @@ struct FirmwarePatchSetCatalogTests {}@Test- func `Userspace debugging is offered on minimal alone, and adds exactly its own patches there`() throws {+ func `Userspace debugging resolves on every preset but Apple TV, taking the debugserver its sets deliver`() throws {let feature = FirmwarePatchSetCatalog.userspaceDebugginglet declared = Set(FirmwarePatchSetCatalog.allDeclarations.map(\.identifier))- #expect(feature.patches.isSubset(of: declared))+ #expect(feature.allPatches.isSubset(of: declared))+ let restoreImage = [VPhonePatchPreset.minimalIdentifier, VPhonePatchPreset.watchOSIdentifier]+ // cfw install refuses the debugserver and launchd patches on an Apple TV.+ let appleTV = [VPhonePatchPreset.tvOSIdentifier, VPhonePatchPreset.tvOS4KIdentifier]for preset in FirmwarePatchSetCatalog.builtInPresets {- #expect(- feature.isAvailable(in: preset) == (preset.identifier == VPhonePatchPreset.minimalIdentifier),- "\(preset.identifier)",- )- }-- for base in ["18.6.2", "26.4"] {- let minimal = try VPhonePatchPlan.resolve(- preset: FirmwarePatchSetCatalog.minimalPreset,- patchSets: FirmwarePatchSetCatalog.bundled,- iOSBase: VPhoneVersion(base),- cloudOS: VPhoneVersion("26.4"),- )- let debugging = try VPhonePatchPlan.resolve(- preset: FirmwarePatchSetCatalog.minimalPreset,+ if appleTV.contains(preset.identifier) {+ #expect(feature.patches(in: preset) == nil, "\(preset.identifier)")+ continue+ }+ let patches = try #require(feature.patches(in: preset), "\(preset.identifier)")+ let debugserver = restoreImage.contains(preset.identifier)+ ? FirmwareRestoreImagePatchSet.debugserver : "system-debugserver-cfw-install"+ #expect(patches.contains(debugserver), "\(preset.identifier)")+ #expect(patches.count == feature.parts.count, "\(preset.identifier)")+ // Allowing them resolves.+ _ = try VPhonePatchPlan.resolve(+ preset: preset,patchSets: FirmwarePatchSetCatalog.bundled,- iOSBase: VPhoneVersion(base),+ iOSBase: VPhoneVersion("26.4"),cloudOS: VPhoneVersion("26.4"),- allowed: feature.patches,+ allowed: patches,)- // Plain minimal keeps a stock kernel; the feature adds only its own.- let kernelSets = [FirmwareKernelBasePatchSet.manifest, FirmwareKernelCustomFirmwarePatchSet.manifest]- .flatMap { $0.patches.map(\.identifier) }- #expect(minimal.enabled.isDisjoint(with: kernelSets), "\(base)")- #expect(debugging.enabled.subtracting(minimal.enabled).isSubset(of: feature.patches), "\(base)")- #expect(debugging.enabled.union(debugging.skippedByVersion).isSuperset(of: feature.patches), "\(base)")+ }++ for preset in [FirmwarePatchSetCatalog.minimalPreset, FirmwarePatchSetCatalog.watchOSPreset] {+ let patches = try #require(feature.patches(in: preset))+ for base in ["18.6.2", "26.4"] {+ let plain = try VPhonePatchPlan.resolve(+ preset: preset,+ patchSets: FirmwarePatchSetCatalog.bundled,+ iOSBase: VPhoneVersion(base),+ cloudOS: VPhoneVersion("26.4"),+ )+ let debugging = try VPhonePatchPlan.resolve(+ preset: preset,+ patchSets: FirmwarePatchSetCatalog.bundled,+ iOSBase: VPhoneVersion(base),+ cloudOS: VPhoneVersion("26.4"),+ allowed: patches,+ )+ // The plain preset keeps a stock kernel; the feature adds only its own.+ let kernelSets = [FirmwareKernelBasePatchSet.manifest, FirmwareKernelCustomFirmwarePatchSet.manifest]+ .flatMap { $0.patches.map(\.identifier) }+ #expect(plain.enabled.isDisjoint(with: kernelSets), "\(preset.identifier) \(base)")+ #expect(debugging.enabled.subtracting(plain.enabled).isSubset(of: patches), "\(preset.identifier) \(base)")+ #expect(debugging.enabled.union(debugging.skippedByVersion).isSuperset(of: patches), "\(preset.identifier) \(base)")+ }}}@Test- func `Standard carries the kernel and TXM half of userspace debugging`() {- // So `standard`, which installs its own debugserver with `cfw install`,- // needs no feature box.+ func `Standard turns userspace debugging on whole, so no box is offered there`() throws {let preset = FirmwarePatchSetCatalog.standardPresetlet named = Set(preset.patchSets.map(\.identifier))let standard = Set(FirmwarePatchSetCatalog.bundled.filter { named.contains($0.identifier) }.flatMap(\.patches).map(\.identifier).filter { preset.selection.includes($0) })- let kernelAndTXM = FirmwarePatchSetCatalog.userspaceDebugging.patches- .subtracting([FirmwareRestoreImagePatchSet.debugserver])- #expect(kernelAndTXM.isSubset(of: standard), "\(kernelAndTXM.subtracting(standard).sorted())")- #expect(standard.contains("system-debugserver-cfw-install"))+ let patches = try #require(FirmwarePatchSetCatalog.userspaceDebugging.patches(in: preset))+ #expect(patches.isSubset(of: standard), "\(patches.subtracting(standard).sorted())")}@Testdiff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swiftindex 6dc2cf9e..1008a8cb 100644--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift@@ -2076,12 +2076,24 @@ struct VPhoneCustomFirmwareInstaller {// launchd needs a short load command; this alias is owned// only by HomePod's isolated installation compatibility.try installLibraryAlias(system: system, alias: "vp", target: library)+ // HomePod's launchd carries the persona adapter, so the+ // jetsam guard (userspace debugging) is patched into the+ // same copy rather than by the iPhone path below.+ let jetsam = on(launchdJetsam)try patchMachO(system: system, work: work, path: "sbin/launchd",+ verbs: jetsam ? ["patch-launchd-jetsam"] : [],preserveEntitlements: true, injectedDylibPath: "/vp")try system.writeFile(personaMarker, contents: Data("1\n".utf8), mode: 0o644, owner: Self.guestOwner)live.insert(personaPatch)print(" [+] \(personaPatch): installed scoped HomePod UserManager adapter")+ if jetsam {+ live.insert(launchdJetsam)+ print(" [+] \(launchdJetsam): patched into HomePod launchd")+ }} else {+ if on(launchdJetsam) {+ print(" [!] \(launchdJetsam): HomePod patches launchd only with \(personaPatch); skipped")+ }if try revertMachO(system: system, work: work, path: "sbin/launchd") {print(" [+] \(personaPatch): restored HomePod launchd from backup")} else if priorGuest.contains(personaPatch) {diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhonePatchCatalogReport.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhonePatchCatalogReport.swiftindex f8c6996c..168c3625 100644--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhonePatchCatalogReport.swift+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhonePatchCatalogReport.swift@@ -169,9 +169,11 @@ public struct VPhonePatchCatalogReport: Sendable {let identifier: Stringlet title: Stringlet summary: String+ /// The patches the active preset turns on for it; empty when it is not+ /// available.let patches: [String]- /// Whether the active preset names every set the feature draws on, so- /// allowing its patches resolves.+ /// Whether the active preset names a set for every part of the+ /// feature, so allowing its patches resolves.let available: Bool}@@ -304,7 +306,7 @@ public struct VPhonePatchCatalogReport: Sendable {identifier: $0.identifier,title: $0.title,summary: $0.summary,- patches: $0.patches.sorted(),+ patches: ($0.patches(in: activePreset) ?? []).sorted(),available: $0.isAvailable(in: activePreset),)},@@ -382,15 +384,17 @@ public struct VPhonePatchCatalogReport: Sendable {}let selected = selectedPatches()- let features = FirmwarePatchSetCatalog.features.filter { $0.isAvailable(in: activePreset) }+ let features = FirmwarePatchSetCatalog.features.compactMap { feature in+ feature.patches(in: activePreset).map { (feature, $0) }+ }if !features.isEmpty {lines.append("")lines.append("Features (turn one on by allowing each of its patches with `fw set-patches`):")- for feature in features {- let on = feature.patches.intersection(selected).count- let state = on == feature.patches.count ? "on" : on == 0 ? "off" : "\(on) of \(feature.patches.count) on"+ for (feature, patches) in features {+ let on = patches.intersection(selected).count+ let state = on == patches.count ? "on" : on == 0 ? "off" : "\(on) of \(patches.count) on"lines.append(" \(feature.identifier) — \(feature.title) (\(state))")- lines.append(" " + feature.patches.sorted().map { "--allow \($0)" }.joined(separator: " "))+ lines.append(" " + patches.sorted().map { "--allow \($0)" }.joined(separator: " "))}}diff --git a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/watchos.plist b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/watchos.plistindex dc38f77b..2580d94a 100644--- a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/watchos.plist+++ b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/watchos.plist@@ -12,6 +12,18 @@<key>Kind</key><string>Bundled</string></dict>+ <dict>+ <key>Identifier</key>+ <string>com.vphone.patchset.kernel.base</string>+ <key>Kind</key>+ <string>Bundled</string>+ </dict>+ <dict>+ <key>Identifier</key>+ <string>com.vphone.patchset.kernel.cfw</string>+ <key>Kind</key>+ <string>Bundled</string>+ </dict><dict><key>Identifier</key><string>com.vphone.patchset.research.board</string>diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadPreview.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadPreview.swiftindex f7b8938d..a50a39c4 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadPreview.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadPreview.swift@@ -147,6 +147,16 @@) { _ in }.environment(model)}+ // Minimal offers the Userspace debugging box; the one turned on.+ await standalone("09d-patch-settings-minimal", suffix, size: NSSize(width: 920, height: 680)) {+ VPhoneLaunchpadPatchSettingsView(+ initial: VPhoneLaunchpadPatchSelection(+ preset: VPhoneLaunchpadPatchSelection.minimalPreset,+ allowed: ["filesystem-exp-debugserver", "kernel-cfw-debugger"],+ ),+ ) { _ in }+ .environment(model)+ }await sheet(.clone(labMachine), "10-clone", suffix)await sheet(.snapshots(labMachine), "10a-snapshots", suffix)await sheet(.snapshots(path("research-01")), "10b-snapshots-running", suffix)@@ -397,6 +407,8 @@static func patchCatalog(preset: String?, machine: Bool = false) -> VPhoneLaunchpadPatchCatalog? {let active = preset ?? "standard"let frida = active == "experimental"+ // Minimal leaves the kernel stock and offers userspace debugging.+ let minimal = active == "minimal"let blocked = machine ? #"["kernel-cfw-debugger","dyld-cfw-camera"]"# : "[]"let records = machine ? #""installed":true,"receiptRecorded":true,"pendingPatches":2,"# : ""func pending(_ part: String, _ value: Bool = false) -> String {@@ -415,12 +427,17 @@{"activePreset":"\(active)","blockedPatches":\(blocked),"allowedPatches":[],\(records)"presets":[{"identifier":"standard","title":"Standard","summary":"The patches every vphone VM needs to boot custom firmware, with a working display and camera.","patchSets":[]},- {"identifier":"experimental","title":"Experimental","summary":"Every patch this bundle declares, including the Frida Stalker relaxations.","patchSets":[]}+ {"identifier":"experimental","title":"Experimental","summary":"Every patch this bundle declares, including the Frida Stalker relaxations.","patchSets":[]},+ {"identifier":"minimal","title":"Minimal","summary":"A stock boot chain, kernel and TXM.","patchSets":[]}+ ],+ "features":[+ {"identifier":"userspace-debugging","title":"Userspace debugging","summary":"A re-signed debugserver, and the kernel and TXM patches it needs to attach to any process in the guest and read its memory.","patches":["filesystem-exp-debugserver","kernel-cfw-debugger"],"available":\(minimal)}],"patches":[{"identifier":"avpbooter-boot-dgst_bypass","title":"AVPBooter digest bypass","summary":"Accepts the resealed boot images instead of the stock digests.","patchSet":"com.vphone.patchset.bootchain","patchSetName":"Boot Chain","target":"AVPBooter","applicability":"any","bootEssential":true,"inPreset":true,"enabled":true\(pending("AVPBooter"))},{"identifier":"ibss-cfw-serial_label","title":"iBSS serial label","summary":"Tags iBSS serial output so the boot log names its stage.","patchSet":"com.vphone.patchset.bootchain","patchSetName":"Boot Chain","target":"iBSS","applicability":"any","bootEssential":false,"inPreset":true,"enabled":true\(pending("iBSS"))},- {"identifier":"kernel-cfw-debugger","title":"Kernel debugger gate","summary":"Lets a debugger attach to any process in the guest.","patchSet":"com.vphone.patchset.kernel.base","patchSetName":"Kernel Base","target":"kernelcache","applicability":"any","bootEssential":false,"inPreset":true,"enabled":true\(pending("kernelcache", true))},+ {"identifier":"kernel-cfw-debugger","title":"Kernel debugger gate","summary":"Lets a debugger attach to any process in the guest.","patchSet":"com.vphone.patchset.kernel.base","patchSetName":"Kernel Base","target":"kernelcache","applicability":"any","bootEssential":false,"inPreset":\(!minimal),"enabled":\(!minimal)\(pending("kernelcache", true))},+ {"identifier":"filesystem-exp-debugserver","title":"debugserver","summary":"Re-signs the guest's debugserver before the reseal.","patchSet":"com.vphone.patchset.restore.image","patchSetName":"Restore Image","target":"Filesystem","applicability":"any","bootEssential":false,"inPreset":false,"enabled":false\(pending("Filesystem"))},{"identifier":"kernel-boot-thread_guard_violation","title":"Thread guard violation","summary":"Stops the guard exception the older kernels raise on first boot.","patchSet":"com.vphone.patchset.kernel.base","patchSetName":"Kernel Base","target":"kernelcache","applicability":"iOS 18.x","bootEssential":true,"inPreset":true,"enabled":true\(pending("kernelcache"))},{"identifier":"kernel-exp-frida_thread_set_state_entitlement_flag","title":"Frida thread state entitlement","summary":"Lets Stalker set thread state without the entitlement the kernel asks for.","patchSet":"com.vphone.patchset.kernel.frida","patchSetName":"Frida Stalker","target":"kernelcache","applicability":"cloudOS 26.4+","bootEssential":false,"inPreset":\(frida),"enabled":\(frida)\(pending("kernelcache"))},{"identifier":"kernel-exp-frida_vm_map_delete_immutable_code","title":"Frida immutable code unmap","summary":"Allows Stalker to unmap the immutable code it rewrote.","patchSet":"com.vphone.patchset.kernel.frida","patchSetName":"Frida Stalker","target":"kernelcache","applicability":"cloudOS 26.4+","bootEssential":false,"inPreset":\(frida),"enabled":\(frida)\(pending("kernelcache"))},