Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

experiment: bridge iOS 16 startup to SpringBoard run loop

黑曜猫23337dc804f3
diff --git a/Research/0_binary_patch_comparison.md b/Research/0_binary_patch_comparison.md
index f089ed23..b1681465 100644
--- a/Research/0_binary_patch_comparison.md
+++ b/Research/0_binary_patch_comparison.md
@@ -6000,3 +6000,217 @@ Existing older-userland SwapEnd, thread-guard and paravirtual-user-client patch
gates and the BSD-only Skywalk boot argument are enabled for this experiment.
The iOS 17 SpringBoard workaround remains gated to 17 until 16's own startup
blockers are measured. No boot or display success is claimed at this stage.
+
+First normal boot exits PID 1 with "could not set up inheritance port".
+The 20G81 launchd calls `_mach_ports_register` at 0x10001682C and branches
+on error at 0x100016830 to the fatal string block at 0x100016958.
+XNU 12377.41.6 `osfmk/mach/task.defs` uses three inline port descriptors for
+task RPCs 3403/3404; the 16.x public API still sends an OOL port array.
+Opt-in `system-launchd-exp-ios16_mach_ports` installs a marker that selects
+register/lookup translation in launchdhook and SystemHook. MIG generates the
+two modern client messages; the existing kobject Mach-message transport sends
+them. No launchd or kernel instruction is skipped. Removing the marker and
+restarting returns to the native APIs. A native self-task round-trip passes;
+guest console confirms register3 succeeds and launchd completes early boot.
+
+The next failure precedes inserted-library constructors: libxpc's initializer
+calls `_mach_ports_lookup` at 0x1E6ECBCA4 and traps in cold.6 at 0x1E6EE647C.
+New opt-in `dyld-exp-ios16_mach_ports_lookup` rewrites only the bounded
+388-byte client at 0x1C5FFC078 in libsystem_kernel. The generated ARM64 payload
+decodes the modern fixed-three-descriptor reply and allocates the old public
+port array. Existing PC-relative request instructions stay in place; saved
+registers keep their FP-relative unwind locations. Reply IDs, sizes and port
+dispositions are checked, and transport/allocation errors retain cleanup.
+Page hashes are re-attested; the normal dyld undo log restores original bytes
+on opt-out. Initial real-cache dry run resolves the site and fits exactly;
+normal-boot validation is pending.
+
+The cache client passes a real boot: libxpc initializes, services spawn and
+vphoned answers RPC. All 70 patch-model tests pass. Offline application,
+idempotence and undo were checked against a full cache copy; the affected
+chunk matches its pristine input byte-for-byte after undo, including hashes.
+SpringBoard now waits on backboardd, whose startup queue waits in
+`_DMPerformMigration` at +300. The migrator itself waits while PreBoard runs;
+SEP keybag errors appear on serial. Opt-in
+`system-backboard-exp-ios16_migration` injects a process/version-scoped library
+into backboardd. The measured method is DMClientAPIController's
+`_migrateWithConnection:checkNecessity:lastRelevantPlugin:testMigrationInfrastructureOnly:`
+with encoding `B40@0:8@16B24@28B36`; the lab hook returns YES to release only
+this startup wait. It does not unlock the keybag or mark global migration
+complete. Removal restores the backed-up executable and removes its library.
+This is a fresh-lab desktop experiment, not general data-migration support.
+
+The non-waiting system-shell check-in releases SpringBoard's
+FBSystemShellInitialize. Its next main-thread wait is MediaExperience's system
+controller because mediaserverd repeatedly exits before main with
+OS_REASON_EXEC/EXEC_EXIT_REASON_SECURITY_POLICY (8). Two temporary copies
+isolate the failure: re-signing with the complete original entitlements still
+gets SIGKILL; removing only `seatbelt-profiles` reaches executable code and
+then aborts when its unmanaged probe cannot register the real service's XPC
+endpoints. New opt-in `system-mediaserver-exp-ios16_profile` re-signs only
+mediaserverd without this legacy profile entitlement, preserving its remaining
+entitlements and its pristine backup. This deliberately removes that guest
+service's sandbox profile in a fresh experimental VM; it is not a sandbox
+compatibility implementation. Opt-out restores the original signed binary.
+
+The managed media daemon next aborts before dyld maps images:
+LIBIGNITION (35), code 2, "failed to close filesystem [optional]: fd = 3: 1".
+The actual installed binary and original UUIDs were inspected on a stopped,
+read-only disk mount. The 20G81 standalone dyld's `_closefd_optional` at
+0x671A8 calls close at 0x671D8, branches to its fatal path at 0x67200 on any
+error, and reports exactly this message. New opt-in
+`system-dyld-exp-ios16_closefd` rewrites only that bounded 60-byte cold block:
+EPERM on FD 3 returns through the existing cleanup; all other errors and FDs
+retain ignition_halt with the original reason, errno, flags and diagnostic.
+It leaves that optional descriptor open rather than defeating its kernel guard.
+The payload uses native encoders, is byte-idempotent on the real dyld, and is
+restored from the standard executable backup on opt-out. Guest retest pending.
+
+The standalone-only guest test still reaches the same ignition abort. The
+shared cache also contains `/usr/lib/dyld`; its `_closefd_optional` resolves to
+0x1A66361A8 and the cold block to 0x1A6636200. Paired opt-in
+`dyld-exp-ios16_closefd` applies the same native payload builder there and
+records the 60 original bytes in the normal cache undo log. Real-cache apply,
+idempotence and undo pass; chunk .11 is identical to pristine after undo.
+A Capstone-driven guard check confirms only FD 3/EPERM reaches the optional
+return; FD 0/4 with EPERM and FD 3 with errno 0/2/9 retain the fatal path.
+
+The paired guest test advances past FD 3 and now reports the same EPERM while
+closing the optional OS cryptex FD 5. The compatibility guard is therefore
+expanded to optional descriptors >=3 on EPERM; stdin/stdout/stderr and every
+other errno retain the native failure. The kernel's close guard remains in
+force, and these optional boot descriptors remain open. This avoids special
+casing a series of filesystem/cryptex handles by arbitrary assigned numbers.
+
+The next real boot passes optional filesystem and OS cryptex closes, and now
+fails on the mandatory shared-cache FD 7. The same shape-checked, 60-byte cold
+handler is applied to both `_closefd_optional` (cold +0x58) and `_closefd`
+(cold +0x54), with their distinct native success returns. This remains limited
+to dyld's boot-resource helpers, EPERM and descriptors above stderr; it does not
+change the general close syscall. Both sites are validated before cache writes.
+The exact-symbol mode added to MachOParser prevents `_closefd` from matching
+`_closefd_optional` by substring. The two original runs and hashes remain
+reversible through the normal backup/undo mechanisms.
+
+With both close helpers adapted, mediaserverd reaches SIGABRT in early process
+initialization instead of LIBIGNITION. No post-initialization hook trace appears.
+An explicit weak load of SystemHook is included in the experimental media-profile
+selection. A temporary C++ throw interposer interfered with other guest services
+and was removed. A speculative platform/no-container/no-sandbox entitlement
+test was also reverted. Native exception-port tracing instead locates the
+pre-constructor failure. No iOS 16 desktop success is claimed yet.
+
+The native inherited EXC_CRASH port captures the actual early media abort:
+`abort <- cc_abort <- ccrng_getentropy_generate <- ccrng_process_init <-
+arc4random_buf <- libobjc initialization`. The 20G81 function at 0x1E6E30FF0
+calls getentropy at +0x34, branches on -1 at +0x3C, and aborts at +0x68.
+An independent native C probe successfully calls getentropy and arc4random_buf
+as both UID 0 and UID 501, so the entropy provider is present; the failure is
+specific to the service's execution policy. Existing research notes document
+that `kernel-boot-syscallmask` misses some per-process filters.
+
+The existing opt-in `kernel-exp-frida_syscall_filter_off` is now structurally
+verified on the actual 23B85/vphone600 original: trap accessor 0xB3E1D0,
+kobject accessor 0xB3E260, MACF Unix syscall check 0x12D0640. All three are unique
+and pass the native prologue checks; the offline run emits six records. Only
+this existing Frida declaration gains cloudOS 26.1 applicability; the other
+Frida relaxations retain 26.4+. Standard remains off. Guest validation pending.
+The unsuccessful temporary C++ throw interposer and speculative extra media
+entitlements have been removed; the native crash observer is diagnostic only.
+
+The crashing media thread's measured 20G81 `__error` TLS layout reports errno 1
+(EPERM). A probe signed with the same retained media entitlements still passes
+getentropy/arc4random as UID 501. The first kernel test only changed the restore
+tree and therefore did not exercise the new patch: normal boot loads Preboot.
+`cfw update-kernel` then re-patched from FirmwareOriginals and replaced the actual
+43,997,230-byte Preboot IMG4 while preserving its manifest and every data volume.
+That replacement is the kernel validation boundary for the next boot.
+
+With the filter change actually in Preboot, `keybagd --init` can execute its
+fatal-path reboot instead of merely logging it. 20G81 lacks the newer MKB
+keybag-less platform path. Its main at 0x100015864 already has an alternative:
+the call to `os_variant_uses_ephemeral_storage` at 0x100015C4C exits successfully
+before loading a system bag. The new opt-in `system-keybag-exp-ios16_ephemeral`
+weak-loads SystemHook and installs its own marker; a C interposer selects that
+native path only for keybagd, exactly `--init`, and its exact subsystem string.
+The manifest is limited to iOS 16.6/cloudOS 26.1 and the firmware preparer still
+limits this experiment to 16.6.1/20G81. All bundled presets leave it off. Opt-out
+restores the executable backup and removes the marker. It does not create keys,
+unlock a bag, or enable passcodes. Guest validation is pending.
+
+The ephemeral keybag path passes on the real guest. mediaserverd now passes
+corecrypto and reaches its constructor, confirming the live syscall-filter
+change removes its entropy EPERM. It later crashes in CFDictionaryGetValue(NULL)
+from FigNotificationListenerStartNotifications while launchd logs denied Mach
+lookups and IOUserClient sandbox failures for that service. The media-profile
+experiment now explicitly grants platform/no-container/no-sandbox booleans along
+with removing seatbelt-profiles, retaining all other original entitlements.
+Unlike the earlier reverted attempt, this test uses the patched Preboot kernel.
+The privilege expansion is isolated to the opt-in media patch, remains guest-only,
+and reverses through the executable backup. Validation pending.
+
+The added media boolean entitlements are confirmed in the pulled guest executable
+but do not change its sandbox denials or null notification dictionary crash, so
+that speculative expansion is removed again. Restoring the original executable
+with its mediaserverd seatbelt profile still produces EXEC namespace 9/code 8.
+SpringBoard's measured main-thread wait is specifically -[AVSystemController init]
+-> FigSystemControllerRemoteCreate -> synchronous XPC. The new opt-in
+system-springboard-exp-ios16_desktop weak-loads a separate, process/version-scoped
+library that returns nil from the measured @16@0:8 init method. This targets a
+desktop-only experiment; it does not claim working audio. All presets leave it
+off, and the original SpringBoard is restored by deselection. Validation pending.
+
+The first desktop-library test did not load the library: remote TASK_DYLD_INFO
+shows only SystemHook, and the pulled SpringBoard has no custom weak load. The
+later MISFix cleanup restored SpringBoard from the shared backup; its exception
+only preserved the iOS 17 desktop selection. That preservation condition now
+also covers the iOS 16 desktop selection. The native probe confirms the actual
+guest reports 16.6.1 and AVSystemController init has encoding @16@0:8.
+
+With the weak load preserved, SpringBoard passes AVSystemController startup and
+blocks building home icons in CHSWidgetDescriptorProvider's
+_lock_loadContentInitiallySynchronouslyIfNecessary. This differs from the iOS 17
+class name. A native guest probe confirms its v16@0:8 method encoding; the iOS 16
+desktop library now skips only that synchronous descriptor fetch. No functioning
+widget content is claimed.
+
+The widget guard passes: SpringBoard reaches CoverSheet construction, then waits
+in FigFlashlightRemoteCreate. The guest probe confirms AVFlashlight init @16@0:8
+and +hasFlashlight B16@0:8; the iOS 16 desktop library now returns nil/NO for these
+unavailable physical-light paths. Temporary inherited exception/signal traces,
+forced launchd console/lifecycle logging and vphoned console redirection have
+been removed. The task-port bridge retains only selected API translation.
+
+After the flashlight guard, SpringBoard reaches its main run loop but the
+Control Center Now Playing module synchronously creates a media routing context.
+Its original Info.plist identifies com.apple.mediaremote.controlcenter.nowplaying.
+The desktop library now wraps CCUIModuleInstanceManager's
+_instantiateModuleWithMetadata: and returns nil only for that exact module ID,
+forwarding every other module to its original implementation. Signature checked.
+Both dyld descriptor-close patches have been deselected and their two cached
+60-byte records and standalone dyld backup restored successfully; the guest still
+boots, confirming those EPERM workarounds are unnecessary with the live filter fix.
+
+Skipping Now Playing removes that stack. The next main-queue task comes from
+MediaControlsAudioModule, which creates the same unavailable route context via
+MRAVEndpointGetLocalEndpoint. Its original bundle ID is
+com.apple.mediaremote.controlcenter.audio; the same wrapper now omits that exact
+second media module as well. Backboardd's main thread is in its normal run loop.
+
+The second guard removes that task as well; the next stack constructs the
+system mirroring context from MediaControls and CCUIContentModuleContainerViewController.
+The original AirPlayMirroringModule ID is
+com.apple.mediaremote.controlcenter.airplaymirroring. It is the third and final
+mediaremote Control Center module in this IPSW; the wrapper now omits these three
+exact IDs. All other modules still call their original factory.
+
+All three media-module guards pass: SpringBoard's main thread is now in
+CFRunLoopRunSpecific/UIApplicationMain, with no synchronous startup blocker.
+Visual verification is pending because the host Mac is locked; the user has
+been asked to unlock it. A generic guest unlock request reports passcode_enabled
+on this fresh, keybag-less lab; no user passcode was provisioned and no passcode
+is guessed. Earlier dyld-close/media-profile experiment implementations have
+been archived outside the source tree and removed from the final declarations,
+presets and installer after successful opt-out restoration. Their unrelated
+encoder/parser additions are also reverted. Only measured startup compatibility
+remains in the source tree. No iOS 16 desktop display success is claimed yet.
diff --git a/Research/Guest/ios16_bringup.md b/Research/Guest/ios16_bringup.md
index 677cef50..b150555f 100644
--- a/Research/Guest/ios16_bringup.md
+++ b/Research/Guest/ios16_bringup.md
@@ -1,7 +1,14 @@
# Local iOS 16.6.1 bring-up experiment
-Status: original IPSW restored; guest custom-firmware installation and normal
-boot are still under investigation. No desktop success is claimed yet.
+Status: original IPSW restored and guest custom firmware installed. Launchd,
+libxpc, backboardd and vphoned run. SpringBoard now reaches its main run loop;
+its unavailable media controllers, widget fetch, flashlight and three media
+Control Center modules have been bypassed. The latest main-thread sample is
+idle in CFRunLoopRunSpecific/UIApplicationMain. Desktop display has not been
+verified: the computer-use tool reports the host Mac is locked, and the user
+has been asked to unlock it. The actual Preboot kernel contains the measured
+syscall-filter relaxation. The original media executable is restored, and both
+temporary dyld close patches are undone and removed from the final source.
- Guest: iPhone 14 Pro, iPhone15,2/d73ap, 1179x2556 at 3x.
- Userland: iOS 16.6.1, 20G81.
@@ -27,6 +34,83 @@ On the pristine 20G81 seputil, the existing patch resolved the complete
It changed only the filename field to `AA` and an immediate second run was
idempotent. This is an offline binary check, not evidence of a normal boot.
-The internal copy and its bundle binding are ready. The full guest install is
-currently waiting for the user's macOS administrator authentication. The UI
-tool cannot access SecurityAgent. Normal boot remains untested.
+The user completed macOS administrator authentication and the internal install
+completed. On first normal boot, launchd exits PID 1 with "could not set up
+inheritance port". Its call at 0x10001682C is `_mach_ports_register`; the next
+instruction branches to that fatal block on failure. XNU 12377.41.6 uses fixed
+three-port descriptors for task RPCs 3403/3404; iOS 16 uses an OOL port array.
+
+The opt-in `system-launchd-exp-ios16_mach_ports` selects an API bridge in
+launchdhook/SystemHook and its marker. Native self-task register/lookup tests
+pass. The VM also blocks `system-launchd-boot-jetsam_panic_guard_bypass`, whose
+pattern is absent on 20G81: otherwise the existing grouped launchd patch fails
+before it inserts launchdhook. The bridge selection now owns launchd's weak
+load and backup in the same group, so installation cannot count only the marker
+as success. Guest console confirms register3 succeeds and launchd completes
+early boot. Spawned xpcproxy processes then trap before inserted-library
+constructors: exception diagnostics locate `__libxpc_initializer.cold.6` at
+0x1E6EE647C, reached from the failed `_mach_ports_lookup` call at 0x1E6ECBCA4.
+
+`dyld-exp-ios16_mach_ports_lookup` is a second, explicitly selected cache
+patch. It replaces the bounded 388-byte `_mach_ports_lookup` client at
+0x1C5FFC078 in libsystem_kernel with the modern inline-three-port reply
+decoder, preserving the public allocated-array API. PC-relative request
+construction stays in place; the expanded reply frame preserves FP-relative
+saved registers and compact unwind. The generated payload validates reply ID,
+size, descriptor count and dispositions and preserves error cleanup. Cache
+writes are re-attested and recorded for opt-out restoration. No guest success
+is claimed for this second patch until normal boot is retested.
+
+Protocol reference: Apple XNU `xnu-12377.41.6`, `osfmk/mach/task.defs` and
+`libsyscall/mach/task.c`. The guest runs `kernelcache.release.vphone600`
+26.1/23B85 (Darwin 25.1.0, xnu-12377.42.6~55).
+
+The inline-port cache client passes the eighth real boot: libxpc initializes,
+system services run and vphoned answers. The full affected cache chunk matches
+its pristine input after offline apply/idempotence/undo testing. 70 selected
+patch-model tests pass; a subsequent catalogue/plan run passes 41 tests.
+
+The next desktop blocker is measured in backboardd's migration queue, waiting
+inside `_DMPerformMigration`. A local opt-in backboard library releases this
+call. On the next boot that stack disappears, but SpringBoard still waits in
+FBSystemShellInitialize. Static analysis of BKSystemShellSentinel's
+`checkInAndWaitForDataMigration:completionBlock:` at 0x100064D30 shows another
+wait on `_lock_migratorDidComplete` and `_lock_systemAppBlocked`. PreBoard is
+running and holds the alternate-system-app block. The next test asks this
+native check-in method to use its existing non-waiting mode. Method encodings
+are checked before replacement. No global migration-complete state is written.
+
+After boot, auto-boot is set false by the incomplete migration flow. A small
+native libirecovery helper, restricted to this VM's ECID C9E118E06642A328 and
+recovery-mode PIDs, restores auto-boot and reboots. This is a lab workaround,
+not a general recovery or SEP compatibility fix.
+
+The native EXC_CRASH observer captured the media failure before inserted-library
+constructors execute: abort <- cc_abort <- ccrng_getentropy_generate <-
+ccrng_process_init <- arc4random_buf <- libobjc initialization. Independent
+getentropy/arc4random probes pass as root and mobile, including a probe signed
+with the media service's retained entitlements. The current investigation reads
+the faulting thread's errno through THREAD_IDENTIFIER_INFO and the measured
+20G81 __error TLS layout. No random bytes are replaced or fabricated.
+
+## Current checkpoint
+
+The active lab is `/Users/Shared/VPhoneLab16/iPhone-14-Pro-iOS16-Lab`.
+The untouched external restore copy was moved out of the machine list to
+`/Volumes/ZHITAI/Data/VPhone/Library/lab-backups/iPhone-14-Pro-iOS16-Lab-restored-original`.
+Use the internal library root explicitly. The current running bundle is
+2.15.0-local.eda73803; the cleaned build has not yet been deployed because
+visual verification of the running guest awaits host unlock.
+
+The standard preset has six explicit allows: registered Mach-port bridge,
+early cache lookup, existing syscall-filter relaxation, ephemeral keybag init,
+backboard migration wait, and SpringBoard desktop startup. The unmatched
+launchd jetsam pattern remains blocked. All new declarations are off in every
+bundled preset. Audio, widget content, flashlight and media Control Center
+modules are unavailable. This is experimental startup, not supported iOS 16.
+
+The cleaned native bundle build and admission pass. The 47 catalogue/plan/parser
+tests pass after removing discarded experiments; the native Mach-port test
+passes register/lookup round-trip, empty slots and count bounds. Earlier
+full-cache apply/idempotence/undo reproduced the pristine affected chunk.
+The iOS 17 PR branch remains unchanged and clean. No iOS 16 work was pushed.
diff --git a/VPhoneDaemon/Daemon/GuestAPI+Environment.swift b/VPhoneDaemon/Daemon/GuestAPI+Environment.swift
index 8c1788d7..ad76b574 100644
--- a/VPhoneDaemon/Daemon/GuestAPI+Environment.swift
+++ b/VPhoneDaemon/Daemon/GuestAPI+Environment.swift
@@ -21,7 +21,7 @@ extension GuestAPI {
"libdevicehubfix.dylib",
"libdevicename.dylib",
"libprefsfix.dylib",
- "libsigninfix.dylib", "libvphoneios17desktop.dylib",
+ "libsigninfix.dylib", "libvphoneios17desktop.dylib", "libvphoneios16migration.dylib", "libvphoneios16desktop.dylib",
"libvphonefolddisplay.dylib",
"libvphonefoldguard.dylib",
"libvphonehinge.dylib",
@@ -31,7 +31,7 @@ extension GuestAPI {
]
/// Must match `VPhoneGuestEnvironment.selectedLibraries`: the VM's patch selection owns these.
static let environmentSelectedLibraries: Set = [
- "libprefsfix.dylib", "libsigninfix.dylib", "libvphoneios17desktop.dylib",
+ "libprefsfix.dylib", "libsigninfix.dylib", "libvphoneios17desktop.dylib", "libvphoneios16migration.dylib", "libvphoneios16desktop.dylib",
"libvphonegyro.dylib", "libvphoneaccelerometer.dylib", "libvphoneattitude.dylib",
"libvphonehinge.dylib", "libvphonefoldguard.dylib", "libvphonefolddisplay.dylib",
]
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/DyldSharedCache/Patchers/DyldSharedCacheMachPortsPatcher.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/DyldSharedCache/Patchers/DyldSharedCacheMachPortsPatcher.swift
new file mode 100644
index 00000000..b04b1c6c
--- /dev/null
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/DyldSharedCache/Patchers/DyldSharedCacheMachPortsPatcher.swift
@@ -0,0 +1,170 @@
+import Foundation
+import VPhonePatchKit
+
+/// iOS 16's libSystem initializes libxpc before inserted libraries can interpose.
+/// Keep its public array API, but decode XNU 12377's three inline port rights.
+public enum DyldSharedCacheMachPortsPatcher {
+ public static let image = "/usr/lib/system/libsystem_kernel.dylib"
+ public struct Prepared {
+ public let address: UInt64
+ public let original: Data
+ public let replacement: Data
+ public var alreadyPatched: Bool { original == replacement }
+ }
+
+ public static func prepare(chunks: DyldSharedCacheChunkSet) throws -> Prepared {
+ let resolver = try DyldSharedCacheSymbolResolver(chunks: chunks)
+ let address = try resolver.address(of: "_mach_ports_lookup", inImage: image)
+ let message = try resolver.address(of: "_mach_msg2_internal", inImage: image)
+ let allocate = try resolver.address(of: "_mach_vm_allocate", inImage: image)
+ let selfPort = try resolver.address(of: "_mach_task_self_", inImage: image)
+ let deallocateReply = try resolver.address(of: "_mig_dealloc_reply_port", inImage: image)
+ let destroy = try resolver.address(of: "_mach_msg_destroy", inImage: image)
+ let decoded = ARM64Disassembler().disassemble(try chunks.readAtVMA(address, length: 1024, allowShort: true), at: address)
+ guard let end = decoded.firstIndex(where: { $0.isReturn }),
+ let send = decoded[..<end].firstIndex(where: {
+ $0.mnemonic == "bl" && $0.detail?.operands.first?.imm == Int64(message)
+ }) else { throw PatcherError.patchSiteNotFound("mach_ports_lookup: bounded MIG client not found") }
+ let instructions = Array(decoded[...end])
+ guard instructions.first?.mnemonic == "pacibsp", instructions.last?.mnemonic == "retab",
+ instructions[1].mnemonic == "sub", let frame = instructions[1].detail?.operands.last?.imm,
+ [0x70, 0x90].contains(frame), send < 40,
+ let fpRestore = instructions.first(where: { isPair($0, "ldp", "x29", "x30", 0x60) }),
+ let savedRestore = instructions.first(where: { isPair($0, "ldp", "x20", "x19", 0x50) }),
+ let extraRestore = instructions.first(where: { isPair($0, "ldp", "x22", "x21", 0x40) })
+ else { throw PatcherError.patchSiteNotFound("mach_ports_lookup: unsupported frame or register preservation") }
+ let prefix = Array(instructions[...send])
+ guard prefix.count > 9,
+ isPair(prefix[2], "stp", "x22", "x21", frame == 0x70 ? 0x40 : 0x60),
+ isPair(prefix[3], "stp", "x20", "x19", frame == 0x70 ? 0x50 : 0x70),
+ isPair(prefix[4], "stp", "x29", "x30", frame == 0x70 ? 0x60 : 0x80),
+ let receive = prefix.firstIndex(where: {
+ $0.mnemonic == "mov" && $0.detail?.operands.first?.reg.name == "w6" &&
+ [64, 80].contains($0.detail?.operands.last?.imm ?? -1)
+ })
+ else { throw PatcherError.patchSiteNotFound("mach_ports_lookup: unsupported receive buffer") }
+ // Grow the reply area while preserving every saved register's
+ // FP-relative location and the original compact-unwind description.
+ // All PC-relative literals and calls stay at their original addresses.
+ var code = Data(prefix.flatMap(\.bytes))
+ func replace(_ index: Int, _ bytes: Data?) throws {
+ guard let bytes else { throw PatcherError.patchVerificationFailed("mach ports encoding") }
+ code.replaceSubrange(index * 4 ..< index * 4 + 4, with: bytes)
+ }
+ try replace(1, ARM64Encoder.encodeSubImm12(rd: 31, rn: 31, imm12: 0x90))
+ try replace(2, ARM64Encoder.encodeStpX(rt1: 22, rt2: 21, rn: 31, offset: 0x60))
+ try replace(3, ARM64Encoder.encodeStpX(rt1: 20, rt2: 19, rn: 31, offset: 0x70))
+ try replace(4, ARM64Encoder.encodeStpX(rt1: 29, rt2: 30, rn: 31, offset: 0x80))
+ try replace(5, ARM64Encoder.encodeAddImm12(rd: 29, rn: 31, imm12: 0x80))
+ try replace(receive, ARM64Encoder.encodeMovzW(rd: 6, imm16: 80))
+
+ var labels: [String: Int] = [:]
+ var fixups: [(Int, String, (Int, Int) -> Data?)] = []
+ func emit(_ bytes: Data?) throws {
+ guard let bytes else { throw PatcherError.patchVerificationFailed("mach ports encoding") }
+ code.append(bytes)
+ }
+ func label(_ name: String) { labels[name] = code.count }
+ func jump(_ name: String, _ encoder: @escaping (Int, Int) -> Data?) {
+ fixups.append((code.count, name, encoder)); code.append(ARM64.nop)
+ }
+ func b(_ name: String) { jump(name) { ARM64Encoder.encodeB(from: $0, to: $1) } }
+ func cb(_ name: String, _ register: UInt32, _ nonzero: Bool = true, _ width64: Bool = false) {
+ jump(name) { ARM64Encoder.encodeCompareBranch(nonzero: nonzero, register: register, from: $0, to: $1, width64: width64) }
+ }
+ func ne(_ name: String) { jump(name) { ARM64Encoder.encodeBCond(from: $0, to: $1, condition: .ne) } }
+ func call(_ target: UInt64) throws { try emit(ARM64Encoder.encodeBL(from: Int(address) + code.count, to: Int(target))) }
+ func lw(_ rt: UInt32, _ offset: UInt32, _ rn: UInt32 = 31) throws { try emit(ARM64Encoder.encodeLdrWUnsignedOffset(rt: rt, rn: rn, offset: offset)) }
+ func sw(_ rt: UInt32, _ offset: UInt32, _ rn: UInt32) throws { try emit(ARM64Encoder.encodeStrWUnsignedOffset(rt: rt, rn: rn, offset: offset)) }
+ func mov(_ rd: UInt32, _ imm: UInt16, _ shift: UInt32 = 0) throws { try emit(ARM64Encoder.encodeMovzW(rd: rd, imm16: imm, shift: shift)) }
+ func cmp(_ reg: UInt32, _ imm: UInt32) throws { try emit(ARM64Encoder.encodeCmpWImmediate(rn: reg, imm12: imm)) }
+
+ cb("transport", 0)
+ try lw(8, 20); try cmp(8, 3504); ne("type")
+ try lw(8, 0)
+ jump("errorReply") { ARM64Encoder.encodeTestBitBranch(nonzero: false, register: 8, bit: 31, from: $0, to: $1) }
+ try lw(8, 4); try cmp(8, 64); ne("type")
+ try lw(8, 24); try cmp(8, 3); ne("type")
+ // A returned port descriptor has zero padding, disposition PORT_SEND,
+ // and type PORT_DESCRIPTOR. All three rights must have this shape.
+ try mov(9, 17, 16)
+ for offset in [UInt32(36), 48, 60] {
+ try lw(8, offset)
+ try emit(ARM64Encoder.encodeAddSubXShifted(subtract: true, rd: 8, rn: 8, rm: 9))
+ cb("type", 8, true, true)
+ }
+ // Reply + trailer occupy [sp, sp+80). Allocate the array through a
+ // separate slot at sp+0x50, clear of saved registers and the reply.
+ try emit(ARM64Encoder.encodeStrXUnsignedOffset(rt: 31, rn: 31, offset: 0x50))
+ try emit(ARM64Encoder.encodeADRP(rd: 8, pc: address + UInt64(code.count), target: selfPort))
+ try lw(0, UInt32(selfPort & 0xFFF), 8)
+ try emit(ARM64Encoder.encodeAddImm12(rd: 1, rn: 31, imm12: 0x50))
+ try mov(2, 12); try mov(3, 1); try call(allocate)
+ cb("allocation", 0)
+ try emit(ARM64Encoder.encodeLdrXUnsignedOffset(rt: 9, rn: 31, offset: 0x50))
+ for (index, offset) in [UInt32(28), 40, 52].enumerated() {
+ try lw(8, offset); try sw(8, UInt32(index * 4), 9)
+ }
+ try emit(ARM64Encoder.encodeStrXUnsignedOffset(rt: 9, rn: 20, offset: 0))
+ try mov(8, 3); try sw(8, 0, 19); try mov(21, 0); b("finish")
+ label("errorReply")
+ try lw(8, 4); try cmp(8, 36); ne("type")
+ try lw(21, 32); cb("finish", 21)
+ label("type")
+ try mov(21, 300)
+ try emit(ARM64Encoder.encodeAddSubXShifted(subtract: true, rd: 21, rn: 31, rm: 21))
+ b("destroy")
+ label("transport")
+ try emit(ARM64Encoder.encodeMovX(rd: 21, rm: 0)); try lw(0, 12)
+ try call(deallocateReply); b("finish")
+ label("allocation")
+ try emit(ARM64Encoder.encodeMovX(rd: 21, rm: 0))
+ label("destroy")
+ try emit(ARM64Encoder.encodeAddImm12(rd: 0, rn: 31, imm12: 0)); try call(destroy)
+ label("finish")
+ try emit(ARM64Encoder.encodeMovX(rd: 0, rm: 21))
+ try emit(ARM64Encoder.encodeAddImm12(rd: 31, rn: 31, imm12: 0x20))
+ try emit(Data(fpRestore.bytes)); try emit(Data(savedRestore.bytes))
+ try emit(Data(extraRestore.bytes))
+ try emit(ARM64Encoder.encodeAddImm12(rd: 31, rn: 31, imm12: 0x70))
+ try emit(Data(instructions.last!.bytes))
+
+ let original = Data(instructions.flatMap(\.bytes))
+ guard code.count <= original.count else {
+ throw PatcherError.patchVerificationFailed("mach_ports_lookup payload needs \(code.count), has \(original.count)")
+ }
+ for (offset, name, encoder) in fixups {
+ guard let target = labels[name], let bytes = encoder(Int(address) + offset, Int(address) + target) else {
+ throw PatcherError.patchVerificationFailed("mach ports branch \(name)")
+ }
+ code.replaceSubrange(offset ..< offset + 4, with: bytes)
+ }
+ while code.count < original.count { code.append(ARM64.nop) }
+ if frame == 0x90, code != original { throw PatcherError.patchVerificationFailed("unknown previous mach ports implementation") }
+ return Prepared(address: address, original: original, replacement: code)
+ }
+
+ private static func isPair(_ i: ARM64Instruction, _ mnemonic: String, _ first: String, _ second: String, _ offset: Int64) -> Bool {
+ guard i.mnemonic == mnemonic, let ops = i.detail?.operands, ops.count == 3,
+ ops[0].reg.name == first, ops[1].reg.name == second,
+ ops[2].type == .memory, ops[2].mem.base.name == "sp", Int64(ops[2].mem.disp) == offset else { return false }
+ return true
+ }
+
+ public static func apply(directory: URL, dryRun: Bool = false, captureUndo: Bool = false,
+ onUndo: ((DyldSharedCacheUndoLog) -> Void)? = nil,
+ log: ((String) -> Void)? = DyldSharedCacheCodeSignature.stderrLog) throws {
+ let chunks = try DyldSharedCacheChunkSet(directory: directory, captureUndo: captureUndo)
+ defer { if captureUndo, let undo = chunks.takeUndoLog() { onUndo?(undo) } }
+ let prepared = try prepare(chunks: chunks)
+ log?(" [.] mach_ports_lookup @ 0x\(String(prepared.address, radix: 16)); inline-three-port client \(prepared.replacement.count) bytes")
+ if prepared.alreadyPatched { log?(" [=] Mach ports lookup already compatible"); return }
+ if dryRun { log?(" [.] dry run: no bytes written"); return }
+ try chunks.write(at: prepared.address, prepared.replacement)
+ try DyldSharedCacheCodeSignature.reattestRecordedWrites(in: chunks, log: log)
+ guard try chunks.bytesAtVMA(prepared.address, length: prepared.replacement.count) == prepared.replacement else {
+ throw PatcherError.patchVerificationFailed("mach ports readback")
+ }
+ log?(" [+] Mach ports lookup compatibility installed")
+ }
+}
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift
index 42d7d0a7..5bd78d99 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift
@@ -25,6 +25,13 @@ public enum FirmwareGuestSystemPatchSet {
public static let homePodAdHocInstall = "system-installd-exp-homepod_adhoc"
public static let homePodMISFixLibrary = "/usr/lib/libvphonehomepodmisfix.dylib"
public static let ios17Desktop = "system-springboard-exp-ios17_desktop"
+ public static let ios16MachPorts = "system-launchd-exp-ios16_mach_ports"
+ public static let ios16PortsLookup = "dyld-exp-ios16_mach_ports_lookup"
+ public static let ios16Migration = "system-backboard-exp-ios16_migration"
+ public static let ios16Desktop = "system-springboard-exp-ios16_desktop"
+ public static let ios16Keybag = "system-keybag-exp-ios16_ephemeral"
+ public static let ios16KeybagMarker = "/usr/lib/vphone-ios16-keybag-ephemeral"
+ public static let ios16MachPortsMarker = "/usr/lib/vphone-ios16-mach-ports"
public static let metalCacheReuse = "system-systemhook-cfw-metal_cache_reuse"
public static let metalCacheReuseMarker = "/usr/lib/vphone-metal-cache-reuse"
public static let gyroscope = "system-backboardd-cfw-gyroscope"
@@ -98,6 +105,41 @@ public enum FirmwareGuestSystemPatchSet {
name: "Guest System",
summary: "Shared-cache policy gates, patched system daemons and the vphone guest payload",
patches: [
+ VPhonePatchDeclaration(
+ identifier: ios16Desktop,
+ title: "iOS 16 lab desktop startup",
+ summary: "Skips SpringBoard's unavailable audio controller, widget descriptor fetch and virtual flashlight startup waits. Audio, widget content and flashlight remain unavailable. Experimental, off by default.",
+ target: .guestExecutable(path: "/System/Library/CoreServices/SpringBoard.app/SpringBoard"),
+ applicability: VPhonePatchApplicability(iOSBase: .release(major: 16, minor: 6), cloudOS: .release(major: 26, minor: 1)),
+ ),
+ VPhonePatchDeclaration(
+ identifier: ios16Keybag,
+ title: "iOS 16 lab keybag init",
+ summary: "Uses keybagd --init's native ephemeral-storage exit on the keybag-less cloudOS platform. Does not provision a keybag or enable passcodes. Experimental, off by default.",
+ target: .guestExecutable(path: "/usr/libexec/keybagd"),
+ applicability: VPhonePatchApplicability(iOSBase: .release(major: 16, minor: 6), cloudOS: .release(major: 26, minor: 1)),
+ ),
+ VPhonePatchDeclaration(
+ identifier: ios16Migration,
+ title: "iOS 16 lab startup migration wait",
+ summary: "Skips backboardd's blocking first-boot migration call on a fresh iOS 16 lab guest. Does not complete data migration or unlock the keybag. Experimental, off by default.",
+ target: .guestExecutable(path: "/usr/libexec/backboardd"),
+ applicability: VPhonePatchApplicability(iOSBase: .major(16)),
+ ),
+ VPhonePatchDeclaration(
+ identifier: ios16PortsLookup,
+ title: "iOS 16 early Mach ports lookup",
+ summary: "Adapts libsystem_kernel's registered-port lookup to cloudOS 26.1's three-descriptor reply before libxpc initializes. Pairs with the launchd registered-port bridge. Experimental, off by default.",
+ target: .dyldSharedCache,
+ applicability: VPhonePatchApplicability(iOSBase: .major(16), cloudOS: .release(major: 26, minor: 1)),
+ ),
+ VPhonePatchDeclaration(
+ identifier: ios16MachPorts,
+ title: "iOS 16 registered Mach ports",
+ summary: "Translates legacy registered-port array RPCs to the fixed three-port protocol used by cloudOS 26.1. Experimental, off by default; restart after changing.",
+ target: .guestExecutable(path: "/sbin/launchd"),
+ applicability: VPhonePatchApplicability(iOSBase: .major(16)),
+ ),
VPhonePatchDeclaration(
identifier: ios17Desktop,
title: "iOS 17 desktop bring-up",
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareKernelFridaPatchSet.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareKernelFridaPatchSet.swift
index 85989e4e..e25bc00d 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareKernelFridaPatchSet.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareKernelFridaPatchSet.swift
@@ -50,7 +50,9 @@ public enum FirmwareKernelFridaPatchSet {
title: "Syscall filters off",
summary: "Ignores per-process syscall filters, so Frida's agent survives inside filtered daemons such as trustd or backboardd.",
target: .firmware(.kernelcache),
- applicability: fridaCapable,
+ applicability: VPhonePatchApplicability(cloudOS: .oneOf([
+ .release(major: 26, minor: 1), .atLeast(major: 26, minor: 4),
+ ])),
),
],
requires: ["vphone.kernel.cfw"],
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwarePatchSetCatalog.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwarePatchSetCatalog.swift
index 964e7621..94df2a86 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwarePatchSetCatalog.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwarePatchSetCatalog.swift
@@ -68,7 +68,7 @@ public enum FirmwarePatchSetCatalog {
Set(FirmwareKernelFridaPatchSet.manifest.patches.map(\.identifier))
.union(hypervisorConcealmentPatches)
.union(experimentalIdentityPatches)
- .union([FirmwareGuestSystemPatchSet.homeViewEnvironmentService, FirmwareGuestSystemPatchSet.ios17Desktop])
+ .union([FirmwareGuestSystemPatchSet.homeViewEnvironmentService, FirmwareGuestSystemPatchSet.ios17Desktop, FirmwareGuestSystemPatchSet.ios16MachPorts, FirmwareGuestSystemPatchSet.ios16Desktop, FirmwareGuestSystemPatchSet.ios16Keybag, FirmwareGuestSystemPatchSet.ios16Migration, FirmwareGuestSystemPatchSet.ios16PortsLookup])
.union([FirmwareGuestSystemPatchSet.homeViewProfileLookup, FirmwareGuestSystemPatchSet.homeViewDisplayLookups, FirmwareGuestSystemPatchSet.homeViewSetupBypass, FirmwareGuestSystemPatchSet.otaUserland, FirmwareGuestSystemPatchSet.homePodTopCap, FirmwareGuestSystemPatchSet.homePodSetupBypass, FirmwareGuestSystemPatchSet.homePodAirPlayVM, FirmwareGuestSystemPatchSet.homePodAudioProduct, FirmwareGuestSystemPatchSet.homePodWelcome, FirmwareGuestSystemPatchSet.homePodSiriSpeech, FirmwareGuestSystemPatchSet.homePodOTAUserland, FirmwareGuestSystemPatchSet.homePodSoundGlow, FirmwareGuestSystemPatchSet.homePodCryptexStaging, FirmwareGuestSystemPatchSet.homePodCryptexClass, FirmwareGuestSystemPatchSet.homePodAdHocInstall])
.union([FirmwareKernelCustomFirmwarePatchSet.tvTPROPagers, misTrustAuthPatch, FirmwareGuestSystemPatchSet.settingsRootRows, FirmwareGuestSystemPatchSet.settingsSoftwareUpdate, FirmwareGuestSystemPatchSet.tvTPRO, FirmwareGuestSystemPatchSet.tvOTAUserland, FirmwareGuestSystemPatchSet.tvSetupDisplayLookup, FirmwareGuestSystemPatchSet.tvSetupFocus, FirmwareGuestSystemPatchSet.tvLocalActivation, FirmwareGuestSystemPatchSet.tvLegacySetup])
@@ -233,7 +233,7 @@ public enum FirmwarePatchSetCatalog {
freshly restored 26.4 guest does not survive. The HomePod-only top cap is off.
""",
patchSets: bundledReferences,
- selection: .block([FirmwareGuestSystemPatchSet.ios17Desktop, FirmwareGuestSystemPatchSet.homeViewEnvironmentService, FirmwareGuestSystemPatchSet.homeViewProfileLookup, FirmwareGuestSystemPatchSet.homeViewDisplayLookups, FirmwareGuestSystemPatchSet.homeViewSetupBypass, FirmwareGuestSystemPatchSet.tvLegacySetup, FirmwareGuestSystemPatchSet.tvSetupDisplayLookup, FirmwareGuestSystemPatchSet.tvSetupFocus, FirmwareGuestSystemPatchSet.tvLocalActivation, FirmwareGuestSystemPatchSet.homePodTopCap, FirmwareGuestSystemPatchSet.homePodSetupBypass, FirmwareGuestSystemPatchSet.homePodAirPlayVM, FirmwareGuestSystemPatchSet.homePodAudioProduct, FirmwareGuestSystemPatchSet.homePodWelcome, FirmwareGuestSystemPatchSet.homePodSiriSpeech, FirmwareGuestSystemPatchSet.homePodOTAUserland, FirmwareGuestSystemPatchSet.homePodSoundGlow, FirmwareGuestSystemPatchSet.homePodCryptexStaging, FirmwareGuestSystemPatchSet.homePodCryptexClass, FirmwareGuestSystemPatchSet.homePodAdHocInstall]),
+ selection: .block([FirmwareGuestSystemPatchSet.ios16Desktop, FirmwareGuestSystemPatchSet.ios16Keybag, FirmwareGuestSystemPatchSet.ios16Migration, FirmwareGuestSystemPatchSet.ios16PortsLookup, FirmwareGuestSystemPatchSet.ios16MachPorts, FirmwareGuestSystemPatchSet.ios17Desktop, FirmwareGuestSystemPatchSet.homeViewEnvironmentService, FirmwareGuestSystemPatchSet.homeViewProfileLookup, FirmwareGuestSystemPatchSet.homeViewDisplayLookups, FirmwareGuestSystemPatchSet.homeViewSetupBypass, FirmwareGuestSystemPatchSet.tvLegacySetup, FirmwareGuestSystemPatchSet.tvSetupDisplayLookup, FirmwareGuestSystemPatchSet.tvSetupFocus, FirmwareGuestSystemPatchSet.tvLocalActivation, FirmwareGuestSystemPatchSet.homePodTopCap, FirmwareGuestSystemPatchSet.homePodSetupBypass, FirmwareGuestSystemPatchSet.homePodAirPlayVM, FirmwareGuestSystemPatchSet.homePodAudioProduct, FirmwareGuestSystemPatchSet.homePodWelcome, FirmwareGuestSystemPatchSet.homePodSiriSpeech, FirmwareGuestSystemPatchSet.homePodOTAUserland, FirmwareGuestSystemPatchSet.homePodSoundGlow, FirmwareGuestSystemPatchSet.homePodCryptexStaging, FirmwareGuestSystemPatchSet.homePodCryptexClass, FirmwareGuestSystemPatchSet.homePodAdHocInstall]),
)
/// The iOS payloads, hooks and shared-cache patches an Apple TV guest has no
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/PatchSets/FirmwarePatchSetCatalogTests.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/PatchSets/FirmwarePatchSetCatalogTests.swift
index 578330a5..086f1768 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/PatchSets/FirmwarePatchSetCatalogTests.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/PatchSets/FirmwarePatchSetCatalogTests.swift
@@ -17,6 +17,22 @@ import VPhonePatchKit
@Suite("Bundled patch set catalogue")
struct FirmwarePatchSetCatalogTests {
+ @Test func `Legacy startup compatibility is opt in and scoped to iOS 16`() throws {
+ for id in [FirmwareGuestSystemPatchSet.ios16MachPorts, FirmwareGuestSystemPatchSet.ios16PortsLookup, FirmwareGuestSystemPatchSet.ios16Desktop, FirmwareGuestSystemPatchSet.ios16Keybag, FirmwareGuestSystemPatchSet.ios16Migration] {
+ for version in ["16.6.1", "17.7", "18.6.2", "26.1", "27.1"] {
+ for selected in [false, true] {
+ var preset = FirmwarePatchSetCatalog.standardPreset
+ if selected { preset.selection = preset.selection.allowing([id]) }
+ let plan = try VPhonePatchPlan.resolve(
+ preset: preset, patchSets: FirmwarePatchSetCatalog.bundled,
+ iOSBase: VPhoneVersion(version), cloudOS: VPhoneVersion("26.1")
+ )
+ #expect(plan.isEnabled(id) == (selected && version == "16.6.1"))
+ }
+ }
+ }
+ }
+
@Test func `iOS 17 desktop workaround is opt in and unavailable on other bases`() throws {
let id = FirmwareGuestSystemPatchSet.ios17Desktop
for version in ["16.6.1", "17.7", "18.6.2", "26.1", "27.1"] {
@@ -518,7 +534,7 @@ struct FirmwarePatchSetCatalogTests {
}
@Test
- func `The Frida relaxations need cloudOS 26.4`() throws {
+ func `Frida gates retain the measured cloudOS 26.1 syscall filter exception`() throws {
for cloud in ["26.1", "26.4"] {
let plan = try VPhonePatchPlan.resolve(
preset: FirmwarePatchSetCatalog.experimentalPreset,
@@ -530,6 +546,12 @@ struct FirmwarePatchSetCatalogTests {
plan.isEnabled($0.identifier)
}
#expect(on == (cloud == "26.4"))
+ #expect(plan.isEnabled("kernel-exp-frida_syscall_filter_off"))
+ let standard = try VPhonePatchPlan.resolve(
+ preset: FirmwarePatchSetCatalog.standardPreset, patchSets: FirmwarePatchSetCatalog.bundled,
+ iOSBase: VPhoneVersion("16.6.1"), cloudOS: VPhoneVersion(cloud)
+ )
+ #expect(!standard.isEnabled("kernel-exp-frida_syscall_filter_off"))
}
}
diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareDyldSharedCacheVerbsCommand.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareDyldSharedCacheVerbsCommand.swift
index 693c27db..49487f7e 100644
--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareDyldSharedCacheVerbsCommand.swift
+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareDyldSharedCacheVerbsCommand.swift
@@ -81,6 +81,7 @@ enum VPhoneCustomFirmwareDyldSharedCacheVerbs {
VPhoneCustomFirmwareDyldSharedCacheRevertCommand.self,
VPhoneCustomFirmwarePatchHypervisorVirtualMachineDyldSharedCacheCommand.self,
VPhoneCustomFirmwarePatchIOMFBSwapEndCommand.self,
+ VPhoneCustomFirmwarePatchIOS16MachPortsCommand.self,
VPhoneCustomFirmwarePatchIOMFBForceKernCommand.self,
VPhoneCustomFirmwarePatchDyldSharedCacheMaxSlideCommand.self,
VPhoneCustomFirmwarePatchLSDEmbeddedRegCommand.self,
@@ -330,6 +331,24 @@ struct VPhoneCustomFirmwarePatchIOMFBForceKernCommand: ParsableCommand {
}
}
+struct VPhoneCustomFirmwarePatchIOS16MachPortsCommand: ParsableCommand {
+ static let configuration = CommandConfiguration(
+ commandName: "patch-ios16-mach-ports",
+ abstract: "Adapt iOS 16's early registered-port lookup to the cloudOS 26.1 protocol"
+ )
+ @Argument(transform: URL.init(fileURLWithPath:)) var chunksDirectory: URL
+ @Flag(name: .customLong("dry-run")) var dryRun = false
+ @OptionGroup var undo: DyldSharedCacheUndoOptions
+ func run() throws {
+ var captured = DyldSharedCacheUndoLog()
+ try DyldSharedCacheMachPortsPatcher.apply(
+ directory: chunksDirectory, dryRun: dryRun, captureUndo: undo.captures,
+ onUndo: { captured.merge($0) }, log: VPhoneCustomFirmwareDyldSharedCacheVerbs.stdout
+ )
+ try undo.persist(captured, dryRun: dryRun)
+ }
+}
+
// MARK: - patch-dsc-maxslide
struct VPhoneCustomFirmwarePatchDyldSharedCacheMaxSlideCommand: ParsableCommand {
diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift
index 9686ec12..3b42a1e1 100644
--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift
+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift
@@ -1324,6 +1324,10 @@ struct VPhoneCustomFirmwareInstaller {
&& identifier != FirmwareGuestSystemPatchSet.hinge
&& identifier != FirmwareGuestSystemPatchSet.foldGuard
&& identifier != FirmwareGuestSystemPatchSet.ios17Desktop
+ && identifier != FirmwareGuestSystemPatchSet.ios16MachPorts
+ && identifier != FirmwareGuestSystemPatchSet.ios16Migration
+ && identifier != FirmwareGuestSystemPatchSet.ios16Desktop
+ && identifier != FirmwareGuestSystemPatchSet.ios16Keybag
}
guard plan.isEnabled(identifier) else {
print(" [·] \(identifier): off in preset \(plan.presetIdentifier)")
@@ -1719,10 +1723,12 @@ struct VPhoneCustomFirmwareInstaller {
// iOS 17 does not reliably propagate the spawn hook to SpringBoard.
// Keep the weak load owned by this selection, with the original binary
// backed up by the same mechanism as the other executable patches.
- let desktop = FirmwareGuestSystemPatchSet.ios17Desktop
+ for (desktop, path, library) in [
+ (FirmwareGuestSystemPatchSet.ios17Desktop, "System/Library/CoreServices/SpringBoard.app/SpringBoard", "libvphoneios17desktop.dylib"),
+ (FirmwareGuestSystemPatchSet.ios16Migration, "usr/libexec/backboardd", "libvphoneios16migration.dylib"),
+ (FirmwareGuestSystemPatchSet.ios16Desktop, "System/Library/CoreServices/SpringBoard.app/SpringBoard", "libvphoneios16desktop.dylib"),
+ ] {
isolate([desktop]) {
- let path = "System/Library/CoreServices/SpringBoard.app/SpringBoard"
- let library = "libvphoneios17desktop.dylib"
if on(desktop) {
try system.replaceFile("usr/lib/" + library, fromFileAt: VPhoneGuestBinaries.resolve(library), mode: 0o755, owner: Self.guestOwner)
try patchMachO(system: system, work: work, path: path,
@@ -1732,12 +1738,13 @@ struct VPhoneCustomFirmwareInstaller {
if priorGuest.contains(desktop) {
guard try revertMachO(system: system, work: work, path: path) else {
live.insert(desktop)
- throw ValidationError("iOS 17 desktop workaround has no SpringBoard backup; cannot safely remove its library.")
+ throw ValidationError("\(desktop) has no \(path) backup; cannot safely remove its library.")
}
}
try system.removeItem("usr/lib/" + library)
}
}
+ }
// 2. The dyld shared cache. The version branches and the declarations'
// applicability say the same thing; this is what a VM with no plan
@@ -1757,6 +1764,7 @@ struct VPhoneCustomFirmwareInstaller {
dyld.append(("dyld-boot-iomfb_swapend", "patch-iomfb-swapend", [dsc, "--target-size", "0x560"]))
}
dyld += [
+ (FirmwareGuestSystemPatchSet.ios16PortsLookup, "patch-ios16-mach-ports", [dsc]),
(FirmwareGuestSystemPatchSet.homeViewEnvironmentService, "patch-homeview-environment", [dsc]),
(FirmwareGuestSystemPatchSet.settingsSoftwareUpdate, "patch-settings-software-update", [dsc]),
(FirmwarePatchSetCatalog.misTrustAuthPatch, "patch-mis-trust-auth", [dsc]),
@@ -1873,6 +1881,17 @@ struct VPhoneCustomFirmwareInstaller {
}
machO("system-seputil-boot-gigalocker_uuid", path: "usr/libexec/seputil", verbs: ["patch-seputil"], codeIdentifier: "com.apple.seputil")
+ let keybag = FirmwareGuestSystemPatchSet.ios16Keybag
+ let keybagMarker = String(FirmwareGuestSystemPatchSet.ios16KeybagMarker.dropFirst())
+ machO(keybag, path: "usr/libexec/keybagd", preserveEntitlements: true,
+ injectedDylibPath: "/usr/lib/SystemHook-vphone.dylib")
+ isolate([keybag]) {
+ if on(keybag), live.contains(keybag) {
+ try system.writeFile(keybagMarker, contents: Data("1\n".utf8), mode: 0o644, owner: Self.guestOwner)
+ } else {
+ try system.removeItem(keybagMarker)
+ }
+ }
machO(
FirmwareGuestSystemPatchSet.settingsRootRows,
path: "Applications/Preferences.app/Preferences",
@@ -2063,10 +2082,12 @@ struct VPhoneCustomFirmwareInstaller {
let launchdJetsam = "system-launchd-boot-jetsam_panic_guard_bypass"
let launchdX1 = FirmwareGuestSystemPatchSet.arm64eX1LaunchdBootstrap
+ let launchdPorts = FirmwareGuestSystemPatchSet.ios16MachPorts
+ let portsMarker = String(FirmwareGuestSystemPatchSet.ios16MachPortsMarker.dropFirst())
let personaPatch = FirmwareGuestSystemPatchSet.installCoordinationPersona
let personaMarker = String(FirmwareGuestSystemPatchSet.installCoordinationPersonaMarker.dropFirst())
let isHomePod = guestDevice.family == .homePod
- isolate([launchdJetsam, launchdX1] + (isHomePod ? [personaPatch] : [])) {
+ isolate([launchdJetsam, launchdX1] + (isHomePod ? [personaPatch] : [launchdPorts])) {
if isHomePod {
let library = FirmwareGuestSystemPatchSet.homePodInstallPersonaLibrary
let path = String(library.dropFirst())
@@ -2099,7 +2120,7 @@ struct VPhoneCustomFirmwareInstaller {
}
return
}
- let enabled = [launchdJetsam, launchdX1].filter(on)
+ let enabled = [launchdJetsam, launchdX1, launchdPorts].filter(on)
if !enabled.isEmpty {
var verbs: [String] = []
if enabled.contains(launchdJetsam) { verbs.append("patch-launchd-jetsam") }
@@ -2112,20 +2133,45 @@ struct VPhoneCustomFirmwareInstaller {
preserveEntitlements: true,
injectedDylibPath: "/vh",
)
+ if enabled.contains(launchdPorts) {
+ try installLibraryAlias(system: system, alias: "vp16", target: "/usr/lib/SystemHook-vphone.dylib")
+ try patchMachO(system: system, work: work, path: "usr/libexec/xpcproxy",
+ preserveEntitlements: true, injectedDylibPath: "/vp16")
+ try system.writeFile(portsMarker, contents: Data("1\n".utf8), mode: 0o644, owner: Self.guestOwner)
+ } else {
+ if priorGuest.contains(launchdPorts) {
+ _ = try revertMachO(system: system, work: work, path: "usr/libexec/xpcproxy")
+ if try system.isSymlink("vp16"), try system.readLink("vp16") == "/usr/lib/SystemHook-vphone.dylib" {
+ try system.removeItem("vp16")
+ }
+ }
+ try system.removeItem(portsMarker)
+ }
live.formUnion(enabled)
} else if try revertMachO(system: system, work: work, path: "sbin/launchd") {
+ if priorGuest.contains(launchdPorts) {
+ _ = try revertMachO(system: system, work: work, path: "usr/libexec/xpcproxy")
+ if try system.isSymlink("vp16"), try system.readLink("vp16") == "/usr/lib/SystemHook-vphone.dylib" {
+ try system.removeItem("vp16")
+ }
+ }
+ try system.removeItem(portsMarker)
print(" [+] launchd patches: restored sbin/launchd from backup")
} else {
- for identifier in [launchdJetsam, launchdX1] where priorGuest.contains(identifier) {
+ for identifier in [launchdJetsam, launchdX1, launchdPorts] where priorGuest.contains(identifier) {
print(" [!] \(identifier): off now but no backup to revert; leaving launchd patched (not revertible)")
live.insert(identifier)
}
+ if !priorGuest.contains(launchdPorts) { try system.removeItem(portsMarker) }
}
}
try requireX1Bootstrap()
if !isHomePod {
- isolate([]) { try restoreMISFixTargets(system: system, preserveSpringBoard: on(FirmwareGuestSystemPatchSet.ios17Desktop)) }
+ isolate([]) {
+ try restoreMISFixTargets(system: system, preserveSpringBoard:
+ on(FirmwareGuestSystemPatchSet.ios17Desktop) || on(FirmwareGuestSystemPatchSet.ios16Desktop))
+ }
}
// HomePod has no misagent/provisioning service. Its research SDK signs
@@ -2355,6 +2401,7 @@ struct VPhoneCustomFirmwareInstaller {
failures: inout [String],
) throws {
func enabled(_ id: String) -> Bool {
+ if id == FirmwareGuestSystemPatchSet.ios16PortsLookup { return plan?.isEnabled(id) == true }
if id == FirmwareGuestSystemPatchSet.homeViewEnvironmentService { return plan?.isEnabled(id) == true }
return plan?.isEnabled(id) ?? !FirmwareGuestSystemPatchSet.settingsRowPatches.contains(id)
}
diff --git a/VPhoneExecutable/VPhoneVirtualization/Build/StageBundle.sh b/VPhoneExecutable/VPhoneVirtualization/Build/StageBundle.sh
index 42041bf9..2fda9472 100755
--- a/VPhoneExecutable/VPhoneVirtualization/Build/StageBundle.sh
+++ b/VPhoneExecutable/VPhoneVirtualization/Build/StageBundle.sh
@@ -132,6 +132,8 @@ guest_compatibility_library="$(/usr/bin/xcrun swift-stdlib-tool --print \
/bin/cp "$guest_products/prefsfix/libprefsfix.dylib" "$guest/libprefsfix.dylib"
/bin/cp "$guest_products/signinfix/libsigninfix.dylib" "$guest/libsigninfix.dylib"
/bin/cp "$guest_products/ios17desktop/libvphoneios17desktop.dylib" "$guest/libvphoneios17desktop.dylib"
+/bin/cp "$guest_products/ios16migration/libvphoneios16migration.dylib" "$guest/libvphoneios16migration.dylib"
+/bin/cp "$guest_products/ios16desktop/libvphoneios16desktop.dylib" "$guest/libvphoneios16desktop.dylib"
/bin/cp "$guest_products/gyroscope/libvphonegyro.dylib" "$guest/libvphonegyro.dylib"
/bin/cp "$guest_products/accelerometer/libvphoneaccelerometer.dylib" "$guest/libvphoneaccelerometer.dylib"
/bin/cp "$guest_products/hinge/libvphonehinge.dylib" "$guest/libvphonehinge.dylib"
diff --git a/VPhoneExecutable/VPhoneVirtualization/Build/ValidateBundle.sh b/VPhoneExecutable/VPhoneVirtualization/Build/ValidateBundle.sh
index 5e45dac7..88ac219b 100755
--- a/VPhoneExecutable/VPhoneVirtualization/Build/ValidateBundle.sh
+++ b/VPhoneExecutable/VPhoneVirtualization/Build/ValidateBundle.sh
@@ -161,7 +161,7 @@ fi
for name in vphoned vphoned-tvos vphoned-watchos libvphonetvsetupfocus.dylib libswiftCompatibilitySpan.dylib launchdhook-vphone.dylib SystemHook-vphone.dylib libcamfix.dylib \
libvcamcaptured.dylib libmisfix.dylib libhapticsfix.dylib libbatteryhealthfix.dylib libdevicehubfix.dylib libdevicename.dylib \
- libprefsfix.dylib libsigninfix.dylib libvphoneios17desktop.dylib libvphonegyro.dylib libvphoneaccelerometer.dylib libvphonehinge.dylib libvphonefoldguard.dylib libvphonefolddisplay.dylib libvphoneattitude.dylib libvphonehomepoddisplay.dylib libvphonecryptexstaging.dylib libvphoneinstallpersona.dylib libvphonehomepodmisfix.dylib vphone-homepod-setup libAppleParavirtCompilerPluginIOGPUFamily.dylib; do
+ libprefsfix.dylib libsigninfix.dylib libvphoneios17desktop.dylib libvphoneios16migration.dylib libvphoneios16desktop.dylib libvphonegyro.dylib libvphoneaccelerometer.dylib libvphonehinge.dylib libvphonefoldguard.dylib libvphonefolddisplay.dylib libvphoneattitude.dylib libvphonehomepoddisplay.dylib libvphonecryptexstaging.dylib libvphoneinstallpersona.dylib libvphonehomepodmisfix.dylib vphone-homepod-setup libAppleParavirtCompilerPluginIOGPUFamily.dylib; do
require_signed_macho "$guest/$name"
done
# iOS 18 must be able to resolve the compatibility library without Xcode.
diff --git a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/experimental.plist b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/experimental.plist
index 45738308..e12569cc 100644
--- a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/experimental.plist
+++ b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/experimental.plist
@@ -94,6 +94,11 @@
<key>Patches</key>
<array>
<string>system-springboard-exp-ios17_desktop</string>
+ <string>system-launchd-exp-ios16_mach_ports</string>
+ <string>dyld-exp-ios16_mach_ports_lookup</string>
+ <string>system-backboard-exp-ios16_migration</string>
+ <string>system-keybag-exp-ios16_ephemeral</string>
+ <string>system-springboard-exp-ios16_desktop</string>
<string>system-userprofilesd-exp-keybag_lookup</string>
<string>system-breadboard-exp-mach_lookup</string>
<string>system-homeview-exp-setup_bypass</string>
diff --git a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/homepod-mini.plist b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/homepod-mini.plist
index d3297244..c0dc437f 100644
--- a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/homepod-mini.plist
+++ b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/homepod-mini.plist
@@ -156,6 +156,11 @@
<string>system-dyld-exp-tv_tpro</string>
<string>kernel-exp-tv_tpro_pagers</string>
<string>system-springboard-exp-ios17_desktop</string>
+ <string>system-launchd-exp-ios16_mach_ports</string>
+ <string>dyld-exp-ios16_mach_ports_lookup</string>
+ <string>system-backboard-exp-ios16_migration</string>
+ <string>system-keybag-exp-ios16_ephemeral</string>
+ <string>system-springboard-exp-ios16_desktop</string>
</array>
</dict>
<key>Summary</key>
diff --git a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/homeview.plist b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/homeview.plist
index 9a880221..88c9eb88 100644
--- a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/homeview.plist
+++ b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/homeview.plist
@@ -164,6 +164,11 @@
<string>system-virtualaudio-cfw-volume_mode_precondition</string>
<string>system-watchdogd-exp-hv_vmm_cache</string>
<string>system-springboard-exp-ios17_desktop</string>
+ <string>system-launchd-exp-ios16_mach_ports</string>
+ <string>dyld-exp-ios16_mach_ports_lookup</string>
+ <string>system-backboard-exp-ios16_migration</string>
+ <string>system-keybag-exp-ios16_ephemeral</string>
+ <string>system-springboard-exp-ios16_desktop</string>
</array>
</dict>
<key>Summary</key>
diff --git a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/standard.plist b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/standard.plist
index d27d2785..f94e22dc 100644
--- a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/standard.plist
+++ b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/standard.plist
@@ -116,6 +116,11 @@
<string>system-tv-exp-legacy_setup</string>
<string>system-exp-ota_userland</string>
<string>system-springboard-exp-ios17_desktop</string>
+ <string>system-launchd-exp-ios16_mach_ports</string>
+ <string>dyld-exp-ios16_mach_ports_lookup</string>
+ <string>system-backboard-exp-ios16_migration</string>
+ <string>system-keybag-exp-ios16_ephemeral</string>
+ <string>system-springboard-exp-ios16_desktop</string>
</array>
</dict>
<key>Summary</key>
diff --git a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/tvos-4k.plist b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/tvos-4k.plist
index 314ba2c3..c0f9bee0 100644
--- a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/tvos-4k.plist
+++ b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/tvos-4k.plist
@@ -163,6 +163,11 @@
<string>system-dyld-exp-tv_tpro</string>
<string>kernel-exp-tv_tpro_pagers</string>
<string>system-springboard-exp-ios17_desktop</string>
+ <string>system-launchd-exp-ios16_mach_ports</string>
+ <string>dyld-exp-ios16_mach_ports_lookup</string>
+ <string>system-backboard-exp-ios16_migration</string>
+ <string>system-keybag-exp-ios16_ephemeral</string>
+ <string>system-springboard-exp-ios16_desktop</string>
</array>
</dict>
<key>Summary</key>
diff --git a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/tvos.plist b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/tvos.plist
index 60ced4b6..15de58c9 100644
--- a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/tvos.plist
+++ b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/tvos.plist
@@ -171,6 +171,11 @@
<string>system-tv-exp-legacy_setup</string>
<string>system-exp-ota_userland</string>
<string>system-springboard-exp-ios17_desktop</string>
+ <string>system-launchd-exp-ios16_mach_ports</string>
+ <string>dyld-exp-ios16_mach_ports_lookup</string>
+ <string>system-backboard-exp-ios16_migration</string>
+ <string>system-keybag-exp-ios16_ephemeral</string>
+ <string>system-springboard-exp-ios16_desktop</string>
</array>
</dict>
<key>Summary</key>
diff --git a/VPhoneGuestComponents/IOS16Desktop/libvphoneios16desktop.m b/VPhoneGuestComponents/IOS16Desktop/libvphoneios16desktop.m
new file mode 100644
index 00000000..12b8ff93
--- /dev/null
+++ b/VPhoneGuestComponents/IOS16Desktop/libvphoneios16desktop.m
@@ -0,0 +1,55 @@
+#import <Foundation/Foundation.h>
+#import <objc/runtime.h>
+#import <objc/message.h>
+#import <dlfcn.h>
+#import <string.h>
+
+static id unavailableController(id self, SEL selector) { return nil; }
+static void skipWidgets(id self, SEL selector) {}
+static BOOL noFlashlightCapability(id self, SEL selector) { return NO; }
+static id (*originalModule)(id, SEL, id);
+static id moduleWithoutMediaServices(id self, SEL selector, id metadata) {
+ SEL identifier = sel_registerName("moduleIdentifier");
+ if ([metadata respondsToSelector:identifier]) {
+ id value = ((id (*)(id, SEL))objc_msgSend)(metadata, identifier);
+ if ([value isEqual:@"com.apple.mediaremote.controlcenter.nowplaying"] ||
+ [value isEqual:@"com.apple.mediaremote.controlcenter.audio"] ||
+ [value isEqual:@"com.apple.mediaremote.controlcenter.airplaymirroring"]) return nil;
+ }
+ return originalModule(self, selector, metadata);
+}
+
+__attribute__((constructor)) static void start(void) {
+ if (NSProcessInfo.processInfo.operatingSystemVersion.majorVersion != 16 ||
+ ![NSProcessInfo.processInfo.processName isEqualToString:@"SpringBoard"]) return;
+ dlopen("/System/Library/PrivateFrameworks/MediaExperience.framework/MediaExperience", RTLD_NOW);
+ Class controller = objc_getClass("AVSystemController");
+ Method method = class_getInstanceMethod(controller, @selector(init));
+ if (method && !strcmp(method_getTypeEncoding(method), "@16@0:8")) {
+ class_replaceMethod(controller, @selector(init), (IMP)unavailableController, method_getTypeEncoding(method));
+ NSLog(@"[ios16-desktop] skipped unavailable audio controller");
+ }
+ dlopen("/System/Library/PrivateFrameworks/ChronoServices.framework/ChronoServices", RTLD_NOW);
+ Class widgets = objc_getClass("CHSWidgetDescriptorProvider");
+ SEL load = sel_registerName("_lock_loadContentInitiallySynchronouslyIfNecessary");
+ Method loader = class_getInstanceMethod(widgets, load);
+ if (loader && !strcmp(method_getTypeEncoding(loader), "v16@0:8"))
+ class_replaceMethod(widgets, load, (IMP)skipWidgets, method_getTypeEncoding(loader));
+ dlopen("/System/Library/PrivateFrameworks/AVFCapture.framework/AVFCapture", RTLD_NOW);
+ Class flashlight = objc_getClass("AVFlashlight");
+ Method lightInit = class_getInstanceMethod(flashlight, @selector(init));
+ Method capability = class_getClassMethod(flashlight, sel_registerName("hasFlashlight"));
+ if (lightInit && !strcmp(method_getTypeEncoding(lightInit), "@16@0:8"))
+ class_replaceMethod(flashlight, @selector(init), (IMP)unavailableController, method_getTypeEncoding(lightInit));
+ if (capability && !strcmp(method_getTypeEncoding(capability), "B16@0:8"))
+ class_replaceMethod(object_getClass(flashlight), sel_registerName("hasFlashlight"),
+ (IMP)noFlashlightCapability, method_getTypeEncoding(capability));
+ dlopen("/System/Library/PrivateFrameworks/ControlCenterUI.framework/ControlCenterUI", RTLD_NOW);
+ Class modules = objc_getClass("CCUIModuleInstanceManager");
+ SEL instantiate = sel_registerName("_instantiateModuleWithMetadata:");
+ Method module = class_getInstanceMethod(modules, instantiate);
+ if (module && !strcmp(method_getTypeEncoding(module), "@24@0:8@16")) {
+ originalModule = (void *)method_getImplementation(module);
+ class_replaceMethod(modules, instantiate, (IMP)moduleWithoutMediaServices, method_getTypeEncoding(module));
+ }
+}
diff --git a/VPhoneGuestComponents/IOS16Migration/libvphoneios16migration.m b/VPhoneGuestComponents/IOS16Migration/libvphoneios16migration.m
new file mode 100644
index 00000000..2463c1b6
--- /dev/null
+++ b/VPhoneGuestComponents/IOS16Migration/libvphoneios16migration.m
@@ -0,0 +1,37 @@
+#import <Foundation/Foundation.h>
+#import <objc/runtime.h>
+#import <dlfcn.h>
+#import <string.h>
+
+// The lab's fresh Data volume cannot complete the old PreBoard unlock path
+// against the newer SEP. Keep this bypass local to backboardd's startup wait;
+// it does not mark global migration complete or change the keybag.
+static BOOL skipStartupMigration(id self, SEL selector, id connection,
+ BOOL checkNecessity, id lastPlugin, BOOL testOnly) {
+ return YES;
+}
+static void (*originalCheckIn)(id, SEL, NSNumber *, id);
+static void checkInWithoutMigrationWait(id self, SEL selector, NSNumber *wait, id reply) {
+ originalCheckIn(self, selector, @NO, reply);
+}
+__attribute__((constructor)) static void start(void) {
+ if (NSProcessInfo.processInfo.operatingSystemVersion.majorVersion != 16 ||
+ ![NSProcessInfo.processInfo.processName isEqualToString:@"backboardd"]) return;
+ dlopen("/System/Library/PrivateFrameworks/DataMigration.framework/DataMigration", RTLD_NOW);
+ Class cls = objc_getClass("DMClientAPIController");
+ SEL sel = sel_registerName("_migrateWithConnection:checkNecessity:lastRelevantPlugin:testMigrationInfrastructureOnly:");
+ Method method = class_getInstanceMethod(cls, sel);
+ if (!method || strcmp(method_getTypeEncoding(method), "B40@0:8@16B24@28B36")) return;
+ class_replaceMethod(cls, sel, (IMP)skipStartupMigration, method_getTypeEncoding(method));
+ // PreBoard separately blocks the system shell even after the local
+ // migration call returns. Preserve the native check-in and reply handling,
+ // requesting its existing non-waiting mode instead.
+ Class sentinel = objc_getClass("BKSystemShellSentinel");
+ SEL checkIn = sel_registerName("checkInAndWaitForDataMigration:completionBlock:");
+ Method check = class_getInstanceMethod(sentinel, checkIn);
+ if (check && !strcmp(method_getTypeEncoding(check), "v32@0:8@16@?24")) {
+ originalCheckIn = (void *)method_getImplementation(check);
+ class_replaceMethod(sentinel, checkIn, (IMP)checkInWithoutMigrationWait, method_getTypeEncoding(check));
+ }
+ NSLog(@"[ios16-migration] backboard startup migration wait disabled for this lab");
+}
diff --git a/VPhoneGuestComponents/Makefile b/VPhoneGuestComponents/Makefile
index 9b6581af..5db4a8a8 100644
--- a/VPhoneGuestComponents/Makefile
+++ b/VPhoneGuestComponents/Makefile
@@ -8,6 +8,8 @@ CLANG := xcrun --sdk iphoneos clang
MACOS_SDK := $(shell xcrun --sdk macosx --show-sdk-path)
MACH_EXC_DEFS := $(MACOS_SDK)/usr/include/mach/mach_exc.defs
LAUNCHHOOK_GENERATED := $(OUT)/generated/launchhook
+MACHPORTS_GENERATED := $(OUT)/generated/machports
+MACHPORTS_STAMP := $(MACHPORTS_GENERATED)/.stamp
GUEST_C_FLAGS := -arch arm64e -miphoneos-version-min=26.0 -Os
COMMON_FLAGS := $(GUEST_C_FLAGS) -fobjc-arc
@@ -38,10 +40,10 @@ VCAMCAPTURED_INPUTS := $(call find_headers,$(VCAM_HEADER_DIRS)) \
$(call find_folders,$(VCAM_HEADER_DIRS))
VCAMCAPTURED_INCLUDE_FLAGS := $(addprefix -I,$(call find_folders,VCamCaptured) $(VCAM_SHARED_DIRS))
LAUNCHHOOK := $(STAGE)/launchhook/launchdhook-vphone.dylib
-LAUNCHHOOK_SOURCES := $(wildcard LaunchHook/*.c) Shared/RootHideLoaderLinks.c Shared/VPhoneX1Spawn.c
+LAUNCHHOOK_SOURCES := $(wildcard LaunchHook/*.c) Shared/RootHideLoaderLinks.c Shared/VPhoneX1Spawn.c Shared/VPhoneMachPortsCompat.c
LAUNCHHOOK_INCLUDES := $(wildcard LaunchHook/*.h LaunchHook/*.inc Shared/*.h)
SYSTEMHOOK := $(STAGE)/systemhook/SystemHook-vphone.dylib
-SYSTEMHOOK_SOURCES := $(wildcard SystemHook/*.c) $(wildcard FlutterRemapFix/*.c) Shared/RootHideLoaderLinks.c Shared/VPhoneX1Spawn.c
+SYSTEMHOOK_SOURCES := $(wildcard SystemHook/*.c) $(wildcard FlutterRemapFix/*.c) Shared/RootHideLoaderLinks.c Shared/VPhoneX1Spawn.c Shared/VPhoneMachPortsCompat.c LaunchHook/VPhoneMachMessage.c
SYSTEMHOOK_INCLUDES := $(wildcard SystemHook/*.h SystemHook/*.inc FlutterRemapFix/*.h Shared/*.h)
# libmis is not a framework and has no header; the iPhoneOS SDK does ship
# libmis.tbd, so the interposed symbols bind two-level like any other import
@@ -86,6 +88,8 @@ PREFSFIX_SOURCES := $(wildcard PrefsFix/*.m PrefsFix/*.c)
PREFSFIX_INCLUDES := $(wildcard PrefsFix/*.h)
# Foundation + ObjC runtime for the sign-in presentation swizzles; AppleAccountUI
# etc. are reached through the runtime at runtime, so nothing is needed at link.
+IOS16DESKTOP := $(STAGE)/ios16desktop/libvphoneios16desktop.dylib
+IOS16MIGRATION := $(STAGE)/ios16migration/libvphoneios16migration.dylib
IOS17DESKTOP := $(STAGE)/ios17desktop/libvphoneios17desktop.dylib
SIGNINFIX := $(STAGE)/signinfix/libsigninfix.dylib
SIGNINFIX_SOURCES := $(wildcard SignInFix/*.m SignInFix/*.c)
@@ -189,7 +193,7 @@ GPU_DYNAMIC_LOOKUP_SYMS := \
VIRTIOSOUND := $(STAGE)/virtiosound/VPhoneVirtIOSound.driver
VIRTIOSOUND_SOURCES := $(wildcard VirtIOSound/*.m VirtIOSound/*.c)
VIRTIOSOUND_INCLUDES := $(wildcard VirtIOSound/*.h) VirtIOSound/Info.plist VirtIOSound/AudioServerDriver.tbd
-ARTIFACTS := $(IOS17DESKTOP) $(CAMFIX) $(VCAMCAPTURED) $(LAUNCHHOOK) $(SYSTEMHOOK) $(MISFIX) $(HAPTICSFIX) $(BATTERYHEALTHFIX) $(DEVICEHUBFIX) $(DEVICENAME) $(PREFSFIX) $(SIGNINFIX) $(GYROSCOPE) $(ACCELEROMETER) $(HINGE) $(FOLDGUARD) $(FOLDDISPLAY) $(ATTITUDE) $(HOMEPODDISPLAY) $(CRYPTEXSTAGING) $(HOMEPODPERSONA) $(HOMEPODMISFIX) $(HOMEPODSETUP) $(TVSETUPFOCUS) $(GPU_PLUGIN) $(VIRTIOSOUND)
+ARTIFACTS := $(IOS16DESKTOP) $(IOS16MIGRATION) $(IOS17DESKTOP) $(CAMFIX) $(VCAMCAPTURED) $(LAUNCHHOOK) $(SYSTEMHOOK) $(MISFIX) $(HAPTICSFIX) $(BATTERYHEALTHFIX) $(DEVICEHUBFIX) $(DEVICENAME) $(PREFSFIX) $(SIGNINFIX) $(GYROSCOPE) $(ACCELEROMETER) $(HINGE) $(FOLDGUARD) $(FOLDDISPLAY) $(ATTITUDE) $(HOMEPODDISPLAY) $(CRYPTEXSTAGING) $(HOMEPODPERSONA) $(HOMEPODMISFIX) $(HOMEPODSETUP) $(TVSETUPFOCUS) $(GPU_PLUGIN) $(VIRTIOSOUND)
PLISTS := $(STAGE)/camfix/libcamfix.plist $(STAGE)/vcamcaptured/libvcamcaptured.plist \
$(STAGE)/misfix/libmisfix.plist
GPU_PROVENANCE := $(STAGE)/gpu/README.md
@@ -235,7 +239,7 @@ gpu: $(GPU_PLUGIN)
package: all
@rm -f $(ARCHIVE)
- @/usr/bin/tar -cf $(ARCHIVE) -C $(STAGE) ios17desktop camfix vcamcaptured launchhook systemhook misfix hapticsfix batteryhealthfix devicehubfix devicename prefsfix signinfix gyroscope accelerometer hinge foldguard attitude homepoddisplay cryptexstaging homepodpersona homepodmisfix homepodsetup tvsetupfocus gpu virtiosound folddisplay
+ @/usr/bin/tar -cf $(ARCHIVE) -C $(STAGE) ios16migration ios17desktop camfix vcamcaptured launchhook systemhook misfix hapticsfix batteryhealthfix devicehubfix devicename prefsfix signinfix gyroscope accelerometer hinge foldguard attitude homepoddisplay cryptexstaging homepodpersona homepodmisfix homepodsetup tvsetupfocus gpu virtiosound folddisplay
@echo "Packaged $(ARCHIVE)"
test-loader-links:
@@ -333,7 +337,18 @@ $(VCAMCAPTURED): $(VCAMCAPTURED_SOURCES) $(VCAMCAPTURED_INPUTS) | $(STAGE)/vcamc
-framework CoreGraphics
@codesign --force --sign - $@
-$(LAUNCHHOOK): $(LAUNCHHOOK_SOURCES) $(LAUNCHHOOK_INCLUDES) LaunchHook Shared $(MACH_EXC_DEFS) | $(STAGE)/launchhook
+$(MACHPORTS_STAMP): Shared/VPhoneMachPorts.defs $(MACOS_SDK)/usr/include/mach/task.defs
+ @mkdir -p $(MACHPORTS_GENERATED)
+ xcrun --sdk macosx mig -arch arm64 -isysroot $(MACOS_SDK) \
+ -server /dev/null -sheader /dev/null \
+ -user $(MACHPORTS_GENERATED)/VPhoneMachPortsUser.c \
+ -header $(MACHPORTS_GENERATED)/VPhoneMachPortsRPC.h Shared/VPhoneMachPorts.defs
+ /usr/bin/sed -i '' 's/msg_result = mach_msg(/msg_result = vp_mach_msg_kobject(/g' $(MACHPORTS_GENERATED)/VPhoneMachPortsUser.c
+ @/usr/bin/grep -q 'msg_result = vp_mach_msg_kobject(' $(MACHPORTS_GENERATED)/VPhoneMachPortsUser.c
+ @! /usr/bin/grep -q 'msg_result = mach_msg(' $(MACHPORTS_GENERATED)/VPhoneMachPortsUser.c
+ @touch $@
+
+$(LAUNCHHOOK): $(LAUNCHHOOK_SOURCES) $(LAUNCHHOOK_INCLUDES) LaunchHook Shared $(MACH_EXC_DEFS) $(MACHPORTS_STAMP) | $(STAGE)/launchhook
@mkdir -p $(LAUNCHHOOK_GENERATED)
xcrun --sdk macosx mig -arch arm64 -isysroot $(MACOS_SDK) \
-server $(LAUNCHHOOK_GENERATED)/mach_excServer.c \
@@ -345,16 +360,17 @@ $(LAUNCHHOOK): $(LAUNCHHOOK_SOURCES) $(LAUNCHHOOK_INCLUDES) LaunchHook Shared $(
@/usr/bin/grep -q 'msg_result = vp_mach_msg_kobject(' $(LAUNCHHOOK_GENERATED)/mach_excUser.c
@! /usr/bin/grep -q 'msg_result = mach_msg(' $(LAUNCHHOOK_GENERATED)/mach_excUser.c
$(CLANG) $(GUEST_C_FLAGS) -dynamiclib \
- -I$(LAUNCHHOOK_GENERATED) -ILaunchHook -include VPhoneMachMessage.h \
+ -I$(LAUNCHHOOK_GENERATED) -I$(MACHPORTS_GENERATED) -ILaunchHook -include VPhoneMachMessage.h \
-install_name /usr/lib/launchdhook-vphone.dylib \
-o $@ $(LAUNCHHOOK_SOURCES) $(LAUNCHHOOK_GENERATED)/mach_excServer.c \
- $(LAUNCHHOOK_GENERATED)/mach_excUser.c -Wl,-not_for_dyld_shared_cache
+ $(LAUNCHHOOK_GENERATED)/mach_excUser.c $(MACHPORTS_GENERATED)/VPhoneMachPortsUser.c -Wl,-not_for_dyld_shared_cache
@codesign --force --sign - $@
-$(SYSTEMHOOK): $(SYSTEMHOOK_SOURCES) $(SYSTEMHOOK_INCLUDES) SystemHook Shared | $(STAGE)/systemhook
+$(SYSTEMHOOK): $(SYSTEMHOOK_SOURCES) $(SYSTEMHOOK_INCLUDES) SystemHook Shared $(MACHPORTS_STAMP) | $(STAGE)/systemhook
$(CLANG) $(GUEST_C_FLAGS) -dynamiclib \
+ -I$(MACHPORTS_GENERATED) -ILaunchHook -include VPhoneMachMessage.h \
-install_name /usr/lib/SystemHook-vphone.dylib \
- -o $@ $(SYSTEMHOOK_SOURCES) -Wl,-not_for_dyld_shared_cache
+ -o $@ $(SYSTEMHOOK_SOURCES) $(MACHPORTS_GENERATED)/VPhoneMachPortsUser.c -Wl,-not_for_dyld_shared_cache
@codesign --force --sign - $@
$(MISFIX): $(MISFIX_SOURCES) $(MISFIX_INCLUDES) MISFix | $(STAGE)/misfix
@@ -678,3 +694,21 @@ test-ios17-desktop:
../.build/ios17-desktop-tests/test ../.build/ios17-desktop-tests/hook.dylib 17 SpringBoard
../.build/ios17-desktop-tests/test ../.build/ios17-desktop-tests/hook.dylib 18 SpringBoard
../.build/ios17-desktop-tests/test ../.build/ios17-desktop-tests/hook.dylib 17 OtherProcess
+
+.PHONY: test-mach-ports-compat
+test-mach-ports-compat: $(MACHPORTS_STAMP)
+ @mkdir -p ../.build/machports-test
+ xcrun --sdk macosx clang -DVP_MACH_PORTS_COMPAT_TEST -IShared -ILaunchHook -I$(MACHPORTS_GENERATED) -include VPhoneMachMessage.h \
+ Shared/VPhoneMachPortsCompat.c $(MACHPORTS_GENERATED)/VPhoneMachPortsUser.c LaunchHook/VPhoneMachMessage.c \
+ Tests/MachPortsCompatTests.c -o ../.build/machports-test/test
+ ../.build/machports-test/test
+
+$(IOS16MIGRATION): IOS16Migration/libvphoneios16migration.m
+ @mkdir -p $(STAGE)/ios16migration
+ $(CLANG) $(COMMON_FLAGS) -dynamiclib -install_name /usr/lib/libvphoneios16migration.dylib -o $@ $< -framework Foundation -lobjc -Wl,-not_for_dyld_shared_cache
+ @codesign --force --sign - $@
+
+$(IOS16DESKTOP): IOS16Desktop/libvphoneios16desktop.m
+ @mkdir -p $(STAGE)/ios16desktop
+ $(CLANG) $(COMMON_FLAGS) -dynamiclib -install_name /usr/lib/libvphoneios16desktop.dylib -o $@ $< -framework Foundation -lobjc -Wl,-not_for_dyld_shared_cache
+ @codesign --force --sign - $@
diff --git a/VPhoneGuestComponents/Shared/VPhoneMachPorts.defs b/VPhoneGuestComponents/Shared/VPhoneMachPorts.defs
new file mode 100644
index 00000000..008a3e96
--- /dev/null
+++ b/VPhoneGuestComponents/Shared/VPhoneMachPorts.defs
@@ -0,0 +1,17 @@
+/* The fixed three-port task RPCs in XNU 12377.41.6 task.defs, slots 3403/3404. */
+subsystem VPhoneMachPorts 3403;
+import <mach/mach_types.h>;
+#include <mach/std_types.defs>
+#include <mach/mach_types.defs>
+
+routine vp_mach_ports_register3(
+ target_task : task_t;
+ port1 : mach_port_t;
+ port2 : mach_port_t;
+ port3 : mach_port_t);
+
+routine vp_mach_ports_lookup3(
+ target_task : task_t;
+ out port1 : mach_port_t;
+ out port2 : mach_port_t;
+ out port3 : mach_port_t);
diff --git a/VPhoneGuestComponents/Shared/VPhoneMachPortsCompat.c b/VPhoneGuestComponents/Shared/VPhoneMachPortsCompat.c
new file mode 100644
index 00000000..ffd0542d
--- /dev/null
+++ b/VPhoneGuestComponents/Shared/VPhoneMachPortsCompat.c
@@ -0,0 +1,53 @@
+#include "VPhoneMachPortsCompat.h"
+#include "VPhoneMachPortsRPC.h"
+#include <unistd.h>
+
+// Match libsyscall/mach/task.c in XNU 12377.41.6. iOS 16's public API uses
+// out-of-line port arrays, while this kernel accepts three inline descriptors.
+kern_return_t vp_mach_ports_register_compat(task_t task, mach_port_array_t ports,
+ mach_msg_type_number_t count) {
+ if (count > 3) return KERN_INVALID_ARGUMENT;
+ mach_port_t slots[3] = {MACH_PORT_NULL, MACH_PORT_NULL, MACH_PORT_NULL};
+ for (mach_msg_type_number_t i = 0; i < count; i++) slots[i] = ports[i];
+ return vp_mach_ports_register3(task, slots[0], slots[1], slots[2]);
+}
+
+kern_return_t vp_mach_ports_lookup_compat(task_t task, mach_port_array_t *ports,
+ mach_msg_type_number_t *count) {
+ vm_address_t address = 0;
+ vm_size_t size = 3 * sizeof(mach_port_t);
+ kern_return_t kr = vm_allocate(mach_task_self(), &address, size, VM_FLAGS_ANYWHERE);
+ if (kr != KERN_SUCCESS) return kr;
+ mach_port_array_t slots = (mach_port_array_t)address;
+ kr = vp_mach_ports_lookup3(task, &slots[0], &slots[1], &slots[2]);
+ if (kr != KERN_SUCCESS) {
+ vm_deallocate(mach_task_self(), address, size);
+ return kr;
+ }
+ *ports = slots;
+ *count = 3;
+ return KERN_SUCCESS;
+}
+
+#ifndef VP_MACH_PORTS_COMPAT_TEST
+static int selected(void) {
+ return access("/usr/lib/vphone-ios16-mach-ports", F_OK) == 0;
+}
+static kern_return_t vpRegister(task_t task, mach_port_array_t ports,
+ mach_msg_type_number_t count) {
+ return selected() ? vp_mach_ports_register_compat(task, ports, count)
+ : mach_ports_register(task, ports, count);
+}
+static kern_return_t vpLookup(task_t task, mach_port_array_t *ports,
+ mach_msg_type_number_t *count) {
+ return selected() ? vp_mach_ports_lookup_compat(task, ports, count)
+ : mach_ports_lookup(task, ports, count);
+}
+__attribute__((used, section("__DATA,__interpose"))) static const struct {
+ const void *replacement;
+ const void *replacee;
+} vpPortsInterpose[] = {
+ {(const void *)vpRegister, (const void *)mach_ports_register},
+ {(const void *)vpLookup, (const void *)mach_ports_lookup},
+};
+#endif
diff --git a/VPhoneGuestComponents/Shared/VPhoneMachPortsCompat.h b/VPhoneGuestComponents/Shared/VPhoneMachPortsCompat.h
new file mode 100644
index 00000000..771811eb
--- /dev/null
+++ b/VPhoneGuestComponents/Shared/VPhoneMachPortsCompat.h
@@ -0,0 +1,6 @@
+#ifndef VPHONE_MACH_PORTS_COMPAT_H
+#define VPHONE_MACH_PORTS_COMPAT_H
+#include <mach/mach.h>
+kern_return_t vp_mach_ports_register_compat(task_t task, mach_port_array_t ports, mach_msg_type_number_t count);
+kern_return_t vp_mach_ports_lookup_compat(task_t task, mach_port_array_t *ports, mach_msg_type_number_t *count);
+#endif
diff --git a/VPhoneGuestComponents/SystemHook/VPhoneIOS16Keybag.c b/VPhoneGuestComponents/SystemHook/VPhoneIOS16Keybag.c
new file mode 100644
index 00000000..f96772d6
--- /dev/null
+++ b/VPhoneGuestComponents/SystemHook/VPhoneIOS16Keybag.c
@@ -0,0 +1,26 @@
+#include <stdbool.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <crt_externs.h>
+
+extern bool os_variant_uses_ephemeral_storage(const char *subsystem);
+
+// 20G81 keybagd has a native ephemeral-platform exit before provisioning the
+// system bag. Use it only for --init on this explicitly selected VM pairing.
+static bool vpKeybagEphemeral(const char *subsystem) {
+ int argc = *_NSGetArgc();
+ char **argv = *_NSGetArgv();
+ if (argc == 2 && !strcmp(getprogname(), "keybagd") &&
+ !strcmp(argv[1], "--init") && subsystem &&
+ !strcmp(subsystem, "com.apple.mobile.keybagd") &&
+ access("/usr/lib/vphone-ios16-keybag-ephemeral", F_OK) == 0) return true;
+ return os_variant_uses_ephemeral_storage(subsystem);
+}
+
+__attribute__((used, section("__DATA,__interpose"))) static const struct {
+ const void *replacement;
+ const void *replacee;
+} vpKeybagInterpose = {
+ (const void *)vpKeybagEphemeral, (const void *)os_variant_uses_ephemeral_storage,
+};
diff --git a/VPhoneGuestComponents/Tests/MachPortsCompatTests.c b/VPhoneGuestComponents/Tests/MachPortsCompatTests.c
new file mode 100644
index 00000000..e52b1da8
--- /dev/null
+++ b/VPhoneGuestComponents/Tests/MachPortsCompatTests.c
@@ -0,0 +1,24 @@
+#include "VPhoneMachPortsCompat.h"
+#include <assert.h>
+#include <stdio.h>
+int main(void) {
+ mach_port_t port = MACH_PORT_NULL;
+ assert(mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &port) == KERN_SUCCESS);
+ assert(mach_port_insert_right(mach_task_self(), port, port, MACH_MSG_TYPE_MAKE_SEND) == KERN_SUCCESS);
+ assert(vp_mach_ports_register_compat(mach_task_self(), &port, 1) == KERN_SUCCESS);
+ mach_port_array_t ports = NULL;
+ mach_msg_type_number_t count = 0;
+ assert(vp_mach_ports_lookup_compat(mach_task_self(), &ports, &count) == KERN_SUCCESS);
+ assert(count == 3 && ports[0] == port && ports[1] == MACH_PORT_NULL && ports[2] == MACH_PORT_NULL);
+ mach_port_deallocate(mach_task_self(), ports[0]);
+ vm_deallocate(mach_task_self(), (vm_address_t)ports, count * sizeof(*ports));
+ assert(vp_mach_ports_register_compat(mach_task_self(), &port, 4) == KERN_INVALID_ARGUMENT);
+ assert(vp_mach_ports_register_compat(mach_task_self(), NULL, 0) == KERN_SUCCESS);
+ assert(vp_mach_ports_lookup_compat(mach_task_self(), &ports, &count) == KERN_SUCCESS);
+ assert(count == 3 && !ports[0] && !ports[1] && !ports[2]);
+ vm_deallocate(mach_task_self(), (vm_address_t)ports, count * sizeof(*ports));
+ mach_port_deallocate(mach_task_self(), port);
+ mach_port_mod_refs(mach_task_self(), port, MACH_PORT_RIGHT_RECEIVE, -1);
+ puts("Mach port register/lookup round-trip, empty slots and count bound passed");
+ return 0;
+}
diff --git a/VPhoneKit/VPhoneCoreKit/VirtualMachine/VPhoneGuestEnvironment.swift b/VPhoneKit/VPhoneCoreKit/VirtualMachine/VPhoneGuestEnvironment.swift
index 5c7f3a43..4ae30e5e 100644
--- a/VPhoneKit/VPhoneCoreKit/VirtualMachine/VPhoneGuestEnvironment.swift
+++ b/VPhoneKit/VPhoneCoreKit/VirtualMachine/VPhoneGuestEnvironment.swift
@@ -17,7 +17,7 @@ public enum VPhoneGuestEnvironment {
"libdevicehubfix.dylib",
"libdevicename.dylib",
"libprefsfix.dylib",
- "libsigninfix.dylib", "libvphoneios17desktop.dylib",
+ "libsigninfix.dylib", "libvphoneios17desktop.dylib", "libvphoneios16migration.dylib", "libvphoneios16desktop.dylib",
"libvphonefolddisplay.dylib",
"libvphonefoldguard.dylib",
"libvphonehinge.dylib",
@@ -36,7 +36,7 @@ public enum VPhoneGuestEnvironment {
/// Selection installs/removes these. A live hash sync may replace an
/// installed copy, but must never reinstall a patch the user turned off.
public static let selectedLibraries: Set<String> = [
- "libprefsfix.dylib", "libsigninfix.dylib", "libvphoneios17desktop.dylib",
+ "libprefsfix.dylib", "libsigninfix.dylib", "libvphoneios17desktop.dylib", "libvphoneios16migration.dylib", "libvphoneios16desktop.dylib",
"libvphonegyro.dylib", "libvphoneaccelerometer.dylib", "libvphoneattitude.dylib",
"libvphonehinge.dylib", "libvphonefoldguard.dylib", "libvphonefolddisplay.dylib",
]