Run a virtual iPhone on an Apple Silicon Mac.
Swift
fix: a broken recipe line, a fake clone, a missing target, a redundant [-]
Lakr8c2cf10c2a62
diff --git a/Makefile b/Makefileindex 0375b71a..084e6530 100644--- a/Makefile+++ b/Makefile@@ -150,7 +150,7 @@ help:# Setup# ═══════════════════════════════════════════════════════════════════-.PHONY: setup_machine setup_tools+.PHONY: setup_machine setup_tools setup_venvsetup_machine:@if count=0; \@@ -177,6 +177,12 @@ setup_machine:setup_tools:VARIANT=$(VARIANT) zsh $(SCRIPTS)/setup_tools.sh+# The venv alone, without the brew packages and the toolchain builds that+# setup_tools also does. Documented in AGENTS.md and in setup_venv.sh's own+# header, both of which named a target that did not exist.+setup_venv:+ zsh $(SCRIPTS)/setup_venv.sh+# ═══════════════════════════════════════════════════════════════════# Clean — remove generated build/tooling files by default.# Destructive VM/IPSW cleanup is opt-in and requires confirmation.@@ -366,7 +372,7 @@ ifeq ($(UID),0)fw_patch_less: patcher_build"$(CURDIR)/$(PATCHER_BINARY)" patch-firmware --vm-directory "$(VM_DIR_ABS)" \--variant less \- $(if $(call truthy,$(NO_BINPACK)),--no-binpack,)+ $(if $(call truthy,$(NO_BINPACK)),--no-binpack,) \$(if $(call truthy,$(NO_VPHONED)),--no-vphoned,)elsefw_patch_less:diff --git a/research/0_binary_patch_comparison.md b/research/0_binary_patch_comparison.mdindex 74fada2d..dfc2110b 100644--- a/research/0_binary_patch_comparison.md+++ b/research/0_binary_patch_comparison.md@@ -135,7 +135,7 @@| JB-03 | C | `patch_cred_label_update_execve` | `_cred_label_update_execve` | Reworked C21-v3: C21-v1 already boots; v3 keeps split late exits and additionally ORs success-only helper bits `0xC` after clearing `0x3F00`; still disabled pending boot validation | N || JB-04 | C | `patch_hook_cred_label_update_execve` | sandbox `mpo_cred_label_update_execve` wrapper (`ops[18]` -> `sub_FFFFFE00093BDB64`) | Faithful upstream C23 trampoline: copy `VSUID`/`VSGID` owner state into pending cred, set `P_SUGID`, then branch back to wrapper | Y || JB-05 | C | `patch_kcall10` | `sysent[439]` (`SYS_kas_info` replacement) | Rebuilt ABI-correct kcall cave: `target + 7 args -> uint64 x0`; re-enabled after focused dry-run validation | Y |-| JB-06 | B | `patch_post_validation_additional` | `_postValidation` (additional) | Disable SHA256-only hash-type reject | Y |+| JB-06 | B | `patch_post_validation_additional` | `_postValidation` (additional) | Disable SHA256-only hash-type reject. **FIX (2026-09-22):** logged `[-] expected 1 postValidation compare site, found 0` on every run, which `make test_fw_patches` is built to fail on. Cause: this patch and base-layer item 9 (`KernelPatchPostValidation`) reveal the *same* site the *same* way — same `"AMFI: code signature validation failed"` string anchor, same caller walk, same `cmp w0,#imm ; b.ne` preceded by a BL (item 9 searches a 2-instruction BL window, this one a wider 3) — and both rewrite it to `cmp w0,w0`. Item 9 runs first and takes the site (observed at file offset `0xDE8360`, `cmp w0,#2` → `cmp w0,w0`), so by the time this runs the only candidate no longer has an immediate operand and a search for one finds nothing. The `[-]` was therefore a redundant no-op, not a missed patch. `patchPostValidationAdditional` now also recognizes `cmp w0,w0` in that slot (same BL-precedence anchor) and reports `[=] already cmp w0,w0 ... (base postValidation patch owns this site)` returning success; the failure message additionally reports how many already-patched sites it saw, so a genuine miss is still distinguishable from this case. | Y || JB-07 | C | `patch_syscallmask_apply_to_proc` | syscallmask apply wrapper (`_proc_apply_syscall_masks` path) | Faithful upstream C22: mutate installed Unix/Mach/KOBJ masks to all-ones via structural cave, then continue into setter; distinct from `NULL`-mask alternative | Y || JB-08 | A | `patch_task_conversion_eval_internal` | `_task_conversion_eval_internal` | Allow task conversion | Y || JB-09 | A | `patch_sandbox_hooks_extended` | Sandbox MACF ops (extended) | Stub remaining 30+ sandbox hooks (incl. IOKit 201..210) + `mpo_proc_check_syscall_unix` (`ops[124]`) → allow. **The ops[124] hook is the iOS-27 DDI-mount syscall fix:** MobileStorageMounter's `mount_apfs` needs the `mount(2)` syscall (unix 167) to mount the personalized DDI at `/System/Developer`; on the 26.4-kernel / 27-userland hybrid the kernel Sandbox otherwise denies it (`Protobox: mount_apfs deny(1) syscall-unix 167`). Index calibrated against the reference-XNU `mac_policy_ops` struct order (co-verified: mpo_vnode_check_open=267, mpo_vnode_check_fsgetpath=316). Validated live on `c0ecdb4b` 26.4 (DDI auto-mounts). | Y |@@ -156,7 +156,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. | 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. **OBSERVED (2026-09-22, cloudOS 26.4 `c0ecdb4b…`, jb):** Shape A did not match on this base either, so with Shape B disabled the patch applies nothing and logs `[-] vm_map_protect write-downgrade gate not found` — which `make test_fw_patches` is built to fail on. Left as-is deliberately: whether a 26.4 base still needs the RWX bypass is a semantics question, not a pattern-matching one, and the boot validated without it. Note the source disagrees with itself about the covered range — `KernelJBPatchVmProtect.swift` headers say "Shape A (26.1 / 26.3)" at lines 9 and 75 but "Shape A stays for 26.1-26.4" at line 69, and this row says 26.1–26.4. One of the three is wrong; resolving that is the prerequisite for deciding whether the `[-]` should become a gated skip. | 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/scripts/fw_prepare.sh b/scripts/fw_prepare.shindex f85b9074..c9655269 100755--- a/scripts/fw_prepare.sh+++ b/scripts/fw_prepare.sh@@ -408,7 +408,14 @@ extract() {firm -rf "$out"echo "==> Cloning ${cache##*/} → ${out##*/} ..."- cp -R "$cache" "$out"+ # -c makes this an APFS clone, which is what the line above already claims+ # it is. Without it a full second copy of the extracted IPSW is written —+ # ~11.5 GB for an iPhone restore — on top of the .ipsw and the cache, and+ # the patchers then rewrite only a handful of files out of it. Cloning is+ # copy-on-write, so the bytes are shared until something changes them.+ # Falls back to copyfile(2) where the target cannot be cloned, so this is+ # safe off APFS too.+ cp -Rc "$cache" "$out"}download_apfs_sealvolume() {diff --git a/sources/FirmwarePatcher/Kernel/JBPatches/CodeSigning/KernelJBPatchPostValidation.swift b/sources/FirmwarePatcher/Kernel/JBPatches/CodeSigning/KernelJBPatchPostValidation.swiftindex 48acc8b2..9bd6c264 100644--- a/sources/FirmwarePatcher/Kernel/JBPatches/CodeSigning/KernelJBPatchPostValidation.swift+++ b/sources/FirmwarePatcher/Kernel/JBPatches/CodeSigning/KernelJBPatchPostValidation.swift@@ -29,6 +29,7 @@ extension KernelJBPatcher {// Collect unique caller function starts.var seenFuncs = Set<Int>()var hits: [Int] = []+ var alreadyPatched: [Int] = []for (adrpOff, _) in refs {guard let callerStart = findFunctionStart(adrpOff),@@ -61,7 +62,16 @@ extension KernelJBPatcher {let op0 = detail0.operands[0]let op1 = detail0.operands[1]guard op0.type == AARCH64_OP_REG, op0.reg == AARCH64_REG_W0 else { continue }- guard op1.type == AARCH64_OP_IMM else { continue }++ let isImmediate = op1.type == AARCH64_OP_IMM+ // `cmp w0, w0` in this slot is this patch's own result. The+ // base layer's postValidation patch reveals the same site+ // the same way — same string anchor, same `cmp w0,#imm ;+ // b.ne` shape, a narrower BL window — and rewrites it+ // before this runs, so the immediate is already gone by+ // then and searching only for one finds nothing at all.+ let isAlreadyPatched = op1.type == AARCH64_OP_REG && op1.reg == AARCH64_REG_W0+ guard isImmediate || isAlreadyPatched else { continue }// Must be preceded by a BL within 3 instructions.var hasBlBefore = false@@ -72,14 +82,28 @@ extension KernelJBPatcher {}}guard hasBlBefore else { continue }- hits.append(off)+ if isAlreadyPatched {+ alreadyPatched.append(off)+ } else {+ hits.append(off)+ }}}}let uniqueHits = Array(Set(hits)).sorted()+ let uniqueAlready = Array(Set(alreadyPatched)).sorted()++ if uniqueHits.isEmpty, uniqueAlready.count == 1 {+ let off = uniqueAlready[0]+ log(" [=] already cmp w0,w0 at \(String(format: "0x%X", off)) (base postValidation "+ + "patch owns this site); nothing to patch")+ return true+ }+guard uniqueHits.count == 1 else {- log(" [-] expected 1 postValidation compare site, found \(uniqueHits.count)")+ log(" [-] expected 1 postValidation compare site, found \(uniqueHits.count)"+ + " (already-patched sites: \(uniqueAlready.count))")return false}