Run a virtual iPhone on an Apple Silicon Mac.
Swift
Read the MIS failure code where 24A435 derives it, and gate the patch to 18/26
Lakr61f76f0b4af3
diff --git a/Research/0_binary_patch_comparison.md b/Research/0_binary_patch_comparison.mdindex e7dbdd5e..a4a46b34 100644--- a/Research/0_binary_patch_comparison.md+++ b/Research/0_binary_patch_comparison.md@@ -1651,13 +1651,62 @@ and lockdown-mode patchers. So this is **not** the already-patched-anchor casefixed earlier the same day for 26.x — 24A435's `checkTrustAndAuthorization`genuinely matches neither shape `locateSite` accepts.-**Why the answer is not to teach the patcher the new shape.** Even when it-applies, this patch stops an iOS 27 guest booting (issue #532: `TXM [Error]:-Errno: selector: 45 | 78` → `dyld[1]: Library not loaded:+**And the message was wrong.** MIS has *not* been rewritten. Measured on the+pristine 24A435 SystemOS cryptex (`043-70113-702.dmg.aea`, decrypted with+`fw aea-key` + `/usr/bin/aea` and mounted read-only; `cfw patch-mis-trust-auth+--dry-run` against it reproduces the failure verbatim, same VMA):++| | 26.6.2 | 24A435 |+|---|---|---|+| function | `0x1BC6AE364` | `0x22406F814` |+| seed | `mov w21, #0x8026 ; movk w21, #0xe800, lsl #16` @ `+0x4C` | `mov w23, #0x8001 ; movk w23, #0xe800, lsl #16` @ `+0x34` |+| reaches `0xE8008026` | seeded directly, **subtracts** down (`sub w21, w21, #0x2` → `…8024`) | **adds** up, `add w26, w23, #0x25` @ `+0x124` |+| return register | `w21` (the seeded one) | `w26` (derived) |++A whole-image decode of `libmis` (94,984 instructions, `0x224060000`–`0x2240BCC23`)+finds **zero** mov-family instructions with immediate `0x8026` and **zero** raw+`0xE8008026` words: on 24A435 the constant is never written literally at all.+Everything else is as the patcher expects — the naming literal at `0x2240BCC23`+occurs once, has exactly one adrp+add reference (`0x22406FB1C`) and that+reference is inside the function; the nearest preceding `pacibsp` is the+function start itself, and the instruction before it is an unconditional `b`.+So the location routes were right and only `findSeededError` missed.++`findSeededError` now accepts both, and the two are not interchangeable. The+`0x8026` low half stands on its own. The `0x8001` low half is only the bottom of+the MIS error range and proves nothing by itself, so it is accepted only when+the same function also contains an `add w<result>, w<seed>, #imm` that+arithmetically equals `0xE8008026`; the scan stops at the next function's+`pacibsp`. That corroboration is not decoration: the function *preceding*+`checkTrustAndAuthorization` on 24A435 carries the identical+`mov w8, #0x8001 ; movk w8, #0xe800` idiom 18 instructions earlier, which is+also why the seed window stays forward-only from the function start. Matching is+on Capstone-decoded immediates and registers throughout, and nothing new is+written, so no new encoder and no keystone trip.++**A version gate went on the declaration with it.** `experimental` is+`Kind = All`, so without one it would still turn this patch on for a 27 guest+and produce an unbootable VM — and after the matcher fix it would now succeed in+doing so. `applicability` is `iOSBase: .oneOf([.major(18), .major(26)])`. That+is not a preference (a preference belongs in a preset's block list, and+`standard` blocks it too) but the statement `applicability` exists for: applying+it on 27 breaks the guest. An unreadable base satisfies only `.any`, so an+unknown release skips the patch, which is the safe direction.++**Why teaching the patcher the new shape is not, by itself, the answer.** Even+when it applies, this patch stops an iOS 27 guest booting (issue #532:+`TXM [Error]: Errno: selector: 45 | 78` → `dyld[1]: Library not loaded:/usr/lib/libSystem.B.dylib … (no such file, no dyld cache)` → `initproc failed-to start`). Making it apply on 24A435 would convert a failed install into a-guest that installs and then does not boot. The hard failure is doing a useful-job: it is stopping a patch that should not be running on 27 at all.+to start`). Making it apply on 24A435 without also taking it out of `standard`+would have converted a failed install into a guest that installs and then does+not boot. Both were done, in that order.++**VERIFIED (2026-09-30):** with the patch out of `standard`, `cfw install+test-27.0` completes, and `iPhone17,3_27.0_24A435` + cloudOS `26.4-23E5207q`+**boots clean** — `panicked: false`, vphoned answering 6s after launch,+SpringBoard running (pid 36), `apps.list` returning 264 apps. **Issue #532 is+closed**, and its cause is confirmed to have been this patch rather than+anything else in the 27 install.**What replaced it.** `libmisfix.dylib` already reaches the same outcome fromuserspace, and by the better route — it steers the call rather than forging thediff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/DyldSharedCache/Patchers/DyldSharedCacheMISTrustAuthPatcher.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/DyldSharedCache/Patchers/DyldSharedCacheMISTrustAuthPatcher.swiftindex 7788bb75..624a2113 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/DyldSharedCache/Patchers/DyldSharedCacheMISTrustAuthPatcher.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/DyldSharedCache/Patchers/DyldSharedCacheMISTrustAuthPatcher.swift@@ -118,9 +118,23 @@ public enum DyldSharedCacheMISTrustAuthPatcher {static let anchorString ="cdHash (%p) or matchedProfileIDs (%p) NULL in checkTrustAndAuthorization"- /// The MIS error the prologue seeds: "missing trust and/or authorization".+ /// The MIS error this patch exists to stop: "missing trust and/or+ /// authorization".static let seededError: UInt32 = 0xE800_8026+ /// The other value the prologue is known to seed.+ ///+ /// 24A435's `libmis` does not materialise `0xE8008026` anywhere — a whole-image+ /// decode finds no `mov`-family instruction with immediate `0x8026` and no such+ /// word in the data. It seeds this base instead and *adds* its way up+ /// (`add w26, w23, #0x25` → `0xE8008026`), where 26.6.2 seeded `0xE8008026` and+ /// subtracted down (`sub w21, w21, #0x2` → `0xE8008024`). Same function, same+ /// prologue, opposite direction.+ static let baseError: UInt32 = 0xE800_8001++ /// The high half both seeds share, and the only part that is actually stable.+ static var errorHighHalf: Int64 { Int64((seededError >> 16) & 0xFFFF) }+/// How far back from the string reference the function start may sit. The/// reference is in the last third of the function; 1024 instructions is/// several times its length.@@ -128,8 +142,18 @@ public enum DyldSharedCacheMISTrustAuthPatcher {/// How far into the prologue the seeded error may sit. It lands around the/// twentieth instruction; 48 is ample and still far short of the body.+ ///+ /// Forward-only from the function start, and that matters: on 24A435 the+ /// preceding function carries the identical `mov w8, #0x8001 ; movk w8,+ /// #0xe800` idiom 18 instructions *before* this one begins.static let maxPrologueInstructions = 48+ /// How far the derivation of `0xE8008026` from the base may sit from the+ /// function start. `checkTrustAndAuthorization` is 226 instructions on 24A435+ /// and the first derivation is at +286 from the prologue's seed; the scan+ /// stops at the next function's `pacibsp` in any case.+ static let maxFunctionInstructions = 1024+/// Bytes written at `functionVMA + 4`: `mov x0, #0` then `retab`.static var replacement: Data {ARM64.movX0_0 + ARM64.retab@@ -137,11 +161,16 @@ public enum DyldSharedCacheMISTrustAuthPatcher {// MARK: - Results- /// Which of the two accepted prologues the located function carries.+ /// Which of the accepted prologues the located function carries.public enum Shape: Sendable, Equatable {- /// The stock prologue, seeding the failure code into the register the- /// function returns. This is the shape that gets written.+ /// The 26.6.2 prologue, seeding `0xE8008026` itself into the register the+ /// function returns, and subtracting its way to the neighbouring errors.case seedsFailure(seedVMA: UInt64, resultRegister: String)+ /// The 24A435 prologue, seeding `0xE8008001` and *adding* its way up.+ /// `deriveVMA` is an `add w<result>, w<seed>, #0x25` in the same function+ /// — literally `0xE8008026` — which is what proves this base register is+ /// the MIS error range and not an unrelated constant.+ case derivesFailure(seedVMA: UInt64, seedRegister: String, deriveVMA: UInt64)/// The prologue already reads `pacibsp ; mov x0, #0 ; retab` — this/// patch's own output, from an earlier run over the same cache.case alreadyShortCircuited@@ -156,18 +185,28 @@ public enum DyldSharedCacheMISTrustAuthPatcher {/// What the prologue looks like right now.public let shape: Shape- /// Address of the `mov w<reg>, #0x8026` that seeds the failure code,+ /// Address of the `mov w<reg>, #<low>` that seeds the MIS error range,/// or `nil` once this patch has replaced the prologue.public var seedVMA: UInt64? {- guard case let .seedsFailure(vma, _) = shape else { return nil }- return vma+ switch shape {+ case let .seedsFailure(vma, _): vma+ case let .derivesFailure(vma, _, _): vma+ case .alreadyShortCircuited: nil+ }}- /// The register the prologue seeds, which is the return value, or- /// `nil` once this patch has replaced the prologue.+ /// The register the prologue seeds, or `nil` once this patch has replaced+ /// the prologue.+ ///+ /// On the 26.6.2 shape this is also the function's return value. On the+ /// 24A435 shape it is only the base the return value is derived from — the+ /// return register there is the destination of the `add` at `deriveVMA`.public var resultRegister: String? {- guard case let .seedsFailure(_, register) = shape else { return nil }- return register+ switch shape {+ case let .seedsFailure(_, register): register+ case let .derivesFailure(_, register, _): register+ case .alreadyShortCircuited: nil+ }}}@@ -241,6 +280,10 @@ public enum DyldSharedCacheMISTrustAuthPatcher {case let .seedsFailure(seedVMA, register):log?(" [.] seeds \(register)=0x\(hex(UInt64(seededError))) "+ "at 0x\(hex(seedVMA))")+ case let .derivesFailure(seedVMA, register, deriveVMA):+ log?(" [.] seeds \(register)=0x\(hex(UInt64(baseError))) "+ + "at 0x\(hex(seedVMA)), derives 0x\(hex(UInt64(seededError))) "+ + "at 0x\(hex(deriveVMA))")case .alreadyShortCircuited:log?(" [.] prologue already reads `pacibsp ; mov x0, #0 ; retab`")}@@ -354,17 +397,14 @@ public enum DyldSharedCacheMISTrustAuthPatcher {guard let seed = try findSeededError(at: functionVMA, in: chunks) else {throw PatcherError.patchSiteNotFound(- "\(function): the prologue at 0x\(hex(functionVMA)) neither seeds "- + "0x\(hex(UInt64(seededError))) nor already reads "+ "\(function): the prologue at 0x\(hex(functionVMA)) seeds neither "+ + "0x\(hex(UInt64(seededError))) nor 0x\(hex(UInt64(baseError))) "+ + "into the MIS error range, and does not already read "+ "`pacibsp ; mov x0, #0 ; retab` — MIS has been rewritten",)}- return Site(- functionVMA: functionVMA,- anchorVMA: anchorVMA,- shape: .seedsFailure(seedVMA: seed.vma, resultRegister: seed.register),- )+ return Site(functionVMA: functionVMA, anchorVMA: anchorVMA, shape: seed)}/// Decode the first few instructions at `functionVMA`.@@ -511,15 +551,29 @@ public enum DyldSharedCacheMISTrustAuthPatcher {return nil}- /// The `mov w<reg>, #0x8026` / `movk w<reg>, #0xe800, lsl #16` pair that- /// seeds the failure code, searched from the function start.+ /// The `mov w<reg>, #<low>` / `movk w<reg>, #0xe800, lsl #16` pair that seeds+ /// the MIS error range, searched forward from the function start.////// Matched on decoded operands: the `mov`'s immediate is the low half, the- /// `movk`'s is the high half, and both must name the same register.+ /// `movk`'s is the high half, and both must name the same `w` register. Two+ /// low halves are accepted, and they are not interchangeable:+ ///+ /// - `0x8026` — the 26.6.2 shape. The seed *is* `0xE8008026` and the+ /// function subtracts down to the neighbouring errors, so the seeded+ /// register is the return value and nothing more is needed.+ /// - `0x8001` — the 24A435 shape. The seed is only the base of the range,+ /// so on its own it proves nothing: `0xE8008001` could be any MIS error.+ /// It is accepted only when the same function also contains an+ /// `add w<result>, w<seed>, #0x25`, which *is* `0xE8008026`. That+ /// corroboration is the whole reason this shape can be trusted.+ ///+ /// Forward-only from the function start. On 24A435 the preceding function+ /// carries the identical seed idiom 18 instructions earlier, and a backward+ /// window would find it.static func findSeededError(at functionVMA: UInt64,in chunks: DyldSharedCacheChunkSet,- ) throws -> (vma: UInt64, register: String)? {+ ) throws -> Shape? {let disassembler = ARM64Disassembler()let buffer = try chunks.readAtVMA(functionVMA,@@ -527,8 +581,6 @@ public enum DyldSharedCacheMISTrustAuthPatcher {allowShort: true,)let decoded = disassembler.disassemble(buffer, at: functionVMA)- let low = Int64(seededError & 0xFFFF)- let high = Int64((seededError >> 16) & 0xFFFF)for index in 0 ..< max(decoded.count - 1, 0) {let first = decoded[index]@@ -540,15 +592,72 @@ public enum DyldSharedCacheMISTrustAuthPatcher {firstOperands.count == 2,firstOperands[0].type == .register,firstOperands[1].type == .immediate,- firstOperands[1].imm == low,secondOperands.count >= 2,secondOperands[1].type == .immediate,- secondOperands[1].imm == high,+ secondOperands[1].imm == errorHighHalf,let register = disassembler.firstRegisterName(first),disassembler.firstRegisterName(second) == register,register.hasPrefix("w")else { continue }- return (first.address, register)++ let low = firstOperands[1].imm+ if low == Int64(seededError & 0xFFFF) {+ return .seedsFailure(seedVMA: first.address, resultRegister: register)+ }+ guard low == Int64(baseError & 0xFFFF),+ let deriveVMA = try findFailureDerivation(+ from: register,+ at: functionVMA,+ in: chunks,+ )+ else { continue }+ return .derivesFailure(+ seedVMA: first.address,+ seedRegister: register,+ deriveVMA: deriveVMA,+ )+ }+ return nil+ }++ /// The `add w<result>, w<seedRegister>, #<imm>` in this function whose result+ /// is `0xE8008026`, given a prologue that seeded `0xE8008001`.+ ///+ /// The immediate is checked by arithmetic — `baseError + imm == seededError` —+ /// rather than by pinning `#0x25`, so the same test keeps working if the base+ /// moves again. The scan stops at the next function's `pacibsp`, so a+ /// derivation belonging to a neighbour cannot corroborate this prologue.+ static func findFailureDerivation(+ from seedRegister: String,+ at functionVMA: UInt64,+ in chunks: DyldSharedCacheChunkSet,+ ) throws -> UInt64? {+ let disassembler = ARM64Disassembler()+ let buffer = try chunks.readAtVMA(+ functionVMA,+ length: maxFunctionInstructions * 4,+ allowShort: true,+ )+ let decoded = disassembler.disassemble(buffer, at: functionVMA)++ for instruction in decoded {+ guard instruction.isDecoded else { continue }+ // The next function begins here; anything past it is not evidence+ // about this one.+ if instruction.mnemonic == "pacibsp", instruction.address > functionVMA {+ return nil+ }+ guard instruction.mnemonic == "add",+ let operands = instruction.detail?.operands,+ operands.count == 3,+ operands[0].type == .register,+ operands[1].type == .register,+ operands[1].reg.name == seedRegister,+ operands[2].type == .immediate,+ operands[0].reg.name?.hasPrefix("w") == true,+ UInt32(truncatingIfNeeded: operands[2].imm) &+ baseError == seededError+ else { continue }+ return instruction.address}return nil}diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swiftindex eb12eed3..b9cd4915 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift@@ -17,6 +17,22 @@ public enum FirmwareGuestSystemPatchSet {private static let ios27 = VPhonePatchApplicability(iOSBase: .major(27))+ /// The bases where short-circuiting `checkTrustAndAuthorization` in the+ /// shared cache is survivable.+ ///+ /// Not a preference — a preference belongs in a preset's block list, and+ /// `standard` blocks this one too. This is the harder statement: on iOS 27 the+ /// patch stops the guest booting. TXM rejects the re-attested page, dyld+ /// cannot map `libSystem.B.dylib`, and `initproc failed to start`+ /// (issue #532). Without the gate, `experimental` — which is `Kind = All` —+ /// would hand a 27 user an unbootable VM.+ ///+ /// An unreadable base satisfies only `.any`, so an unknown release skips the+ /// patch. That is the safe direction here.+ private static let misTrustAuthBases = VPhonePatchApplicability(+ iOSBase: .oneOf([.major(18), .major(26)]),+ )+public static let manifest = VPhonePatchSetManifest(identifier: identifier,name: "Guest System",@@ -68,9 +84,11 @@ public enum FirmwareGuestSystemPatchSet {same check from userspace in installd and misagent, and editing the cache for it \stops an iOS 27 guest booting. Turn it on only on a 26.x base, and only to launch \an app signed with a free personal-team certificate — that launch goes through \- SpringBoard, which the hook does not cover.+ SpringBoard, which the hook does not cover. Not offered on iOS 27, where it stops \+ the guest booting.""",target: .dyldSharedCache,+ applicability: misTrustAuthBases,),// MARK: System Daemonsdiff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/DyldSharedCache/DyldSharedCacheMISTrustAuthPatcherTests.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/DyldSharedCache/DyldSharedCacheMISTrustAuthPatcherTests.swiftindex 1467383b..4cc4b110 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/DyldSharedCache/DyldSharedCacheMISTrustAuthPatcherTests.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/DyldSharedCache/DyldSharedCacheMISTrustAuthPatcherTests.swift@@ -71,6 +71,10 @@ private enum MISFixture {/// `functionVMA + 4`, the 27.0 shape from issue #532: the two words/// this patch overwrites *are* the seed.case inTheWordsWeOverwrite+ /// The 24A435 shape: the prologue seeds the *base* `0xE8008001` and the+ /// function adds its way up to `0xE8008026`, which is never written as a+ /// literal anywhere in that image.+ case derivedFromBase}/// What to put in the function when the point of the test is that neither@@ -79,6 +83,9 @@ private enum MISFixture {case none/// Prologue present, seed absent, and not this patch's output either.case seedRemoved+ /// The 24A435 base seed present but nothing deriving `0xE8008026` from+ /// it, so `0xE8008001` could be any MIS error and proves nothing.+ case derivationRemoved}/// `movk w<rd>, #<imm16>, lsl #<shift>`.@@ -104,6 +111,36 @@ private enum MISFixture {+ movkW(rd: 21, imm16: 0xE800, shift: 16)}+ /// The 24A435 seed, `mov w23, #0x8001 ; movk w23, #0xe800, lsl #16`.+ static var baseSeed: Data {+ (ARM64Encoder.encodeMovzW(rd: 23, imm16: 0x8001, shift: 0) ?? Data())+ + movkW(rd: 23, imm16: 0xE800, shift: 16)+ }++ /// `add w<rd>, w<rn>, #<imm12>`.+ ///+ /// Derived from `ARM64Encoder.encodeAddImm12`, the same way ``movkW(rd:imm16:shift:)``+ /// is derived from `encodeMovzW`: ADD (immediate) 32-bit and 64-bit differ+ /// only in `sf`, bit 31, so clearing it turns the X form into the W form.+ /// `A derived 32-bit add word disassembles as a w-register add` asserts that+ /// against Capstone rather than trusting it. Fixture input only — nothing the+ /// patcher writes comes from here.+ static func addWImm(rd: UInt32, rn: UInt32, imm12: UInt32) -> Data {+ guard let addX = ARM64Encoder.encodeAddImm12(rd: rd, rn: rn, imm12: imm12) else {+ return Data()+ }+ let word = addX.withUnsafeBytes { $0.loadUnaligned(as: UInt32.self) }+ return withUnsafeBytes(of: (UInt32(littleEndian: word) & ~UInt32(0x8000_0000)).littleEndian) {+ Data($0)+ }+ }++ /// `add w26, w23, #0x25` — the instruction that makes `0xE8008001` into+ /// `0xE8008026`, and the only reason the base seed can be trusted.+ static var derivation: Data {+ addWImm(rd: 26, rn: 23, imm12: 0x25)+ }+/// The stand-in function's instruction stream, from `functionVMA`.static func functionWords(seedAt placement: SeedPlacement, damage: Damage) -> Data {var code = ARM64.pacibsp@@ -123,6 +160,15 @@ private enum MISFixture {if case .afterPrologue = placement, case .none = damage {code += seed}+ if case .derivedFromBase = placement, damage != .seedRemoved {+ code += baseSeed+ // The 24A435 layout: the add is hundreds of instructions further in,+ // but only its presence and its operands matter here.+ if damage != .derivationRemoved {+ code += ARM64.nop+ code += derivation+ }+ }// The ADRP+ADD pair that materialises the naming literal, then the// return. `locateSite` walks back from the ADD to the `pacibsp`.@@ -550,3 +596,96 @@ struct DyldSharedCacheMISTrustAuthShapeDetectorTests {))}}++// MARK: - The 24A435 shape: a seeded base plus a derivation+//+// Measured on a pristine `iPhone17,3_27.0_24A435` SystemOS cryptex, decrypted+// and mounted read-only. `libmis` there does not materialise `0xE8008026`+// anywhere — a whole-image decode of 94,984 instructions finds no mov-family+// instruction with immediate `0x8026` and no such word in the data. The+// function at `0x22406F814` is the right one (the naming literal at+// `0x2240BCC23` has exactly one adrp+add reference, at `0x22406FB1C`, inside+// it; the nearest preceding `pacibsp` is the function start itself, and the+// instruction before it is an unconditional `b`). It seeds+// `mov w23, #0x8001 ; movk w23, #0xe800, lsl #16` at `+0x34`, and reaches the+// failure with `add w26, w23, #0x25` at `+0x124`. 26.6.2 did the reverse: it+// seeded `0xE8008026` and subtracted.++@Suite(.serialized)+struct DyldSharedCacheMISTrustAuthDerivedSeedTests {+ @Test+ func `A derived 32-bit add word disassembles as a w-register add`() {+ let decoded = ARM64Disassembler().disassemble(MISFixture.derivation, at: 0)+ let instruction = try? #require(decoded.first)+ #expect(instruction?.mnemonic == "add")+ let operands = instruction?.detail?.operands+ #expect(operands?.count == 3)+ #expect(operands?[0].reg.name == "w26")+ #expect(operands?[1].reg.name == "w23")+ #expect(operands?[2].imm == 0x25)+ }++ @Test+ func `A prologue seeding the base and deriving the failure is patched`() throws {+ let directory = MISFixture.scratch("derived")+ defer { MISFixture.discard(directory) }+ try MISFixture.makeCache(at: directory, seedAt: .derivedFromBase)++ let chunks = try DyldSharedCacheChunkSet(directory: directory)+ let site = try #require(try DyldSharedCacheMISTrustAuthPatcher.locateSite(in: chunks))+ #expect(site.functionVMA == MISFixture.functionVMA)+ guard case let .derivesFailure(_, register, deriveVMA) = site.shape else {+ Issue.record("expected the derived shape, got \(site.shape)")+ return+ }+ #expect(register == "w23")+ #expect(deriveVMA > MISFixture.functionVMA)++ let report = try DyldSharedCacheMISTrustAuthPatcher.patch(+ chunksDirectory: directory,+ log: nil,+ )+ #expect(report.outcome == .patched)+ #expect(try DyldSharedCacheChunkSet(directory: directory)+ .bytesAtVMA(MISFixture.functionVMA + 4, length: 8) == ARM64.movX0_0 + ARM64.retab)+ }++ @Test+ func `The base seed alone is not enough`() throws {+ // `0xE8008001` is just the bottom of the MIS error range. Without an+ // instruction deriving `0xE8008026` from it, this function has not been+ // shown to be the one that produces that error, and guessing is exactly+ // what this patcher refuses to do.+ let directory = MISFixture.scratch("derived-uncorroborated")+ defer { MISFixture.discard(directory) }+ try MISFixture.makeCache(+ at: directory,+ seedAt: .derivedFromBase,+ damage: .derivationRemoved,+ )++ let chunks = try DyldSharedCacheChunkSet(directory: directory)+ #expect(throws: PatcherError.self) {+ _ = try DyldSharedCacheMISTrustAuthPatcher.locateSite(in: chunks)+ }+ }++ @Test+ func `Patching the derived shape twice is a no-op the second time`() throws {+ // The 24A435 seed sits at +0x34, clear of the two words at +4, so unlike+ // the issue-#532 layout it survives the write. Both recognitions must+ // still agree on the second run.+ let directory = MISFixture.scratch("derived-rerun")+ defer { MISFixture.discard(directory) }+ try MISFixture.makeCache(at: directory, seedAt: .derivedFromBase)++ try DyldSharedCacheMISTrustAuthPatcher.patch(chunksDirectory: directory, log: nil)+ let second = try DyldSharedCacheMISTrustAuthPatcher.patch(+ chunksDirectory: directory,+ log: nil,+ )+ #expect(second.outcome == .alreadyPatched)+ #expect(second.sitesWritten == 0)+ #expect(second.site?.shape == .alreadyShortCircuited)+ }+}