Run a virtual iPhone on an Apple Silicon Mac.
Swift
Admit every manifest in TXM's selector-24 pre-check
Jackyd14bc4b48f74
diff --git a/Documents/Guides/compatibility.md b/Documents/Guides/compatibility.mdindex af17695c..c0c05940 100644--- a/Documents/Guides/compatibility.md+++ b/Documents/Guides/compatibility.md@@ -31,6 +31,15 @@ The cloudOS 26.4 beta image (`26.4-23E5207q`) is the newest one that contains `vUse `vphone-cli fw catalog` to inspect the current catalogue. Other iPhone and iPad versions may work with `26.4-23E5207q`, but they have not passed this same end-to-end check.+**iPhone17,3 27.0.1 (24A446)** fails first boot on bundle 2.5.0 and earlier+(reproduced 2026-10-04, including with the pristine Apple launchd): TXM's+selector-24 pre-check rejects every binary at init and the boot panics with+`unexpected SIGKILL of init`. The `txm-boot-precheck_admission` patch+(`Research/Firmware/txm_selector24_cms_gate.md`) fixes it; verified the same+day: `iPhone17,3 27.0.1 + 26.4-23E5207q` with the patch boots to the guest+and answers a vphoned `device.info`. Until a bundle release carrying the+patch ships, treat 27.0.x past 24A435 as needing a current local build.+## iPadOSSee [iPadOS guests](ipados.md).diff --git a/Research/0_binary_patch_comparison.md b/Research/0_binary_patch_comparison.mdindex ac13e96b..3fb58a50 100644--- a/Research/0_binary_patch_comparison.md+++ b/Research/0_binary_patch_comparison.md@@ -419,6 +419,22 @@| 10 | Selector42\|29 shellcode: branch back | Return from shellcode to stub+4 | - | Y | Y || 11 | Debugger entitlement (selector 42\|37) | `bl` -> `mov w0, #1` | - | Y | Y || 12 | Developer mode bypass | NOP conditional guard before deny path | - | Y | Y |+| 13 | Pre-check admission: `mov w8, #0xa` | Tolerated validation-type byte (iOS 27+) | - | Y | Y |+| 14 | Pre-check admission: `strb w8, [x19]` | Write the type byte to the out param | - | Y | Y |+| 15 | Pre-check admission: `mov w0, #0x90` | The policy walk's PASS status | - | Y | Y |+| 16 | Pre-check admission: `b <epilogue>` | Skip the policy callback walk | - | Y | Y |++> **Pre-check admission (2026-10-04):** rows 13–16 (`txm-boot-precheck_admission`,+> iOS 27+ only) force the selector-24 pre-check policy walk in TXM 187.100.3+> (cloudOS 26.4) to its PASS exit. On an iOS 27.0.1 iPhone guest that walk+> rejects every manifest — Apple's own launchd included, re-signed or pristine —+> because the trust state it consults never loads from a 27.0.1 restore; the+> selector-24 caller then exhausts its ad-hoc / CMS / third fallback ladder and+> kills init (`0x32202`, previously misread as `0x12491`). The anchor is the+> walk's unique `mov x17, #0x7e51 ; blraa x8, x17` policy-callback invocation+> combined with its post-indexed `ldr x22, [x20], #0x40` table walk; on+> 187.100.3 that pair resolves to exactly one function. Full analysis and the+> experiment trail: `Research/Firmware/txm_selector24_cms_gate.md`.## Kernelcachediff --git a/Research/Firmware/txm_selector24_cms_gate.md b/Research/Firmware/txm_selector24_cms_gate.mdnew file mode 100644index 00000000..17abc46d--- /dev/null+++ b/Research/Firmware/txm_selector24_cms_gate.md@@ -0,0 +1,329 @@+# TXM selector 24 CMS gate — the iPhone 17,3 / 27.0.1 (24A446) first-boot panic++Investigated 2026-10-04, after a `vm create` that defaulted to+`iPhone17,3 27.0.1 (24A446)` restored and CFW-installed cleanly, then panicked+on first boot:++```+TXM [Error]: CodeSignature: selector: 24 | 0x91 | 0x24 | 1+panic: unexpected SIGKILL of init with reason -- namespace 9 code 0x1+```++The VM (`unlocktest-iphone`) was deleted before this analysis; everything+below was rebuilt statically from the IPSWs themselves (members fetched by+HTTP range from the CDN zips; artifacts kept under `/tmp/txm-*.bin`).++## Which TXM actually boots++`mergeCloudOS` (`VPhoneFirmwarePreparer.swift`) copies cloudOS+`Firmware/*.im4p` into the iPhone restore tree **with overwrite**, so+`txm.iphoneos.research.im4p` from cloudOS `26.4-23E5207q`+(**`TrustedExecutionMonitor_Guarded-187.100.3`**, 442400 bytes) replaces the+iPhone IPSW's own before the patcher and restore ever see it:++| Source | TXM build | Size |+| --- | --- | --- |+| cloudOS `26.4-23E5207q` (**what boots**) | 187.100.3 | 442400 |+| iPhone `26.6.2_23G90` (silently discarded since PR #486) | 187.120.2 | 442400 |+| iPhone `27.0_24A435` / `27.0.1_24A446` (silently discarded) | 217.0.2 | 557088 |++Through 26.x the two sides shipped near-identical TXMs, so the override was+invisible and harmless. iOS 27 moved the TXM a full version (+115 KB) while+the VM kept booting the 26.4-era 187.100.3. The 12 dev patches apply to (and+were verified against) 187.100.3. The VM's SPTM is also cloudOS's+(`sptm.vresearch1.release.im4p`); the iPhone IPSW only ships `sptm.t8140`+for its own hardware. TXM and SPTM in the guest are a matched 26.4 pair.++Offsets below are raw file offsets, given for **187.100.3** (what boots)+with 217.0.2 in parentheses where useful. 187.100.3 `__TEXT_EXEC`: file+offset `0x1c000`; 217.0.2: file offset `0x2c000`, vmaddr+`0xfffffff017030000` (neither is the 26.3 layout in `txm_jb_patches.md`).++## Decoding the panic value++The kernel-side log prints the selector number followed by the low, middle+and high bytes of TXM's 32-bit error return. `0x91 | 0x24 | 1` is+**0x0001_2491**.++## The selector-24 ladder (identical shape in both TXM versions)++### `sub_31F74` (217.0.2: `sub_43CB8`) — multi-step validator++```asm+0x31f94: str wzr, [sp, #0xc] ; flags = 0+0x31fb4: ldp x0, x1, [x20, #0x30] ; ctx->blob30, size+0x31fbc: bl 0x2fc54 ; read BE u32 at blob+0xC → flags+0x31fc8: bl 0x30bac ; policy pre-check walk+0x31fd0: b.eq 0x32000 ; pre-check PASSED → return 2 (accept)+0x31fd8: ldrb w8, [x8, #0xd0] ; table flag+0x31fdc: tbz w8, #0, 0x32020 ; clear → fall to ladder+ ... ; set → tolerated (marks type 0xa/5)+0x32020: ldrb w8, [sp, #0xc]+0x32024: tbnz w8, #1, 0x32040 ; flags bit1 (CS_ADHOC) → sub_30B1C+0x32030: bl 0x30774 ; ← CMS full verification (this panic)+0x32048: bl 0x30b1c ; ad-hoc / alternate path+0x3205c: bl 0x30a78 ; third fallback+```++The pre-check walk (`sub_30BAC`) is the 217/187 equivalent of the 26.x+pre-check chain (library validation, runtime flag, jit entitlement, team+id, SRD, extended research, hash type). The patched `check_hash_flags`+(187.100.3: near `0x31a84`, early-returned PASS by+`txm-boot-selector24_bypass`) is one step inside it.++### `sub_30774` (217.0.2: `sub_424A8`) — the CMS gate that fired++```asm+0x307e8: mov w25, #0xb01+0x307ec: movk w25, #0xfade, lsl #16 ; CSMAGIC_BLOBWRAPPER+0x307f0: mov w21, #0x2491+0x307f4: movk w21, #1, lsl #16 ; w21 = 0x12491 (step error)+0x307f8: ldp x0, x1, [x20, #0x30] ; blob30, size+0x30804: bl 0x301a8 ; parse one byte → sp+7+0x30808: ldp x0, x1, [x20, #0x18] ; signature buffer, size+0x30810: mov w2, #0x10000 ; limit+0x30814: mov w3, #0xfade0b01 ; magic+0x30820: bl 0x2ecb8 ; find_blob(buf, size, limit, magic, 0)+0x30824: cbz x0, 0x30860 ; NOT FOUND →+0x30860: mov w8, #0x124 ; exit code 0x124 → returns 0x12491+```++If the wrapper *is* found, the function locates the CodeDirectory+(`0xfade0c02`, searched as `magic + 0x101`), parses both, and verifies the+manifest cdhash (≤0x40-byte hash at `ctx+0x40`) — the full "the CMS says who+signed this" step. The exit packs the printed error:+`mid=(w8&0xff)<<8` (0x24), `low=w21&0xff` (0x91), `high=w22` (0x10000 → 1).++**0x12491 means: no `CSMAGIC_BLOBWRAPPER` blob in the signature data that+selector 24 was handed.**++## Why our launchd dies there++`patchMachO` re-signs `/sbin/launchd` (jetsam guard patch + `/vh` injection,+`system-launchd-boot-jetsam_panic_guard_bypass`) with `VPhoneSigner` at its+default `style: .ldid`:++```swift+case ldid:+ // "there is no CMS blob and the ad-hoc flag is not set"+case appleAdHoc:+ signature.flags = 0x2 // kSecCodeSignatureAdhoc+ signature.cmsReservation = 0+```++(`VPhoneSign/Signing/VPhoneSigner.swift`.) So the re-signed launchd carries+**no CMS wrapper and CodeDirectory flags = 0**: flags bit1 is clear (the+ad-hoc branch is not taken), and the CMS branch finds no `0xfade0b01`+anywhere → 0x12491 → init SIGKILLed. None of the 12 applied TXM patches+touches this ladder — hence a clean patch log with no warnings.++## What is and is not the trigger (elimination, 2026-10-04)++The failing machine ran iPhone-class iOS 27.0.1 with local bundle+`2.4.0-local.ed71da3b` (installed 2026-10-04 00:26, mid audio-branch WIP).+Every candidate signed artifact in the boot path was then compared between+the failing and passing combinations:++| Artifact | Check | Result |+| --- | --- | --- |+| TXM | sha256, 24A435 vs 24A446 IPSW | identical (and both overridden by cloudOS 187.100.3 anyway) |+| `/sbin/launchd` | extracted from both rootfs (AEA-decrypted), `cmp` + entitlements + `codesign -dv` | **byte-identical**, both Apple ad-hoc (`flags=0x2`, no team, CD v0x20400, 150+9 hashes) |+| dyld shared cache | chunk CD flags/version/slot layout, 435 vs 446 | identical shape: CD v0x20400 `flags=0x2`, slots {CD, empty requirements, empty CMS}; 27.0.1 is a minimal update (a few chunks shift by ~16 KB) |+| DSC patching | all nine verbs on both caches | identical site counts (29 cstrings, 31 forced, maxSlide overflow→0, 2/2 camera, …), re-attest clean |+| `/vh` launchdhook dylib | `codesign -dv --verify` in ed71da3b vs 2.5.0 | structurally valid, adhoc `flags=0x2`, same CD shape |++Known boots, for contrast:++| Guest | iOS | Bundle | Result |+| --- | --- | --- | --- |+| iPhone-class (D47) | 27.0 (24A435) | audio-branch local, 2026-10-04 ~15:00 (commit `c812baf` measurement) | boots |+| iPad16,1 | 27.0.1 (24A446) | 2.5.0 (2026-10-04) | boots |+| iPhone17,3 | 27.0 | PR #486 (2026-09-24, pre-migration Python pipeline) | boots |+| iPhone-class | 27.0.1 | `2.4.0-local.ed71da3b` (2026-10-04 00:26) | **0x12491 panic** |++Note the launchd result kills the earlier "27.0.1 launchd data trips a+policy" theory: the binary the gate rejected — if it was launchd at all — is+byte-for-byte what boots on 27.0. Whatever flipped the `sub_30BAC` pre-check+into the CMS fallback is either (a) something in that WIP bundle's install+output (the audio branch was mid-refactor at 00:26; today's bundles carry the+fixes from `8fa502a`/`fa50d48`/`62ee326` and boot), or (b) a 27.0.1+system-volume input outside launchd/cache/DSC (restore ramdisk, Preboot+content), or (c) TXM runtime policy state that boot handed it differently.+The one discriminating experiment: **iPhone 17,3 + 27.0.1 + current bundle** —+`vphone-launchpad-cli vm create t271 --iphone-source ~/.vphone/ipsws/iPhone17_3_27.0.1_24A446_Restore-1c2c1e8da8de.ipsw`+(IPSW already cached). Boots ⇒ the WIP bundle was the trigger; panics+identically ⇒ 27.0.1-specific input, pursue the fixes below.++## Confirming the remaining link (reveal procedure)++1. Download `043-70113-711.dmg.aea` (24A446 rootfs) and `043-70113-702.dmg.aea`+ (24A435) from the two iPhone IPSWs (zip members; the rest of the 12 GB is+ not needed).+2. `vphone-cli fw aea-key <dmg.aea>` → `aea decrypt -key-value …` (documented+ flow; it worked on both 24A435 volumes before).+3. Attach the decrypted APFS images, pull `sbin/launchd` from each (and from+ the iPad 16,1 27.0.1 IPSW as the passing 27.0.1 control).+4. Compare, in order of likelihood: embedded entitlements (plist and DER+ slots), CodeDirectory version/hashType/flags/identifier, superblob slot+ list (magics and order).+5. Reproduce by re-running the CFW launchd staging on all three and diffing+ `VPhoneSigner` output.++## Round 3 (2026-10-04 evening): every input-side artifact is now identical++The `0x32202` boot was compared against patchtest-iphone (iPhone-class, iOS+27.0, boots, driven by the parallel session) artifact by artifact:++| Artifact | t271 (27.0.1, dies) | patchtest (27.0, boots) |+| --- | --- | --- |+| console, boot start → ignition | same APFS/root-snapshot/root-hash-auth lines on both (benign) | same |+| magazine/nonce errors | present (`pdmg/d1ma/c1ge/…` errno 2, and `cptx/c1bt` 13/6 on earlier boots — the tag set varies *between boots of the same machine*) | present (`cptx` 13, `c1bt` 6) — noisy, not the discriminator |+| installed devicetree.img4 (Preboot) | parsed both DTBs (Apple flattened format: LE u32 counts, LE u32 length with bit 31 as a syscfg flag): **605/605 properties identical** | identical |+| on-disk re-signed launchd | flags=0x2 → dies 0x32202; flags=0 → died 0x12491 | **flags=0x0 (ldid shape) and passes the pre-check — no selector-24 line at all** |+| trust cache files on disk | none found on System/Preboot/Cryptexes of either machine — the volume trust caches are personalized into the boot chain at restore time (the `magazine`/nonce path), not stored as files | none either |++The signature shape is therefore **not** what the pre-check keys on (a+flags=0 ldid launchd passes on 27.0; both shapes die on 27.0.1). With+launchd, device tree, dyld cache, TXM, kernel, SEP and SPTM all eliminated,+what remains is per-build data the restore personalizes into the guest's+trust chain — the **trust cache content itself** (27.0.1's TCTF/magazine+format or its personalization metadata vs what the fixed 26.4 kernel/TXM+can admit). Where to go next:++1. Ask the restore side where trust caches land: `VPhoneRestore` /+ idevicerestore personalize `*.dmg.trustcache` — trace what it writes and+ what the 26.4 kernel expects to find at boot.+2. Reverse the three policy callbacks behind `sub_30BAC`'s walk in TXM+ 187.100.3 (selector `0x7e51`, table slots `+0x20/+0x18`) — the definitive+ answer to which input flips.+3. Empirical discriminator: boot 27.0.1 with an *unpatched* Apple launchd+ (swap `sbin/launchd.bak` back in through the CFW mount). If the original+ — whose cdhash is in Apple's cache — also dies, the trust caches never+ load at all on 27.0.1 and the ladder is unreachable for everyone; if it+ boots, the caches load and the policies specifically reject re-signed+ hashes on 27.0.1.++## Round 4 (2026-10-04 night): the definitive experiment — it is not the signing++`system-launchd-boot-jetsam_panic_guard_bypass` was blocked through+`PatchSelection.plist` (`BlockedPatches`, honored by `fw patch` with a+boot-essential warning), the tree re-prepared and CFW re-installed, so the+guest booted the **pristine Apple launchd** — ad-hoc flags=0x2 straight from+the IPSW, its cdhash in Apple's static trust cache, no `/vh` injection, no+re-signing at all.++**It died identically**: `TXM [Error]: CodeSignature: selector: 24 | 0x02 |+0x22 | 3` (0x32202) → `unexpected SIGKILL of init`.++That closes the case at this level:++- The re-signed binaries were never the problem. On the iPhone17,3 27.0.1+ guest, **TXM's selector-24 admission rejects every binary — including+ Apple's own, trust-cache-listed launchd** — because whatever its pre-check+ policies and the ad-hoc branch's callback consult (the trust caches) is+ **not loaded at boot on 27.0.1**, while the identical 27.0 flow loads it+ (booting even ldid-shaped re-signed binaries).+- The StaticTrustCache files themselves are format-identical between builds+ (same size 91441, same TCTF structure, only hash values differ), and the+ restore delivers them as personalized TSS assets (`StaticTrustCache` in+ `restore.c`'s asset list). The failing console's+ `magazine[…]: failed to read nonce slot data: 2` (ENOENT — a nonce *slot*+ missing) vs 27.0's errno 13/6 points at the **personalization/nonce-slot+ handshake differing for 27.0.1's images against the fixed 26.4 SEP/TXM**.+- Open wrinkle: the iPad16,1 27.0.1 guest booted today, so either its+ restore personalized differently or the iPad tree configures TXM policies+ to tolerate an empty magazine. Worth one look when fixing.++**The fix surface is the restore's TSS/personalization of 27.0.1's trust+caches** (nonce slot selection in `VPhoneRestore`/tss code), or the+kernel/TXM patch route (force-pass the `sub_30BAC` pre-check walk, which+covers every branch of the ladder at once).++## The patch: `txm-boot-precheck_admission` (2026-10-04) — **VERIFIED, 27.0.1 boots**++Machine `t271x` (iPhone17,3 + 27.0.1 + cloudOS 26.4 + the patch, bundle+`2.5.0-local.94f7c22c`): restore, CFW install, first boot — `running`,+`panicked: false`, no selector-24 line in the console, and vphoned answers+`device.info` live. The acceptance bar is met. (Note for retesting: the+boot-chain TXM is flashed at restore time — a machine restored before the+patch keeps booting the old TXM until re-restored.)++`TXMDevPatcher.patchPrecheckForcePass()` forces the pre-check walk+(`sub_30BAC`, 187.100.3 offsets; `sub_428F0` in 217.0.2) to its PASS exit, so+the selector-24 caller accepts at the top of the ladder and none of the+fallback branches — ad-hoc, CMS gate, third fallback — ever run.++**Reveal procedure** (how the site was found and how to re-find it on a new+TXM):++1. Decompress `Firmware/txm.iphoneos.research.im4p` from the merged restore+ tree (it is cloudOS 26.4's 187.100.3; the iPhone IPSW's copy is overwritten+ by `mergeCloudOS` — see above).+2. Scan for `mov x17, #0x7e51` (movz encoding `0xD28FCA31`) followed by+ `blraa x8, x17`. On 187.100.3 this hits three times; only the pre-check+ walk's function also contains the post-indexed `ldr x22, [x20], #0x40`+ policy-table walk before the hit (the other two hits share an unrelated+ function at `0x32d78`).+3. Walk back to the `pacibsp` prologue; the two instructions after it are+ `mov x19, x1 ; mov x20, x0` — the patch overwrites the four instructions+ that follow with `mov w8, #0xa ; strb w8, [x19] ; mov w0, #0x90 ;+ b <epilogue>` (epilogue = the `retab`'s preceding `ldp x29, x30`).+ `0x90` is the walk's own PASS status (byte 1 clear); `0xa` is the+ validation-type byte the table-tolerated path writes to the out param.++**Validation:** constant words are capstone round-trip verified and frozen in+`ARM64EncoderTests`; the anchor pair resolves to exactly one function on+187.100.3; the boot test on `t271` (iPhone17,3 + 27.0.1 + the patched bundle)+is the acceptance bar. The patch is declared `txm-boot-precheck_admission`+(bootchain set, `iOSBase: .major(27)`, bootEssential) — on 27.0 the walk+already admits everything, so the patch changes bytes but not behavior.++## Fix options and what the 2026-10-04 experiments proved++++1. **Reproduction done** (machine `t271`, iPhone17,3 + 27.0.1 + release+ 2.5.0): identical `0x12491` panic — the trigger is 27.0.1-specific, the+ WIP-bundle theory is dead. (An iPhone-class 27.0 guest booted the same+ day on the same Mac.)+2. **`style: .appleAdHoc` re-signing — implemented and tested.** All three+ `VPhoneSigner.sign` call sites in `VPhoneCustomFirmwareInstaller.swift`+ now pass `style: .appleAdHoc`. Deployed through+ `vm set-bundle t271 2.5.0-local.4f3be451` + `cfw install` (note:+ `vm create --from installCFW --bundle …` does **not** rebind the machine —+ verify `launchpad.json` and the on-disk `flags=0x2` before believing a+ test). Result: the on-disk launchd carries `flags=0x2(adhoc)`, the+ `0x12491` CMS-gate error is **gone** (the ladder analysis held), but init+ still dies — now with `selector: 24 | 0x02 | 0x22 | 3` (**0x32202**), the+ error after the *whole* ladder is exhausted: pre-check walk → ad-hoc+ branch `sub_30B1C` → third fallback `sub_30A78` all rejected, and the+ table tolerance bytes are clear. The signing change is correct but not+ sufficient; it is **not yet regression-tested on a booting guest**+ (patchtest-iphone is the candidate).+3. **The layer under the ladder: trust caches never load in the 27.0.1+ guest.** The failing console uniquely shows, before the kill:+ `TXM [Error]: Errno: selector: 45 | 78`, `AppleImage4: failed to set boot+ uuid in supervisor: 78`, `magazine[cptx]: failed to get nonce: 13`,+ `magazine[c1bt]: failed to get nonce: 6`, and+ `is_root_hash_authentication_required: disk1s1 Root Volume, root hash+ authentication is required`. Every passing machine's console+ (patchtest-iphone 27.0, both iPads 26.6.2) has **none** of these and+ instead shows a successful runtime+ `AppleMobileFileIntegrityUserClient::loadTrustCache … requesting a trust+ cache load`. With the trust-cache magazine empty in TXM, the selector-24+ pre-check policies have nothing to admit against, which is what pushes+ the re-signed launchd into the ladder at all. Why the 27.0.1 magazine /+ nonce path fails against the fixed 26.4 SEP/SPTM/TXM (format change?+ new nonce protocol?) is the open question — that is where a real fix+ lives, not in the signature shape.+4. **A new TXM dev patch** forcing the `sub_30774` wrapper-not-found exit to+ pass is now the wrong lever: the ladder has three more rejection points+ after it (0x32202 proves it). A patch that force-passes the *pre-check*+ walk would cover all of them at once, but it is a policy-grade change+ (see `Skills/authoring-patch-sets/SKILL.md`).+5. **Stop discarding the iPhone's TXM**: exclude `txm.*` from the cloudOS+ `Firmware/*.im4p` overwrite so the guest boots the TXM contemporary with+ its userland (217.0.2 on iOS 27.x). Not a cloudOS version bump (none is+ possible; nothing after `26.4-23E5207q` carries `vphone600ap`). Risk: the+ booted TXM must pair with cloudOS 26.4's `sptm.vresearch1` and the 26.4+ kernel's selector call convention; needs an empirical boot.diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareBootChainPatchSet.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareBootChainPatchSet.swiftindex 37b15598..109ab6b0 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareBootChainPatchSet.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareBootChainPatchSet.swift@@ -160,6 +160,14 @@ public enum FirmwareBootChainPatchSet {target: .firmware(.txm),bootEssential: true,),+ VPhonePatchDeclaration(+ identifier: "txm-boot-precheck_admission",+ title: "TXM pre-check admission",+ summary: "Forces the selector-24 pre-check policy walk to admit. Without it an iOS 27.0.1 iPhone guest is rejected at first boot — every binary, Apple's own launchd included, because the trust state the walk consults never loads from a 27.0.1 restore.",+ target: .firmware(.txm),+ applicability: VPhonePatchApplicability(iOSBase: .major(27)),+ bootEssential: true,+ ),VPhonePatchDeclaration(identifier: "txm-boot-sel42_29",title: "TXM selector 42/29 shellcode",diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/TXM/TXMDevPatcher.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/TXM/TXMDevPatcher.swiftindex 4f89b16e..e306c650 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/TXM/TXMDevPatcher.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/TXM/TXMDevPatcher.swift@@ -18,6 +18,7 @@ public final class TXMDevPatcher: TXMPatcher {patches = []try patchTrustcacheBypass() // base patchpatchSelector24ForcePass()+ patchPrecheckForcePass()patchGetTaskAllowForceTrue()patchSelector42_29Shellcode()patchDebuggerEntitlementForceTrue()@@ -204,6 +205,138 @@ public final class TXMDevPatcher: TXMPatcher {// MARK: - Dev Patches+ /// Force the selector-24 pre-check policy walk to admit every manifest.+ ///+ /// On an iOS 27.0.1 iPhone guest the walk (`sub_30BAC` in cloudOS 26.4's+ /// TXM 187.100.3) rejects everything — Apple's own launchd included —+ /// because the trust state it consults never loads from a 27.0.1 restore;+ /// the selector-24 caller then falls through its ad-hoc, CMS and third+ /// fallback branches and kills init (0x32202 / 0x12491). Forcing the+ /// walk's PASS exit admits at the top of the ladder, before any of those+ /// branches run. See Research/Firmware/txm_selector24_cms_gate.md.+ ///+ /// Anchor: the walk is the only function that invokes its policy+ /// callbacks with PAC selector `0x7e51` (`mov x17, #0x7e51` immediately+ /// followed by `blraa x8, x17`) after walking a policy table with a+ /// post-indexed `ldr x22, [x20], #0x40`. The patch replaces the first+ /// four body instructions with:+ ///+ /// mov w8, #0xa ; tolerated validation-type byte+ /// strb w8, [x19] ; *out = 0xa, as the tolerated path writes+ /// mov w0, #0x90 ; the walk's PASS status+ /// b <epilogue>+ func patchPrecheckForcePass() {+ let size = buffer.count+ var off = 0+ while off + 8 <= size {+ defer { off += 4 }++ guard let selector = disasm.disassembleOne(in: buffer.data, at: off),+ selector.mnemonic == "mov",+ let selOps = selector.detail?.operands, selOps.count == 2,+ selOps[0].type == .register, selOps[0].reg == .x(17),+ selOps[1].type == .immediate, selOps[1].imm == 0x7e51,+ let call = disasm.disassembleOne(in: buffer.data, at: off + 4),+ call.mnemonic == "blraa"+ else {+ if verbose, let ins = disasm.disassembleOne(in: buffer.data, at: off),+ ins.mnemonic == "mov",+ let ops = ins.detail?.operands,+ ops.count == 2, ops[1].type == .immediate, ops[1].imm == 0x7e51+ {+ let next = disasm.disassembleOne(in: buffer.data, at: off + 4)+ print(" [·] TXM: selector 0x7e51 at \(String(format: "%06X", off)); next: \(next.map { "\($0.mnemonic) \($0.operandString)" } ?? "decode-fail")")+ }+ continue+ }++ guard let funcStart = findFuncStart(off) else { continue }++ // The walk dereferences the policy table through a writeback+ // load (`ldr x22, [x20], #0x40`, the only three-operand ldr in+ // the function); confirm it is here before trusting the site.+ // The operand string is matched whole — as `patchSelector24ForcePass`+ // matches its own anchors — because capstone reports post-index+ // loads with an operand-shape that varies by version.+ var sawTableWalk = false+ var scan = funcStart+ while scan + 4 <= off {+ if let i = disasm.disassembleOne(in: buffer.data, at: scan),+ i.mnemonic == "ldr",+ i.operandString == "x22, [x20], #0x40"+ {+ sawTableWalk = true+ break+ }+ scan += 4+ }+ guard sawTableWalk else { continue }++ // Body starts after the two argument-register moves that open it.+ var body: Int? = nil+ var p = funcStart+ while p + 8 <= off {+ guard+ let a = disasm.disassembleOne(in: buffer.data, at: p),+ let b = disasm.disassembleOne(in: buffer.data, at: p + 4)+ else { p += 4; continue }+ if a.mnemonic == "mov", let aops = a.detail?.operands, aops.count == 2,+ aops[0].reg == .x(19), aops[1].reg == .x(1),+ b.mnemonic == "mov", let bops = b.detail?.operands, bops.count == 2,+ bops[0].reg == .x(20), bops[1].reg == .x(0)+ {+ body = p + 8+ break+ }+ p += 4+ }+ guard let bodyStart = body else {+ log(" [-] TXM: pre-check walk body start not found")+ return+ }++ // Epilogue: the walk's retab, back to its frame restore.+ var epilogue: Int? = nil+ var r = off+ while r < min(off + 0x200, size) {+ if let ri = disasm.disassembleOne(in: buffer.data, at: r), ri.mnemonic == "retab" {+ var e = r - 4+ while e > max(r - 0x40, funcStart) {+ if let ei = disasm.disassembleOne(in: buffer.data, at: e),+ ei.mnemonic == "ldp", ei.operandString.contains("x29, x30")+ {+ epilogue = e+ break+ }+ e -= 4+ }+ break+ }+ r += 4+ }+ guard let epilogueOff = epilogue else {+ log(" [-] TXM: pre-check walk epilogue not found")+ return+ }++ emit(bodyStart, ARM64.movW8_0xA, patchID: "txm-boot-precheck_admission.mark_type",+ description: "pre-check admission: mov w8, #0xa (tolerated type)")+ emit(bodyStart + 4, ARM64.strbW8X19, patchID: "txm-boot-precheck_admission.store_type",+ description: "pre-check admission: strb w8, [x19]")+ emit(bodyStart + 8, ARM64.movW0_0x90, patchID: "txm-boot-precheck_admission.pass",+ description: "pre-check admission: mov w0, #0x90 (PASS)")+ guard let bInsn = ARM64Encoder.encodeB(from: bodyStart + 12, to: epilogueOff) else {+ log(" [-] TXM: pre-check admission branch encoding failed")+ return+ }+ emit(bodyStart + 12, bInsn, patchID: "txm-boot-precheck_admission.branch",+ description: "pre-check admission: b epilogue")+ return+ }++ log(" [-] TXM: pre-check walk (selector 0x7e51 policy callbacks) not found")+ }+/// Patch selector24 handler to return 0xA1 (PASS) immediately.////// Inserts `mov w0, #0xa1 ; b <epilogue>` right after the prologue,diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/Core/ARM64EncoderTests.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/Core/ARM64EncoderTests.swiftindex c4cf6c23..29b9758f 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/Core/ARM64EncoderTests.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/Core/ARM64EncoderTests.swift@@ -492,6 +492,9 @@ struct ARM64EncoderKeystoneParityTests {("movz w0, #1", ARM64.movW0_1, 0x5280_0020),("mov x0, x20", ARM64.movX0X20, 0xAA14_03E0),("movz w0, #0xa1", ARM64.movW0_0xA1, 0x5280_1420),+ ("movz w0, #0x90", ARM64.movW0_0x90, 0x5280_1200),+ ("movz w8, #0xa", ARM64.movW8_0xA, 0x5280_0148),+ ("strb w8, [x19]", ARM64.strbW8X19, 0x3900_0268),("cmp w0, w0", ARM64.cmpW0W0, 0x6B00_001F),("cmp x0, x0", ARM64.cmpX0X0, 0xEB00_001F),("strb w0, [x20, #0x30]", ARM64.strbW0X20_30, 0x3900_C280),diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swiftindex 241c869c..0b7a94b0 100644--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift@@ -1413,9 +1413,15 @@ struct VPhoneCustomFirmwareInstaller {if let injectedDylibPath {try patch("inject-dylib", [staged.path, injectedDylibPath])}+ // The ad-hoc shape, not ldid's: TXM 187.100.3 routes a CodeDirectory+ // without the CS_ADHOC flag into a selector-24 branch that demands a+ // CMS wrapper no ad-hoc re-sign carries, and iOS 27.0.1's launchd is+ // the first binary to fall through to it (Research/Firmware/+ // txm_selector24_cms_gate.md). Apple's own platform binaries and the+ // bundle-shipped guest dylibs all carry the flag; match them.try VPhoneSigner.sign(fileAt: staged,- options: .init(identifier: identifier, entitlements: entitlements, mergesExisting: true),+ options: .init(identifier: identifier, entitlements: entitlements, mergesExisting: true, style: .appleAdHoc),)try system.replaceFile(path, fromFileAt: staged, mode: 0o755, owner: Self.guestOwner)}@@ -1479,7 +1485,7 @@ struct VPhoneCustomFirmwareInstaller {// cannot delete one.try VPhoneSigner.sign(fileAt: staged,- options: .init(entitlements: data),+ options: .init(entitlements: data, style: .appleAdHoc),)try system.replaceFile(target, fromFileAt: staged, mode: 0o755, owner: Self.guestOwner)}@@ -1502,6 +1508,7 @@ struct VPhoneCustomFirmwareInstaller {options: .init(entitlements: Data(contentsOf: ent, options: .mappedIfSafe),mergesExisting: true,+ style: .appleAdHoc,),)try system.replaceFile(target, fromFileAt: staged, mode: 0o755, owner: Self.guestOwner)diff --git a/VPhoneExecutable/VPhoneCommand/VPhonePatchKit/ARM64/ARM64Constants.swift b/VPhoneExecutable/VPhoneCommand/VPhonePatchKit/ARM64/ARM64Constants.swiftindex bb5141b6..0501a7ce 100644--- a/VPhoneExecutable/VPhoneCommand/VPhonePatchKit/ARM64/ARM64Constants.swift+++ b/VPhoneExecutable/VPhoneCommand/VPhonePatchKit/ARM64/ARM64Constants.swift@@ -46,6 +46,12 @@ public enum ARM64 {/// MOV W0, #0xA1 (MOVZ W0, #0xA1)public static let movW0_0xA1 = encodeU32(0x5280_1420)+ /// MOV W0, #0x90 (MOVZ W0, #0x90) — the pre-check walk's PASS status+ public static let movW0_0x90 = encodeU32(0x5280_1200)++ /// MOV W8, #0xA (MOVZ W8, #0xA) — the tolerated validation-type byte+ public static let movW8_0xA = encodeU32(0x5280_0148)+// MARK: Compare/// CMP W0, W0 (SUBS WZR, W0, W0)@@ -59,6 +65,9 @@ public enum ARM64 {/// STRB W0, [X20, #0x30]public static let strbW0X20_30 = encodeU32(0x3900_C280)+ /// STRB W8, [X19]+ public static let strbW8X19 = encodeU32(0x3900_0268)+// MARK: CFW Constants/// CBZ X2, #8 (branch if X2 == 0, skip 2 instructions)