Run a virtual iPhone on an Apple Silicon Mac.
Swift
Record why iOS 27 capture has no microphone on a guest
Jacky71b15c002661
diff --git a/Research/0_binary_patch_comparison.md b/Research/0_binary_patch_comparison.mdindex 0ce09bb5..9697d0d9 100644--- a/Research/0_binary_patch_comparison.md+++ b/Research/0_binary_patch_comparison.md@@ -524,6 +524,7 @@ do NOT execute these).| 19 | **Superseded 2026-09-30, as row 18.** The same `libmisfix.dylib` injected into `misagent`, where it interposes `MGCopyAnswer` / `MGCopyAnswerWithError` and answers `UniqueDeviceID` from a config file — **all bases** | `/usr/libexec/misagent` (+ `/usr/lib/libmisfix.plist`) | **Let a provisioning profile written for a device you already own install on the guest.** `0xE8008012` (`misagent: attempt to install invalid profile`) is the ordinary refusal when the profile's `ProvisionedDevices` does not list this device — correct behaviour, and distinct from row 17's `0xE8008026`. It blocks the case the user actually wants: reusing a paid team's already-registered device rather than burning a registration slot on every VM. The UDID being compared comes from `MGCopyAnswer(kMGUniqueDeviceID)`, and three cheaper routes were ruled out by measurement before any hook was written. (1) **AMFI cannot supply it**: `security.codesigning.config` is a 4-byte flags word (read back as `0x000000CC`), not a string, so `amfi_emulate_device_udid` is dead on this board. (2) **No daemon can write it**: `/private/var/root/Library/Lockdown/data_ark.plist` carries no `UniqueDeviceID` — lockdown derives it each boot. (3) **The real source is out of reach**: TXM composes `UniqueDeviceID` from the device tree's `/chosen/chip-id`, `/chosen/unique-chip-id` and `/product/udid-version` *before the kernel runs*, and `chip-id` is fixed at `0x0000FE01` while `unique-chip-id` is the ECID the SHSH blob is bound to — changing it means the VM no longer restores. So `MGCopyAnswer` is necessarily where this is done. Fix: interpose it in `misagent` only, return a `+1` copy (matching `MGCopyAnswer`'s contract) of the configured string for `UniqueDeviceID`, and fall through untouched for every other property. Configuration is `/var/db/vphone/misfix.plist`, falling back to `/usr/lib/libmisfix.plist`, cached against mtime and size so editing the file takes effect on the next query with no restart — that is the "put it in the plist and it applies" entry point. The shipped plist is **empty**: with no `UniqueDeviceID` key the interpose returns NULL and the patch is inert, so it changes nothing until someone deliberately pastes a real device's UDID in. `installMISFixDefaults` writes the fallback plist **only when it is absent**, so re-running `cfw install` never clobbers a configured value. **Accepted inconsistency, agreed with the user rather than hidden:** only `misagent`'s profile matching sees the borrowed UDID. Xcode, lockdown and `devicectl` keep reporting the VM's own (`0000FE01-…`), because those come from a different process that is not hooked. The two therefore disagree, which is exactly what makes the profile match while the device stays identifiable as itself. Declared `system-misagent-cfw-device_identity` in `com.vphone.patchset.guest.system`; no `applicability`, not `bootEssential`, on in `standard` but inert without a configured UDID. **Partially validated (2026-09-30, `06-xcode-27`):** `cfw install` reports `[+] LC_LOAD_WEAK_DYLIB /usr/lib/libmisfix.dylib -> misagent` and `misagent` runs normally on the booted guest. Installing a real paid-team IPA against a borrowed UDID is **not** yet demonstrated, for the same host-side `devicectl` reason as row 18. See `VPhoneGuestComponents/MISFix/MISFixDeviceIdentity.c`, `MISFixConfig.c` and `Research/Guest/xcode_install_signature_gate.md`. | Y | Y | Y || 20 | No binary change: the launchd hook inserts `libmisfix.dylib` into `SpringBoard` at spawn, beside SystemHook, and both spawn hooks do the same for `installd`, `misagent`, `lockdownd` and `remoted` (the last two for the UDID override only) — **all bases** | none (the guest environment's `launchdhook-vphone.dylib` and `SystemHook-vphone.dylib`) | **Let an installed developer-signed app launch.** SpringBoard validates the app with MIS again before launch and, on a hacktivated guest, fails row 17's `checkTrustAndAuthorization` with `0xE8008026` ("Unable to Verify App"). The hook's `MISValidateSignatureAndCopyInfoWithProgress` detour passes `RespectUppTrustAndAuthorization = false`, so the check is never called — row 17's effect with no shared-cache write, which is what makes it usable on 27.0. launchd starts SpringBoard itself rather than through xpcproxy, so the libraries it gets are the launchd hook's choice; that hook now asks the same `vpIsMISFixTarget` SystemHook does. `MISFixInstallPolicy` stays out of it. No declaration of its own: it ships with `system-launchdaemons-boot-environment`. A load-command version (`/mf` alias, `LC_SOURCE_VERSION` dropped) was committed and reverted the same day. See "One route for libmisfix, SpringBoard included (2026-09-30)" below. | Y | Y | Y || 21 | No binary change: SystemHook `dlopen`s `libhapticsfix.dylib` into `SpringBoard` at startup, where it replaces every `CHHapticEngine` initialiser's IMP so the initialiser returns nil — **all bases** | none (new guest dylib `VPhoneGuestComponents/HapticsFix/libhapticsfix.c`, installed at `/usr/lib/libhapticsfix.dylib`) | **Stop SpringBoard dying the first time UIKit plays a haptic.** The VM has no haptic device — Virtualization.framework exposes none on any base — and a real device without one gets nil from `CHHapticEngine`'s initialisers, so UIKit runs with no feedback, as on every non-Pro iPad. A guest reporting an iPad Pro model instead has an OS that *expects* the haptic stack, and CoreHaptics treats its absence as an internal error: measured on `iPad16,1 26.6.2 (23G90)`, 4h14m after launch, the first feedback event ran `-[_UIFeedbackCoreHapticsIgnoreCaptureHapticsOnlyEngine _internal_createCoreHapticsEngine]` → `-[CHHapticEngine initWithAudioSession:sessionIsShared:options:error:]` → `createHapticPlayerWithOptions:` → `Haptic_RaiseException` → `objc_exception_throw`, and the unwind resumed at an address inside a `---/---` Memory Tag 255 COW region next to the commpage — `EXC_BAD_ACCESS (SIGBUS)`, `KERN_PROTECTION_FAILURE`, a dead SpringBoard. The hook restores the no-hardware answer before UIKit can reach an initialiser: the constructor `dlopen`s CoreHaptics (it is not loaded that early, and the class must be in the runtime before UIKit asks), then `method_setImplementation` on every selector that is `init` or `init` + uppercase part — covering `initWithAudioSession:sessionIsShared:options:error:` today and any renamed sibling on other bases — with one IMP that ignores its arguments and returns nil, the framework's own answer on haptic-less hardware. Scope is SpringBoard only (`vpIsSpringBoard` in SystemHook, loaded before the app/bootstrap gate that would otherwise return first): it is the one UIKit process measured creating the haptics-only engine without asking CoreHaptics first, and apps that follow the documented `capabilitiesForHardware` path already answer no on the guest. Loaded like the camera hooks rather than inserted like libmisfix because interposing must be in place at launch while a method swizzle just has to run before first use; `DISABLE_TWEAKS` and safe mode skip it with everything else SystemHook loads. Ships with `system-launchdaemons-boot-environment`; existing guests receive it through the vphoned environment update (a missing file reports no hash, which is what triggers the push) and need a respring, which is deliberately the caller's call. See `VPhoneGuestComponents/HapticsFix/libhapticsfix.c`. | Y | Y | Y |+| 22 | No binary change: `libvcamcaptured.dylib` (already loaded into `cameracaptured` by SystemHook) wraps `+[FigCaptureSourceBackingsProvider sharedCaptureSourceBackingsProvider]` from its constructor; when the original returns nil it returns a microphone-only provider instead — **iOS 26.6+ layout, measured on iOS 27.0** | none (`VPhoneGuestComponents/VCamCaptured/Microphone/VCamMicrophoneSource.m`) | **Give an audio-only `AVCaptureSession` its microphone on a guest with no camera.** The built-in sources come from one provider that CMCapture builds only after `BWFigCaptureDeviceVendor` creates the `Default` camera device; a VM has no ISP plugin, so `Cannot create device without create function!`, -12786, `Wiping com.apple.cameracapture.volatile`, and no provider — the microphone, described by the same `AVCaptureSession.plist` call, is lost with the camera, and iOS 27 Voice Memos fails with `CaptureSessionRecorderError` 1 (`failedToCreateAudioDevice`). The wrapper feeds the exported `FigCaptureCreateSourceInfoArrayFromDeviceAndModelSpecificPlist` a NULL device and the shipped product plist (the guest's own `VPHONE600` has none; `D47` on the iPhone17,3 image) reduced to its `"soun"` entries, without persisting, and builds the provider with `-initWithSourceInfoDictionaries:commonSettings:`. A provider the daemon built itself passes through untouched. See `Research/Guest/ios27_capture_microphone_source.md`. | Y | Y | Y |### Swift port status — the eight DSC patchers (2026-09-23)diff --git a/Research/Guest/ios27_capture_microphone_source.md b/Research/Guest/ios27_capture_microphone_source.mdnew file mode 100644index 00000000..cfd2375c--- /dev/null+++ b/Research/Guest/ios27_capture_microphone_source.md@@ -0,0 +1,163 @@+# iOS 27 capture sources: the microphone goes with the camera++On an iPhone guest (`mictest-iphone`, iPhone99,11, iOS 27.0 24A435) Voice+Memos' Record failed before any audio I/O, while the same build of the sound+plugin records on an iPad guest (iPadOS 26.6.2). The audio route was fine+(`virtio_sound_microphone.md` §6). This note is the capture-stack half:+which code decides the capture source list, why it ends empty on a VM, and+what the hook in `libvcamcaptured` does about it.++Sources: CMCapture, AVFCapture and the VoiceMemos framework extracted from+the 24A435 iPhone17,3 restore image's shared cache (`ipsw extract --dyld`,+symbols from its `.symbols` file; addresses below are that cache's), the+guest's own `VoiceMemos.app/VoiceMemos` and+`CMCapture.framework/D47/AVCaptureSession.plist`, the guest's syslog, and+`/var/mobile/Media/SimulatedCamera/vcamcaptured.log`.++## 1. What Voice Memos asks for++iOS 27's Voice Memos records through `VoiceMemos.CaptureSessionRecorder`, an+`AVCaptureSession` with an audio device input and an+`AVCaptureMovieFileOutput` / `AVCaptureAudioDataOutput` (the app's strings:+`defaultDeviceWithDeviceType:mediaType:position:`,+`So24AVCaptureMovieFileOutputC`, `So24AVCaptureAudioDataOutputC`). Its error+enum, from the app's Swift metadata (`ipsw swift-dump`):++```+enum VoiceMemos.CaptureSessionRecorder.CaptureSessionRecorderError {+ case failedToCreateAudioDeviceInput(Error) // code 0+ case failedToCreateAudioDevice // code 1+ case cantAddAudioDeviceInput+ case cantAddAudioFileOutput+ case cantAddSampleOutput+ case multichannelAudioModeNotSupported+}+```++Swift numbers payload cases first, then the rest in declaration order, so+`CaptureSessionRecorderError Code=1` is `failedToCreateAudioDevice`: the+lookup of the microphone `AVCaptureDevice` returned nil. (The numbering rule is+the compiler's, not read from the app's code.)++The iPad guest's Voice Memos (26.6.2) records without `AVCaptureSession`, which+is why it never met this.++## 2. Where the capture sources come from++AVFoundation clients get their devices from cameracaptured's source server.+In iOS 27 (and 26.6, whose cache has the same strings and the same exported+functions) the built-in sources are made by+`+[FigCaptureSourceBackingsProvider sharedCaptureSourceBackingsProvider]`+(0x1b0447838), the function that logs as `cs_getBackingsForBuiltInCameras`:++1. Read `CaptureSourceInfo` from the preferences domain+ `com.apple.cameracapture.volatile`. If present and still valid+ (`csu_createBackingsFromCaptureSourceInfoDict` compares+ `DependentUserDefaults`, `FileModificationDate`, `InterpreterBuildDate`,+ `DeviceModel`, `ExperimentsEnabled`), make the backings from it.+2. Otherwise ("is empty, will repopulate") call+ `csu_createSourceInfoDictionariesFromAVCaptureSessionPlistForCaptureDeviceIDs`+ (0x1b07affe0) for `@[BWFigCaptureDeviceID_Default]`. For each device ID it+ asks `-[BWFigCaptureDeviceVendor copyDeviceForPublishingWithID:error:]`+ for the device. Only when that succeeds (0x1b07b0564 `cbnz x0`) does it+ load the model's `AVCaptureSession.plist` and call+ `FigCaptureCreateSourceInfoArrayFromDeviceAndModelSpecificPlist(device,+ plist, …)`. A failed copy is logged (`Error copying device %@ (%d)`), the+ error kept, and the device skipped.+3. A non-zero error makes the caller bail: `Error %d while creating+ FigCaptureDevice. Wiping com.apple.cameracapture.volatile…`,+ `Fig assert: "err == 0 " at bail (FigCaptureSourceBackingsProvider.m:1083)`.+ No provider is stored; the method returns nil, and the server reports+ `0 total in-memory backings`.++`FigCaptureCreateSourceInfoArrayFromDeviceAndModelSpecificPlist` (exported,+0x1b07a9ecc) is where the microphone is described. It walks the plist's+`AVCaptureDevices`, and the entry with `mediaType` `"soun"` and `uniqueName`+`"Microphone"` becomes a source info dictionary with `MediaType` `'soun'`,+`NonLocalizedName` "Microphone", `UniqueID`/`ModelID`+`kFigCaptureAudioSourceUniqueID_Microphone`, `PrefersDecoupledIO` and the+per-preset audio settings. That branch does not use the device; the camera+entries do (`csu_addSecureMetadataKeysToDeviceDict`,+`-[FigCaptureSourceStreamsContainer initWithDeviceType:…device:…]` inside+`csu_createVideoCaptureSourceInfoForCaptureDeviceFromModelSpecificPlist`).+`-[FigCaptureSourceBackingsProvider _addBackingsForSourceInfoDictionaries:]`+sets `_hasMicSource` when it meets the `'soun'` dictionary.++So the microphone's source is built in the same call as the cameras', and that+call is reached only after the camera device exists.++## 3. Why the camera device does not exist on a VM++`-[BWFigCaptureDeviceVendor _createDevice:reason:clientPID:figCaptureDevice:]`+logs `Cannot create device without create function!`: the vendor was made+with `initWithDefaultDeviceCreateFunction:` and no function. The function+comes from the ISP capture plugin (`/System/Library/MediaCapture/H16ISP.mediacapture`+and its siblings are the paths CMCapture knows); the guest's+`/System/Library/MediaCapture` is empty. The copy fails with -12786, and §2+step 3 follows.++Verified on the guest: `vcamcaptured.log` with a logging wrapper around the+provider method shows the original returning nil at the daemon's first source+query, and the guest syslog shows the -12786 chain quoted in+`virtio_sound_microphone.md` §6.++## 4. The virtual camera does not change this++`libvcamcaptured` is loaded into cameracaptured by SystemHook whether or not+the host streams a camera; host streaming only feeds the shared frame. Its+camera source is installed by appending a synthetic source to `_sSourceList`,+the iOS 26.x source-server list, and on iOS 27 that fails before anything is+appended:++```+filter-chain scan: pc=0x0 si_fn=0x0 prewarm_fn=0x0+init-statics block-invoke lookup failed+data global resolve failed: _sSourceList not located+```++Even where it works, it appends one camera source and hands out its synthetic+device only for its own device ID (`copyDeviceWithID:forClient:…`), never for+`copyDeviceForPublishingWithID:` with `Default`. Nothing in it gives the vendor+a create function or touches the backings provider, so switching the virtual+camera on cannot bring the microphone back. The iOS 27 virtual camera is a+separate open item.++## 5. The fix: a microphone-only provider++`VPhoneGuestComponents/VCamCaptured/Microphone/VCamMicrophoneSource.m`,+installed from the dylib's constructor (not with the camera hooks, which wait+3 s), wraps `+sharedCaptureSourceBackingsProvider` with+`method_setImplementation`:++* The original runs first. A provider it returns is passed through unchanged.+* When it returns nil, the wrapper builds a provider once and returns it from+ then on:+ 1. Plist: `FigCaptureSourcePlistCreateAndPreprocessForModelSpecificName`+ (exported) for `FigCaptureGetModelSpecificName()`. On the iPhone guest+ that name is `VPHONE600`, which has no folder; CMCapture ships one per+ product in the restore image (`D47/AVCaptureSession.plist` for+ iPhone17,3) next to `iOS/` (external cameras). The wrapper then tries+ each product folder that has an `AVCaptureSession.plist` and takes the+ first with a `"soun"` device.+ 2. That plist with `AVCaptureDevices` reduced to its `"soun"` entries goes+ to `FigCaptureCreateSourceInfoArrayFromDeviceAndModelSpecificPlist` with+ a NULL device, a non-NULL date (it is stored into a dictionary+ unconditionally) and `persist` false, so nothing is written to+ `com.apple.cameracapture.volatile`.+ 3. `-[FigCaptureSourceBackingsProvider initWithSourceInfoDictionaries:commonSettings:]`+ with the result.++The function's signature, read from its two call sites and its body:+`void (device, CFDictionaryRef plist, CFDateRef date, Boolean persist,+CFArrayRef *outSources /* +1 */, CFDictionaryRef *outCommonSettings /* +1 */)`.++Seeding `CaptureSourceInfo` in the volatile domain instead was rejected: the+cached dictionary is checked against five values (§2 step 1), the+provider's `+initialize` writes the same key (0x1b098b7d0), and every failed+build wipes the domain.++No firmware byte changes; the dylib already ships in the guest environment.++## 6. Validation++PENDINGdiff --git a/Research/Guest/virtio_sound_microphone.md b/Research/Guest/virtio_sound_microphone.mdindex 5a73ff9f..8eb1a4eb 100644--- a/Research/Guest/virtio_sound_microphone.md+++ b/Research/Guest/virtio_sound_microphone.md@@ -587,7 +587,9 @@ Not done:That is the capture stack's device discovery on a VM, not the soundplugin. No sound has been recorded on an iPhone guest: nothing run there- records without `AVCaptureSession`.+ records without `AVCaptureSession`. The cause and the cameracaptured hook+ that publishes the microphone anyway are in+ `ios27_capture_microphone_source.md`.## 7. Open