Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Prefilter the two whole-text kernel scans before Capstone

Lakrdc4b5340e37b
diff --git a/Research/0_binary_patch_comparison.md b/Research/0_binary_patch_comparison.md
index f0373945..d7d4c321 100644
--- a/Research/0_binary_patch_comparison.md
+++ b/Research/0_binary_patch_comparison.md
@@ -406,7 +406,7 @@
| JB-23 | B | `patch_thid_should_crash` | `_thid_should_crash` | Prevent GUARD_TYPE_MACH_PORT crash | Y |
| JB-23b| B | `patchThreadSetStateEntitlementFlag` | `thread_set_state_from_user` / inlined `act_set_state_from_user` flags materialization | **Frida Stalker existing-thread support (opt-in `--frida`).** Stalker updates an existing thread's core registers via `thread_set_state_from_user`, which passes `flags = TSSF_TRANSLATE_TO_USER \| TSSF_CHECK_ENTITLEMENT` (0x201) into `thread_set_state_internal`; the inlined `thread_set_state_allowed()` then demands `com.apple.private.thread-set-state` (which the target lacks) → `GUARD_TYPE_MACH_PORT / THREAD_SET_STATE`. Rather than NOP the entitlement check, clear TSSF_CHECK_ENTITLEMENT (bit 9) in the flags the user setters pass: rewrite `mov w6, #0x201` → `mov w6, #0x1`. This preserves TSSF_TRANSLATE_TO_USER (user-pointer translation) and leaves the independent `TH_IN_MACH_EXCEPTION` guard enforced — it only stops user-initiated `thread_set_state` from being entitlement-gated. Anchor: entitlement-string xref cluster → the single containing function (thread_set_state_internal); then its direct `b`/`bl` callers that set `w6` (the 7th-arg = flags, a calling-convention anchor, not an allocation guess) to 0x201. Both setters (`thread_set_state_from_user` + inlined `act_set_state_from_user`) are patched. No offsets/VAs/registers/bytes hardcoded; replacement from the Keystone-backed `ARM64Encoder.encodeMovzW`, Capstone-verified. Kernels without the shape are skipped (fail-open no-op). Verified on the `c0ecdb4b` 26.4 kernel (UUID `BCD06230-CCBE-8E48-50FF-D9C166D83CD5`): exactly two records at file-off `0x1D95720`/`0x1D9594C`. | `--frida` |
| JB-24 | B | `patch_vm_fault_enter_prepare` | `_vm_fault_enter_prepare` | Force `cs_bypass` fast path in runtime fault validation | Y |
-| JB-25 | B | `patch_vm_map_protect` | `_vm_map_protect` | Skip upstream write-downgrade gate. Shape A (26.1–26.4) active; **Shape B (26.5) disabled 2026-07-05** — widened the `~VM_PROT_WRITE` COW strip (vm_map.c:6202) instead of the RWX gate (vm_map.c:5997), breaking COW and crashing the debugger (SPTM `VIOLATION_ILLEGAL_MAP`). Retired on 26.5+: SPTM code-mod (debugger + Substrate tweaks) uses write-then-flip via `vm_protect(VM_PROT_COPY)` → `XNU_USER_DEBUG`, so no RWX patch is needed. **SHAPE C ADDED (2026-09-22, cloudOS 26.4 `c0ecdb4b…`, jb):** the patch logged `[-] vm_map_protect write-downgrade gate not found` on this base, which `make test_fw_patches` is built to fail on. Two independent causes, both confirmed by disassembling the 26.4 research kernelcache. **(1) The gate is compiled differently.** Where 26.1/26.3 emit a flag-setting `bics` plus a separate `tbnz wFlags,#22,skip`, 26.4 folds the two conditions into a conditional compare and leaves one branch: `and wFlags,wFlags,#0x400000` / `mov wMask,#6` / `bic wMask,wMask,wProt` / `cmp wMask,#0` / `ccmp wFlags,#0,#0,eq` / `b.ne skip`, with `and wProt,wProt,#0xfffffffb` (clear `VM_PROT_EXECUTE`, keep R|W) inside the guarded block. Same mask `#6`, same entry bit 22, same downgrade — rewriting that single `b.ne` to an unconditional `b` bypasses both conditions at once, exactly as Shape A's rewrite does (there the `tbnz` becomes dead). Observed at VA `0xFFFFFE0008DCAEA0` → `0xFFFFFE0008DCAED0` (file `0x1DC6EA0`). **(2) The search window stopped short.** `findFuncEnd` ends at the next `pacibsp`; on 26.4 the block holding the `"vm_map_protect("` panic string ends at its own prologue `0x6B8` bytes *before* the gate, so the window derived from the string anchor never reached it. **Reveal procedure for Shape C:** the signature is its own anchor rather than a byte window — across the whole `com.apple.kernel __TEXT_EXEC` (8.4 MB) even the bare `mov wMask,#6 ; bic wMask,wMask,wProt` prefix occurs **exactly once**, and the matcher additionally requires the bit-22 mask before it and the execute-clearing `and` inside the guarded block, then demands a unique hit across all code ranges. Widening by an offset was rejected as an offset-shaped anchor. **Backward compatibility:** Shape A is untouched and still tried first, so 26.1/26.3 take precisely the path they always took and Shape C is unreachable there. **VALIDATED on-device (2026-09-23, `17,3_26.4_23E246` + cloudOS 26.4 `23E5207q`, JB, `vm create` host-mount deploy):** the deployed `kernelcache.research.vphone600` carries the rewritten gate — `0xFFFFFE0008DCAEA0` disassembles as unconditional `b #0xfffffe0008dcaed0` with `and w8,w8,#0x400000 / mov w9,#6 / bic w9,w9,w20 / cmp w9,#0 / ccmp w8,#0,#0,eq` intact above it — and the VM boots clean: zero `panic(` / `stackshot` markers across the whole boot log, SpringBoard up, Safari and Sileo both running, so the JB userland and TweakLoader come up with the patch live. The gate is the same one on a 26.4 base whichever userland rides on top, since `fw_patch_jb` patches the cloudOS kernelcache, not the iOS one. Matching was separately checked on `17,3_27.0_24A435` + the same base. **Still not exercised:** a debugger attach or a tweak RWX write specifically — that is the failure mode Shape B produced (broken COW, SPTM `VIOLATION_ILLEGAL_MAP`), and a clean boot with Sileo running is good evidence but not that test. Note the source also disagreed with itself about the covered range — headers said "Shape A (26.1 / 26.3)", line 69 said "26.1-26.4"; on 26.4 the answer is neither, it is Shape C. | Y/N |
+| JB-25 | B | `patch_vm_map_protect` | `_vm_map_protect` | Skip upstream write-downgrade gate. Shape A (26.1–26.4) active; **Shape B (26.5) disabled 2026-07-05** — widened the `~VM_PROT_WRITE` COW strip (vm_map.c:6202) instead of the RWX gate (vm_map.c:5997), breaking COW and crashing the debugger (SPTM `VIOLATION_ILLEGAL_MAP`). Retired on 26.5+: SPTM code-mod (debugger + Substrate tweaks) uses write-then-flip via `vm_protect(VM_PROT_COPY)` → `XNU_USER_DEBUG`, so no RWX patch is needed. **SHAPE C ADDED (2026-09-22, cloudOS 26.4 `c0ecdb4b…`, jb):** the patch logged `[-] vm_map_protect write-downgrade gate not found` on this base, which `make test_fw_patches` is built to fail on. Two independent causes, both confirmed by disassembling the 26.4 research kernelcache. **(1) The gate is compiled differently.** Where 26.1/26.3 emit a flag-setting `bics` plus a separate `tbnz wFlags,#22,skip`, 26.4 folds the two conditions into a conditional compare and leaves one branch: `and wFlags,wFlags,#0x400000` / `mov wMask,#6` / `bic wMask,wMask,wProt` / `cmp wMask,#0` / `ccmp wFlags,#0,#0,eq` / `b.ne skip`, with `and wProt,wProt,#0xfffffffb` (clear `VM_PROT_EXECUTE`, keep R|W) inside the guarded block. Same mask `#6`, same entry bit 22, same downgrade — rewriting that single `b.ne` to an unconditional `b` bypasses both conditions at once, exactly as Shape A's rewrite does (there the `tbnz` becomes dead). Observed at VA `0xFFFFFE0008DCAEA0` → `0xFFFFFE0008DCAED0` (file `0x1DC6EA0`). **(2) The search window stopped short.** `findFuncEnd` ends at the next `pacibsp`; on 26.4 the block holding the `"vm_map_protect("` panic string ends at its own prologue `0x6B8` bytes *before* the gate, so the window derived from the string anchor never reached it. **Reveal procedure for Shape C:** the signature is its own anchor rather than a byte window — across the whole `com.apple.kernel __TEXT_EXEC` (8.4 MB) even the bare `mov wMask,#6 ; bic wMask,wMask,wProt` prefix occurs **exactly once**, and the matcher additionally requires the bit-22 mask before it and the execute-clearing `and` inside the guarded block, then demands a unique hit across all code ranges. Widening by an offset was rejected as an offset-shaped anchor. **Backward compatibility:** Shape A is untouched and still tried first, so 26.1/26.3 take precisely the path they always took and Shape C is unreachable there. **VALIDATED on-device (2026-09-23, `17,3_26.4_23E246` + cloudOS 26.4 `23E5207q`, JB, `vm create` host-mount deploy):** the deployed `kernelcache.research.vphone600` carries the rewritten gate — `0xFFFFFE0008DCAEA0` disassembles as unconditional `b #0xfffffe0008dcaed0` with `and w8,w8,#0x400000 / mov w9,#6 / bic w9,w9,w20 / cmp w9,#0 / ccmp w8,#0,#0,eq` intact above it — and the VM boots clean: zero `panic(` / `stackshot` markers across the whole boot log, SpringBoard up, Safari and Sileo both running, so the JB userland and TweakLoader come up with the patch live. The gate is the same one on a 26.4 base whichever userland rides on top, since `fw_patch_jb` patches the cloudOS kernelcache, not the iOS one. Matching was separately checked on `17,3_27.0_24A435` + the same base. **Still not exercised:** a debugger attach or a tweak RWX write specifically — that is the failure mode Shape B produced (broken COW, SPTM `VIOLATION_ILLEGAL_MAP`), and a clean boot with Sileo running is good evidence but not that test. Note the source also disagreed with itself about the covered range — headers said "Shape A (26.1 / 26.3)", line 69 said "26.1-26.4"; on 26.4 the answer is neither, it is Shape C. **PREFILTERED (2026-09-28, no change to the gate or the patch):** because the Shape C scan is deliberately unscoped it walks all 8.4 MB of kernel text, and it was decoding five instructions at every one of the ~2.1M offsets only to reject almost all of them on the first one. Sampling a Release `fw patch` (8623 samples, `sample`) put 93% of the whole run in `scanRange` → `ARM64Disassembler.disassemble`, and 72% of that inside `cs_disasm` — not in the decoder but in Capstone's *printer*: `printInst` / `printAliasInstr` / `matchAliasPatterns`, `vsnprintf` / `SStream_concat`, and `map_set_alias_id` → `name2id`'s `strcmp` chain. `AArch64_LLVM_getInstruction`, the actual decode, was 6%. A rejection-only raw-word gate now runs first (`ARM64Inst.isMOVZW` + `movImm16 == 6`, or `isORRImmW` + `rn == 31`), so Capstone is only asked about offsets that could open with `mov wMask,#6`. **Nothing is decided by the prefilter** — survivors take exactly the decode and the checks they always did, and every positive determination is still Capstone's. Both encodings of `mov wD,#6` are accepted although only MOVZ can reach the existing `mnemonic == "mov"` check (the MOV-bitmask alias applies only when the immediate is *not* MOVZ-encodable, so `orr w9,wzr,#6` = `0x321F07E9` prints as `orr`), which keeps the gate independent of that aliasing rule; `ARM64InstTests` pins both words and the printer's answer for each. The same treatment was applied to the one other full-text scan, `patchThreadSetStateEntitlementFlag` (`isBorBL`, extended-only). Measured on `17,3_26.4` + cloudOS 26.4, Release: the patch step 28.81 s → 1.28 s, whole `fw patch` 48.98 s → 21.68 s standard and ~61 s → ~28 s extended, instructions retired 1.006e12 → 5.38e11. **Verified byte-identical:** all four bases (26.1 / 26.4 / 26.6.2 / 27.0) × both presets, HEAD vs HEAD+prefilter, every file in each restore tree hashed — 12/12 identical (196/186/186/185 files), same 172 standard / 183 extended patch counts, same `0x1DC6EA0` rewrite, no undeclared-patch warnings. | Y/N |
| JB-25c| B | `patchVmMapDeleteImmutableCode` | `_vm_map_delete` permanent-entry immutable-code exception (vm_map.c:8855) | **Frida Stalker repeated-`VM_PROT_COPY` fix (opt-in `--frida`).** Stalker's write-then-flip leaves a CSM-associated permanent entry at current `RW` / max `RWX`; XNU's "debugger may undo executable mappings" exception tests `entry->protection & VM_PROT_EXECUTE` (current, bit 9), which is clear, so the entry stays permanent and the next fixed overwrite returns `KERN_PROTECTION_FAILURE`. Retarget the execute test to the packed `max_protection` bit (bit 9 → bit 13; `protection:3`@7..9, `max_protection:4`@11..14 in the `[entry,#0x38]` flags word). Semantic matcher: packed-flags load + `vme_permanent` (bit 19) + the inlined `developer_mode_state()` byte-bit-0 read + the current-X test bound to the immutable-code cluster (Shape A: shares the remove-flags fallback target; Shape B: branches to the permanent-continuation target). The remove-flags bit is matched structurally (a test of a non-entry register), not by source constant (VM_MAP_REMOVE_* bit numbers drift across XNU versions). The later CSM current-X `#9` test in the same window is deliberately excluded (different branch target). Exactly two gates or fail closed; branch bytes from the Keystone-backed `ARM64Encoder.encodeTestBitBranch`, Capstone round-trip verified (sense/bit/target). Verified on the `c0ecdb4b` 26.4 kernel: two records at file-off `0x1DBE14C` (`tbz w8,#9→#0xd`) and `0x1DBE828` (`tbnz w8,#9→#0xd`). | `--frida` |
| JB-26 | B | `patch_iomfb_swapend_variable_size` | IOMFB userclient method-5 (SwapEnd) `__DATA_CONST` dispatch entry (`checkStructureInputSize`) | **iOS-27 VZ-view fix, kernel half — paired with DSC force-kern (DSC-patch item 11).** The 26.4 userclient's method-5 dispatch entry hard-checks `checkStructureInputSize == 0x588`; forced-kern iOS 27 sends its native `0x6e0`. Rewrite the size field to `kIOUCVariableStructureSize (0xFFFFFFFF)` so `IOUserClient::externalMethod` accepts 27's struct and reaches the handler. Anchor (structural): the sole `__DATA_CONST` entry `{ptr(ptrauth, top-byte≥0x80), scalarIn=0, structIn=0x588, scalarOut=0, structOut=0}` (verified unique; decompressed file-off 0x9c7228). No-op-in-effect for version-matched 26.x (sends 0x588). Re-enabled 2026-07-15 (was disabled when 27 present-path was still unknown). | Y |
| JB-27 | B | `patch_iomfb_swapend_handler_size` | method-5 handler internal size gate (`cmp w2,#0x588 ; b.ne <err>`) | Companion to JB-26: beyond the dispatch-table check the handler re-checks the struct size (`cmp w2,#0x588 ; b.ne <kIOReturnBadArgument>`; verified unique at decompressed file-off 0x16ae22c; success path forwards the raw struct ptr to a `vtable+0x590` paravirt swap method). Retarget the `cmp` immediate to `0x6e0` so forced-kern iOS 27's native SwapEnd reaches real swap processing (27's IOMFBSwapRec prefix matches 26.x → handler reads valid fields). Semantic anchor (`cmp w2,#imm` word + following `b.ne` decode). Enabled together with JB-26 + DSC force-kern for iOS 27. | Y |
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/Kernel/JailbreakPatches/Frida/KernelJailbreakPatchThreadSetState.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/Kernel/JailbreakPatches/Frida/KernelJailbreakPatchThreadSetState.swift
index 77daa56a..4456b9e9 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/Kernel/JailbreakPatches/Frida/KernelJailbreakPatchThreadSetState.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/Kernel/JailbreakPatches/Frida/KernelJailbreakPatchThreadSetState.swift
@@ -43,6 +43,11 @@ extension KernelJailbreakPatcher {
var off = range.start
while off + 4 <= min(range.end, buffer.count) {
defer { off += 4 }
+ // Rejection-only gate ahead of the decode, for the same reason as
+ // the vm_map_protect scan: this walks all of kernel text, and B/BL
+ // are the only two encodings `isBorBL` accepts, so a word it
+ // rejects could never have satisfied the mnemonic check below.
+ guard ARM64Inst.isBorBL(buffer.readU32(at: off)) else { continue }
guard let branch = disasAt(off),
branch.mnemonic == "b" || branch.mnemonic == "bl",
let target = branchTargetFileOffset(branch),
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/Kernel/JailbreakPatches/Memory/KernelJailbreakPatchVmProtect.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/Kernel/JailbreakPatches/Memory/KernelJailbreakPatchVmProtect.swift
index 91417bf9..b205d533 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/Kernel/JailbreakPatches/Memory/KernelJailbreakPatchVmProtect.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/Kernel/JailbreakPatches/Memory/KernelJailbreakPatchVmProtect.swift
@@ -129,6 +129,29 @@ extension KernelJailbreakPatcher {
var off = start
while off + 0x18 < end {
defer { off += 4 }
+
+ // Rejection-only gate, ahead of Capstone. Nothing is decided here: a
+ // word that survives goes through exactly the decode and the checks it
+ // always did, and every positive determination below is still
+ // Capstone's. It exists because this scan is deliberately unscoped
+ // (see findFusedWriteDowngradeGate), so it walks all 8.4 MB of kernel
+ // text — and decoding five instructions at every one of the ~2.1M
+ // offsets to reject almost all of them on the first one cost ~29 s of
+ // a ~49 s `fw patch`, nearly all of it inside Capstone's printer.
+ //
+ // The window has to open with `mov wMask, #6`, which an assembler can
+ // spell two ways: MOVZ, or `orr wMask, wzr, #6`. Both are let through.
+ // In practice the ORR form disassembles as `orr`, not `mov` — the
+ // MOV-bitmask alias applies only when the immediate is *not*
+ // MOVZ-encodable, and #6 is — so the check below would reject it
+ // anyway. Accepting it here regardless keeps this gate from depending
+ // on that aliasing rule, which is the one way a cheap prefilter could
+ // silently narrow the match.
+ let word = buffer.readU32(at: off)
+ guard (ARM64Inst.isMOVZW(word) && ARM64Inst.movImm16(word) == 6)
+ || (ARM64Inst.isORRImmW(word) && ARM64Inst.rn(word) == 31)
+ else { continue }
+
let insns = disasm.disassemble(in: buffer.data, at: off, count: 5)
guard insns.count >= 5 else { continue }
let movMask = insns[0], bicInsn = insns[1]
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/Core/FirmwarePatcherTests.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/Core/FirmwarePatcherTests.swift
index 96a92e40..c9e53213 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/Core/FirmwarePatcherTests.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/Core/FirmwarePatcherTests.swift
@@ -272,6 +272,41 @@ struct ARM64InstTests {
#expect(!ARM64Inst.isMOVZW(0xF941_F001))
}
+ /// The prefilter in front of the vm_map_protect Shape C scan accepts both ways
+ /// an assembler can spell `mov wD, #imm`, so it cannot narrow what Capstone is
+ /// then asked to confirm. This pins both encodings and records which mnemonic
+ /// the printer gives each: for a MOVZ-encodable value like #6 the ORR form
+ /// prints as `orr`, because the MOV-bitmask alias applies only when MOVZ cannot
+ /// hold the immediate. The scan does not rely on that — it lets the ORR form
+ /// through either way — but if the printer ever changed its mind, this is where
+ /// it shows up.
+ @Test func `orr immediate W is the other mov immediate encoding`() {
+ // `mov w9, #6` and `movz w9, #6` both assemble to this (clang, arm64).
+ let movz: UInt32 = 0x5280_00C9
+ #expect(mnemonic(of: movz) == "mov" || mnemonic(of: movz) == "movz")
+ #expect(ARM64Inst.isMOVZW(movz))
+ #expect(ARM64Inst.movImm16(movz) == 6)
+ #expect(ARM64Inst.rd(movz) == 9)
+ #expect(!ARM64Inst.isORRImmW(movz))
+
+ // `orr w9, wzr, #6` — same value, logical-immediate encoding.
+ let orr6: UInt32 = 0x321F_07E9
+ #expect(ARM64Inst.isORRImmW(orr6))
+ #expect(ARM64Inst.rn(orr6) == 31) // wzr
+ #expect(ARM64Inst.rd(orr6) == 9)
+ #expect(!ARM64Inst.isMOVZW(orr6))
+ #expect(mnemonic(of: orr6) == "orr")
+
+ // `orr w9, wzr, #7` — a different element size behind the same mask.
+ let orr7: UInt32 = 0x3200_0BE9
+ #expect(ARM64Inst.isORRImmW(orr7))
+ #expect(ARM64Inst.rn(orr7) == 31)
+
+ // Neither a register-form AND nor a branch is an ORR-immediate.
+ #expect(!ARM64Inst.isORRImmW(0x0A05_0083))
+ #expect(!ARM64Inst.isORRImmW(0x1400_0000))
+ }
+
@Test func `and reg W`() {
let w: UInt32 = 0x0A05_0083 // and w3, w4, w5
#expect(mnemonic(of: w) == "and")
@@ -296,6 +331,28 @@ struct ARM64InstTests {
#expect(!ARM64Inst.isBEQ(0x5400_0021)) // b.ne #4
}
+ /// `isBorBL` gates the thread_set_state scan, which then checks the decoded
+ /// mnemonic for exactly `b` or `bl`. It has to accept both and nothing else, or
+ /// the scan quietly loses sites.
+ @Test func `b or bl`() throws {
+ let b = try #require(ARM64Encoder.encodeB(from: 0x1000, to: 0x2000)?
+ .withUnsafeBytes { $0.load(as: UInt32.self) })
+ let bl = try #require(ARM64Encoder.encodeBL(from: 0x1000, to: 0x2000)?
+ .withUnsafeBytes { $0.load(as: UInt32.self) })
+ #expect(mnemonic(of: b) == "b")
+ #expect(mnemonic(of: bl) == "bl")
+ #expect(ARM64Inst.isBorBL(b))
+ #expect(ARM64Inst.isBorBL(bl))
+ // Backward branches set the sign bits of imm26; the mask must ignore them.
+ let back = try #require(ARM64Encoder.encodeB(from: 0x2000, to: 0x1000)?
+ .withUnsafeBytes { $0.load(as: UInt32.self) })
+ #expect(ARM64Inst.isBorBL(back))
+ // A conditional branch, a cbz and a movz are not unconditional branches.
+ #expect(!ARM64Inst.isBorBL(0x5400_0020)) // b.eq #4
+ #expect(!ARM64Inst.isBorBL(0x3400_0020)) // cbz w0, #4
+ #expect(!ARM64Inst.isBorBL(0x5280_02C0)) // movz w0, #0x16
+ }
+
@Test func `compare and branch`() {
#expect(ARM64Inst.isCBZW(0x3400_0020)) // cbz w0, #4
#expect(!ARM64Inst.isCBZW(0x3500_0020)) // that is cbnz
diff --git a/VPhoneExecutable/VPhoneCommand/VPhonePatchKit/ARM64/ARM64Inst.swift b/VPhoneExecutable/VPhoneCommand/VPhonePatchKit/ARM64/ARM64Inst.swift
index a8b4e4be..8f16e2e3 100644
--- a/VPhoneExecutable/VPhoneCommand/VPhonePatchKit/ARM64/ARM64Inst.swift
+++ b/VPhoneExecutable/VPhoneCommand/VPhonePatchKit/ARM64/ARM64Inst.swift
@@ -68,6 +68,22 @@ public enum ARM64Inst {
(i & 0xFFE0_0000) == 0x5280_0000
}
+ /// ORR Wd, WZR, #imm — 32-bit logical-immediate ORR, [31:22]=0011001000
+ /// (sf=0, opc=01, N=0). This is the *other* encoding an assembler may pick to
+ /// materialise a small constant, so a scanner looking for `mov wD, #imm` has
+ /// to let it through as well. Rn is left free: a caller that means WZR
+ /// specifically checks `rn(i) == 31` itself.
+ ///
+ /// The immediate field is not decoded here. Logical immediates carry their own
+ /// element size, so the same value has several legal spellings — `orr w9, wzr,
+ /// #6` is 0x321F07E9 (element size 32) while `orr w9, wzr, #7` is 0x32000BE9 —
+ /// and reproducing that table would be the kind of hand-rolled decode the
+ /// kernel patcher guardrails exist to keep out. Callers confirm the value with
+ /// Capstone.
+ public static func isORRImmW(_ i: UInt32) -> Bool {
+ (i & 0xFFC0_0000) == 0x3200_0000
+ }
+
/// AND Wd, Wn, Wm — 32-bit shifted-register AND (imm6=0; shift type left free,
/// harmless at shift amount 0): [31:24]=00001010, N=0.
public static func isANDRegW(_ i: UInt32) -> Bool {
@@ -84,6 +100,13 @@ public enum ARM64Inst {
i >> 26 == 0b100101
}
+ /// B or BL — unconditional branch (immediate), [30:26]=00101. Bit 31 is the
+ /// link bit and is left free, so both forms pass and nothing else does: those
+ /// two are the only encodings in the group.
+ public static func isBorBL(_ i: UInt32) -> Bool {
+ (i & 0x7C00_0000) == 0x1400_0000
+ }
+
/// B.EQ — conditional branch, [31:24]=0x54, bit4=0, cond=0000.
public static func isBEQ(_ i: UInt32) -> Bool {
(i & 0xFF00_001F) == 0x5400_0000