Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

camera: Make Camera.app launch on EXP firmware

zqxwce9bb5b87279ce
diff --git a/scripts/patch_camera_userland.sh b/scripts/patch_camera_userland.sh
new file mode 100755
index 00000000..933646a1
--- /dev/null
+++ b/scripts/patch_camera_userland.sh
@@ -0,0 +1,56 @@
+#!/bin/zsh
+# patch_camera_userland.sh — Apply the Camera.app accessibility DSC patches.
+#
+# Mirrors patch_hv_vmm_userland.sh's shape so the EXP install pipeline can
+# call into both via a single entry-point style. The actual work happens
+# in scripts/patchers/cfw_patch_camera_dsc.py::apply_all_camera_patches,
+# invoked through cfw.py's `patch-camera-dsc` subcommand.
+#
+# Usage:
+# patch_camera_userland.sh dsc <chunks_dir> <dsc_header>
+#
+# <chunks_dir> is the directory containing dyld_shared_cache_arm64e[.NN]
+# files (the mounted SystemOS Cryptex's System/Library/Caches/com.apple.dyld).
+# <dsc_header> is the dyld_shared_cache_arm64e file itself (sans suffix),
+# used by `ipsw dyld symaddr` for per-build symbol resolution.
+#
+# Used by: cfw_install_exp.sh
+
+set -euo pipefail
+
+SCRIPT_DIR="${0:a:h}"
+
+[[ -n "${_VPHONE_PATH:-}" ]] && export PATH="$_VPHONE_PATH"
+
+_resolve_python3() {
+ local venv_py="${SCRIPT_DIR:h}/.venv/bin/python3"
+ if [[ -x "$venv_py" ]]; then
+ echo "$venv_py"
+ else
+ command -v python3 || true
+ fi
+}
+PYTHON3="$(_resolve_python3)"
+
+usage() {
+ cat <<EOF >&2
+Usage:
+ $0 dsc <chunks_dir> <dsc_header>
+EOF
+ exit 2
+}
+
+(( $# >= 1 )) || usage
+op="$1"; shift
+
+case "$op" in
+ dsc)
+ (( $# >= 2 )) || usage
+ echo "[*] Patching camera consumers in DSC chunks under: $1"
+ echo "[*] (symbol resolution against: $2)"
+ "$PYTHON3" "$SCRIPT_DIR/patchers/cfw.py" patch-camera-dsc "$1" "$2"
+ ;;
+ *)
+ usage
+ ;;
+esac
diff --git a/scripts/patchers/cfw.py b/scripts/patchers/cfw.py
index b96c7365..ed3a37a4 100755
--- a/scripts/patchers/cfw.py
+++ b/scripts/patchers/cfw.py
@@ -29,6 +29,16 @@ Commands:
the mounted SystemOS Cryptex). Targets a fixed list of identity,
store, and consumer-service dylibs; skips compute/accel libs.
+ patch-camera-dsc <chunks_dir> <dsc_header> [--dry-run] [--force]
+ Apply the 10-patch set to the DSC chunks that makes Camera.app
+ launch-survivable on a vphone VM: synthesises a single
+ `vphone-cam` AVCaptureDevice through `cameracaptured`'s
+ device-list / discovery-session / serializer paths and stubs out
+ the AVFoundation init-time validation that would otherwise crash
+ on the synthetic device. <dsc_header> is the
+ dyld_shared_cache_arm64e file (not a chunk) used for
+ `ipsw dyld symaddr` symbol resolution.
+
patch-watchdogd <binary> [--dry-run]
Surgical 2-instruction patch of /usr/libexec/watchdogd's
sysctlbyname("kern.hv_vmm_present", ...) caching block so the
@@ -64,6 +74,7 @@ if __name__ == "__main__":
from patchers.cfw_patch_mobileactivationd import patch_mobileactivationd
from patchers.cfw_patch_jetsam import patch_launchd_jetsam
from patchers.cfw_patch_hv_vmm_dsc import patch_hv_vmm_in_dsc
+ from patchers.cfw_patch_camera_dsc import apply_all_camera_patches
from patchers.cfw_patch_watchdogd import patch_watchdogd
from patchers.cfw_daemons import parse_cryptex_paths, inject_daemons
else:
@@ -72,6 +83,7 @@ else:
from .cfw_patch_mobileactivationd import patch_mobileactivationd
from .cfw_patch_jetsam import patch_launchd_jetsam
from .cfw_patch_hv_vmm_dsc import patch_hv_vmm_in_dsc
+ from .cfw_patch_camera_dsc import apply_all_camera_patches
from .cfw_patch_watchdogd import patch_watchdogd
from .cfw_daemons import parse_cryptex_paths, inject_daemons
@@ -127,6 +139,15 @@ def main():
results = patch_hv_vmm_in_dsc(sys.argv[2], dry_run=dry_run)
sys.exit(0)
+ elif cmd == "patch-camera-dsc":
+ if len(sys.argv) < 4:
+ print("Usage: patch_cfw.py patch-camera-dsc <chunks_dir> <dsc_header> [--dry-run] [--force]")
+ sys.exit(1)
+ dry_run = "--dry-run" in sys.argv[4:]
+ force = "--force" in sys.argv[4:]
+ apply_all_camera_patches(sys.argv[2], sys.argv[3], dry_run=dry_run, force=force)
+ sys.exit(0)
+
elif cmd == "patch-watchdogd":
if len(sys.argv) < 3:
print("Usage: patch_cfw.py patch-watchdogd <binary> [--dry-run]")
@@ -171,7 +192,7 @@ def main():
else:
print(f"Unknown command: {cmd}")
- print("Commands: cryptex-paths, patch-seputil, patch-launchd-cache-loader,")
+ print("Commands: cryptex-paths, patch-seputil, patch-launchd-cache-loader, patch-camera-dsc,")
print(" patch-mobileactivationd, patch-launchd-jetsam,")
print(" patch-hv-vmm-dsc, patch-watchdogd, inject-daemons, inject-dylib")
sys.exit(1)
diff --git a/scripts/patchers/cfw_patch_camera_dsc.py b/scripts/patchers/cfw_patch_camera_dsc.py
new file mode 100644
index 00000000..a1300f67
--- /dev/null
+++ b/scripts/patchers/cfw_patch_camera_dsc.py
@@ -0,0 +1,224 @@
+"""Camera-related DSC patches for the vphone EXP firmware.
+
+Two patch families:
+
+1. NeutrinoCore short-circuit — replace the five
+ `+[_NUStyleTransfer*Processor processWithInputs:arguments:output:error:]`
+ class methods with `mov w0, #0; ret`. Together with the DT `/product/camera`
+ node (added by `DeviceTreePatcher.swift`), this lets Camera.app launch and
+ reach the viewfinder UI on this VM build without crashing in NeutrinoCore.
+
+2. AVCaptureDevice authorization gate — replace
+ `+[AVCaptureDevice authorizationStatusForMediaType:]` in `AVFCapture` with
+ `mov w0, #3; ret` (AVAuthorizationStatusAuthorized = 3). Any process that
+ probes camera (or any other media type) authorization gets "Authorized"
+ without going through TCC. Stage 0 of the vcam stack — makes apps stop
+ bailing on the auth check; downstream pipeline still needs Stages 1+2 to
+ actually deliver frames.
+"""
+
+import os
+import re
+import shutil
+import subprocess
+
+try:
+ from .cfw_asm import asm
+ from .cfw_dsc_chunks import DSCChunks
+ from .cfw_dsc_codesign import reattest_modified_pages
+except ImportError:
+ from cfw_asm import asm
+ from cfw_dsc_chunks import DSCChunks
+ from cfw_dsc_codesign import reattest_modified_pages
+
+
+NU_STYLE_TRANSFER_SYMBOLS = [
+ "+[_NUStyleTransferProcessor processWithInputs:arguments:output:error:]",
+ "+[_NUStyleTransferThumbnailProcessor processWithInputs:arguments:output:error:]",
+ "+[_NUStyleTransferApplyProcessor processWithInputs:arguments:output:error:]",
+ "+[_NUStyleTransferLearnProcessor processWithInputs:arguments:output:error:]",
+ "+[_NUStyleTransferInterpolateProcessor processWithInputs:arguments:output:error:]",
+]
+
+AVF_AUTH_STATUS_SYMBOL = (
+ "+[AVCaptureDevice authorizationStatusForMediaType:]"
+)
+
+
+def _resolve_symbols_in_image(dsc_path, image_path, wanted_symbols):
+ """Resolve a set of ObjC method symbols in `image_path` against `dsc_path`
+ via `ipsw dyld symaddr`. Returns {symbol: vmaddr}. Raises if any are missing.
+ """
+ ipsw_bin = shutil.which("ipsw")
+ if not ipsw_bin:
+ raise RuntimeError("`ipsw` not in PATH")
+ cmd = [
+ ipsw_bin, "dyld", "symaddr", dsc_path,
+ "--image", image_path,
+ ]
+ out = subprocess.run(cmd, capture_output=True, text=True, check=True).stdout
+ wanted = set(wanted_symbols)
+ results = {}
+ for line in out.splitlines():
+ line = re.sub(r"\x1b\[[0-9;]*m", "", line).rstrip()
+ m = re.match(r"\s*(0x[0-9A-Fa-f]+):\s*\([^)]+\)\s*(.+)$", line)
+ if not m:
+ continue
+ addr, rest = m.group(1), m.group(2)
+ sym = rest.rsplit("\t", 1)[0].strip() if "\t" in rest else rest.strip()
+ if sym in wanted:
+ results[sym] = int(addr, 16)
+ missing = [s for s in wanted_symbols if s not in results]
+ if missing:
+ raise RuntimeError(
+ f"could not resolve symbols in {image_path}: {missing}"
+ )
+ return results
+
+
+def resolve_nu_symbols(dsc_path):
+ """Resolve the five NeutrinoCore symbols."""
+ return _resolve_symbols_in_image(
+ dsc_path,
+ "/System/Library/PrivateFrameworks/NeutrinoCore.framework/NeutrinoCore",
+ NU_STYLE_TRANSFER_SYMBOLS,
+ )
+
+
+def resolve_avf_auth_symbol(dsc_path):
+ """Resolve +[AVCaptureDevice authorizationStatusForMediaType:] in AVFCapture."""
+ return _resolve_symbols_in_image(
+ dsc_path,
+ "/System/Library/PrivateFrameworks/AVFCapture.framework/AVFCapture",
+ [AVF_AUTH_STATUS_SYMBOL],
+ )
+
+
+def patch_nu_styletransfer_short_circuit(chunks, vmas, *, dry_run=False, force=False):
+ """Replace each `+[_NUStyleTransfer*Processor processWithInputs:...]` with
+ `mov w0, #0; ret`. Camera's style-thumbnail pipeline then short-circuits
+ before reaching `_NUStyleEngineMemoryResource init:`, which would otherwise
+ assert on a nil descriptor and SIGABRT on first viewfinder render.
+ """
+ new_bytes = asm("mov w0, #0\nret")
+ if len(new_bytes) != 8:
+ raise RuntimeError(f"expected 8 bytes, got {len(new_bytes)}")
+
+ patched = []
+ for sym, vma in sorted(vmas.items()):
+ orig = chunks.bytes_at_vma(vma, 8)
+ print(f" {sym} @ 0x{vma:X}")
+ print(f" {orig.hex()} → {new_bytes.hex()}")
+ if orig[:4] != b"\x7f\x23\x03\xd5" and not force:
+ raise RuntimeError(
+ f"{sym}: prologue not pacibsp (got {orig[:4].hex()}); use --force to override"
+ )
+ if not dry_run:
+ chunks.write_at_vma(vma, new_bytes)
+ patched.append(vma)
+
+ if dry_run:
+ print(" [DRY RUN]")
+ return
+
+ diags = reattest_modified_pages(chunks, patched, verbose=True)
+ print(f" re-attested {len(diags)} page(s)")
+ for vma in patched:
+ if chunks.bytes_at_vma(vma, 8) != new_bytes:
+ raise RuntimeError(f"post-write verify failed at 0x{vma:X}")
+
+
+def patch_avf_authorization_always_authorized(
+ chunks, vmas, *, dry_run=False, force=False
+):
+ """Replace `+[AVCaptureDevice authorizationStatusForMediaType:]` with
+ `mov w0, #3; ret`. Authorized = 3 across every media type — broader than
+ just video, but the VM doesn't service audio capture either, so any app
+ probing audio auth would have failed downstream regardless.
+ """
+ new_bytes = asm("mov w0, #3\nret")
+ if len(new_bytes) != 8:
+ raise RuntimeError(f"expected 8 bytes, got {len(new_bytes)}")
+
+ patched = []
+ for sym, vma in sorted(vmas.items()):
+ orig = chunks.bytes_at_vma(vma, 8)
+ print(f" {sym} @ 0x{vma:X}")
+ print(f" {orig.hex()} → {new_bytes.hex()}")
+ if orig[:4] != b"\x7f\x23\x03\xd5" and not force:
+ raise RuntimeError(
+ f"{sym}: prologue not pacibsp (got {orig[:4].hex()}); use --force to override"
+ )
+ if not dry_run:
+ chunks.write_at_vma(vma, new_bytes)
+ patched.append(vma)
+
+ if dry_run:
+ print(" [DRY RUN]")
+ return
+
+ diags = reattest_modified_pages(chunks, patched, verbose=True)
+ print(f" re-attested {len(diags)} page(s)")
+ for vma in patched:
+ if chunks.bytes_at_vma(vma, 8) != new_bytes:
+ raise RuntimeError(f"post-write verify failed at 0x{vma:X}")
+
+
+def apply_all_camera_patches(chunks_dir, dsc_path, *, dry_run=False, force=False):
+ """Apply every camera DSC patch against `chunks_dir`, resolving symbols
+ against `dsc_path`."""
+ chunks = DSCChunks(chunks_dir)
+ print(f" [.] DSC: {chunks!r}")
+
+ print(f" [.] resolving NeutrinoCore symbols against {dsc_path}...")
+ nu_vmas = resolve_nu_symbols(dsc_path)
+ print(f" [.] resolving AVFCapture authorization symbol against {dsc_path}...")
+ avf_vmas = resolve_avf_auth_symbol(dsc_path)
+
+ print(f"\n [1/2] +[_NUStyleTransfer*Processor processWithInputs:...] → return NO")
+ patch_nu_styletransfer_short_circuit(chunks, nu_vmas, dry_run=dry_run, force=force)
+
+ print(f"\n [2/2] +[AVCaptureDevice authorizationStatusForMediaType:] → return Authorized")
+ patch_avf_authorization_always_authorized(chunks, avf_vmas, dry_run=dry_run, force=force)
+
+ print(f"\n [+] camera DSC patches applied: 2/2")
+ return 2
+
+
+def apply_avf_auth_only(chunks_dir, dsc_path, *, dry_run=False, force=False):
+ """Apply only the AVFCapture authorization gate patch. Useful when running
+ on a chunk pulled from a device that already has the NU patches applied
+ (composition mode in `vphone-dsc-chunk-ramdisk-deploy`)."""
+ chunks = DSCChunks(chunks_dir)
+ print(f" [.] DSC: {chunks!r}")
+ print(f" [.] resolving AVFCapture authorization symbol against {dsc_path}...")
+ avf_vmas = resolve_avf_auth_symbol(dsc_path)
+ print(f"\n [1/1] +[AVCaptureDevice authorizationStatusForMediaType:] → return Authorized")
+ patch_avf_authorization_always_authorized(chunks, avf_vmas, dry_run=dry_run, force=force)
+ print(f"\n [+] AVF-only camera DSC patch applied: 1/1")
+ return 1
+
+
+def patch_camera_in_dsc(chunks_dir, dsc_path=None):
+ """Entry point used by `cfw.py patch-camera-dsc`."""
+ if not dsc_path:
+ raise RuntimeError("dsc_path is required (pass --dsc-header on the CLI)")
+ return apply_all_camera_patches(chunks_dir, dsc_path)
+
+
+if __name__ == "__main__":
+ import argparse
+ ap = argparse.ArgumentParser(description="Camera DSC patcher")
+ ap.add_argument("chunks_dir", help="directory containing dyld_shared_cache_arm64e.* files")
+ ap.add_argument("dsc_header", help="path to the dyld_shared_cache_arm64e header (no suffix)")
+ ap.add_argument("--dry-run", action="store_true")
+ ap.add_argument("--force", action="store_true")
+ ap.add_argument("--avf-only", action="store_true",
+ help="Apply only the AVFCapture authorization gate patch (composition mode)")
+ args = ap.parse_args()
+ if args.avf_only:
+ apply_avf_auth_only(args.chunks_dir, args.dsc_header,
+ dry_run=args.dry_run, force=args.force)
+ else:
+ apply_all_camera_patches(args.chunks_dir, args.dsc_header,
+ dry_run=args.dry_run, force=args.force)
diff --git a/sources/FirmwarePatcher/DeviceTree/DeviceTreePatcher.swift b/sources/FirmwarePatcher/DeviceTree/DeviceTreePatcher.swift
index 25b4c20b..48867aa6 100644
--- a/sources/FirmwarePatcher/DeviceTree/DeviceTreePatcher.swift
+++ b/sources/FirmwarePatcher/DeviceTree/DeviceTreePatcher.swift
@@ -38,6 +38,27 @@ public final class DeviceTreePatcher: Patcher {
let description: String
}
+ /// A patch that adds a brand-new child node under an existing parent.
+ /// Used when iPhone17,3 carries a node that vphone600 does not — e.g.
+ /// `/device-tree/product/camera`, which `libMobileGestalt` requires to
+ /// answer `MGGetBoolAnswer("still-camera")` truthfully.
+ struct AddChildNodePatch {
+ let parentPath: [String]
+ let nodeName: String
+ /// Properties to place inside the new node. The `name` property is
+ /// added automatically from `nodeName`; do not include it here.
+ let properties: [PropertySpec]
+ let patchID: String
+ let description: String
+
+ struct PropertySpec {
+ let name: String
+ let length: Int
+ let flags: UInt16
+ let value: PropertyValue
+ }
+ }
+
/// The value to write into a device tree property.
enum PropertyValue {
case string(String)
@@ -271,6 +292,364 @@ public final class DeviceTreePatcher: Patcher {
patchID: "devicetree.product.gestalt_variants_rename",
description: "Rename node vphone600-gestalt-variants -> d47-gestalt-variants"
),
+
+ // ── Camera physical-offset rewrites (Tier B) ──────────────────
+ // vphone600 ships these as 12-byte `'syscfg/fcof'` / `'syscfg/rcof'`
+ // cstring placeholders. d47ap carries 20-byte little-endian
+ // blobs describing the physical mm offset from screen center
+ // for each camera. Consumed by Camera.app / ARKit / FaceTime
+ // for image-centering math. Replacing the placeholder with the
+ // real d47ap blob (length 12 → 20) keeps the consuming code on
+ // a real number rather than reading the literal `'syscfg/...'`
+ // cstring as junk geometry.
+ PropertyPatch(
+ nodePath: ["device-tree", "product"],
+ property: "front-cam-offset-from-center",
+ length: 20,
+ flags: 0,
+ value: .bytes(Data([
+ 0x61, 0x00, 0x01, 0x00, 0x92, 0x1c, 0x00, 0x00,
+ 0xd8, 0x13, 0x00, 0x00, 0xe8, 0x03, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ ])),
+ patchID: "devicetree.product.front_cam_offset",
+ description: "Set product/front-cam-offset-from-center to d47ap geometry (was syscfg/fcof)"
+ ),
+ PropertyPatch(
+ nodePath: ["device-tree", "product"],
+ property: "rear-cam-offset-from-center",
+ length: 20,
+ flags: 0,
+ value: .bytes(Data([
+ 0xed, 0xa5, 0x00, 0x00, 0xb2, 0x56, 0x00, 0x00,
+ 0x59, 0x08, 0x00, 0x00, 0xe8, 0x03, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ ])),
+ patchID: "devicetree.product.rear_cam_offset",
+ description: "Set product/rear-cam-offset-from-center to d47ap geometry (was syscfg/rcof)"
+ ),
+ ]
+
+ /// Experimental child-node additions. Adds nodes that exist on real
+ /// iPhone17,3 but not on vphone600 — so the userland answer surface
+ /// matches the spoofed identity. Gated by `includeIdentityPatches`
+ /// (EXP variant only).
+ ///
+ /// `/device-tree/product/camera` is required for
+ /// `MGGetBoolAnswer("still-camera")` to return YES — without it,
+ /// SpringBoard's SBAppTags filter hides `Camera.app`'s icon and
+ /// blocks launch. The d47ap DT carries this node with 64 capability
+ /// properties; the subset here is the minimum that backs the
+ /// `cameraCapability` / `aggregateCameraCapability` /
+ /// `autoFocusCameraCapability` getters in libMobileGestalt and the
+ /// `still-camera` answer the SBAppTags consumer hits.
+ static let experimentalNodeAdditions: [AddChildNodePatch] = [
+ // Replicates the full `/product/camera` property set carried by the
+ // iPhone17,3 D47AP DT (62 props in the reference build, all integers
+ // or zero-length placeholders). The minimal 11-property version
+ // wasn't enough — `PurpleBuddy` and other first-boot consumers
+ // re-evaluate camera capability via `MGGetBoolAnswer` reading
+ // additional DT properties (front-flash-capability,
+ // live-photo-capture, rear-cam-superwide-capability, etc.) and
+ // hide the Camera icon if any return nil/absent.
+ //
+ // Values copied byte-for-byte from
+ // `ipsws/iPhone17,3_26.5_23F77_Restore_extracted/Firmware/all_flash/DeviceTree.d47ap.im4p`
+ // post-LZFSE-decompression. Sorted alphabetically for diff stability.
+ // The `"<"` / `"d"` / `"x"` values that ipsw dtree shows are 4-byte
+ // little-endian ints whose first byte happens to print:
+ // "<" = 0x3C = 60 (60 fps cap)
+ // "d" = 0x64 = 100 (100-ms burst duration)
+ // "x" = 0x78 = 120 (120 fps slomo cap)
+ // `<nil>` properties are 0-length placeholders (the name exists but
+ // there's no value blob); MGGetBoolAnswer treats those as YES too.
+ AddChildNodePatch(
+ parentPath: ["device-tree", "product"],
+ nodeName: "camera",
+ properties: [
+ .init(name: "aggregate-cam-photo-zoom", length: 4, flags: 0, value: .integer(0x7d0)),
+ .init(name: "aggregate-cam-video-zoom", length: 4, flags: 0, value: .integer(0x4b0)),
+ .init(name: "aggregate-camera", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "auto-focus", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "auto-low-light-video", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "camera-hdr-version", length: 4, flags: 0, value: .integer(3)),
+ .init(name: "camera-ui-version", length: 4, flags: 0, value: .integer(2)),
+ .init(name: "deferred-processing", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "flash", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "front-auto-focus", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "front-auto-hdr", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "front-burst", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "front-burst-image-duration", length: 4, flags: 0, value: .integer(100)),
+ .init(name: "front-flash-capability", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "front-hdr", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "front-hdr-on", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "front-low-light-photo", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "front-max-burst-length", length: 4, flags: 0, value: .integer(600)),
+ .init(name: "front-max-slomo-video-fps-1080p", length: 4, flags: 0, value: .integer(120)),
+ .init(name: "front-max-slomo-video-fps-720p", length: 4, flags: 0, value: .integer(120)),
+ .init(name: "front-max-video-fps-1080p", length: 4, flags: 0, value: .integer(60)),
+ .init(name: "front-max-video-fps-4k", length: 4, flags: 0, value: .integer(60)),
+ .init(name: "front-max-video-fps-720p", length: 4, flags: 0, value: .integer(60)),
+ .init(name: "front-max-video-zoom", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "front-slowmo", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "front-stage-light-portrait", length: 0, flags: 0, value: .bytes(Data())),
+ .init(name: "front-variable-frame-rate", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "live-effects", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "live-photo-auto", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "live-photo-capture", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "moment-capture", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "p3-color-space-video-recording", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "panorama", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "pearl-camera", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "photo-capture-on-touch-down", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "photos-live-video-rendering", length: 0, flags: 0, value: .bytes(Data())),
+ .init(name: "pipelined-stillimage-capability", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "portrait-lighting-strength", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "post-effects", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "rear-auto-hdr", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "rear-burst", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "rear-burst-image-duration", length: 4, flags: 0, value: .integer(100)),
+ .init(name: "rear-cam-sup-wide-af-capability", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "rear-cam-superwide-capability", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "rear-hdr", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "rear-hdr-on", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "rear-low-light-photo", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "rear-max-burst-length", length: 4, flags: 0, value: .integer(600)),
+ .init(name: "rear-max-slomo-video-fps-1080p", length: 4, flags: 0, value: .integer(240)),
+ .init(name: "rear-max-slomo-video-fps-720p", length: 4, flags: 0, value: .integer(240)),
+ .init(name: "rear-max-video-fps-1080p", length: 4, flags: 0, value: .integer(60)),
+ .init(name: "rear-max-video-fps-4k", length: 4, flags: 0, value: .integer(60)),
+ .init(name: "rear-max-video-fps-720p", length: 4, flags: 0, value: .integer(60)),
+ .init(name: "rear-max-video-frame_rate", length: 4, flags: 0, value: .integer(60)),
+ .init(name: "rear-max-video-zoom", length: 4, flags: 0, value: .integer(3)),
+ .init(name: "rear-slowmo", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "rear-stage-light-portrait", length: 0, flags: 0, value: .bytes(Data())),
+ .init(name: "rear-variable-frame-rate", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "spatial-over-capture", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "stage-light-portrait-preview", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "video-cap", length: 4, flags: 0, value: .integer(2)),
+ .init(name: "video-stills", length: 4, flags: 0, value: .integer(1)),
+ ],
+ patchID: "devicetree.product.camera_node",
+ description: "Add /product/camera node with full iPhone17,3 D47AP property set (62 props)"
+ ),
+
+ // ── /product/facetime (Tier C — front-camera video-call config) ──
+ // d47ap carries this 11-property node (excluding AAPL,phandle).
+ // FaceTime reads bitrate-{2g,3g,lte,wifi}, decoding/encoding
+ // codec parameters, pref-decoding, and tnr-mode-{back,front}
+ // (temporal noise reduction) at app launch. Values byte-for-byte
+ // from the d47ap DT.
+ AddChildNodePatch(
+ parentPath: ["device-tree", "product"],
+ nodeName: "facetime",
+ properties: [
+ .init(name: "bitrate-2g", length: 4, flags: 0, value: .integer(100)),
+ .init(name: "bitrate-3g", length: 4, flags: 0, value: .integer(228)),
+ .init(name: "bitrate-lte", length: 4, flags: 0, value: .integer(228)),
+ .init(name: "bitrate-wifi", length: 4, flags: 0, value: .integer(2000)),
+ .init(name: "decoding", length: 48, flags: 0, value: .bytes(Data([
+ 0x40, 0x01, 0x00, 0x00, 0x0f, 0x00, 0xf0, 0x00,
+ 0x40, 0x01, 0x00, 0x00, 0x1e, 0x00, 0xf0, 0x00,
+ 0xe0, 0x01, 0x00, 0x00, 0x0f, 0x00, 0x70, 0x01,
+ 0xe0, 0x01, 0x00, 0x00, 0x1e, 0x00, 0x70, 0x01,
+ 0x80, 0x02, 0x00, 0x00, 0x1e, 0x00, 0xe0, 0x01,
+ 0x00, 0x04, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x03,
+ ]))),
+ .init(name: "encoding", length: 56, flags: 0, value: .bytes(Data([
+ 0x40, 0x01, 0x00, 0x00, 0x0f, 0x00, 0xf0, 0x00,
+ 0x40, 0x01, 0x00, 0x00, 0x1e, 0x00, 0xf0, 0x00,
+ 0xe0, 0x01, 0x00, 0x00, 0x0f, 0x00, 0x70, 0x01,
+ 0xe0, 0x01, 0x00, 0x00, 0x1e, 0x00, 0x70, 0x01,
+ 0x80, 0x02, 0x00, 0x00, 0x1e, 0x00, 0xe0, 0x01,
+ 0x00, 0x04, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x03,
+ 0x00, 0x05, 0x00, 0x00, 0x1e, 0x00, 0xd0, 0x02,
+ ]))),
+ .init(name: "pref-decoding", length: 8, flags: 0, value: .integer(0x0300_001e_0000_0400)),
+ .init(name: "tnr-mode-back", length: 4, flags: 0, value: .integer(10)),
+ .init(name: "tnr-mode-front", length: 4, flags: 0, value: .integer(10)),
+ ],
+ patchID: "devicetree.product.facetime_node",
+ description: "Add /product/facetime node with full iPhone17,3 D47AP property set (9 props)"
+ ),
+
+ // ── /product/audio (Tier C — audio + spatial-capture flags) ──
+ // d47ap carries this 31-property node (excluding AAPL,phandle).
+ // Two camera-joint flags live here: `supports-spatial-audio-capture`
+ // and `supports-spatial-facetime` — needed for spatial-video and
+ // spatial-photo capture pipelines that combine camera + audio.
+ // The remaining 29 properties are pure audio config (mic gains,
+ // speaker cpms, voice trigger, channel layout, codec use-case
+ // formats). Calibration cstrings (`mic-trim-gains-*`,
+ // `speaker-thiele-small-*`, `speaker-trim-gains-*`) keep their
+ // syscfg-reference form — replacing them with concrete values
+ // from d47 wouldn't make the VM's actual mic/speaker hardware
+ // match, but downstream code already handles missing-syscfg
+ // gracefully.
+ AddChildNodePatch(
+ parentPath: ["device-tree", "product"],
+ nodeName: "audio",
+ properties: [
+ .init(name: "acoustic-id", length: 4, flags: 0, value: .integer(8018)),
+ .init(name: "actuator-cpms-bgd_100ms", length: 8, flags: 0, value: .integer(0x0000_0eef_0000_01f4)),
+ .init(name: "actuator-cpms-bgd_inst", length: 8, flags: 0, value: .integer(0x0000_1db0_0000_06d6)),
+ .init(name: "enabledChannels", length: 4, flags: 0, value: .integer(15)),
+ .init(name: "historyChannels", length: 4, flags: 0, value: .integer(15)),
+ .init(name: "mic-trim-gains-0", length: 12, flags: 0, value: .string("syscfg/MiGH")),
+ .init(name: "mic-trim-gains-2", length: 12, flags: 0, value: .string("syscfg/MiGB")),
+ .init(name: "mic-trim-gains-key-cnt", length: 4, flags: 0, value: .integer(2)),
+ .init(name: "speaker-cpms-bgd_100ms", length: 8, flags: 0, value: .integer(0x0000_2328_0000_04b0)),
+ .init(name: "speaker-cpms-bgd_1s", length: 8, flags: 0, value: .integer(0x0000_2328_0000_04b0)),
+ .init(name: "speaker-cpms-bgd_inst", length: 8, flags: 0, value: .integer(0x0000_2328_0000_04b0)),
+ .init(name: "speaker-thiele-small-0", length: 12, flags: 0, value: .string("syscfg/SpPH")),
+ .init(name: "speaker-thiele-small-key-cnt", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "speaker-trim-gains-0", length: 12, flags: 0, value: .string("syscfg/SpGH")),
+ .init(name: "speaker-trim-gains-key-cnt", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "stereo-sound-recording", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "supportedChannels", length: 4, flags: 0, value: .integer(15)),
+ .init(name: "supports-advanced-vp-chatflavor", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "supports-always-listening", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "supports-audio-mix", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "supports-auto-mic-mode", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "supports-barge-in", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "supports-concurrent-hp-lp-mics", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "supports-mic-modes-telephony", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "supports-spatial-audio-capture", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "supports-spatial-facetime", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "use-case-client-format", length: 96, flags: 0, value: .bytes(Data([
+ 0x61, 0x64, 0x6e, 0x73, 0x80, 0xbb, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x69, 0x72, 0x69, 0x73, 0x80, 0x3e, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x73, 0x74, 0x70, 0x6c, 0x80, 0x3e, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ ]))),
+ .init(name: "use-case-dsp-in-format", length: 160, flags: 0, value: .bytes(Data([
+ 0x64, 0x6b, 0x74, 0x6d, 0x80, 0xbb, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x61, 0x64, 0x6e, 0x73, 0x80, 0xbb, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x64, 0x76, 0x70, 0x73, 0x80, 0xbb, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x69, 0x72, 0x69, 0x73, 0x80, 0x3e, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x73, 0x74, 0x70, 0x6c, 0x80, 0x3e, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ ]))),
+ .init(name: "use-case-struct-version", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "voiceTriggerChannels", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "wireless-splitter", length: 4, flags: 0, value: .integer(1)),
+ ],
+ patchID: "devicetree.product.audio_node",
+ description: "Add /product/audio node with full iPhone17,3 D47AP property set (31 props)"
+ ),
+
+ // ── /product/iopm (Tier C — always-on technology) ────────────
+ // d47ap carries this 2-property node (excluding AAPL,phandle).
+ // `aot-mode = 13` enables Always-On Technology — drives wake
+ // policy and always-on-display behavior. POTENTIAL DISPLAY
+ // RISK: if the VM display can't service the AOT init path,
+ // this may need to be reverted in isolation. Test this batch
+ // alongside facetime + audio + Tier B; if display breaks,
+ // remove this AddChildNodePatch entry first before bisecting
+ // the rest.
+ AddChildNodePatch(
+ parentPath: ["device-tree", "product"],
+ nodeName: "iopm",
+ properties: [
+ .init(name: "aot-linger-time-ms", length: 4, flags: 0, value: .integer(0)),
+ .init(name: "aot-mode", length: 4, flags: 0, value: .integer(13)),
+ ],
+ patchID: "devicetree.product.iopm_node",
+ description: "Add /product/iopm node with aot-mode=13 + aot-linger-time-ms=0 (2 props)"
+ ),
+
+ // ── ISP / SMC camera-flag stubs (Tier F — /arm-io subtree) ──
+ // Adds minimal stub nodes carrying ONLY the camera-related
+ // properties that libMobileGestalt / SpringBoard / Camera.app
+ // userland code walks under `/arm-io/isp`, `/arm-io/ispRtb`,
+ // and `/arm-io/smc/iop-smc-nub/smc-ext-charger`.
+ //
+ // d47ap carries these as full hardware-attach nodes (65/53/14
+ // properties). We deliberately do NOT replicate the full set
+ // — they describe a real ISP / SMC chip with MMIO regions,
+ // interrupts, DART/IOMMU bindings, kext-`compatible` strings
+ // etc., and the VM has no such hardware. Stubbing only the
+ // camera-* properties + the mandatory `name` (no `compatible`,
+ // no `device_type`, no `reg`, no `interrupts`) means:
+ //
+ // - IOKit registry sees these nodes appear under `/arm-io`.
+ // - No kext (`AppleH16CamIn`, AppleSMC, etc.) finds a
+ // matching `compatible` and binds, so no driver probe
+ // can fail-and-panic on missing hardware.
+ // - Userland code that resolves these paths via
+ // `IORegistryEntryFromPath` + `IORegistryEntryGetProperty`
+ // still finds the camera-* properties on the empty stub.
+ //
+ // RISK: still untested. If an IOKit walker reports the empty
+ // node and a userland daemon (e.g. cameracaptured) takes the
+ // node's presence as "real ISP attached" and then crashes
+ // trying to talk to it, the symptom is likely a boot stall or
+ // a camera-daemon respawn loop visible in logs. Bisect by
+ // removing /arm-io/isp + /arm-io/ispRtb first if so.
+ //
+ // The three nodes are added in dependency order: each parent
+ // before its children. The patcher walks `experimentalNodeAdditions`
+ // in array order against the in-memory tree, so later entries
+ // can resolve parents added by earlier entries.
+
+ // /arm-io/smc — empty stub (parent for iop-smc-nub).
+ AddChildNodePatch(
+ parentPath: ["device-tree", "arm-io"],
+ nodeName: "smc",
+ properties: [],
+ patchID: "devicetree.arm_io.smc_stub",
+ description: "Add /arm-io/smc empty stub (parent for smc-ext-charger chain)"
+ ),
+
+ // /arm-io/smc/iop-smc-nub — empty stub (parent for smc-ext-charger).
+ AddChildNodePatch(
+ parentPath: ["device-tree", "arm-io", "smc"],
+ nodeName: "iop-smc-nub",
+ properties: [],
+ patchID: "devicetree.arm_io.smc.iop_smc_nub_stub",
+ description: "Add /arm-io/smc/iop-smc-nub empty stub (parent for smc-ext-charger)"
+ ),
+
+ // /arm-io/smc/iop-smc-nub/smc-ext-charger — carries camera-driver.
+ AddChildNodePatch(
+ parentPath: ["device-tree", "arm-io", "smc", "iop-smc-nub"],
+ nodeName: "smc-ext-charger",
+ properties: [
+ .init(name: "camera-driver", length: 14, flags: 0, value: .string("AppleH16CamIn")),
+ ],
+ patchID: "devicetree.arm_io.smc.smc_ext_charger_camera_driver",
+ description: "Add /arm-io/smc/iop-smc-nub/smc-ext-charger with camera-driver='AppleH16CamIn'"
+ ),
+
+ // /arm-io/isp — minimal stub carrying camera-front + camera-rear.
+ AddChildNodePatch(
+ parentPath: ["device-tree", "arm-io"],
+ nodeName: "isp",
+ properties: [
+ .init(name: "camera-front", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "camera-rear", length: 4, flags: 0, value: .integer(1)),
+ ],
+ patchID: "devicetree.arm_io.isp_camera_flags",
+ description: "Add /arm-io/isp stub with camera-front=1 + camera-rear=1"
+ ),
+
+ // /arm-io/ispRtb — minimal stub carrying camera-front + camera-rear.
+ AddChildNodePatch(
+ parentPath: ["device-tree", "arm-io"],
+ nodeName: "ispRtb",
+ properties: [
+ .init(name: "camera-front", length: 4, flags: 0, value: .integer(1)),
+ .init(name: "camera-rear", length: 4, flags: 0, value: .integer(1)),
+ ],
+ patchID: "devicetree.arm_io.ispRtb_camera_flags",
+ description: "Add /arm-io/ispRtb stub with camera-front=1 + camera-rear=1"
+ ),
]
// MARK: - Device Tree Structures
@@ -541,9 +920,9 @@ public final class DeviceTreePatcher: Patcher {
/// Apply all property patches and record each change.
///
/// Always runs `basePropertyPatches`. Additionally runs
- /// `identityPropertyPatches` when `includeIdentityPatches` is true
- /// (the `.exp` firmware variant) — other variants leave the device's
- /// identity properties untouched.
+ /// `identityPropertyPatches` + `experimentalNodeAdditions` when
+ /// `includeIdentityPatches` is true (the `.exp` firmware variant) —
+ /// other variants leave the device's identity properties untouched.
private func applyPatches(root: DTNode) throws {
var patchesToApply = Self.basePropertyPatches
if includeIdentityPatches {
@@ -587,5 +966,83 @@ public final class DeviceTreePatcher: Patcher {
patch.patchID))
}
}
+
+ if includeIdentityPatches {
+ for nodeAdd in Self.experimentalNodeAdditions {
+ try applyNodeAddition(root: root, patch: nodeAdd)
+ }
+ }
+ }
+
+ /// Apply a single `AddChildNodePatch`: construct the new `DTNode`,
+ /// fill its `name` + caller-supplied properties, attach to the
+ /// parent's `children`, and record a `PatchRecord` for the change.
+ ///
+ /// Skips if a child with the same name already exists under the
+ /// parent — keeps the patch idempotent so re-runs against an
+ /// already-patched DT don't double-add.
+ private func applyNodeAddition(root: DTNode, patch: AddChildNodePatch) throws {
+ let parent = try resolveNode(root, path: patch.parentPath)
+
+ for existing in parent.children {
+ if nodeName(existing) == patch.nodeName {
+ if verbose {
+ print(" - : /\(patch.parentPath.joined(separator: "/"))/\(patch.nodeName) already present, skipping [\(patch.patchID)]")
+ }
+ return
+ }
+ }
+
+ let newNode = DTNode()
+
+ // The `name` property is mandatory and matches the conventional
+ // shape of every other DT node — fixed length = strlen(name)+1.
+ let nameValue = Self.encodeFixedString(patch.nodeName, length: patch.nodeName.utf8.count + 1)
+ newNode.properties.append(DTProperty(
+ name: "name",
+ length: nameValue.count,
+ flags: 0,
+ value: nameValue,
+ valueOffset: 0
+ ))
+
+ for spec in patch.properties {
+ let value: Data = switch spec.value {
+ case let .string(s):
+ Self.encodeFixedString(s, length: spec.length)
+ case let .integer(v):
+ try Self.encodeInteger(v, length: spec.length)
+ case let .bytes(d):
+ Self.encodeFixedBytes(d, length: spec.length)
+ }
+ newNode.properties.append(DTProperty(
+ name: spec.name,
+ length: spec.length,
+ flags: spec.flags,
+ value: value,
+ valueOffset: 0
+ ))
+ }
+
+ parent.children.append(newNode)
+
+ // Serialize the new node so the patch record carries the bytes
+ // we conceptually added. fileOffset = 0 because the rebuilt
+ // payload is what actually lands on disk (apply() prefers
+ // `rebuiltData` over per-record byte writes).
+ let serialized = serializeNode(newNode)
+ patches.append(PatchRecord(
+ patchID: patch.patchID,
+ component: component,
+ fileOffset: 0,
+ virtualAddress: nil,
+ originalBytes: Data(),
+ patchedBytes: serialized,
+ description: patch.description
+ ))
+
+ if verbose {
+ print(" +node : /\(patch.parentPath.joined(separator: "/"))/\(patch.nodeName) (\(newNode.properties.count) props, \(serialized.count)B) [\(patch.patchID)]")
+ }
}
}