Run a virtual iPhone on an Apple Silicon Mac.
Swift
Remove guest bootstrap and legacy signing assets
Lakrf88d667e8fbe
diff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex 7b8021c5..ccd2f740 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -18,12 +18,6 @@ jobs:- name: Checkoutuses: actions/checkout@v4with:- lfs: true-- - name: Init submodules- # SwiftPM resolves code dependencies from Package.resolved.- # insert_dylib is a test reference, not a product dependency.- run: git submodule update --init --depth 1 scripts/resources- name: Toolchain versionsrun: |diff --git a/.gitmodules b/.gitmodulesindex dc9014a9..92bf6ef1 100644--- a/.gitmodules+++ b/.gitmodules@@ -1,6 +1,3 @@-[submodule "scripts/resources"]- path = scripts/resources- url = https://github.com/zqxwce/vphone-cli-storage.git[submodule "scripts/repos/insert_dylib"]path = scripts/repos/insert_dyliburl = https://github.com/tyilo/insert_dylib.gitdiff --git a/AGENTS.md b/AGENTS.mdindex 8bd82fa0..3579478a 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -12,7 +12,7 @@ Virtual iPhone boot tool using Apple's Virtualization.framework with PCC researc- **Restore:** `vphone-cli restore`, in process. Vendored libirecovery + idevicerestore (`sources/MobileRecoveryCore`, `sources/MobileRestoreCore`) over the `AppleMobileDeviceLibrary` xcframeworks. No interpreter, no environment to provision, no setup step. See `research/p2_restore_off_python.md`.- **Platform:** macOS 15+ (Sequoia). `vphone-vm` needs amfid to accept its private entitlements: either SIP off with `amfi_get_out_of_my_way=1`, or SIP on (`--without debug`) plus an allowlist bypass the user runs. Both are in README's "SIP/AMFI Relaxation"; neither is installed by this project.- **Language:** Swift 6.0 (SwiftPM), private APIs via [Dynamic](https://github.com/mhdhejazi/Dynamic). This package's own manifest is `swift-tools-version:6.0`, but the **toolchain floor is Swift 6.2**: `libcapstone-spm` declares 6.2 so that it can reach `CSetting.disableWarning` instead of `.unsafeFlags`, which is what lets it be depended on by version at all.-- **Dependencies:** seven SwiftPM packages, every one resolved by URL and **every one by version** — there is no `vendor/` directory, no `branch:` requirement, and `Package.resolved` pins fourteen once transitives are counted. Two git submodules are left: `scripts/resources` and `scripts/repos/insert_dylib`. **No Python anywhere, and no Homebrew package at runtime** — see Tiers below.+- **Dependencies:** seven SwiftPM packages, every one resolved by URL and **every one by version** — there is no `vendor/` directory, no `branch:` requirement, and `Package.resolved` pins fourteen once transitives are counted. The only git submodule is `scripts/repos/insert_dylib`, a build-time test reference. **No Python anywhere, and no Homebrew package at runtime** — see Tiers below.- **Tiers.** Three environments run code here and the rules differ. **build** (the machine that builds the `.app`) may use Xcode, `xcrun`, clang, swift, git and Homebrew. **dist** (the shipped `.app`, on a clean macOS) may use `/usr/lib`, `/System` and the bundle — nothing else, no `PATH` lookup. **guest** (inside the VM) is out of host self-containment scope. Every script declares its tier on **line 2** (`# vphone-tier: dist`); `scripts/dist_manifest.sh` reads those and is what `build.sh` and `make bundle` stage from, so a script that declares nothing ships nowhere. `make check-aux` gates all of it. The dist tier's registered-exception list is **empty** and a release requires it to stay that way.## Workflow Rules@@ -31,8 +31,9 @@ For any changes applying new patches, also update research/0_binary_patch_compar## Firmware ModeThe public CLI exposes only JB: `vphone-cli fw patch` and `vphone-cli cfw install`.-The legacy CFW shell installer still contains first-boot package setup; its-removal is tracked in the integration work. Do not add another public variant.+The guest contains vphoned and required system patches; package-manager+bootstrap and first-boot installation are outside this project. Do not add+another public variant.See `research/` for detailed firmware pipeline, component origins, patch breakdowns, and boot flow documentation.@@ -175,23 +176,17 @@ scripts/ # Shell only — the CFW patchers are `vphone-│ # and there is no Python here at all. Every .sh declares its│ # tier on line 2; `[d]` = dist (ships), `[b]` = build, `[g]` = guest├── dist_manifest.sh [b] # What ships. The allowlist build.sh and `make bundle` stage from-├── guest_binaries.mk [b] # Cross-compiles the five iOS binaries (needs the iPhoneOS SDK)+├── guest_binaries.mk [b] # Cross-compiles vphoned (needs the iPhoneOS SDK)├── check_aux.sh [b] # The self-containment admission gates — `make check-aux`├── setup_tools.sh [b] # Builds insert_dylib, the Mach-O byte-parity test reference├── tail_jb_patch_logs.sh [b] # Tail JB patch log output-├── cfw_install.sh [d] # Install CFW (regular)-├── cfw_install_dev.sh [d] # Regular + rpcserver daemon-├── cfw_install_jb.sh [d] # Regular + jetsam fix + procursus-├── cfw_install_exp.sh [d] # JB + experimental research patches (hv_vmm rename, DT identity)+├── cfw_install.sh [d] # Base system patches and vphoned+├── cfw_install_jb.sh [d] # JB system patches; no package bootstrap├── cfw_install_host.sh [d] # Host-mount CFW driver (attaches Disk.img, VM off; re-execs sudo)-├── fetch_debs.sh [d] # Extra-deb downloader, reads debs.list-├── patch_{camera,hv_vmm}_userland.sh [d]├── boot_host_preflight.sh [d] # Why the host cannot launch vphone-vm-├── vphone_jb_setup.sh [g] # First-boot JB finalization, LaunchDaemon inside the VM-├── resources/ [d] # Resource archives (git submodule; needs git-lfs to clone)-├── vphoned/ # Guest daemon source (ObjC). Only the three plists and the-│ # signcert ship; the binary is built by guest_binaries.mk-├── tweakloader/ vpregister/ vcamcaptured/ camfix/ # The other four guest sources; same deal+├── payloads/ [d] # Small GPU driver archive; no bootstrap payloads+├── vphoned/ # Guest daemon source; only its plist and entitlements ship+├── tweakloader/ vpregister/ vcamcaptured/ camfix/ # Unshipped experimental sources└── repos/ # Toolchain source (git submodule: insert_dylib)research/ # Detailed firmware/patch documentationdiff --git a/Makefile b/Makefileindex 19fc2cd3..f4e170a5 100644--- a/Makefile+++ b/Makefile@@ -239,7 +239,7 @@ include $(SCRIPTS)/guest_binaries.mkvphoned: $(GUEST_DIR)/vphoned $(BINARY)@cp -f $(GUEST_DIR)/vphoned .build/vphoned.signed@$(BINARY) sign --entitlements $(SCRIPTS)/vphoned/entitlements.plist --merge \- --pkcs12 $(SCRIPTS)/vphoned/signcert.p12 .build/vphoned.signed+ .build/vphoned.signed@echo " signed → .build/vphoned.signed"# ═══════════════════════════════════════════════════════════════════@@ -440,4 +440,4 @@ restore_offline: build.PHONY: cfw_installcfw_install:- $(if $(call truthy,$(FRIDA)),VPHONE_FRIDA=1) zsh "$(CURDIR)/$(SCRIPTS)/cfw_install_host.sh" --variant jb "$(VM_DIR_ABS)"+ $(if $(call truthy,$(FRIDA)),VPHONE_FRIDA=1) zsh "$(CURDIR)/$(SCRIPTS)/cfw_install_host.sh" "$(VM_DIR_ABS)"diff --git a/README.md b/README.mdindex 93509a1f..ca706df7 100644--- a/README.md+++ b/README.md@@ -18,14 +18,11 @@ Boot a virtual iPhone via Apple's Virtualization.framework using PCC research VMno Xcode. Everything vphone-cli runs is either a system binary under `/usr/bin`,`/bin`, `/usr/sbin` or `/sbin`, or is inside the `.app` — including the signer(it replaced `ldid`), the archive reader (`gtar`, `zstd`, `unzip`), the firmware-catalogue and IM4P/AEA handling (`ipsw`), and the five iOS binaries the CFW-installers put in the guest, which are cross-compiled at build time and shipped+catalogue and IM4P/AEA handling (`ipsw`), and the vphoned daemon installed in the guest, which is cross-compiled at build time and shippedrather than built on your machine. `make check-aux` is the gate that keeps itthat way.-**To build it from source**, add Xcode — its iOS SDK is what those guest-binaries are cross-compiled against — and `git-lfs`, which `git clone` needs for-the archives in `scripts/resources`.+**To build it from source**, add Xcode for the iOS SDK used to compile vphoned.## Install@@ -36,7 +33,6 @@ brew install zqxwce/tap/vphone-cli## Build```bash-brew install git-lfsgit clone --recurse-submodules https://github.com/Lakr233/vphone-cli.git./scripts/build.sh # build + sign vphone-cli, cross-compile the guest@@ -125,7 +121,6 @@ Everything vphone-cli creates lives under `~/.vphone/` — kept outside the repo| `~/.vphone/VMs/` | VM bundles — one directory per VM. This is the library; override with `$VPHONE_LIBRARY_ROOT`. || `~/.vphone/ipsws/`| Downloaded iPhone + cloudOS IPSWs, cached and reused across VMs. || `~/.vphone/tools/`| Cached APFS seal-volume artifacts used by firmware patching. |-| `~/.vphone/debs/` | Cached `.deb` packages the `jb`/`exp` CFW install lays into the guest (Sileo, apt, …). |Precedence: the per-item override `$VPHONE_LIBRARY_ROOT` wins over `$VPHONE_ROOT`, which wins over the `~/.vphone` default. The `ipsws/`, `tools/`, and `debs/` caches always sit directly under whichever root is active.@@ -241,7 +236,7 @@ always launches, so its cdhash is not the one you want.**Install a `.ipa`/`.tipa`** — use the running VM's Install menu (drag-drop or file picker).-**Do I need Homebrew, or Xcode, to use this?** — No. `vphone-cli` runs on a clean macOS 15+: everything it shells out to is in `/usr/bin`, `/bin`, `/usr/sbin` or `/sbin`, and everything else is inside the `.app`. `make check-aux` is the gate that keeps it that way — it walks the bundle's dependency closure, checks the bundle holds exactly what it is supposed to, scans every shipped script for a `PATH` lookup, and smoke-tests the binaries with `env -i PATH=/usr/bin:/bin`. Building from source is the other story: that needs Xcode (for the iOS SDK the guest binaries are cross-compiled against) and `git-lfs` (to check out `scripts/resources`).+**Do I need Homebrew, or Xcode, to use this?** — No. `vphone-cli` runs on a clean macOS 15+: everything it shells out to is in `/usr/bin`, `/bin`, `/usr/sbin` or `/sbin`, and everything else is inside the `.app`. `make check-aux` is the gate that keeps it that way — it walks the bundle's dependency closure, checks the bundle holds exactly what it is supposed to, scans every shipped script for a `PATH` lookup, and smoke-tests the binaries with `env -i PATH=/usr/bin:/bin`. Building from source needs Xcode for the iOS SDK used to compile vphoned.**`cfw install` hangs re-signing a system binary (e.g. `Campo`), memory climbing unbounded** — this was a bug in `ldid-procursus` up to `2.1.5-procursus7`: `bytes(uint64_t)` called `__builtin_clzll(0)` with no zero-guard, which is undefined behavior, and on that build resolved to a `0`-length that underflowed an unsigned loop counter, so `ldid` span writing one byte at a time into a growing buffer instead of terminating. Any entitlements plist with an integer value of exactly `0` triggered it, and some real Apple system binaries have one. It cannot happen any more: signing is `vphone-cli sign`, in-process, and `ldid` is not installed, invoked or shipped.diff --git a/debs.list b/debs.listdeleted file mode 100644index c6e8f3e5..00000000--- a/debs.list+++ /dev/null@@ -1,17 +0,0 @@-# debs.list — URLs of .deb packages to download during machine setup (JB/EXP).-#-# One URL per line. Blank lines and lines starting with '#' are ignored.-#-# Downloads are cached in ./debs/ (keyed by filename); a file already present-# there is not re-downloaded. You may also drop .deb files into ./debs/-# manually — they are installed on first boot alongside the downloaded ones.-#-# A failed download prints an error and is skipped; it never aborts setup.-# Packages are installed with `dpkg -i` on first boot (same as Sileo); this-# does not resolve dependencies.-#-# Example:-# https://havoc.app/get/com.example.pkg/com.example.pkg_1.0_iphoneos-arm64.deb-https://apt.procurs.us/pool/main/iphoneos-arm64-rootless/3000/openssh/openssh-client_9.7p1-1_iphoneos-arm64.deb-https://apt.procurs.us/pool/main/iphoneos-arm64-rootless/3000/openssh/openssh-sftp-server_9.7p1-1_iphoneos-arm64.deb-https://apt.procurs.us/pool/main/iphoneos-arm64-rootless/3000/openssh/openssh-server_9.7p1-1_iphoneos-arm64.debdiff --git a/research/0_binary_patch_comparison.md b/research/0_binary_patch_comparison.mdindex 1589abc1..5b554c39 100644--- a/research/0_binary_patch_comparison.md+++ b/research/0_binary_patch_comparison.md@@ -1,5 +1,13 @@# Patch Comparison: Regular / Development / Jailbreak / Experimental+> **Current product scope (September 2026):** the tables below preserve the+> historical patch comparison. The public runtime now exposes only JB. Guest+> package managers, Procursus, BaseBin hooks, and first-boot package setup are+> outside this repository. The JB install retains the base system patches,+> launchd jetsam guard, debugserver entitlement edit, iOS 27 Campo entitlement+> edit, GPU driver, and mandatory vphoned. Old variant rows are research history,+> not available install modes.+> **`scripts/patchers/*.py` no longer exists.** The tables below cite those> filenames throughout, because that is where each patch was first written and> where its on-device validation notes were recorded. Every one is now a Swiftdiff --git a/scripts/build.sh b/scripts/build.shindex 7cb7623f..a989d3d7 100755--- a/scripts/build.sh+++ b/scripts/build.sh@@ -111,7 +111,7 @@ cp -f "$ASKPASS_BINARY" "$BUNDLE_ASKPASS"cp -f "$AMFI_BINARY" "$BUNDLE_AMFI"cp -f "$INFO_PLIST" "${BUNDLE}/Contents/Info.plist"cp -f "sources/AppIcon.icns" "${BUNDLE}/Contents/Resources/AppIcon.icns"-cp -f "scripts/vphoned/signcert.p12" "${BUNDLE}/Contents/Resources/signcert.p12"+rm -f "${BUNDLE}/Contents/Resources/signcert.p12"# The bundle is built over whatever is already there, so these two are removed# although nothing copies either one any more: bundles built before VPhoneSign# replaced ldid carry the Homebrew ldid, the only thing in here linking@@ -134,7 +134,7 @@ codesign --force --sign - --entitlements "$ENTITLEMENTS" "$BUNDLE_VM"echo " bundled → ${BUNDLE}"# --- Guest binaries (cross-compiled for iOS; see scripts/guest_binaries.mk) ----# All five of them, because compiling them at CFW-install time is what made+# The guest daemon, because compiling it at CFW-install time would make# Xcode a requirement for running a VM. This is the build machine; it has Xcode.make -f scripts/guest_binaries.mk guest_binaries GIT_HASH="$GIT_HASH"# vphoned.signed is the copy the host pushes into a running guest over vsock.@@ -142,7 +142,6 @@ echo "=== Signing vphoned ==="cp .build/guest/vphoned .build/vphoned.signed"$BINARY" sign \--entitlements scripts/vphoned/entitlements.plist --merge \- --pkcs12 scripts/vphoned/signcert.p12 \.build/vphoned.signedecho " signed → .build/vphoned.signed"@@ -162,23 +161,21 @@ echo "=== Bundling runtime assets → ${RES} ==="# and the only reason the dependency gate had anything left to find. The trust# cache itself is generated by /System/Library/SecurityResearch's cryptexctl.rm -rf "${RES}/scripts" "${RES}/guest" "${RES}/tools" "${RES}/.tools" \- "${RES}/vphoned.signed" "${RES}/requirements.txt"+ "${RES}/vphoned.signed" "${RES}/requirements.txt" "${RES}/debs.list"mkdir -p "${RES}/scripts"# An ALLOWLIST, from each script's own `# vphone-tier:` line. This used to be a# list of exclusions, which meant anything new shipped by default — and so the# .app carried build.sh, check_aux.sh and setup_tools.sh, the last of which runs# `brew install`. See scripts/dist_manifest.sh for the three tiers.zsh scripts/dist_manifest.sh | rsync -a --files-from=- scripts/ "${RES}/scripts/"-# The five guest binaries, cross-compiled above. They are iOS Mach-Os and never-# run on this host; the CFW installers copy and sign them into the VM.-[[ -d .build/guest ]] && cp -R .build/guest "${RES}/guest"+# Only vphoned ships into the guest; old build outputs may still contain+# binaries for the removed bootstrap and must not leak into the bundle.+mkdir -p "${RES}/guest"+cp -f .build/guest/vphoned "${RES}/guest/vphoned"[[ -f .build/vphoned.signed ]] && cp -f .build/vphoned.signed "${RES}/vphoned.signed" || true-# debs.list = extra-deb manifest (fetch_debs.sh reads $base/debs.list); README.md-# = the Tested-Environments table `vphone-cli fw prepare` reads for firmware status.-cp -f debs.list "${RES}/debs.list"+# README.md holds the Tested-Environments table used by `fw prepare`.cp -f README.md "${RES}/README.md"-echo " bundled: scripts/ (dist tier), guest/ (5 iOS binaries), vphoned.signed,"-echo " debs.list, README.md"+echo " bundled: scripts/ (dist tier), guest/vphoned, vphoned.signed, README.md"# Re-sign: codesign seals Contents/Resources at sign time, so the earlier# bundle-step signature (made before these assets existed) is now stale —diff --git a/scripts/cfw_install.sh b/scripts/cfw_install.shindex fabd2b49..9c418f2a 100755--- a/scripts/cfw_install.sh+++ b/scripts/cfw_install.sh@@ -2,8 +2,7 @@# vphone-tier: dist# cfw_install.sh — Install base CFW modifications on vphone.#-# Installs Cryptexes, patches system binaries, installs jailbreak tools-# and configures LaunchDaemons for persistent SSH/VNC access.+# Installs Cryptexes, patches required system binaries, and installs vphoned.## Files are placed directly on the VM's Disk.img volumes, which cfw_install_host.sh# attaches and mounts on the host; the VM must be off.@@ -16,7 +15,7 @@# - /usr/bin/aea (macOS 12+) — the only external program this script runs# - vphone-cli built (make build) — every CFW patcher, the signer, the# archive reader and the prebuilt guest binaries come with it-# - cfw_input/ or resources/cfw_input.tar.zst present+# - the bundled GPU driver payload and prebuilt vphoned present## Usage: make cfw_installset -euo pipefail@@ -59,7 +58,7 @@ VPHONE_ARCHIVE="${VPHONE_CLI:h}/vphone-archive"exit 1}-# The five iOS binaries this install puts in the guest are cross-compiled at+# The vphoned binary this install puts in the guest is cross-compiled at# BUILD time (scripts/guest_binaries.mk) and shipped, because compiling them# here would make Xcode and the iPhoneOS SDK a requirement for running a VM.# Contents/Resources/guest in the .app, .build/guest in a dev tree.@@ -69,8 +68,6 @@ for candidate in "${SCRIPT_DIR:h}/guest" "${SCRIPT_DIR:h}/.build/guest"; dodone# ── Configuration ───────────────────────────────────────────────-CFW_INPUT="cfw_input"-CFW_ARCHIVE="cfw_input.tar.zst"TEMP_DIR="$VM_DIR/.cfw_temp"# ── Helpers ─────────────────────────────────────────────────────@@ -86,12 +83,12 @@ die() {# carrying it worked on the machine that built it and nowhere else.## The three shapes this file ever called it in map one to one:-# ldid -S -M -K<p12> [-I<id>] f -> guest_sign f [id]-# ldid -S<ent> -M -K<p12> [-I] f -> guest_sign_ent f ent [id]+# ldid -S -M [-I<id>] f -> guest_sign f [id]+# ldid -S<ent> -M [-I] f -> guest_sign_ent f ent [id]# ldid -e f -> guest_entitlements fguest_sign() {local file="$1" bundle_id="${2:-}"- local args=(--merge --pkcs12 "$VM_DIR/$CFW_INPUT/signcert.p12")+ local args=(--merge)[[ -n "$bundle_id" ]] && args+=(--identifier "$bundle_id")"$VPHONE_CLI" sign "${args[@]}" "$file"}@@ -101,7 +98,7 @@ guest_sign() {# profile + private DA/apfs entitlements).guest_sign_ent() {local file="$1" ent="$2" bundle_id="${3:-}"- local args=(--entitlements "$ent" --merge --pkcs12 "$VM_DIR/$CFW_INPUT/signcert.p12")+ local args=(--entitlements "$ent" --merge)[[ -n "$bundle_id" ]] && args+=(--identifier "$bundle_id")"$VPHONE_CLI" sign "${args[@]}" "$file"}@@ -166,21 +163,6 @@ find_restore_dir() {die "No restore directory found in $VM_DIR"}-# ── Setup input resources ──────────────────────────────────────-setup_cfw_input() {- [[ -d "$VM_DIR/$CFW_INPUT" ]] && return- local archive- for search_dir in "$SCRIPT_DIR/resources" "$SCRIPT_DIR" "$VM_DIR"; do- archive="$search_dir/$CFW_ARCHIVE"- if [[ -f "$archive" ]]; then- echo " Extracting $CFW_ARCHIVE..."- guest_untar "$archive" "$VM_DIR"- return- fi- done- die "Neither $CFW_INPUT/ nor $CFW_ARCHIVE found"-}-# ── Check prerequisites ────────────────────────────────────────# What used to be here was `command -v ipsw` and `command -v aea`. The first is# gone: the one thing this script asked ipsw for was the SystemOS AEA key, and@@ -228,10 +210,6 @@ require_firmware_toolsRESTORE_DIR=$(find_restore_dir)echo "[+] Restore directory: $RESTORE_DIR"-setup_cfw_input-INPUT_DIR="$VM_DIR/$CFW_INPUT"-echo "[+] Input resources: $INPUT_DIR"-mkdir -p "$TEMP_DIR"# ── Parse Cryptex paths from BuildManifest ─────────────────────@@ -380,9 +358,8 @@ esac# at slide 0. (The patcher also self-gates on the actual span, but older userlands# fit with full slide and never need it — so it is not run there at all.)# - lsd embedded-registration gate: opens lsd's containerized-registration path so-# the iOS-27 vpregister first-boot tool can register JB apps (uicache's-# registerApplicationDictionary is a no-op stub on 27). Not needed on 26.x/18.x,-# where uicache registers apps normally.+# registerApplicationDictionary is a no-op stub on 27. The gate remains+# part of the maximal JB patch set even though app bootstrap is external.# - xpc LWCR self-check: iOS 27's libxpc brk-aborts when its Lightweight Code# Requirement matcher returns the contradictory (matched=0, error_code=MATCH) pair# that our JB code-signing environment produces. That crash-loops every daemon which@@ -464,8 +441,7 @@ echo " [+] seputil patched"echo ""echo "[3/7] Installing AppleParavirtGPUMetalIOGPUFamily..."-cp -R "$INPUT_DIR/custom/AppleParavirtGPUMetalIOGPUFamily.tar" "$MNT1"-guest_untar "$MNT1/AppleParavirtGPUMetalIOGPUFamily.tar" "$MNT1" \+guest_untar "$SCRIPT_DIR/payloads/AppleParavirtGPUMetalIOGPUFamily.tar" "$MNT1" \--preserve-permissions --no-overwrite-dirBUNDLE="$MNT1/System/Library/Extensions/AppleParavirtGPUMetalIOGPUFamily.bundle"@@ -478,24 +454,8 @@ find $BUNDLE -name '._*' -delete 2>/dev/null || true/bin/chmod 0755 $BUNDLE/_CodeSignature/bin/chmod 0644 $BUNDLE/_CodeSignature/CodeResources/bin/chmod 0644 $BUNDLE/Info.plist-/bin/rm -f $MNT1/AppleParavirtGPUMetalIOGPUFamily.tar-echo " [+] GPU driver installed"-# ═══════════ 4/7 INSTALL IOSBINPACK64 ════════════════════════-echo ""-echo "[4/7] Installing iosbinpack64..."--cp -R "$INPUT_DIR/jb/iosbinpack64.tar" "$MNT1"-guest_untar "$MNT1/iosbinpack64.tar" "$MNT1" --preserve-permissions --no-overwrite-dir-/bin/rm -f $MNT1/iosbinpack64.tar--# dropbear host keys are generated on first boot by dropbear -R; just ensure-# the key directory exists for it to write into.-/bin/mkdir -p $MNT3/dropbear--echo " [+] iosbinpack64 installed"-# ═══════════ 5/7 PATCH LAUNCHD_CACHE_LOADER ══════════════════echo ""echo "[5/7] Patching launchd_cache_loader..."@@ -541,8 +501,7 @@ echo "[7/7] Installing LaunchDaemons..."# It used to be cross-compiled right here, out of .m sources shipped inside the# .app, whenever they looked newer than the binary — which made Xcode and the# iPhoneOS SDK a requirement for installing CFW onto a VM. It is built at build-# time now (scripts/guest_binaries.mk) and shipped compiled. Signing stays here,-# because it uses this VM's own cfw_input/signcert.p12.+# time now (scripts/guest_binaries.mk) and shipped compiled.VPHONED_SRC="$SCRIPT_DIR/vphoned"VPHONED_BIN="$GUEST_BIN/vphoned"[[ -f "$VPHONED_BIN" ]] || die "missing prebuilt vphoned at $VPHONED_BIN — run 'make build'"@@ -554,17 +513,6 @@ cp -R "$TEMP_DIR/vphoned" "$MNT1/usr/bin/vphoned"cp "$TEMP_DIR/vphoned" "$VM_DIR/.vphoned.signed"echo " [+] vphoned installed (signed copy at .vphoned.signed)"-# Send daemon plists (overwrite on re-run)-for plist in bash.plist dropbear.plist trollvnc.plist rpcserver_ios.plist; do- plist_src="$INPUT_DIR/jb/LaunchDaemons/$plist"- if [[ "$plist" == "dropbear.plist" ]]; then- plist_src="$TEMP_DIR/dropbear.plist"- cp "$INPUT_DIR/jb/LaunchDaemons/dropbear.plist" "$plist_src"- "$VPHONE_CLI" cfw patch-dropbear-plist "$plist_src"- fi- cp -R "$plist_src" "$MNT1/System/Library/LaunchDaemons/"- /bin/chmod 0644 $MNT1/System/Library/LaunchDaemons/$plist-donecp -R "$VPHONED_SRC/vphoned.plist" "$MNT1/System/Library/LaunchDaemons/"/bin/chmod 0644 $MNT1/System/Library/LaunchDaemons/vphoned.plist@@ -576,8 +524,8 @@ if ! [[ -e "$MNT1/System/Library/xpc/launchd.plist.bak" ]]; thenficp "$MNT1/System/Library/xpc/launchd.plist.bak" "$TEMP_DIR/launchd.plist"-cp "$VPHONED_SRC/vphoned.plist" "$INPUT_DIR/jb/LaunchDaemons/"-"$VPHONE_CLI" cfw inject-daemons "$TEMP_DIR/launchd.plist" "$INPUT_DIR/jb/LaunchDaemons"+"$VPHONE_CLI" cfw inject-daemon "$TEMP_DIR/launchd.plist" \+ "$VPHONED_SRC/vphoned.plist" --name vphonedcp -R "$TEMP_DIR/launchd.plist" "$MNT1/System/Library/xpc/launchd.plist"/bin/chmod 0644 $MNT1/System/Library/xpc/launchd.plist@@ -595,4 +543,3 @@ rm -rf "$TEMP_DIR"echo ""echo "[+] CFW installation complete!"echo " Boot to apply changes."-echo " After boot, SSH will be available on port 22222 (password: alpine)"diff --git a/scripts/cfw_install_dev.sh b/scripts/cfw_install_dev.shdeleted file mode 100755index b49df240..00000000--- a/scripts/cfw_install_dev.sh+++ /dev/null@@ -1,506 +0,0 @@-#!/bin/zsh-# vphone-tier: dist-# cfw_install_dev.sh — Install base CFW modifications on vphone (dev variant).-#-# Installs Cryptexes, patches system binaries, installs jailbreak tools-# and configures LaunchDaemons for persistent SSH/VNC access.-#-# Files are placed directly on the VM's Disk.img volumes, which cfw_install_host.sh-# attaches and mounts on the host; the VM must be off.-#-# Safe to run multiple times — always patches from original .bak files,-# keeps decrypted Cryptex DMGs cached, handles already-mounted filesystems.-#-# Prerequisites:-# - VM restored (make restore) and powered off-# - /usr/bin/aea (macOS 12+) — the only external program this script runs-# - vphone-cli built (make build) — every CFW patcher, the signer, the-# archive reader and the prebuilt guest binaries come with it-# - cfw_input/ or resources/cfw_input.tar.zst + resources/cfw_dev/rpcserver_ios present-#-# Usage: make cfw_install_dev-set -euo pipefail--# ── Restore caller's PATH — Nix /etc/zshenv resets PATH on zsh startup ─-[[ -n "${_VPHONE_PATH:-}" ]] && export PATH="$_VPHONE_PATH"--VM_DIR="${1:-.}"-SCRIPT_DIR="${0:a:h}"--# Resolve absolute paths-VM_DIR="$(cd "$VM_DIR" && pwd)"--# ── vphone-cli resolver — every CFW patcher this script calls lives in it ─-# Same order as scripts/cfw_install_host.sh and cfw-kit/run.sh: VPHONE_CLI_BIN-# when a vphone-cli subcommand invoked us, otherwise a dev tree or the .app,-# where scripts/ sits in Contents/Resources and the binaries are one level up-# in MacOS. Never `command -v` — the binary has to be the one we built beside-# these scripts, not whatever else is on PATH.-VPHONE_CLI="${VPHONE_CLI_BIN:-}"-if [[ -z "$VPHONE_CLI" ]]; then- for candidate in "${SCRIPT_DIR:h}/.build/release/vphone-cli" "${SCRIPT_DIR:h:h}/MacOS/vphone-cli"; do- [[ -x "$candidate" ]] && { VPHONE_CLI="$candidate"; break }- done-fi-[[ -x "$VPHONE_CLI" ]] || {- echo "[-] cannot find vphone-cli (the CFW patchers live in it) — run 'make build'" >&2- exit 1-}--# Siblings of the binary just resolved, never PATH. See cfw_install.sh.-VPHONE_ARCHIVE="${VPHONE_CLI:h}/vphone-archive"-[[ -x "$VPHONE_ARCHIVE" ]] || {- echo "[-] cannot find vphone-archive beside $VPHONE_CLI — run 'make build'" >&2- exit 1-}-GUEST_BIN=""-for candidate in "${SCRIPT_DIR:h}/guest" "${SCRIPT_DIR:h}/.build/guest"; do- [[ -d "$candidate" ]] && { GUEST_BIN="$candidate"; break }-done--# ── Configuration ───────────────────────────────────────────────-CFW_INPUT="cfw_input"-CFW_ARCHIVE="cfw_input.tar.zst"-TEMP_DIR="$VM_DIR/.cfw_temp"--# ── Helpers ─────────────────────────────────────────────────────-die() {- echo "[-] $*" >&2- exit 1-}--# ldid, gtar and zstd are gone from this script — see the long note in-# cfw_install.sh for why. `vphone-cli sign` and `vphone-archive` write the same-# bytes and ship in the bundle.-guest_sign() {- local file="$1" bundle_id="${2:-}"- local args=(--merge --pkcs12 "$VM_DIR/$CFW_INPUT/signcert.p12")- [[ -n "$bundle_id" ]] && args+=(--identifier "$bundle_id")- "$VPHONE_CLI" sign "${args[@]}" "$file"-}--guest_sign_ent() {- local file="$1" entitlements_plist="$2" bundle_id="${3:-}"- local args=(--entitlements "$entitlements_plist" --pkcs12 "$VM_DIR/$CFW_INPUT/signcert.p12")- [[ -n "$bundle_id" ]] && args+=(--identifier "$bundle_id")- "$VPHONE_CLI" sign "${args[@]}" "$file"-}--guest_entitlements() {- "$VPHONE_CLI" dump-entitlements "$1"-}--guest_untar() { # guest_untar <archive> <dest> [extra flags…]- local archive="$1" dest="$2"; shift 2- "$VPHONE_ARCHIVE" extract -f "$archive" -C "$dest" "$@"-}--# Detach a DMG mountpoint if currently mounted, ignore errors-safe_detach() {- local mnt="$1"- if mount | grep -Fq " on $mnt "; then- sudo ${SUDO_ASKPASS:+-A} hdiutil detach -force "$mnt" 2>/dev/null || true- fi-}--assert_mount_under_vm() {- local mnt="$1" label="${2:-mountpoint}"- local abs_vm abs_mnt-- abs_vm="$(cd "$VM_DIR" && pwd -P)"- abs_mnt="$(cd "$mnt" && pwd -P)"- case "$abs_mnt/" in- "$abs_vm/"*) ;;- *) die "Unsafe ${label}: ${abs_mnt} (must be inside ${abs_vm})" ;;- esac-}--# ── Find restore directory ─────────────────────────────────────-find_restore_dir() {- for dir in "$VM_DIR"/iPhone*_Restore; do- [[ -f "$dir/BuildManifest.plist" ]] && echo "$dir" && return- done- die "No restore directory found in $VM_DIR"-}--# ── Setup input resources ──────────────────────────────────────-setup_cfw_input() {- [[ -d "$VM_DIR/$CFW_INPUT" ]] && return- local archive- for search_dir in "$SCRIPT_DIR/resources" "$SCRIPT_DIR" "$VM_DIR"; do- archive="$search_dir/$CFW_ARCHIVE"- if [[ -f "$archive" ]]; then- echo " Extracting $CFW_ARCHIVE..."- guest_untar "$archive" "$VM_DIR"- return- fi- done- die "Neither $CFW_INPUT/ nor $CFW_ARCHIVE found"-}--# ── Apply dev overlay (replace rpcserver_ios in iosbinpack64) ──-apply_dev_overlay() {- local dev_bin- for search_dir in "$SCRIPT_DIR/resources/cfw_dev" "$SCRIPT_DIR/cfw_dev"; do- dev_bin="$search_dir/rpcserver_ios"- if [[ -f "$dev_bin" ]]; then- echo " Applying dev overlay (rpcserver_ios)..."- local iosbinpack="$VM_DIR/$CFW_INPUT/jb/iosbinpack64.tar"- local tmpdir="$VM_DIR/.iosbinpack_tmp"- mkdir -p "$tmpdir"- guest_untar "$iosbinpack" "$tmpdir"- cp "$dev_bin" "$tmpdir/iosbinpack64/usr/local/bin/rpcserver_ios"- # -C "$tmpdir" packs what is under it, and the only thing under it- # is iosbinpack64/ — the same single top-level member `tar -cf …- # iosbinpack64` from inside $tmpdir produced.- "$VPHONE_ARCHIVE" create -f "$iosbinpack" -C "$tmpdir"- rm -rf "$tmpdir"- return- fi- done- die "Dev overlay not found (cfw_dev/rpcserver_ios)"-}--# ── Check prerequisites ────────────────────────────────────────-require_firmware_tools() {- [[ -x /usr/bin/aea ]] || die "/usr/bin/aea missing (it ships with macOS 12+)"- [[ -n "$GUEST_BIN" ]] || die "no prebuilt guest binaries — run 'make build'"- echo "[*] Patchers: $VPHONE_CLI cfw"-}--# ── Cleanup trap (unmount DMGs on error) ───────────────────────-cleanup_on_exit() {- safe_detach "$TEMP_DIR/mnt_sysos"- safe_detach "$TEMP_DIR/mnt_appos"-}-trap cleanup_on_exit EXIT--# The VM's Disk.img is attached on the host by cfw_install_host.sh; its APFS-# volumes are mounted here and every file is placed with plain cp/chmod/etc.-# (the VM is off — nothing runs "on the device").-: "${CFW_HOST_CONTAINER:?CFW_HOST_CONTAINER unset — run via cfw_install_host.sh}"-HOST_MNT="${CFW_HOST_MNT:-/private/tmp/cfwhost}"-MNT1="$HOST_MNT/mnt1" # disk1s1 (System / rootfs)-MNT3="$HOST_MNT/mnt3" # disk1s3-mkdir -p "$HOST_MNT"--# Mount an APFS volume of the attached image container at a host mount point.-mount_vol() { # mount_vol <slice, e.g. s1> <mountpoint> [opts]- local dev="/dev/${CFW_HOST_CONTAINER}$1" mnt="$2" opts="${3:-rw}"- /bin/mkdir -p "$mnt"- /sbin/mount | /usr/bin/grep -q " on $mnt " && return 0- /sbin/mount_apfs -o "$opts" "$dev" "$mnt" 2>/dev/null || true- /sbin/mount | /usr/bin/grep -q " on $mnt " || die "mount failed: $dev -> $mnt"-}--# ════════════════════════════════════════════════════════════════-# Main-# ════════════════════════════════════════════════════════════════-echo "[*] cfw_install.sh — Installing CFW on vphone..."--require_firmware_tools--RESTORE_DIR=$(find_restore_dir)-echo "[+] Restore directory: $RESTORE_DIR"--setup_cfw_input-apply_dev_overlay-INPUT_DIR="$VM_DIR/$CFW_INPUT"-echo "[+] Input resources: $INPUT_DIR"--mkdir -p "$TEMP_DIR"--# ── Parse Cryptex paths from BuildManifest ─────────────────────-echo ""-echo "[*] Parsing iPhone BuildManifest for Cryptex paths..."-CRYPTEX_PATHS=$("$VPHONE_CLI" cfw cryptex-paths "$RESTORE_DIR/iPhone-BuildManifest.plist")-CRYPTEX_SYSOS=$(echo "$CRYPTEX_PATHS" | head -1)-CRYPTEX_APPOS=$(echo "$CRYPTEX_PATHS" | tail -1)-echo " SystemOS: $CRYPTEX_SYSOS"-echo " AppOS: $CRYPTEX_APPOS"--# ═══════════ 1/7 INSTALL CRYPTEX ══════════════════════════════-echo ""-echo "[1/7] Installing Cryptex (SystemOS + AppOS)..."--SYSOS_DMG="$TEMP_DIR/CryptexSystemOS.dmg"-APPOS_DMG="$TEMP_DIR/CryptexAppOS.dmg"-MNT_SYSOS="$TEMP_DIR/mnt_sysos"-MNT_APPOS="$TEMP_DIR/mnt_appos"--# Decrypt SystemOS AEA (cached — skip if already decrypted)-if [[ ! -f "$SYSOS_DMG" ]]; then- echo " Extracting AEA key..."- AEA_KEY=$("$VPHONE_CLI" fw aea-key "$RESTORE_DIR/$CRYPTEX_SYSOS")- echo " key: $AEA_KEY"- echo " Decrypting SystemOS..."- /usr/bin/aea decrypt -i "$RESTORE_DIR/$CRYPTEX_SYSOS" -o "$SYSOS_DMG" -key-value "$AEA_KEY"-else- echo " Using cached SystemOS DMG"-fi--# Copy AppOS (unencrypted, cached)-if [[ ! -f "$APPOS_DMG" ]]; then- cp "$RESTORE_DIR/$CRYPTEX_APPOS" "$APPOS_DMG"-else- echo " Using cached AppOS DMG"-fi--# Detach any leftover mounts from previous runs-safe_detach "$MNT_SYSOS"-safe_detach "$MNT_APPOS"-mkdir -p "$MNT_SYSOS" "$MNT_APPOS"-assert_mount_under_vm "$MNT_SYSOS" "SystemOS mountpoint"-assert_mount_under_vm "$MNT_APPOS" "AppOS mountpoint"--echo " Mounting SystemOS..."-sudo ${SUDO_ASKPASS:+-A} hdiutil attach -mountpoint "$MNT_SYSOS" "$SYSOS_DMG" -nobrowse -owners off-echo " Mounting AppOS..."-sudo ${SUDO_ASKPASS:+-A} hdiutil attach -mountpoint "$MNT_APPOS" "$APPOS_DMG" -nobrowse -owners off--# Mount the image's System volume (tolerate already-mounted)-echo " Mounting rootfs rw..."-mount_vol s1 "$MNT1"--# Patch launchd jetsum guard-echo ""-echo " Patching launchd (jetsam guard)..."--if ! [[ -e "$MNT1/sbin/launchd.bak" ]]; then- echo " Creating backup..."- /bin/cp $MNT1/sbin/launchd $MNT1/sbin/launchd.bak-fi--cp "$MNT1/sbin/launchd.bak" "$TEMP_DIR/launchd"--"$VPHONE_CLI" cfw patch-launchd-jetsam "$TEMP_DIR/launchd"-guest_sign "$TEMP_DIR/launchd"-cp -R "$TEMP_DIR/launchd" "$MNT1/sbin/launchd"-/bin/chmod 0755 $MNT1/sbin/launchd--echo " [+] launchd patched"--# remove seatbelt profile and add task_for_pid-allow for debugserver-echo ""-echo " Patch debugserver entitlements..."--cp "$MNT1/usr/libexec/debugserver" "$TEMP_DIR/debugserver"-guest_entitlements "$TEMP_DIR/debugserver" > "$TEMP_DIR/debugserver-entitlements.plist"-plutil -remove seatbelt-profiles "$TEMP_DIR/debugserver-entitlements.plist" || true-plutil -insert task_for_pid-allow -bool YES "$TEMP_DIR/debugserver-entitlements.plist" || true-guest_sign_ent "$TEMP_DIR/debugserver" "$TEMP_DIR/debugserver-entitlements.plist"-cp -R "$TEMP_DIR/debugserver" "$MNT1/usr/libexec/debugserver"-/bin/chmod 0755 $MNT1/usr/libexec/debugserver--echo " [+] debugserver entitlements patched"---/bin/rm -rf $MNT1/System/Cryptexes/App $MNT1/System/Cryptexes/OS-/bin/mkdir -p $MNT1/System/Cryptexes/App $MNT1/System/Cryptexes/OS-/bin/chmod 0755 $MNT1/System/Cryptexes/App $MNT1/System/Cryptexes/OS--# Copy Cryptex files onto the volume-echo " Copying Cryptexes..."-cp -R "$MNT_SYSOS/." "$MNT1/System/Cryptexes/OS"-cp -R "$MNT_APPOS/." "$MNT1/System/Cryptexes/App"--# Create dyld symlinks (ln -sf is idempotent)-echo " Creating dyld symlinks..."-/bin/ln -sf ../../../System/Cryptexes/OS/System/Library/Caches/com.apple.dyld \- $MNT1/System/Library/Caches/com.apple.dyld-/bin/ln -sf ../../../../System/Cryptexes/OS/System/DriverKit/System/Library/dyld \- $MNT1/System/DriverKit/System/Library/dyld--# Unmount Cryptex DMGs-echo " Unmounting Cryptex DMGs..."-safe_detach "$MNT_SYSOS"-safe_detach "$MNT_APPOS"--echo " [+] Cryptex installed"--# Some userland versions send an IOMobileFramebuffer SwapEnd state whose size-# differs from what the PCC vphone600 userclient expects (an exact-# checkStructureInputSize check), so SwapEnd returns kIOReturnBadArgument and-# the host VZ display stays black (guest still renders; visible over VNC).-#-# The accepted size is a property of the BASE KERNEL, not the userland:-# - 26.1 base: userclient expects 0x560-# - 26.4 base (xnu-12377, current): userclient expects 0x588-# Reliably reading it from the kernelcache needs the IOMFB userclient dispatch-# table (a blind shape-scan is ambiguous — 8 candidates), so until that dynamic-# detection lands we key the target off the userland version as a proxy for the-# validated base pairing:-# - 27.x runs on the 26.4 base -> 0x588-# - 26.0/26.0.1 and 18.x validated on 26.1 base -> 0x560-# Known userland-sent sizes: 18.x -> 0x514, 26.0/26.0.1 -> 0x548, 27.0 -> 0x6e0.-# Patch only that immediate in the installed DSC; the patcher is semantic +-# idempotent (rewrites the SwapEnd size to the target, no-op if already there).-# NOTE: iOS 27 is intentionally NOT truncated here — its swap struct (0x6e0) has-# a new layout, so size-truncation to 0x588 feeds the kernel misaligned data.-# Instead the JB kernel patch `patchIomfbSwapEndVariableSize` makes the userclient-# accept iOS 27's native 0x6e0 struct (variable-size dispatch), so 27 must send-# its native size — leave it unpatched here.-IOS_VERSION=$(/usr/bin/plutil -extract ProductVersion raw -o - "$MNT1/System/Library/CoreServices/SystemVersion.plist" 2>/dev/null || true)-case "$IOS_VERSION" in- 26.0*|18.*)- echo " [*] Patching IOMobileFramebuffer SwapEnd payload size (iOS $IOS_VERSION -> 0x560)..."- DSC_DIR="$MNT1/System/Cryptexes/OS/System/Library/Caches/com.apple.dyld"- [[ -d "$DSC_DIR" ]] || die "dyld cache dir missing: $DSC_DIR"- "$VPHONE_CLI" cfw patch-iomfb-swapend "$DSC_DIR" --target-size 0x560- ;;-esac--# ═══════════ 2/7 PATCH SEPUTIL ════════════════════════════════-echo ""-echo "[2/7] Patching seputil..."--# Always patch from .bak (original unpatched binary)-if ! [[ -e "$MNT1/usr/libexec/seputil.bak" ]]; then- echo " Creating backup..."- /bin/cp $MNT1/usr/libexec/seputil $MNT1/usr/libexec/seputil.bak-fi--cp "$MNT1/usr/libexec/seputil.bak" "$TEMP_DIR/seputil"-"$VPHONE_CLI" cfw patch-seputil "$TEMP_DIR/seputil"-guest_sign "$TEMP_DIR/seputil" "com.apple.seputil"-cp -R "$TEMP_DIR/seputil" "$MNT1/usr/libexec/seputil"-/bin/chmod 0755 $MNT1/usr/libexec/seputil--# Rename gigalocker (mv to same name is fine on re-run)-echo " Renaming gigalocker..."-mount_vol s3 "$MNT3"-mv "$MNT3"/*.gl(N) "$MNT3/AA.gl" 2>/dev/null || true--echo " [+] seputil patched"--# ═══════════ 3/7 INSTALL GPU DRIVER ══════════════════════════-echo ""-echo "[3/7] Installing AppleParavirtGPUMetalIOGPUFamily..."--cp -R "$INPUT_DIR/custom/AppleParavirtGPUMetalIOGPUFamily.tar" "$MNT1"-guest_untar "$MNT1/AppleParavirtGPUMetalIOGPUFamily.tar" "$MNT1" \- --preserve-permissions --no-overwrite-dir--BUNDLE="$MNT1/System/Library/Extensions/AppleParavirtGPUMetalIOGPUFamily.bundle"-# Clean macOS resource fork files (._* files from tar xattrs)-find $BUNDLE -name '._*' -delete 2>/dev/null || true-/usr/sbin/chown -R 0:0 $BUNDLE-/bin/chmod 0755 $BUNDLE-/bin/chmod 0755 $BUNDLE/libAppleParavirtCompilerPluginIOGPUFamily.dylib-/bin/chmod 0755 $BUNDLE/AppleParavirtGPUMetalIOGPUFamily-/bin/chmod 0755 $BUNDLE/_CodeSignature-/bin/chmod 0644 $BUNDLE/_CodeSignature/CodeResources-/bin/chmod 0644 $BUNDLE/Info.plist-/bin/rm -f $MNT1/AppleParavirtGPUMetalIOGPUFamily.tar--echo " [+] GPU driver installed"--# ═══════════ 4/7 INSTALL IOSBINPACK64 ════════════════════════-echo ""-echo "[4/7] Installing iosbinpack64..."--cp -R "$INPUT_DIR/jb/iosbinpack64.tar" "$MNT1"-guest_untar "$MNT1/iosbinpack64.tar" "$MNT1" --preserve-permissions --no-overwrite-dir-/bin/rm -f $MNT1/iosbinpack64.tar--# dropbear host keys are generated on first boot by dropbear -R; just ensure-# the key directory exists for it to write into.-/bin/mkdir -p $MNT3/dropbear--echo " [+] iosbinpack64 installed"--# ═══════════ 5/7 PATCH LAUNCHD_CACHE_LOADER ══════════════════-echo ""-echo "[5/7] Patching launchd_cache_loader..."--# Always patch from .bak (original unpatched binary)-if ! [[ -e "$MNT1/usr/libexec/launchd_cache_loader.bak" ]]; then- echo " Creating backup..."- /bin/cp $MNT1/usr/libexec/launchd_cache_loader $MNT1/usr/libexec/launchd_cache_loader.bak-fi--cp "$MNT1/usr/libexec/launchd_cache_loader.bak" "$TEMP_DIR/launchd_cache_loader"-"$VPHONE_CLI" cfw patch-launchd-cache-loader "$TEMP_DIR/launchd_cache_loader"-guest_sign "$TEMP_DIR/launchd_cache_loader" "com.apple.launchd_cache_loader"-cp -R "$TEMP_DIR/launchd_cache_loader" "$MNT1/usr/libexec/launchd_cache_loader"-/bin/chmod 0755 $MNT1/usr/libexec/launchd_cache_loader--echo " [+] launchd_cache_loader patched"--# ═══════════ 6/7 PATCH MOBILEACTIVATIOND ═════════════════════-echo ""-echo "[6/7] Patching mobileactivationd..."--# Always patch from .bak (original unpatched binary)-if ! [[ -e "$MNT1/usr/libexec/mobileactivationd.bak" ]]; then- echo " Creating backup..."- /bin/cp $MNT1/usr/libexec/mobileactivationd $MNT1/usr/libexec/mobileactivationd.bak-fi--cp "$MNT1/usr/libexec/mobileactivationd.bak" "$TEMP_DIR/mobileactivationd"-"$VPHONE_CLI" cfw patch-mobileactivationd "$TEMP_DIR/mobileactivationd"-guest_sign "$TEMP_DIR/mobileactivationd"-cp -R "$TEMP_DIR/mobileactivationd" "$MNT1/usr/libexec/mobileactivationd"-/bin/chmod 0755 $MNT1/usr/libexec/mobileactivationd--echo " [+] mobileactivationd patched"--# ═══════════ 7/7 LAUNCHDAEMONS + LAUNCHD.PLIST ══════════════-echo ""-echo "[7/7] Installing LaunchDaemons..."--# Install vphoned (vsock HID injector daemon). Cross-compiled at build time —-# see the note in cfw_install.sh. Only the signing stays here.-VPHONED_SRC="$SCRIPT_DIR/vphoned"-VPHONED_BIN="$GUEST_BIN/vphoned"-[[ -f "$VPHONED_BIN" ]] || die "missing prebuilt vphoned at $VPHONED_BIN — run 'make build'"-cp "$VPHONED_BIN" "$TEMP_DIR/vphoned"-guest_sign_ent "$TEMP_DIR/vphoned" "$VPHONED_SRC/entitlements.plist"-cp -R "$TEMP_DIR/vphoned" "$MNT1/usr/bin/vphoned"-/bin/chmod 0755 $MNT1/usr/bin/vphoned-# Keep a copy of the signed binary for host-side auto-update-cp "$TEMP_DIR/vphoned" "$VM_DIR/.vphoned.signed"-echo " [+] vphoned installed (signed copy at .vphoned.signed)"--# Send daemon plists (overwrite on re-run)-for plist in bash.plist dropbear.plist trollvnc.plist rpcserver_ios.plist; do- plist_src="$INPUT_DIR/jb/LaunchDaemons/$plist"- if [[ "$plist" == "dropbear.plist" ]]; then- plist_src="$TEMP_DIR/dropbear.plist"- cp "$INPUT_DIR/jb/LaunchDaemons/dropbear.plist" "$plist_src"- "$VPHONE_CLI" cfw patch-dropbear-plist "$plist_src"- fi- cp -R "$plist_src" "$MNT1/System/Library/LaunchDaemons/"- /bin/chmod 0644 $MNT1/System/Library/LaunchDaemons/$plist-done-cp -R "$VPHONED_SRC/vphoned.plist" "$MNT1/System/Library/LaunchDaemons/"-/bin/chmod 0644 $MNT1/System/Library/LaunchDaemons/vphoned.plist--# Always patch launchd.plist from .bak (original)-echo " Patching launchd.plist..."-if ! [[ -e "$MNT1/System/Library/xpc/launchd.plist.bak" ]]; then- echo " Creating backup..."- /bin/cp $MNT1/System/Library/xpc/launchd.plist $MNT1/System/Library/xpc/launchd.plist.bak-fi--cp "$MNT1/System/Library/xpc/launchd.plist.bak" "$TEMP_DIR/launchd.plist"-cp "$VPHONED_SRC/vphoned.plist" "$INPUT_DIR/jb/LaunchDaemons/"-"$VPHONE_CLI" cfw inject-daemons "$TEMP_DIR/launchd.plist" "$INPUT_DIR/jb/LaunchDaemons"-cp -R "$TEMP_DIR/launchd.plist" "$MNT1/System/Library/xpc/launchd.plist"-/bin/chmod 0644 $MNT1/System/Library/xpc/launchd.plist--echo " [+] LaunchDaemons installed"--# ═══════════ CLEANUP ═════════════════════════════════════════-echo ""-echo "[*] Unmounting image volumes..."-/sbin/umount $MNT1 2>/dev/null || true-/sbin/umount $MNT3 2>/dev/null || true--echo "[*] Cleaning up temp..."-rm -rf "$TEMP_DIR"--echo ""-echo "[+] CFW installation complete!"-echo " Boot to apply changes."-echo " After boot, SSH will be available on port 22222 (password: alpine)"diff --git a/scripts/cfw_install_exp.sh b/scripts/cfw_install_exp.shdeleted file mode 100755index 9e88ffa9..00000000--- a/scripts/cfw_install_exp.sh+++ /dev/null@@ -1,769 +0,0 @@-#!/bin/zsh-# vphone-tier: dist-# cfw_install_exp.sh — Install base CFW + JB extensions + EXP experimental-# patches on vphone. Files are placed directly on the VM's Disk.img volumes,-# which cfw_install_host.sh attaches and mounts on the host; the VM must be off.-#-# Runs the base CFW installer first (phases 1-7), the JB-specific-# modifications (launchd jetsam patch, dylib injection, procursus bootstrap,-# BaseBin hook deployment, JB-1..JB-5), and additionally the experimental-# phases — labeled `EXP-JB-N` to make their EXP-only scope obvious:-# - Pre-step : byte-5 mangle of kern.hv_vmm_present in DSC dylibs-# (paired with KernelEXPPatcher's kernel-side rename).-# - EXP-JB-3.5 : surgical 2-insn patch of watchdogd's hv_vmm cache +-# slot re-attest of the standalone Mach-O.-# - EXP-JB-6 : post-restore DT identity rewrite (root model /-# target-type / compatible[0]) inside-# $MNT5/.../devicetree.img4.-# - EXP-JB-7 : optional ProductBuildVersion rewrite in-# SystemVersion.plist (gated on the SPOOF_BUILD env var).-#-# Stages JB-1..JB-5 remain genuine jailbreak phases (inherited from the JB-# pipeline). Stages prefixed EXP-JB-* are EXP-exclusive — they do NOT run-# when the JB or DEV install scripts are used. JB and DEV remain on their-# pre-experimental baseline.-#-# Prerequisites (in addition to cfw_install.sh requirements):-# - cfw_jb_input/ or resources/cfw_jb_input.tar.zst present-#-# Usage: make cfw_install_exp-set -euo pipefail--# ── Restore caller's PATH — Nix /etc/zshenv resets PATH on zsh startup ─-[[ -n "${_VPHONE_PATH:-}" ]] && export PATH="$_VPHONE_PATH"-VM_DIR="$(cd "${1:-.}" && pwd)"-SCRIPT_DIR="${0:a:h}"--# ── vphone-cli resolver — the Swift CFW patchers the phases below call ─-# Same order as scripts/cfw_install_host.sh and cfw-kit/run.sh: VPHONE_CLI_BIN-# when a vphone-cli subcommand invoked us, otherwise a dev tree or the .app,-# where scripts/ sits in Contents/Resources and the binaries are one level up-# in MacOS. Never `command -v` — the binary has to be the one we built beside-# these scripts, not whatever else is on PATH.-# Resolved up front, before anything is mounted or written: a missing binary-# should stop the run here, not halfway through with volumes attached.-VPHONE_CLI="${VPHONE_CLI_BIN:-}"-if [[ -z "$VPHONE_CLI" ]]; then- for candidate in "${SCRIPT_DIR:h}/.build/release/vphone-cli" "${SCRIPT_DIR:h:h}/MacOS/vphone-cli"; do- [[ -x "$candidate" ]] && { VPHONE_CLI="$candidate"; break }- done-fi-[[ -x "$VPHONE_CLI" ]] || {- echo "[-] cannot find vphone-cli (the JB/EXP phases need it) — run 'make build'" >&2- exit 1-}--# Siblings of the binary just resolved, never PATH. See cfw_install.sh.-VPHONE_ARCHIVE="${VPHONE_CLI:h}/vphone-archive"-[[ -x "$VPHONE_ARCHIVE" ]] || {- echo "[-] cannot find vphone-archive beside $VPHONE_CLI — run 'make build'" >&2- exit 1-}-# All four guest binaries this variant installs are cross-compiled at build time-# (scripts/guest_binaries.mk) and shipped: TweakLoader.dylib, vpregister,-# libvcamcaptured.dylib and libcamfix.dylib.-GUEST_BIN=""-for candidate in "${SCRIPT_DIR:h}/guest" "${SCRIPT_DIR:h}/.build/guest"; do- [[ -d "$candidate" ]] && { GUEST_BIN="$candidate"; break }-done--# ════════════════════════════════════════════════════════════════-# Step 1: Run base CFW install (skip halt — we continue with JB phases)-# ════════════════════════════════════════════════════════════════-echo "[*] cfw_install_exp.sh — Installing CFW + JB extensions + EXP experimental patches..."-echo ""--# ────────────────────────────────────────────────────────────────────-# Pre-step: patch hv_vmm_present user-mode consumers in the SystemOS-# Cryptex's DSC chunks BEFORE running cfw_install.sh.-#-# cfw_install.sh decrypts the SystemOS Cryptex AEA into-# $TEMP_DIR/CryptexSystemOS.dmg and reuses it on subsequent runs. We-# pre-create that decrypted DMG here, mount it, patch the DSC chunks-# in place, unmount, and let cfw_install.sh pick up the cached-# (already-patched) DMG. cfw_install.sh itself is unmodified — this-# is the EXP variant's device-like user-mode patching, kept out of-# the JB install path so JB remains unaffected.-# ────────────────────────────────────────────────────────────────────-JB_TEMP_DIR="$VM_DIR/.cfw_temp"-JB_SYSOS_DMG="$JB_TEMP_DIR/CryptexSystemOS.dmg"-JB_MNT_SYSOS="$JB_TEMP_DIR/mnt_sysos_hv_vmm"-mkdir -p "$JB_TEMP_DIR"--# Find the restore directory (same logic as cfw_install.sh)-JB_RESTORE_DIR=""-for d in "$VM_DIR"/iPhone*_Restore; do- [[ -d "$d" ]] && { JB_RESTORE_DIR="$d"; break; }-done--if [[ -z "$JB_RESTORE_DIR" ]]; then- echo "[!] hv_vmm DSC patch: no restore directory found, skipping"-elif [[ ! -f "$JB_SYSOS_DMG" ]]; then- # Not yet decrypted — decrypt to the cache location cfw_install.sh expects.- echo "[*] hv_vmm DSC patch: decrypting SystemOS into cache..."- # Two lines out, SystemOS first then AppOS; head -1 takes SystemOS.- JB_CRYPTEX_SYSOS=$("$VPHONE_CLI" cfw cryptex-paths "$JB_RESTORE_DIR/iPhone-BuildManifest.plist" | head -1)- JB_AEA_KEY=$("$VPHONE_CLI" fw aea-key "$JB_RESTORE_DIR/$JB_CRYPTEX_SYSOS")- /usr/bin/aea decrypt -i "$JB_RESTORE_DIR/$JB_CRYPTEX_SYSOS" -o "$JB_SYSOS_DMG" -key-value "$JB_AEA_KEY"-fi--if [[ -f "$JB_SYSOS_DMG" ]]; then- # Mount, patch chunks (hv_vmm + camera, same cryptex), unmount.- # Idempotent: re-running on an already-patched DMG is a no-op- # (hv_vmm patcher detects already-patched cstrings; camera patcher- # refuses pre-patched function entries unless --force is passed).- echo "[*] DSC patches: mounting cached SystemOS DMG..."- mkdir -p "$JB_MNT_SYSOS"- sudo ${SUDO_ASKPASS:+-A} hdiutil detach "$JB_MNT_SYSOS" -force 2>/dev/null || true- sudo ${SUDO_ASKPASS:+-A} hdiutil attach -mountpoint "$JB_MNT_SYSOS" "$JB_SYSOS_DMG" -nobrowse -owners off-- JB_DSC_CHUNKS_DIR="$JB_MNT_SYSOS/System/Library/Caches/com.apple.dyld"- JB_DSC_HEADER="$JB_DSC_CHUNKS_DIR/dyld_shared_cache_arm64e"- if [[ -d "$JB_DSC_CHUNKS_DIR" ]]; then- echo "[*] hv_vmm DSC patch: patching chunks under $JB_DSC_CHUNKS_DIR..."- "$SCRIPT_DIR/patch_hv_vmm_userland.sh" dsc "$JB_DSC_CHUNKS_DIR"- echo "[+] hv_vmm DSC patch: chunks patched"-- # Camera DSC patches: (1) short-circuit the NeutrinoCore- # _NUStyleTransfer*Processor methods so Camera.app's style-- # thumbnail pipeline doesn't crash on this VM build, and (2)- # force +[AVCaptureDevice authorizationStatusForMediaType:] =- # Authorized so apps don't bail at the TCC gate. Both are- # resolved per-build via `ipsw dyld symaddr` and verified by- # pacibsp prologue match — version-portable as long as the- # named ObjC symbols continue to exist. Combined with the- # /product/camera DT node added at fw_patch time, this lets- # Camera.app's icon show on Home Screen and the app launch- # without immediately bailing.- if [[ -f "$JB_DSC_HEADER" ]]; then- echo "[*] camera DSC patch: patching chunks under $JB_DSC_CHUNKS_DIR..."- if "$SCRIPT_DIR/patch_camera_userland.sh" dsc "$JB_DSC_CHUNKS_DIR" "$JB_DSC_HEADER"; then- echo "[+] camera DSC patch: chunks patched"- else- echo "[!] camera DSC patch: failed (likely build-version mismatch); continuing"- fi- else- echo "[-] camera DSC patch: $JB_DSC_HEADER not found, skipping"- fi- else- echo "[-] DSC patches: $JB_DSC_CHUNKS_DIR not found, skipping"- fi-- sudo ${SUDO_ASKPASS:+-A} hdiutil detach "$JB_MNT_SYSOS" -force-fi--# Now run the regular CFW install. It will see the cached (patched)-# CryptexSystemOS.dmg and use it as-is, so the patched DSC chunks land-# in $MNT1/System/Cryptexes/OS.-zsh "$SCRIPT_DIR/cfw_install.sh" "$VM_DIR"--# ════════════════════════════════════════════════════════════════-# Step 2: JB-specific phases-# ════════════════════════════════════════════════════════════════--# ── Configuration ───────────────────────────────────────────────-CFW_INPUT="cfw_input"-CFW_JB_INPUT="cfw_jb_input"-CFW_JB_ARCHIVE="cfw_jb_input.tar.zst"-TEMP_DIR="$VM_DIR/.cfw_temp"-DISABLE_LAUNCHD_HOOK="${DISABLE_LAUNCHD_HOOK:-0}"--# ── Helpers ─────────────────────────────────────────────────────-die() {- echo "[-] $*" >&2- exit 1-}--check_prerequisites() {- # ldid and xcrun used to be checked here. Neither is reachable from this- # script any more: signing is `vphone-cli sign` (see cfw_install.sh), and- # the four guest binaries below are cross-compiled at build time rather than- # here, so no iPhoneOS SDK is needed on the machine running the install.- [[ -n "$GUEST_BIN" ]] || die "no prebuilt guest binaries — run 'make build'"-}--guest_sign() {- local file="$1" bundle_id="${2:-}"- local args=(--merge --pkcs12 "$VM_DIR/$CFW_INPUT/signcert.p12")- [[ -n "$bundle_id" ]] && args+=(--identifier "$bundle_id")- "$VPHONE_CLI" sign "${args[@]}" "$file"-}--guest_sign_ent() {- local file="$1" entitlements_plist="$2" bundle_id="${3:-}"- local args=(--entitlements "$entitlements_plist" --pkcs12 "$VM_DIR/$CFW_INPUT/signcert.p12")- [[ -n "$bundle_id" ]] && args+=(--identifier "$bundle_id")- "$VPHONE_CLI" sign "${args[@]}" "$file"-}--# `ldid -S<ent> -M`: entitlements captured off the original binary, merged back-# over whatever the patched one carries.-guest_sign_ent_merge() {- "$VPHONE_CLI" sign --entitlements "$2" --merge \- --pkcs12 "$VM_DIR/$CFW_INPUT/signcert.p12" "$1"-}--guest_entitlements() {- "$VPHONE_CLI" dump-entitlements "$1"-}--guest_untar() { # guest_untar <archive> <dest> [extra flags…]- local archive="$1" dest="$2"; shift 2- "$VPHONE_ARCHIVE" extract -f "$archive" -C "$dest" "$@"-}--# One shape for all four prebuilt guest artifacts: copy it out of the bundle,-# sign it with this VM's cert, print where it landed. They used to be compiled-# here through `xcrun --sdk iphoneos`, which made Xcode a prerequisite for-# installing CFW onto a VM; they are built by scripts/guest_binaries.mk now.-stage_guest_artifact() { # stage_guest_artifact <name> [entitlements]- local name="$1" ent="${2:-}"- local src="$GUEST_BIN/$name"- local out="$TEMP_DIR/$name"- [[ -f "$src" ]] || die "Missing prebuilt $name at $src — run 'make build'"- cp -f "$src" "$out"- if [[ -n "$ent" ]]; then guest_sign_ent "$out" "$ent"; else guest_sign "$out"; fi- echo "$out"-}--stage_tweakloader() { stage_guest_artifact TweakLoader.dylib }--# vpregister — registers JB apps via the containerized LaunchServices API on-# iOS 27, where -[LSApplicationWorkspace registerApplicationDictionary:] (uicache -a)-# is a deprecated no-op stub. Needs the lsd embedded-reg gate patch-# (cfw_patch_lsd_embedded_reg, applied by cfw_install.sh). Deployed to /cores and-# invoked by vphone_jb_setup.sh at first boot.-stage_vpregister() {- stage_guest_artifact vpregister "$SCRIPT_DIR/vphoned/entitlements.plist"-}--# Builds the libvcamcaptured.dylib injected into /usr/libexec/cameracaptured-# via the TweakLoader allowlist. Output goes to TEMP_DIR; caller copies the-# binary + companion plist to procursus/Library/MobileSubstrate/DynamicLibraries.-stage_libvcamcaptured() { stage_guest_artifact libvcamcaptured.dylib }--# Builds the libcamfix.dylib substrate plugin. Loaded into every process-# that links AVFoundation via TweakLoader's Filter.Frameworks key —-# Camera.app, third-party apps, anywhere the-# documented capture interface is used. Implements the photo-delivery-# path through CAMCaptureEngine + the preview/state guards that keep-# the viewfinder live on the virtual camera.-stage_libcamfix() { stage_guest_artifact libcamfix.dylib }--get_boot_manifest_hash() {- /bin/ls $MNT5 2>/dev/null | awk 'length($0)==96{print; exit}'-}--# ── Setup JB input resources ──────────────────────────────────-setup_cfw_jb_input() {- [[ -d "$VM_DIR/$CFW_JB_INPUT" ]] && return- local archive- for search_dir in "$SCRIPT_DIR/resources" "$SCRIPT_DIR" "$VM_DIR"; do- archive="$search_dir/$CFW_JB_ARCHIVE"- if [[ -f "$archive" ]]; then- echo " Extracting $CFW_JB_ARCHIVE..."- guest_untar "$archive" "$VM_DIR"- return- fi- done- die "JB mode: neither $CFW_JB_INPUT/ nor $CFW_JB_ARCHIVE found"-}--# ── Apply dev overlay (replace rpcserver_ios in iosbinpack64) ──-apply_dev_overlay() {- local dev_bin- for search_dir in "$SCRIPT_DIR/resources/cfw_dev" "$SCRIPT_DIR/cfw_dev"; do- dev_bin="$search_dir/rpcserver_ios"- if [[ -f "$dev_bin" ]]; then- echo " Applying dev overlay (rpcserver_ios)..."- local iosbinpack="$VM_DIR/$CFW_INPUT/jb/iosbinpack64.tar"- local tmpdir="$VM_DIR/.iosbinpack_tmp"- mkdir -p "$tmpdir"- guest_untar "$iosbinpack" "$tmpdir"- cp "$dev_bin" "$tmpdir/iosbinpack64/usr/local/bin/rpcserver_ios"- # -C "$tmpdir" packs what is under it, and the only thing under it- # is iosbinpack64/ — the same single top-level member `tar -cf …- # iosbinpack64` from inside $tmpdir produced.- "$VPHONE_ARCHIVE" create -f "$iosbinpack" -C "$tmpdir"- rm -rf "$tmpdir"- return- fi- done- die "Dev overlay not found (cfw_dev/rpcserver_ios)"-}--# The VM's Disk.img is attached on the host by cfw_install_host.sh; its APFS-# volumes are mounted here and every file is placed with plain cp/chmod/etc.-# (the VM is off — nothing runs "on the device").-: "${CFW_HOST_CONTAINER:?CFW_HOST_CONTAINER unset — run via cfw_install_host.sh}"-HOST_MNT="${CFW_HOST_MNT:-/private/tmp/cfwhost}"-MNT1="$HOST_MNT/mnt1" # disk1s1 (System / rootfs)-MNT3="$HOST_MNT/mnt3" # disk1s3-MNT5="$HOST_MNT/mnt5" # disk1s5 (per-boot-manifest OS dir / procursus bootstrap)-mkdir -p "$HOST_MNT"--# Mount an APFS volume of the attached image container at a host mount point.-mount_vol() { # mount_vol <slice, e.g. s1> <mountpoint> [opts]- local dev="/dev/${CFW_HOST_CONTAINER}$1" mnt="$2" opts="${3:-rw}"- /bin/mkdir -p "$mnt"- /sbin/mount | /usr/bin/grep -q " on $mnt " && return 0- /sbin/mount_apfs -o "$opts" "$dev" "$mnt" 2>/dev/null || true- /sbin/mount | /usr/bin/grep -q " on $mnt " || die "mount failed: $dev -> $mnt"-}--# ── Check JB prerequisites ────────────────────────────────────-# zstd(1) used to be required here for the bootstrap. vphone-archive links-# libzstd and decompresses in-process; check_prerequisites below is what is left.--setup_cfw_jb_input-JB_INPUT_DIR="$VM_DIR/$CFW_JB_INPUT"-echo ""-echo "[+] JB input resources: $JB_INPUT_DIR"-check_prerequisites--mkdir -p "$TEMP_DIR"--# Mount the image's System volume (may already be mounted from base install)-mount_vol s1 "$MNT1"--# ═══════════ JB-1 PATCH LAUNCHD (JETSAM + DYLIB INJECTION) ════-echo ""-echo "[JB-1] Patching launchd (jetsam guard + hook injection)..."--if ! [[ -e "$MNT1/sbin/launchd.bak" ]]; then- echo " Creating backup..."- /bin/cp $MNT1/sbin/launchd $MNT1/sbin/launchd.bak-fi--cp "$MNT1/sbin/launchd.bak" "$TEMP_DIR/launchd"--# Extract original entitlements before patching (must preserve for spawn permissions)-echo " Extracting original entitlements..."-guest_entitlements "$TEMP_DIR/launchd" > "$TEMP_DIR/launchd.entitlements" 2>/dev/null || true-if [[ -s "$TEMP_DIR/launchd.entitlements" ]]; then- echo " [+] Preserved launchd entitlements"-else- echo " [!] No entitlements found on original launchd"-fi--# Injecting launchdhook into pid 1 is on by default. This boot-critical hook-# path has produced boot-analysis failures; set DISABLE_LAUNCHD_HOOK=1 to keep-# BaseBin deployed without loading /b from launchd.-if [[ "$DISABLE_LAUNCHD_HOOK" == "1" ]]; then- echo " [*] Skipping launchdhook dylib injection (DISABLE_LAUNCHD_HOOK=1)"-elif [[ -d "$JB_INPUT_DIR/basebin" ]]; then- echo " Injecting weak dylib load for /b (short launchdhook alias)..."- # Stays exactly here: the injector leaves launchd unsigned, so it has to- # run after the `ldid -e` entitlement capture above and before the- # patch-launchd-jetsam + ldid re-sign below.- "$VPHONE_CLI" cfw inject-dylib "$TEMP_DIR/launchd" "/b"-else- echo " [!] BaseBin is missing; skipping launchdhook injection"-fi--"$VPHONE_CLI" cfw patch-launchd-jetsam "$TEMP_DIR/launchd"--# Re-sign with original entitlements to avoid "operation not permitted" on spawn-if [[ -s "$TEMP_DIR/launchd.entitlements" ]]; then- guest_sign_ent_merge "$TEMP_DIR/launchd" "$TEMP_DIR/launchd.entitlements"-else- guest_sign "$TEMP_DIR/launchd"-fi-cp -R "$TEMP_DIR/launchd" "$MNT1/sbin/launchd"-/bin/chmod 0755 $MNT1/sbin/launchd--echo " [+] launchd patched"--# ═══════════ JB-2 INSTALL IOSBINPACK64 ════════════════════════-echo ""-echo "[JB-2] Installing iosbinpack64..."--apply_dev_overlay-cp -R "$VM_DIR/$CFW_INPUT/jb/iosbinpack64.tar" "$MNT1"-guest_untar "$MNT1/iosbinpack64.tar" "$MNT1" --preserve-permissions --no-overwrite-dir-/bin/rm -f $MNT1/iosbinpack64.tar--echo " [+] iosbinpack64 installed"--# ═══════════ JB-3 PATCH debugserver entitlements ════-echo ""-echo "[JB-3] Patching debugserver entitlements..."--cp "$MNT1/usr/libexec/debugserver" "$TEMP_DIR/debugserver"-guest_entitlements "$TEMP_DIR/debugserver" > "$TEMP_DIR/debugserver-entitlements.plist"-plutil -remove seatbelt-profiles "$TEMP_DIR/debugserver-entitlements.plist" || true-plutil -insert task_for_pid-allow -bool YES "$TEMP_DIR/debugserver-entitlements.plist" || true-guest_sign_ent "$TEMP_DIR/debugserver" "$TEMP_DIR/debugserver-entitlements.plist"-cp -R "$TEMP_DIR/debugserver" "$MNT1/usr/libexec/debugserver"-/bin/chmod 0755 $MNT1/usr/libexec/debugserver--echo " [+] debugserver entitlements patched"---# ═══════════ JB-3b CAMPO SANDBOX FIX (iOS 27 only) ════════════-# Grant Campo the backboard/frontboard mach-lookups the 26.4 temporary-sandbox denies (see 0_binary_patch_comparison.md #14).-# 27-gated on the mounted rootfs SystemVersion.plist: 26.x userlands don't need it and Campo.app exists there too.-CAMPO_BIN="$MNT1/Applications/Campo.app/Campo"-BASE_IOS=$(/usr/bin/plutil -extract ProductVersion raw -o - "$MNT1/System/Library/CoreServices/SystemVersion.plist" 2>/dev/null || true)-case "$BASE_IOS" in-27.*)- if [[ -f "$CAMPO_BIN" ]]; then- echo ""- echo "[JB-3b] Granting Campo backboard/frontboard mach-lookup exceptions (iOS $BASE_IOS)..."- cp "$CAMPO_BIN" "$TEMP_DIR/Campo"- guest_entitlements "$TEMP_DIR/Campo" > "$TEMP_DIR/Campo.entitlements" 2>/dev/null || true- if [[ -s "$TEMP_DIR/Campo.entitlements" ]]; then- "$VPHONE_CLI" cfw patch-campo-entitlements "$TEMP_DIR/Campo.entitlements"- guest_sign_ent "$TEMP_DIR/Campo" "$TEMP_DIR/Campo.entitlements"- cp -R "$TEMP_DIR/Campo" "$CAMPO_BIN"- /bin/chmod 0755 "$CAMPO_BIN"- echo " [+] Campo re-signed with backboard/frontboard mach-lookup exceptions"- else- echo " [!] Could not read Campo entitlements; skipping Campo sandbox fix"- fi- else- echo "[JB-3b] Campo.app not present in this OS image; skipping Campo sandbox fix"- fi- ;;-*)- echo "[JB-3b] skip Campo sandbox fix (base iOS ${BASE_IOS:-unknown} — 27-only)"- ;;-esac---# ═══════════ EXP-JB-3.5 PATCH watchdogd hv_vmm_present cache ══-#-# Background: the kernel-side OID rename (KernelEXPPatchHvVmmRename)-# makes sysctlbyname("kern.hv_vmm_present", ...) return ENOENT on this-# image. watchdogd caches that answer at startup and uses it to decide-# whether to look for the IOWatchdog kext. The unpatched flow takes-# the "not on a VM" branch on ENOENT, fails to find the kext (it-# doesn't exist on the VM), calls _os_crash -> brk #1, and launchd's-# `_PanicOnCrash` knob in com.apple.watchdogd.plist escalates the-# resulting SIGTRAP to a kernel panic.-#-# Patch shape: two-instruction surgical edit at every site in-# watchdogd that has the canonical-# adrp/add(kern.hv_vmm_present) -> bl _sysctlbyname -> cbnz w0,skip-# -> cset wN,ne -> strb wN,[global]-# shape. The edit forces the cached byte to 1 regardless of the-# sysctl result, so the downstream branch at +0x58e0 takes watchdogd's-# pre-existing "detected virtual machine environment" clean-exit path.-# The patcher also recomputes the affected CodeDirectory slot hashes-# (cfw_macho_codesign) so TXM still accepts the modified pages on-# demand-page-in. We deliberately do NOT re-sign with ldid — the-# Apple-issued code-signing identifier ("com.apple.watchdogd") must be-# preserved for launchd boot-task identity validation.-echo ""-echo "[EXP-JB-3.5] Patching watchdogd hv_vmm_present cache..."--cp "$MNT1/usr/libexec/watchdogd" "$TEMP_DIR/watchdogd"-"$SCRIPT_DIR/patch_hv_vmm_userland.sh" watchdogd "$TEMP_DIR/watchdogd"-cp -R "$TEMP_DIR/watchdogd" "$MNT1/usr/libexec/watchdogd"-/bin/chmod 0755 $MNT1/usr/libexec/watchdogd--echo " [+] watchdogd patched"---# ═══════════ JB-4 INSTALL PROCURSUS BOOTSTRAP ══════════════════-echo ""-echo "[JB-4] Installing procursus bootstrap..."--mount_vol s5 "$MNT5"-BOOT_HASH="$(get_boot_manifest_hash)"-[[ -n "$BOOT_HASH" ]] || die "Could not find 96-char boot manifest hash in $MNT5"-echo " Boot manifest hash: $BOOT_HASH"--BOOTSTRAP_ZST="$JB_INPUT_DIR/jb/bootstrap-iphoneos-arm64.tar.zst"-SILEO_DEB="$JB_INPUT_DIR/jb/org.coolstar.sileo_2.5.1_iphoneos-arm64.deb"-[[ -f "$BOOTSTRAP_ZST" ]] || die "Missing $BOOTSTRAP_ZST"--BOOTSTRAP_TAR="$TEMP_DIR/bootstrap-iphoneos-arm64.tar"-"$VPHONE_ARCHIVE" decompress -f "$BOOTSTRAP_ZST" -o "$BOOTSTRAP_TAR"--cp -R "$BOOTSTRAP_TAR" "$MNT5/$BOOT_HASH/bootstrap-iphoneos-arm64.tar"-if [[ -f "$SILEO_DEB" ]]; then- cp -R "$SILEO_DEB" "$MNT5/$BOOT_HASH/org.coolstar.sileo_2.5.1_iphoneos-arm64.deb"-fi--# ── Extra debs: download from manifest, then stage the whole cache ──────-echo " Fetching extra debs..."-zsh "$SCRIPT_DIR/fetch_debs.sh" || true-DEBS_CACHE="${VPHONE_DEBS_DIR:-${SCRIPT_DIR:h}/debs}"-DEBS_DEST="$MNT5/$BOOT_HASH/debs"-/bin/rm -rf "$DEBS_DEST"-deb_count=0-for deb in "$DEBS_CACHE"/*.deb(N); do- (( deb_count == 0 )) && /bin/mkdir -p "$DEBS_DEST"- cp -R "$deb" "$DEBS_DEST/"- deb_count=$((deb_count + 1))-done-if (( deb_count > 0 )); then- echo " [+] Staged $deb_count extra deb(s) for first-boot install"-else- echo " [=] No extra debs to stage"-fi--JB_DIR_NAME="jb-vphone"-/bin/rm -rf $MNT5/$BOOT_HASH/jb-/bin/rm -rf $MNT5/$BOOT_HASH/$JB_DIR_NAME-/bin/mkdir -p $MNT5/$BOOT_HASH/$JB_DIR_NAME-/bin/chmod 0755 $MNT5/$BOOT_HASH/$JB_DIR_NAME-/usr/sbin/chown 0:0 $MNT5/$BOOT_HASH/$JB_DIR_NAME-guest_untar "$MNT5/$BOOT_HASH/bootstrap-iphoneos-arm64.tar" \- "$MNT5/$BOOT_HASH/$JB_DIR_NAME/" --preserve-permissions-/bin/mv $MNT5/$BOOT_HASH/$JB_DIR_NAME/var $MNT5/$BOOT_HASH/$JB_DIR_NAME/procursus-mv "$MNT5/$BOOT_HASH/$JB_DIR_NAME/procursus/jb"/*(N) "$MNT5/$BOOT_HASH/$JB_DIR_NAME/procursus" 2>/dev/null || true-/bin/rm -rf $MNT5/$BOOT_HASH/$JB_DIR_NAME/procursus/jb-/bin/rm -f $MNT5/$BOOT_HASH/bootstrap-iphoneos-arm64.tar-rm -f "$BOOTSTRAP_TAR"--# NOTE: /var/jb symlink is created on first normal boot by vphone_jb_setup.sh-# (Data volume is encrypted and not mountable at install time).--echo " [+] procursus bootstrap installed"--# ═══════════ JB-4 DEPLOY BASEBIN HOOKS ═════════════════════════-BASEBIN_DIR="$JB_INPUT_DIR/basebin"--if [[ -d "$BASEBIN_DIR" ]]; then- echo ""- echo "[JB-4] Deploying BaseBin hooks to /cores/..."-- # Clean previous dylibs before re-uploading- echo " Cleaning old /cores/ dylibs..."- /bin/rm -rf $MNT1/cores- /bin/mkdir -p $MNT1/cores- /bin/chmod 0755 $MNT1/cores-- # Install all pre-built dylibs from basebin payload- for dylib in "$BASEBIN_DIR"/*.dylib; do- [[ -f "$dylib" ]] || continue- dylib_name="$(basename "$dylib")"- echo " Installing $dylib_name..."- guest_sign "$dylib"- cp -R "$dylib" "$MNT1/cores/$dylib_name"- /bin/chmod 0755 $MNT1/cores/$dylib_name- done-- # Short alias for launchdhook (header space is tight)- if [[ -f "$BASEBIN_DIR/launchdhook.dylib" ]]; then- echo " Installing short launchdhook alias at /b..."- cp "$BASEBIN_DIR/launchdhook.dylib" "$TEMP_DIR/b"- guest_sign "$TEMP_DIR/b"- /bin/rm -f $MNT1/b- cp -R "$TEMP_DIR/b" "$MNT1/b"- /bin/chmod 0755 $MNT1/b- fi-- echo " [+] BaseBin hooks deployed"-fi--# ═══════════ JB-4 INSTALL TWEAKLOADER ════════════════════════════-echo ""-echo "[JB-4] Building and installing TweakLoader..."--TWEAKLOADER_OUT="$(stage_tweakloader)"-/bin/mkdir -p $MNT5/$BOOT_HASH/$JB_DIR_NAME/procursus/usr/lib-cp -R "$TWEAKLOADER_OUT" "$MNT5/$BOOT_HASH/$JB_DIR_NAME/procursus/usr/lib/TweakLoader.dylib"-/usr/sbin/chown 0:0 $MNT5/$BOOT_HASH/$JB_DIR_NAME/procursus/usr/lib/TweakLoader.dylib-/bin/chmod 0755 $MNT5/$BOOT_HASH/$JB_DIR_NAME/procursus/usr/lib/TweakLoader.dylib--echo " [+] TweakLoader installed to procursus/usr/lib/TweakLoader.dylib"--# ═══════════ JB-4.1 INSTALL libvcamcaptured ═════════════════════════-# Inject dylib loaded into /usr/libexec/cameracaptured (via TweakLoader-# allowlist in TweakLoader.m's kVPhoneAllowedDaemonPaths). Hosts the-# synthetic FigCaptureSource + shm-frame reader paired with vphoned's-# vsock 1338 listener on the guest side.-echo ""-echo "[JB-4.1] Building and installing libvcamcaptured..."-LIBVCAM_OUT="$(stage_libvcamcaptured)"-LIBVCAM_DIR="$MNT5/$BOOT_HASH/$JB_DIR_NAME/procursus/Library/MobileSubstrate/DynamicLibraries"-/bin/mkdir -p $LIBVCAM_DIR-cp -R "$LIBVCAM_OUT" "$LIBVCAM_DIR/libvcamcaptured.dylib"-/usr/sbin/chown 0:0 $LIBVCAM_DIR/libvcamcaptured.dylib-/bin/chmod 0755 $LIBVCAM_DIR/libvcamcaptured.dylib--# The plist tells TweakLoader to load the dylib only inside cameracaptured-# (Filter.Executables = ["cameracaptured"]); keep it next to the dylib.-LIBVCAM_PLIST="$SCRIPT_DIR/vcamcaptured/libvcamcaptured.plist"-if [[ -f "$LIBVCAM_PLIST" ]]; then- cp -R "$LIBVCAM_PLIST" "$LIBVCAM_DIR/libvcamcaptured.plist"- /bin/chmod 0644 $LIBVCAM_DIR/libvcamcaptured.plist-fi-echo " [+] libvcamcaptured installed to procursus/Library/MobileSubstrate/DynamicLibraries/"--# ═══════════ JB-4.2 INSTALL libcamfix ═══════════════════════════════-# Substrate plugin loaded by TweakLoader into every process that links-# AVFoundation. The companion plist's Filter.Frameworks = ["AVFoundation"]-# tells TweakLoader to defer the dlopen until AVFoundation actually-# appears in the loaded image list (via _dyld_register_func_for_add_image),-# so processes that don't use AVF don't pay any cost.-echo ""-echo "[JB-4.2] Building and installing libcamfix..."-LIBCAMFIX_OUT="$(stage_libcamfix)"-cp -R "$LIBCAMFIX_OUT" "$LIBVCAM_DIR/libcamfix.dylib"-/usr/sbin/chown 0:0 $LIBVCAM_DIR/libcamfix.dylib-/bin/chmod 0755 $LIBVCAM_DIR/libcamfix.dylib--LIBCAMFIX_PLIST="$SCRIPT_DIR/camfix/libcamfix.plist"-if [[ -f "$LIBCAMFIX_PLIST" ]]; then- cp -R "$LIBCAMFIX_PLIST" "$LIBVCAM_DIR/libcamfix.plist"- /bin/chmod 0644 $LIBVCAM_DIR/libcamfix.plist-fi-echo " [+] libcamfix installed to procursus/Library/MobileSubstrate/DynamicLibraries/"--# ═══════════ JB-5 DEPLOY FIRST-BOOT SETUP ══════════════════════-echo ""-echo "[JB-5] Deploying first-boot setup..."--# Deploy first-boot JB setup script + LaunchDaemon-SETUP_SCRIPT="$SCRIPT_DIR/vphone_jb_setup.sh"-SETUP_PLIST="$SCRIPT_DIR/vphone_jb_setup.plist"-if [[ -f "$SETUP_SCRIPT" ]]; then- cp -R "$SETUP_SCRIPT" "$MNT1/cores/vphone_jb_setup.sh"- /bin/chmod 0755 $MNT1/cores/vphone_jb_setup.sh- echo " [+] vphone_jb_setup.sh -> /cores/"-fi-# vpregister: registers JB apps via the containerized LS API at first boot (uicache -a's-# registerApplicationDictionary is a deprecated no-op on iOS 27). Deployed ONLY on a 27-# base — it needs the 27-only lsd embedded-reg gate, and on 26.x/18.x uicache registers-# apps normally. Its /cores presence IS the runtime gate in vphone_jb_setup.sh (that-# script must NOT version-check on guest sw_vers — the hybrid guest does not reliably-# report the 27 userland version at first boot). Version read from the mounted rootfs-# SystemVersion.plist, the same source cfw_install.sh gates its 27 patches on.-case "$BASE_IOS" in- 27.*)- VPREGISTER="$(stage_vpregister)"- if [[ -f "$VPREGISTER" ]]; then- cp -R "$VPREGISTER" "$MNT1/cores/vpregister"- /bin/chmod 0755 $MNT1/cores/vpregister- echo " [+] vpregister -> /cores/ (iOS $BASE_IOS)"- fi- ;;- *)- echo " [skip] vpregister (base iOS ${BASE_IOS:-unknown} — 27-only; uicache registers apps on older bases)"- ;;-esac-if [[ -f "$SETUP_PLIST" ]]; then- cp -R "$SETUP_PLIST" "$MNT1/System/Library/LaunchDaemons/com.vphone.jb-setup.plist"- /bin/chmod 0644 $MNT1/System/Library/LaunchDaemons/com.vphone.jb-setup.plist-- # Inject into launchd.plist so launchd starts it at boot- echo " Injecting com.vphone.jb-setup into launchd.plist..."- cp "$MNT1/System/Library/xpc/launchd.plist" "$TEMP_DIR/launchd.plist"- "$VPHONE_CLI" cfw inject-daemon "$TEMP_DIR/launchd.plist" "$SETUP_PLIST" --name com.vphone.jb-setup- cp -R "$TEMP_DIR/launchd.plist" "$MNT1/System/Library/xpc/launchd.plist"- /bin/chmod 0644 $MNT1/System/Library/xpc/launchd.plist- echo " [+] com.vphone.jb-setup.plist injected into launchd.plist"-fi--# ═══════════ EXP-JB-6 POST-RESTORE DT IDENTITY REWRITE ════════-#-# Apply the three restore-unsafe DT property edits that broke earlier-# attempts when applied at fw_patch time:-# root/model iPhone99,11 -> iPhone17,3-# root/target-type VPHONE600 -> D47-# root/compatible reordered to [D47AP, VPHONE600AP, AppleVirtualPlatformARM]-#-# These are restore-time-fatal (restored_external / iBoot's restore mode-# cross-checks model+target-type against the BuildManifest's signed-# identity) but NOT boot-time-fatal — the existing iBSS/iBEC/LLB-# image4_validate_property_callback bypass patches accept any IM4P-# contents on subsequent boots.-#-# $MNT5 is still mounted at this point in the install flow (the umount-# happens in the CLEANUP block below). We copy the live devicetree.img4-# out, patch it on the host, copy it back. Next boot, iBoot loads the-# modified DT, kernel populates machine_info from the new values, and-# sysctl hw.machine / hw.product / hw.model flip to iPhone17,3 / D47 /-# (whatever IOPlatformExpert resolves from compatible[0]=D47AP).-echo ""-echo "[EXP-JB-6] Post-restore DT identity rewrite..."--if [[ -z "$BOOT_HASH" ]]; then- BOOT_HASH="$(get_boot_manifest_hash)"-fi-if [[ -z "$BOOT_HASH" ]]; then- echo " [-] BOOT_HASH not discoverable, skipping EXP-JB-6"-else- JB6_DT_REMOTE="$MNT5/$BOOT_HASH/usr/standalone/firmware/devicetree.img4"- JB6_DT_LOCAL="$TEMP_DIR/devicetree.img4"- if [[ -e "$JB6_DT_REMOTE" ]]; then- cp "$JB6_DT_REMOTE" "$JB6_DT_LOCAL"- "$VPHONE_CLI" cfw patch-post-restore-dt "$JB6_DT_LOCAL"- cp -R "$JB6_DT_LOCAL" "$JB6_DT_REMOTE"- /usr/sbin/chown 0:0 $JB6_DT_REMOTE- /bin/chmod 0644 $JB6_DT_REMOTE- echo " [+] devicetree.img4 rewritten in place"- else- echo " [-] $JB6_DT_REMOTE not found, skipping EXP-JB-6"- fi-fi--# ═══════════ EXP-JB-7 BUILD-VERSION REWRITE (SystemVersion.plist) ══-#-# OPT-IN. Only runs when SPOOF_BUILD is set in the environment (e.g.-# `make setup_machine JB=1 SPOOF_BUILD=23F77` or `make cfw_install_jb-# SPOOF_BUILD=23F77`). When SPOOF_BUILD is unset/empty the step is-# skipped entirely and the build identifier stays at whatever the IPSW-# shipped.-#-# What it does (when enabled): flips ProductBuildVersion in the two-# SystemVersion.plist files iOS reads for "Build" display and-# MGCopyAnswer("BuildVersion"):-# /System/Library/CoreServices/SystemVersion.plist (rootfs)-# /private/preboot/Cryptexes/OS/System/Library/CoreServices/SystemVersion.plist (Cryptex)-#-# Both are plain plist files (no Apple signature on individual plists),-# so no image4 / cdHash / TXM concerns. Both volumes are writable at-# install time:-# $MNT1 (rootfs) — writable before the install-time seal is established-# $MNT5 (preboot) — apfs writable-#-# After this, Settings -> About -> Build, MG BuildVersion key, and every-# framework that reads SystemVersion.plist see the new identifier.-# `sysctl kern.osversion` still reports the kernel image's own build-# (e.g. 23B78 from the PCC vphone600/vresearch101 kernel) — that comes-# from a kernel global populated at boot from boot args, not from this-# plist.-if [[ -n "${SPOOF_BUILD:-}" ]]; then- echo ""- echo "[EXP-JB-7] Rewriting ProductBuildVersion to $SPOOF_BUILD in SystemVersion plists..."-- for jb7_remote in \- "$MNT1/System/Library/CoreServices/SystemVersion.plist" \- "$MNT5/Cryptexes/OS/System/Library/CoreServices/SystemVersion.plist"- do- if [[ -e "$jb7_remote" ]]; then- jb7_local="$TEMP_DIR/$(echo "$jb7_remote" | tr '/' '_').plist"- cp "$jb7_remote" "$jb7_local"- # The SPOOF_BUILD gate stays in the shell above: the Swift- # subcommand has no gate of its own, exactly as the Python had- # none, and always rewrites the build it is handed.- "$VPHONE_CLI" cfw patch-build-version "$jb7_local" "$SPOOF_BUILD"- cp -R "$jb7_local" "$jb7_remote"- else- echo " [-] $jb7_remote not found, skipping"- fi- done-else- echo ""- echo "[EXP-JB-7] Skipped — SPOOF_BUILD not set (pass SPOOF_BUILD=<id> to enable)"-fi--# ═══════════ CLEANUP ═════════════════════════════════════════-echo ""-echo "[*] Unmounting image volumes..."-/sbin/umount $MNT1 2>/dev/null || true-/sbin/umount $MNT3 2>/dev/null || true-/sbin/umount $MNT5 2>/dev/null || true--echo "[*] Cleaning up temp..."-rm -rf "$TEMP_DIR"--echo ""-echo "[+] CFW + JB + EXP installation complete!"-echo " Boot to apply changes."-echo " After boot, SSH will be available on port 22222 (password: alpine)"diff --git a/scripts/cfw_install_host.sh b/scripts/cfw_install_host.shindex 97218f8a..f6e084e6 100755--- a/scripts/cfw_install_host.sh+++ b/scripts/cfw_install_host.sh@@ -2,8 +2,8 @@# vphone-tier: dist# cfw_install_host.sh — CFW install by host-mounting the VM's Disk.img.#-# Attaches the VM's Disk.img on the host and hands the container to the variant-# installer (cfw_install*.sh), which mounts the APFS volumes and places every+# Attaches the VM's Disk.img on the host and hands the container to the JB+# installer, which mounts the APFS volumes and places every# CFW file directly. Then flips the boot snapshot offline# (`vphone-cli cfw flip-snapshot`) so the VM boots the live volume.#@@ -14,33 +14,19 @@# needs nothing outside macOS. SIP disabled (project baseline); NO# authenticated-root/ARV change needed.#-# Usage: cfw_install_host.sh [--variant regular|dev|jb|exp] [vm_dir]+# Usage: cfw_install_host.sh [vm_dir]# Runs as root (mount_apfs/chown/cp to owners-honored mounts); re-execs under# sudo automatically (honors SUDO_ASKPASS for non-interactive use).set -euo pipefailSCRIPT_DIR="${0:a:h}"PROJ="${SCRIPT_DIR:h}"-VARIANT=exp-VM_DIR="$PROJ/vm"-while (( $# )); do- case "$1" in- --variant) VARIANT="$2"; shift 2 ;;- *) VM_DIR="$1"; shift ;;- esac-done--case "$VARIANT" in- regular) INSTALLER=cfw_install.sh ;;- dev) INSTALLER=cfw_install_dev.sh ;;- jb) INSTALLER=cfw_install_jb.sh ;;- exp) INSTALLER=cfw_install_exp.sh ;;- *) echo "[-] unknown variant: $VARIANT (regular|dev|jb|exp)" >&2; exit 1 ;;-esac+VM_DIR="${1:-$PROJ/vm}"+[[ $# -le 1 ]] || { echo "[-] expected one VM directory" >&2; exit 1; }# Re-exec as root; owners-honored mounts + chown/cp require it.if [[ "${EUID:-$(id -u)}" -ne 0 ]]; then- exec sudo ${SUDO_ASKPASS:+-A} -E /bin/zsh "$0" --variant "$VARIANT" "$VM_DIR"+ exec sudo ${SUDO_ASKPASS:+-A} -E /bin/zsh "$0" "$VM_DIR"fiunset SUDO_ASKPASS # already root: host_hdiutil/pre-step use plain sudo/hdiutil@@ -68,7 +54,7 @@ if /usr/sbin/lsof "$IMG" >/dev/null 2>&1; thenecho "[-] $IMG is in use — stop the VM first." >&2; exit 1fi-echo "[*] host-mode CFW install: variant=$VARIANT vm=$VM_DIR"+echo "[*] host-mode JB CFW install: vm=$VM_DIR"AO=$(hdiutil attach -nomount -imagekey diskimage-class=CRawDiskImage "$IMG" 2>/dev/null)BASEDISK=$(awk 'NR == 1 { print $1; exit }' <<< "$AO")CONT=$(diskutil info -plist "${BASEDISK}s1" | /usr/bin/plutil -extract APFSContainerReference raw -o - - 2>/dev/null || true)@@ -84,13 +70,13 @@ cleanup() {}trap cleanup EXIT-echo "[*] running $INSTALLER (files placed on host mounts)..."+echo "[*] running cfw_install_jb.sh (files placed on host mounts)..."# via env: an expansion-produced ${VAR:+NAME=val} isn't parsed as a shell assignment.( cd "$VM_DIR" && env CFW_HOST_CONTAINER="$CONT" _VPHONE_PATH="$P" \${SPOOF_BUILD:+SPOOF_BUILD="$SPOOF_BUILD"} \${FORCE_DSC_MAXSLIDE:+FORCE_DSC_MAXSLIDE="$FORCE_DSC_MAXSLIDE"} \${VPHONE_FRIDA:+VPHONE_FRIDA="$VPHONE_FRIDA"} \- zsh "$SCRIPT_DIR/$INSTALLER" . )+ zsh "$SCRIPT_DIR/cfw_install_jb.sh" . )cleanuptrap - EXIT@@ -108,14 +94,8 @@ fi[[ -x "$VPHONE_CLI" ]] || { echo "[-] cannot find vphone-cli to flip the snapshot" >&2; exit 1; }"$VPHONE_CLI" cfw flip-snapshot "$IMG"-# Drop the extracted CFW input dirs (source .tar.zst re-extracts). VPHONE_KEEP_ARTIFACTS opts out.-if [[ -z "${VPHONE_KEEP_ARTIFACTS:-}" ]]; then- rm -rf "${VM_DIR:?}/cfw_input" "${VM_DIR:?}/cfw_jb_input"-fi-# The whole install ran as root (owners-honored mounts / chown / cp). Hand the-# host-side artifacts it created (vm/.vphoned.signed, vm/.cfw_temp, extracted-# cfw_input/cfw_jb_input) back to the invoking user, so the subsequent user-run+# host-side artifacts it created (vm/.vphoned.signed and vm/.cfw_temp) back to the invoking user, so the subsequent user-run# steps (make boot / setup_machine first boot, which rewrite# vm/.vphoned.signed) don't hit "Permission denied".#diff --git a/scripts/cfw_install_jb.sh b/scripts/cfw_install_jb.shindex 300ef02d..015d9593 100755--- a/scripts/cfw_install_jb.sh+++ b/scripts/cfw_install_jb.sh@@ -1,490 +1,86 @@#!/bin/zsh# vphone-tier: dist-# cfw_install_jb.sh — Install base CFW + JB extensions on vphone.-#-# Runs the base CFW installer first (phases 1-7), then applies JB-specific-# modifications: launchd jetsam patch, dylib injection, procursus bootstrap,-# and BaseBin hook deployment. Files are placed directly on the VM's Disk.img-# volumes, which cfw_install_host.sh attaches and mounts on the host; VM off.-#-# Prerequisites (in addition to cfw_install.sh requirements):-# - cfw_jb_input/ or resources/cfw_jb_input.tar.zst present-#-# Usage: make cfw_install_jb+# Install the JB-specific system patches after the base CFW and vphoned.+# User package managers, bootstrap payloads, and first-boot installers are out+# of scope: the guest is left empty except for the required daemon.set -euo pipefail-# ── Restore caller's PATH — Nix /etc/zshenv resets PATH on zsh startup ─[[ -n "${_VPHONE_PATH:-}" ]] && export PATH="$_VPHONE_PATH"-VM_DIR="${1:-.}"SCRIPT_DIR="${0:a:h}"+VM_DIR="${1:-.}"+VM_DIR="$(cd "$VM_DIR" && pwd -P)"-# ── vphone-cli resolver — the Swift CFW patchers the JB phases call ─-# Same order as scripts/cfw_install_host.sh and cfw-kit/run.sh: VPHONE_CLI_BIN-# when a vphone-cli subcommand invoked us, otherwise a dev tree or the .app,-# where scripts/ sits in Contents/Resources and the binaries are one level up-# in MacOS. Never `command -v` — the binary has to be the one we built beside-# these scripts, not whatever else is on PATH.-# Resolved up front, before anything is mounted or written: a missing binary-# should stop the run here, not halfway through JB-1 with volumes attached.VPHONE_CLI="${VPHONE_CLI_BIN:-}"if [[ -z "$VPHONE_CLI" ]]; thenfor candidate in "${SCRIPT_DIR:h}/.build/release/vphone-cli" "${SCRIPT_DIR:h:h}/MacOS/vphone-cli"; do[[ -x "$candidate" ]] && { VPHONE_CLI="$candidate"; break }donefi-[[ -x "$VPHONE_CLI" ]] || {- echo "[-] cannot find vphone-cli (the JB phases need it) — run 'make build'" >&2- exit 1-}+[[ -x "$VPHONE_CLI" ]] || { echo "[-] vphone-cli is missing — run make build" >&2; exit 1; }-# Siblings of the binary just resolved, never PATH. See cfw_install.sh.-VPHONE_ARCHIVE="${VPHONE_CLI:h}/vphone-archive"-[[ -x "$VPHONE_ARCHIVE" ]] || {- echo "[-] cannot find vphone-archive beside $VPHONE_CLI — run 'make build'" >&2- exit 1-}-# The guest binaries this variant installs — TweakLoader.dylib and vpregister —-# are cross-compiled at build time (scripts/guest_binaries.mk) and shipped.-GUEST_BIN=""-for candidate in "${SCRIPT_DIR:h}/guest" "${SCRIPT_DIR:h}/.build/guest"; do- [[ -d "$candidate" ]] && { GUEST_BIN="$candidate"; break }-done--# ════════════════════════════════════════════════════════════════-# Step 1: Run base CFW install, then continue with JB phases-# ════════════════════════════════════════════════════════════════-echo "[*] cfw_install_jb.sh — Installing CFW + JB extensions..."-echo ""+echo "[*] Installing JB CFW and vphoned..."zsh "$SCRIPT_DIR/cfw_install.sh" "$VM_DIR"-# ════════════════════════════════════════════════════════════════-# Step 2: JB-specific phases-# ════════════════════════════════════════════════════════════════--# Resolve absolute paths (same as base script)-VM_DIR="$(cd "${VM_DIR}" && pwd)"--# ── Configuration ───────────────────────────────────────────────-CFW_INPUT="cfw_input"-CFW_JB_INPUT="cfw_jb_input"-CFW_JB_ARCHIVE="cfw_jb_input.tar.zst"-TEMP_DIR="$VM_DIR/.cfw_temp"-DISABLE_LAUNCHD_HOOK="${DISABLE_LAUNCHD_HOOK:-0}"--# ── Helpers ─────────────────────────────────────────────────────-die() {- echo "[-] $*" >&2- exit 1-}--check_prerequisites() {- # ldid and xcrun used to be checked here. Neither is reachable from this- # script any more: signing is `vphone-cli sign` (see cfw_install.sh), and- # the two guest binaries below are cross-compiled at build time rather than- # here, so no iPhoneOS SDK is needed on the machine running the install.- [[ -n "$GUEST_BIN" ]] || die "no prebuilt guest binaries — run 'make build'"-}--guest_sign() {- local file="$1" bundle_id="${2:-}"- local args=(--merge --pkcs12 "$VM_DIR/$CFW_INPUT/signcert.p12")- [[ -n "$bundle_id" ]] && args+=(--identifier "$bundle_id")- "$VPHONE_CLI" sign "${args[@]}" "$file"-}--guest_sign_ent() {- local file="$1" entitlements_plist="$2" bundle_id="${3:-}"- local args=(--entitlements "$entitlements_plist" --pkcs12 "$VM_DIR/$CFW_INPUT/signcert.p12")- [[ -n "$bundle_id" ]] && args+=(--identifier "$bundle_id")- "$VPHONE_CLI" sign "${args[@]}" "$file"-}--# `ldid -S<ent> -M`: entitlements captured off the original binary, merged back-# over whatever the patched one carries.-guest_sign_ent_merge() {- "$VPHONE_CLI" sign --entitlements "$2" --merge \- --pkcs12 "$VM_DIR/$CFW_INPUT/signcert.p12" "$1"-}--guest_entitlements() {- "$VPHONE_CLI" dump-entitlements "$1"-}--guest_untar() { # guest_untar <archive> <dest> [extra flags…]- local archive="$1" dest="$2"; shift 2- "$VPHONE_ARCHIVE" extract -f "$archive" -C "$dest" "$@"-}--# TweakLoader — arm64 + arm64e, built by scripts/guest_binaries.mk. This used to-# compile TweakLoader.m through `xcrun --sdk iphoneos`, which meant a user who-# only wanted to run a VM still had to install Xcode. Signing stays, because it-# uses this VM's own signcert.-stage_tweakloader() {- local src="$GUEST_BIN/TweakLoader.dylib"- local out="$TEMP_DIR/TweakLoader.dylib"- [[ -f "$src" ]] || die "Missing prebuilt TweakLoader.dylib at $src — run 'make build'"- cp -f "$src" "$out"- guest_sign "$out"- echo "$out"-}--# vpregister — registers JB app bundles via the containerized LaunchServices-# API on iOS 27, where -[LSApplicationWorkspace registerApplicationDictionary:]-# (uicache -a) is a deprecated no-op stub. Needs the lsd embedded-reg gate patch-# (cfw_patch_lsd_embedded_reg, applied by cfw_install.sh). Deployed to /cores and-# invoked by vphone_jb_setup.sh at first boot.-stage_vpregister() {- local src="$GUEST_BIN/vpregister"- local out="$TEMP_DIR/vpregister"- [[ -f "$src" ]] || die "Missing prebuilt vpregister at $src — run 'make build'"- cp -f "$src" "$out"- guest_sign_ent "$out" "$SCRIPT_DIR/vphoned/entitlements.plist"- echo "$out"-}--get_boot_manifest_hash() {- /bin/ls $MNT5 2>/dev/null | awk 'length($0)==96{print; exit}'-}--# ── Setup JB input resources ──────────────────────────────────-setup_cfw_jb_input() {- [[ -d "$VM_DIR/$CFW_JB_INPUT" ]] && return- local archive- for search_dir in "$SCRIPT_DIR/resources" "$SCRIPT_DIR" "$VM_DIR"; do- archive="$search_dir/$CFW_JB_ARCHIVE"- if [[ -f "$archive" ]]; then- echo " Extracting $CFW_JB_ARCHIVE..."- guest_untar "$archive" "$VM_DIR"- return- fi- done- die "JB mode: neither $CFW_JB_INPUT/ nor $CFW_JB_ARCHIVE found"-}--# ── Apply dev overlay (replace rpcserver_ios in iosbinpack64) ──-apply_dev_overlay() {- local dev_bin- for search_dir in "$SCRIPT_DIR/resources/cfw_dev" "$SCRIPT_DIR/cfw_dev"; do- dev_bin="$search_dir/rpcserver_ios"- if [[ -f "$dev_bin" ]]; then- echo " Applying dev overlay (rpcserver_ios)..."- local iosbinpack="$VM_DIR/$CFW_INPUT/jb/iosbinpack64.tar"- local tmpdir="$VM_DIR/.iosbinpack_tmp"- mkdir -p "$tmpdir"- guest_untar "$iosbinpack" "$tmpdir"- cp "$dev_bin" "$tmpdir/iosbinpack64/usr/local/bin/rpcserver_ios"- # -C "$tmpdir" packs what is under it, and the only thing under it- # is iosbinpack64/ — the same single top-level member `tar -cf …- # iosbinpack64` from inside $tmpdir produced.- "$VPHONE_ARCHIVE" create -f "$iosbinpack" -C "$tmpdir"- rm -rf "$tmpdir"- return- fi- done- die "Dev overlay not found (cfw_dev/rpcserver_ios)"-}--# The VM's Disk.img is attached on the host by cfw_install_host.sh; its APFS-# volumes are mounted here and every file is placed with plain cp/chmod/etc.-# (the VM is off — nothing runs "on the device").: "${CFW_HOST_CONTAINER:?CFW_HOST_CONTAINER unset — run via cfw_install_host.sh}"HOST_MNT="${CFW_HOST_MNT:-/private/tmp/cfwhost}"-MNT1="$HOST_MNT/mnt1" # disk1s1 (System / rootfs)-MNT3="$HOST_MNT/mnt3" # disk1s3-MNT5="$HOST_MNT/mnt5" # disk1s5 (per-boot-manifest OS dir / procursus bootstrap)-mkdir -p "$HOST_MNT"--# Mount an APFS volume of the attached image container at a host mount point.-mount_vol() { # mount_vol <slice, e.g. s1> <mountpoint> [opts]- local dev="/dev/${CFW_HOST_CONTAINER}$1" mnt="$2" opts="${3:-rw}"- /bin/mkdir -p "$mnt"- /sbin/mount | /usr/bin/grep -q " on $mnt " && return 0- /sbin/mount_apfs -o "$opts" "$dev" "$mnt" 2>/dev/null || true- /sbin/mount | /usr/bin/grep -q " on $mnt " || die "mount failed: $dev -> $mnt"+MNT1="$HOST_MNT/mnt1"+TEMP_DIR="$VM_DIR/.cfw_temp"+/bin/mkdir -p "$MNT1" "$TEMP_DIR"+cleanup() {+ /sbin/umount "$MNT1" 2>/dev/null || true+ /bin/rm -rf "$TEMP_DIR"}+trap cleanup EXIT-# ── Check JB prerequisites ────────────────────────────────────-# zstd(1) used to be required here for the bootstrap. vphone-archive links-# libzstd and decompresses in-process, so the check below is the only one left.--setup_cfw_jb_input-JB_INPUT_DIR="$VM_DIR/$CFW_JB_INPUT"-echo ""-echo "[+] JB input resources: $JB_INPUT_DIR"-check_prerequisites--mkdir -p "$TEMP_DIR"--# Mount the image's System volume (may already be mounted from base install)-mount_vol s1 "$MNT1"--# ═══════════ JB-1 PATCH LAUNCHD (JETSAM + DYLIB INJECTION) ════-echo ""-echo "[JB-1] Patching launchd (jetsam guard + hook injection)..."--if ! [[ -e "$MNT1/sbin/launchd.bak" ]]; then- echo " Creating backup..."- /bin/cp $MNT1/sbin/launchd $MNT1/sbin/launchd.bak+if ! /sbin/mount | /usr/bin/grep -q " on $MNT1 "; then+ /sbin/mount_apfs -o rw "/dev/${CFW_HOST_CONTAINER}s1" "$MNT1"fi-cp "$MNT1/sbin/launchd.bak" "$TEMP_DIR/launchd"--# Extract original entitlements before patching (must preserve for spawn permissions)-echo " Extracting original entitlements..."-guest_entitlements "$TEMP_DIR/launchd" > "$TEMP_DIR/launchd.entitlements" 2>/dev/null || true+echo "[*] Patching launchd jetsam guard..."+LAUNCHD="$MNT1/sbin/launchd"+[[ -f "$LAUNCHD.bak" ]] || /bin/cp "$LAUNCHD" "$LAUNCHD.bak"+/bin/cp "$LAUNCHD.bak" "$TEMP_DIR/launchd"+"$VPHONE_CLI" dump-entitlements "$TEMP_DIR/launchd" > "$TEMP_DIR/launchd.entitlements" 2>/dev/null || true+"$VPHONE_CLI" cfw patch-launchd-jetsam "$TEMP_DIR/launchd"if [[ -s "$TEMP_DIR/launchd.entitlements" ]]; then- echo " [+] Preserved launchd entitlements"+ "$VPHONE_CLI" sign --entitlements "$TEMP_DIR/launchd.entitlements" --merge "$TEMP_DIR/launchd"else- echo " [!] No entitlements found on original launchd"+ "$VPHONE_CLI" sign --merge "$TEMP_DIR/launchd"fi--# Injecting launchdhook into pid 1 is on by default. This boot-critical hook-# path has produced boot-analysis failures; set DISABLE_LAUNCHD_HOOK=1 to keep-# BaseBin deployed without loading /b from launchd.-if [[ "$DISABLE_LAUNCHD_HOOK" == "1" ]]; then- echo " [*] Skipping launchdhook dylib injection (DISABLE_LAUNCHD_HOOK=1)"-elif [[ -d "$JB_INPUT_DIR/basebin" ]]; then- echo " Injecting weak dylib load for /b (short launchdhook alias)..."- # Stays exactly here: the injector leaves launchd unsigned, so it has to- # run after the `ldid -e` entitlement capture above and before the- # patch-launchd-jetsam + ldid re-sign below.- "$VPHONE_CLI" cfw inject-dylib "$TEMP_DIR/launchd" "/b"+/bin/cp "$TEMP_DIR/launchd" "$LAUNCHD"+/bin/chmod 0755 "$LAUNCHD"++echo "[*] Patching debugserver entitlements..."+DEBUGSERVER="$MNT1/usr/libexec/debugserver"+if [[ -f "$DEBUGSERVER" ]]; then+ /bin/cp "$DEBUGSERVER" "$TEMP_DIR/debugserver"+ "$VPHONE_CLI" dump-entitlements "$TEMP_DIR/debugserver" > "$TEMP_DIR/debugserver.entitlements"+ /usr/bin/plutil -remove seatbelt-profiles "$TEMP_DIR/debugserver.entitlements" 2>/dev/null || true+ /usr/bin/plutil -insert task_for_pid-allow -bool YES "$TEMP_DIR/debugserver.entitlements"+ "$VPHONE_CLI" sign --entitlements "$TEMP_DIR/debugserver.entitlements" --merge "$TEMP_DIR/debugserver"+ /bin/cp "$TEMP_DIR/debugserver" "$DEBUGSERVER"+ /bin/chmod 0755 "$DEBUGSERVER"else- echo " [!] BaseBin is missing; skipping launchdhook injection"+ echo "[!] debugserver is absent; entitlement patch skipped" >&2fi-"$VPHONE_CLI" cfw patch-launchd-jetsam "$TEMP_DIR/launchd"--# Re-sign with original entitlements to avoid "operation not permitted" on spawn-if [[ -s "$TEMP_DIR/launchd.entitlements" ]]; then- guest_sign_ent_merge "$TEMP_DIR/launchd" "$TEMP_DIR/launchd.entitlements"-else- guest_sign "$TEMP_DIR/launchd"-fi-cp -R "$TEMP_DIR/launchd" "$MNT1/sbin/launchd"-/bin/chmod 0755 $MNT1/sbin/launchd--echo " [+] launchd patched"--# ═══════════ JB-2 INSTALL IOSBINPACK64 ════════════════════════-echo ""-echo "[JB-2] Installing iosbinpack64..."--apply_dev_overlay-cp -R "$VM_DIR/$CFW_INPUT/jb/iosbinpack64.tar" "$MNT1"-guest_untar "$MNT1/iosbinpack64.tar" "$MNT1" --preserve-permissions --no-overwrite-dir-/bin/rm -f $MNT1/iosbinpack64.tar--echo " [+] iosbinpack64 installed"--# ═══════════ JB-3 PATCH debugserver entitlements ════-echo ""-echo "[JB-3] Patching debugserver entitlements..."--cp "$MNT1/usr/libexec/debugserver" "$TEMP_DIR/debugserver"-guest_entitlements "$TEMP_DIR/debugserver" > "$TEMP_DIR/debugserver-entitlements.plist"-plutil -remove seatbelt-profiles "$TEMP_DIR/debugserver-entitlements.plist" || true-plutil -insert task_for_pid-allow -bool YES "$TEMP_DIR/debugserver-entitlements.plist" || true-guest_sign_ent "$TEMP_DIR/debugserver" "$TEMP_DIR/debugserver-entitlements.plist"-cp -R "$TEMP_DIR/debugserver" "$MNT1/usr/libexec/debugserver"-/bin/chmod 0755 $MNT1/usr/libexec/debugserver--echo " [+] debugserver entitlements patched"---# ═══════════ JB-3b CAMPO SANDBOX FIX (iOS 27 only) ════════════-# Grant Campo the backboard/frontboard mach-lookups the 26.4 temporary-sandbox denies (see 0_binary_patch_comparison.md #14).-# 27-gated on the mounted rootfs SystemVersion.plist (same source as vpregister/DSC gates): 26.x userlands don't need it and Campo.app exists there too.-CAMPO_BIN="$MNT1/Applications/Campo.app/Campo"-BASE_IOS=$(/usr/bin/plutil -extract ProductVersion raw -o - "$MNT1/System/Library/CoreServices/SystemVersion.plist" 2>/dev/null || true)-case "$BASE_IOS" in-27.*)- if [[ -f "$CAMPO_BIN" ]]; then- echo ""- echo "[JB-3b] Granting Campo backboard/frontboard mach-lookup exceptions (iOS $BASE_IOS)..."- cp "$CAMPO_BIN" "$TEMP_DIR/Campo"- guest_entitlements "$TEMP_DIR/Campo" > "$TEMP_DIR/Campo.entitlements" 2>/dev/null || true+IOS_VERSION=$(/usr/bin/plutil -extract ProductVersion raw -o - \+ "$MNT1/System/Library/CoreServices/SystemVersion.plist" 2>/dev/null || true)+if [[ "$IOS_VERSION" == 27.* ]]; then+ CAMPO="$MNT1/Applications/Campo.app/Campo"+ if [[ -f "$CAMPO" ]]; then+ echo "[*] Patching Campo entitlements for iOS $IOS_VERSION..."+ /bin/cp "$CAMPO" "$TEMP_DIR/Campo"+ "$VPHONE_CLI" dump-entitlements "$TEMP_DIR/Campo" > "$TEMP_DIR/Campo.entitlements" 2>/dev/null || trueif [[ -s "$TEMP_DIR/Campo.entitlements" ]]; then"$VPHONE_CLI" cfw patch-campo-entitlements "$TEMP_DIR/Campo.entitlements"- guest_sign_ent "$TEMP_DIR/Campo" "$TEMP_DIR/Campo.entitlements"- cp -R "$TEMP_DIR/Campo" "$CAMPO_BIN"- /bin/chmod 0755 "$CAMPO_BIN"- echo " [+] Campo re-signed with backboard/frontboard mach-lookup exceptions"+ "$VPHONE_CLI" sign --entitlements "$TEMP_DIR/Campo.entitlements" "$TEMP_DIR/Campo"+ /bin/cp "$TEMP_DIR/Campo" "$CAMPO"+ /bin/chmod 0755 "$CAMPO"else- echo " [!] Could not read Campo entitlements; skipping Campo sandbox fix"+ echo "[!] Campo has no readable entitlements; patch skipped" >&2fi- else- echo "[JB-3b] Campo.app not present in this OS image; skipping Campo sandbox fix"- fi- ;;-*)- echo "[JB-3b] skip Campo sandbox fix (base iOS ${BASE_IOS:-unknown} — 27-only)"- ;;-esac---# ═══════════ JB-4 INSTALL PROCURSUS BOOTSTRAP ══════════════════-echo ""-echo "[JB-4] Installing procursus bootstrap..."--mount_vol s5 "$MNT5"-BOOT_HASH="$(get_boot_manifest_hash)"-[[ -n "$BOOT_HASH" ]] || die "Could not find 96-char boot manifest hash in $MNT5"-echo " Boot manifest hash: $BOOT_HASH"--BOOTSTRAP_ZST="$JB_INPUT_DIR/jb/bootstrap-iphoneos-arm64.tar.zst"-SILEO_DEB="$JB_INPUT_DIR/jb/org.coolstar.sileo_2.5.1_iphoneos-arm64.deb"-[[ -f "$BOOTSTRAP_ZST" ]] || die "Missing $BOOTSTRAP_ZST"--BOOTSTRAP_TAR="$TEMP_DIR/bootstrap-iphoneos-arm64.tar"-"$VPHONE_ARCHIVE" decompress -f "$BOOTSTRAP_ZST" -o "$BOOTSTRAP_TAR"--cp -R "$BOOTSTRAP_TAR" "$MNT5/$BOOT_HASH/bootstrap-iphoneos-arm64.tar"-if [[ -f "$SILEO_DEB" ]]; then- cp -R "$SILEO_DEB" "$MNT5/$BOOT_HASH/org.coolstar.sileo_2.5.1_iphoneos-arm64.deb"-fi--# ── Extra debs: download from manifest, then stage the whole cache ──────-echo " Fetching extra debs..."-zsh "$SCRIPT_DIR/fetch_debs.sh" || true-DEBS_CACHE="${VPHONE_DEBS_DIR:-${SCRIPT_DIR:h}/debs}"-DEBS_DEST="$MNT5/$BOOT_HASH/debs"-/bin/rm -rf "$DEBS_DEST"-deb_count=0-for deb in "$DEBS_CACHE"/*.deb(N); do- (( deb_count == 0 )) && /bin/mkdir -p "$DEBS_DEST"- cp -R "$deb" "$DEBS_DEST/"- deb_count=$((deb_count + 1))-done-if (( deb_count > 0 )); then- echo " [+] Staged $deb_count extra deb(s) for first-boot install"-else- echo " [=] No extra debs to stage"-fi--JB_DIR_NAME="jb-vphone"-/bin/rm -rf $MNT5/$BOOT_HASH/jb-/bin/rm -rf $MNT5/$BOOT_HASH/$JB_DIR_NAME-/bin/mkdir -p $MNT5/$BOOT_HASH/$JB_DIR_NAME-/bin/chmod 0755 $MNT5/$BOOT_HASH/$JB_DIR_NAME-/usr/sbin/chown 0:0 $MNT5/$BOOT_HASH/$JB_DIR_NAME-guest_untar "$MNT5/$BOOT_HASH/bootstrap-iphoneos-arm64.tar" \- "$MNT5/$BOOT_HASH/$JB_DIR_NAME/" --preserve-permissions-/bin/mv $MNT5/$BOOT_HASH/$JB_DIR_NAME/var $MNT5/$BOOT_HASH/$JB_DIR_NAME/procursus-mv "$MNT5/$BOOT_HASH/$JB_DIR_NAME/procursus/jb"/*(N) "$MNT5/$BOOT_HASH/$JB_DIR_NAME/procursus" 2>/dev/null || true-/bin/rm -rf $MNT5/$BOOT_HASH/$JB_DIR_NAME/procursus/jb-/bin/rm -f $MNT5/$BOOT_HASH/bootstrap-iphoneos-arm64.tar-rm -f "$BOOTSTRAP_TAR"--# NOTE: /var/jb symlink is created on first normal boot by vphone_jb_setup.sh-# (Data volume is encrypted and not mountable at install time).--echo " [+] procursus bootstrap installed"--# ═══════════ JB-4 DEPLOY BASEBIN HOOKS ═════════════════════════-BASEBIN_DIR="$JB_INPUT_DIR/basebin"--if [[ -d "$BASEBIN_DIR" ]]; then- echo ""- echo "[JB-4] Deploying BaseBin hooks to /cores/..."-- # Clean previous dylibs before re-uploading- echo " Cleaning old /cores/ dylibs..."- /bin/rm -rf $MNT1/cores- /bin/mkdir -p $MNT1/cores- /bin/chmod 0755 $MNT1/cores-- # Install all pre-built dylibs from basebin payload- for dylib in "$BASEBIN_DIR"/*.dylib; do- [[ -f "$dylib" ]] || continue- dylib_name="$(basename "$dylib")"- echo " Installing $dylib_name..."- guest_sign "$dylib"- cp -R "$dylib" "$MNT1/cores/$dylib_name"- /bin/chmod 0755 $MNT1/cores/$dylib_name- done-- # Short alias for launchdhook (header space is tight)- if [[ -f "$BASEBIN_DIR/launchdhook.dylib" ]]; then- echo " Installing short launchdhook alias at /b..."- cp "$BASEBIN_DIR/launchdhook.dylib" "$TEMP_DIR/b"- guest_sign "$TEMP_DIR/b"- /bin/rm -f $MNT1/b- cp -R "$TEMP_DIR/b" "$MNT1/b"- /bin/chmod 0755 $MNT1/bfi-- echo " [+] BaseBin hooks deployed"fi-# ═══════════ JB-4 INSTALL TWEAKLOADER ════════════════════════════-echo ""-echo "[JB-4] Building and installing TweakLoader..."--TWEAKLOADER_OUT="$(stage_tweakloader)"-/bin/mkdir -p $MNT5/$BOOT_HASH/$JB_DIR_NAME/procursus/usr/lib-cp -R "$TWEAKLOADER_OUT" "$MNT5/$BOOT_HASH/$JB_DIR_NAME/procursus/usr/lib/TweakLoader.dylib"-/usr/sbin/chown 0:0 $MNT5/$BOOT_HASH/$JB_DIR_NAME/procursus/usr/lib/TweakLoader.dylib-/bin/chmod 0755 $MNT5/$BOOT_HASH/$JB_DIR_NAME/procursus/usr/lib/TweakLoader.dylib--echo " [+] TweakLoader installed to procursus/usr/lib/TweakLoader.dylib"--# ═══════════ JB-5 DEPLOY FIRST-BOOT SETUP ══════════════════════-echo ""-echo "[JB-5] Deploying first-boot setup..."--# Deploy first-boot JB setup script + LaunchDaemon-SETUP_SCRIPT="$SCRIPT_DIR/vphone_jb_setup.sh"-SETUP_PLIST="$SCRIPT_DIR/vphone_jb_setup.plist"-if [[ -f "$SETUP_SCRIPT" ]]; then- cp -R "$SETUP_SCRIPT" "$MNT1/cores/vphone_jb_setup.sh"- /bin/chmod 0755 $MNT1/cores/vphone_jb_setup.sh- echo " [+] vphone_jb_setup.sh -> /cores/"-fi-# vpregister: registers JB apps via the containerized LS API at first boot (uicache -a's-# registerApplicationDictionary is a deprecated no-op on iOS 27). Deployed ONLY on a 27-# base — it needs the 27-only lsd embedded-reg gate, and on 26.x/18.x uicache registers-# apps normally. Its /cores presence IS the runtime gate in vphone_jb_setup.sh (that-# script must NOT version-check on guest sw_vers — the hybrid guest does not reliably-# report the 27 userland version at first boot). Version read from the mounted rootfs-# SystemVersion.plist, the same source cfw_install.sh gates its 27 patches on.-case "$BASE_IOS" in- 27.*)- VPREGISTER="$(stage_vpregister)"- if [[ -f "$VPREGISTER" ]]; then- cp -R "$VPREGISTER" "$MNT1/cores/vpregister"- /bin/chmod 0755 $MNT1/cores/vpregister- echo " [+] vpregister -> /cores/ (iOS $BASE_IOS)"- fi- ;;- *)- echo " [skip] vpregister (base iOS ${BASE_IOS:-unknown} — 27-only; uicache registers apps on older bases)"- ;;-esac-if [[ -f "$SETUP_PLIST" ]]; then- cp -R "$SETUP_PLIST" "$MNT1/System/Library/LaunchDaemons/com.vphone.jb-setup.plist"- /bin/chmod 0644 $MNT1/System/Library/LaunchDaemons/com.vphone.jb-setup.plist-- # Inject into launchd.plist so launchd starts it at boot- echo " Injecting com.vphone.jb-setup into launchd.plist..."- cp "$MNT1/System/Library/xpc/launchd.plist" "$TEMP_DIR/launchd.plist"- "$VPHONE_CLI" cfw inject-daemon "$TEMP_DIR/launchd.plist" "$SETUP_PLIST" --name com.vphone.jb-setup- cp -R "$TEMP_DIR/launchd.plist" "$MNT1/System/Library/xpc/launchd.plist"- /bin/chmod 0644 $MNT1/System/Library/xpc/launchd.plist- echo " [+] com.vphone.jb-setup.plist injected into launchd.plist"-fi--# ═══════════ CLEANUP ═════════════════════════════════════════-echo ""-echo "[*] Unmounting image volumes..."-/sbin/umount $MNT1 2>/dev/null || true-/sbin/umount $MNT3 2>/dev/null || true-/sbin/umount $MNT5 2>/dev/null || true--echo "[*] Cleaning up temp..."-rm -rf "$TEMP_DIR"--echo ""-echo "[+] CFW + JB installation complete!"-echo " Boot to apply changes."-echo " After boot, SSH will be available on port 22222 (password: alpine)"+echo "[+] JB system patches installed; no bootstrap payload staged."diff --git a/scripts/dist_manifest.sh b/scripts/dist_manifest.shindex 62390161..7dbbc40d 100755--- a/scripts/dist_manifest.sh+++ b/scripts/dist_manifest.sh@@ -63,10 +63,6 @@ done# artifacts ship in Contents/Resources/guest instead, so the# install needs no iPhoneOS SDK# vphoned/*.m *.h vendor/ Makefile same, and it is the bulk of scripts/-print -r -- "resources" # cfw_input*.tar.zst + cfw_dev/, read by setup_cfw_input+print -r -- "payloads/AppleParavirtGPUMetalIOGPUFamily.tar" # guest GPU driverprint -r -- "vphoned/vphoned.plist" # LaunchDaemon plist, injectLaunchDaemons-print -r -- "vphoned/entitlements.plist" # guest_sign_ent for vphoned and vpregister-print -r -- "vphoned/signcert.p12" # VPhoneResources.signcert, for live installs-print -r -- "vphone_jb_setup.plist" # LaunchDaemon that runs vphone_jb_setup.sh-print -r -- "camfix/libcamfix.plist" # companion plist, copied beside the dylib-print -r -- "vcamcaptured/libvcamcaptured.plist"+print -r -- "vphoned/entitlements.plist" # guest_sign_ent for vphoneddiff --git a/scripts/fetch_debs.sh b/scripts/fetch_debs.shdeleted file mode 100755index c5f17b20..00000000--- a/scripts/fetch_debs.sh+++ /dev/null@@ -1,124 +0,0 @@-#!/bin/zsh-# vphone-tier: dist-# fetch_debs.sh — Download debs from a URL manifest into a cache dir.-# Skips files already cached; leaves manually-added debs alone. A failed-# download is reported and skipped, never fatal (always exits 0).-#-# Usage: fetch_debs.sh [cache_dir] [manifest_file]-# defaults: <repo>/debs and <repo>/debs.list--set -uo pipefail--[[ -n "${_VPHONE_PATH:-}" ]] && export PATH="$_VPHONE_PATH"--SCRIPT_DIR="${0:a:h}"-REPO_ROOT="${SCRIPT_DIR:h}"--# VPHONE_DEBS_DIR (set by the app to a writable ~/.vphone/debs) keeps the cache-# out of the read-only .app bundle; the manifest is bundled next to this script's-# repo/Resources root, so $REPO_ROOT/debs.list resolves in both dev and .app.-CACHE_DIR="${1:-${VPHONE_DEBS_DIR:-$REPO_ROOT/debs}}"-MANIFEST="${2:-$REPO_ROOT/debs.list}"--mkdir -p "$CACHE_DIR"--deb_filename_from_url() {- local url="$1"- url="${url%%\#*}"- url="${url%%\?*}"- print -r -- "${url##*/}"-}--downloaded=0-cached=0-failed=0--if [[ -f "$MANIFEST" ]]; then- while IFS= read -r line || [[ -n "$line" ]]; do- line="${line#"${line%%[![:space:]]*}"}"- line="${line%"${line##*[![:space:]]}"}"- [[ -z "$line" || "$line" == \#* ]] && continue-- name="$(deb_filename_from_url "$line")"- if [[ "$name" != *.deb ]]; then- echo " [!] ERROR: URL does not resolve to a .deb filename, skipping: $line" >&2- failed=$((failed + 1))- continue- fi-- dest="$CACHE_DIR/$name"- if [[ -s "$dest" ]]; then- echo " [=] Cached: $name"- cached=$((cached + 1))- continue- fi-- echo " [>] Downloading: $line"- tmp="$dest.download"- if curl -fL --retry 2 --connect-timeout 20 \- --speed-limit 1024 --speed-time 30 -o "$tmp" "$line"; then- mv -f "$tmp" "$dest"- echo " [+] Downloaded: $name"- downloaded=$((downloaded + 1))- else- rc=$?- rm -f "$tmp"- echo " [!] ERROR: download failed (curl exit $rc), skipping: $line" >&2- failed=$((failed + 1))- fi- done < "$MANIFEST"-else- echo " [=] No manifest at $MANIFEST (skipping downloads)"-fi--# Opt-in (vm create --frida): fetch the latest Frida iOS release deb. It's-# re.frida.server (no deps, rootless layout), so the first-boot dpkg -i handles it.-if [[ "${VPHONE_FRIDA:-0}" == "1" ]]; then- echo " [>] Resolving latest Frida iOS release..."- frida_url="$(curl -fsSL --connect-timeout 20 \- https://api.github.com/repos/frida/frida/releases/latest 2>/dev/null \- | grep -o 'https://[^"]*/frida_[^"]*_iphoneos-arm64\.deb' | head -1)"- if [[ -n "$frida_url" ]]; then- frida_name="$(deb_filename_from_url "$frida_url")"- # Keep only one Frida deb in the cache so a newer "latest" fully replaces- # any previously-pinned version at install time.- for old in "$CACHE_DIR"/frida_*_iphoneos-arm64.deb(N); do- [[ "${old:t}" == "$frida_name" ]] || rm -f "$old"- done- dest="$CACHE_DIR/$frida_name"- if [[ -s "$dest" ]]; then- echo " [=] Cached: $frida_name"- cached=$((cached + 1))- else- echo " [>] Downloading: $frida_url"- tmp="$dest.download"- if curl -fL --retry 2 --connect-timeout 20 -o "$tmp" "$frida_url"; then- mv -f "$tmp" "$dest"- echo " [+] Downloaded: $frida_name"- downloaded=$((downloaded + 1))- else- rc=$?- rm -f "$tmp"- echo " [!] ERROR: Frida download failed (curl exit $rc), skipping" >&2- failed=$((failed + 1))- fi- fi- else- echo " [!] ERROR: could not resolve latest Frida iOS deb URL, skipping" >&2- failed=$((failed + 1))- fi-fi--total=0-for f in "$CACHE_DIR"/*.deb(N); do- total=$((total + 1))-done--echo " [i] debs: $total in cache ($downloaded downloaded, $cached already cached, $failed failed)"--# Return the cache to the invoking user when run under sudo.-if [[ "$(id -u)" == "0" && -n "${SUDO_USER:-}" ]]; then- chown -R "$SUDO_USER" "$CACHE_DIR" 2>/dev/null || true-fi--exit 0diff --git a/scripts/guest_binaries.mk b/scripts/guest_binaries.mkindex f327da7e..97345b8b 100644--- a/scripts/guest_binaries.mk+++ b/scripts/guest_binaries.mk@@ -1,157 +1,20 @@-# guest_binaries.mk — the five iOS binaries the CFW installers put in the guest,-# cross-compiled HERE, at build time, instead of on the user's machine at install-# time.-## vphone-tier: build-#-# Every one of these used to be compiled by the installer itself, from a `.m`-# file shipped inside the .app, through `xcrun --sdk iphoneos -f clang`. That-# made a full Xcode install a runtime prerequisite for `cfw install` — on a-# machine whose only job is to run a VM. It is the plainest violation of the-# dist rule there was: the shipped product reaching for a toolchain that is not-# in the bundle and is not part of macOS.-#-# So the split is: THIS file needs Xcode and the iPhoneOS SDK, and runs on the-# machine that builds the .app. The installers get the finished Mach-Os and only-# sign them, because signing is the one step that genuinely cannot move here —-# it uses the signing certificate from the target VM's own cfw_input, which does-# not exist until a VM does.-#-# Included by the top-level Makefile; `scripts/build.sh` drives it directly with-# `make -f`. Both put the results in $(GUEST_DIR), and both stage that directory-# into the bundle as Contents/Resources/guest.+# Compile the only guest binary shipped by the JB runtime. This runs on the+# build machine, where Xcode and the iPhoneOS SDK are allowed.GUEST_DIR ?= .build/guest-GIT_HASH ?= unknown--# Resolved once. `xcrun` is allowed here and nowhere downstream; if it is-# missing, this is the file that says so, with the reason.-IOS_SDK := $(shell xcrun --sdk iphoneos --show-sdk-path 2>/dev/null)-IOS_CC := $(shell xcrun --sdk iphoneos -f clang 2>/dev/null)--# 15.0 on every one of them, matching what the installers passed. Raising it-# here silently drops support for the older guest bases the JB variant still-# installs onto.-IOS_MIN := -miphoneos-version-min=15.0-IOS_CFLAGS = -isysroot $(IOS_SDK) $(IOS_MIN) -fobjc-arc--GUEST_BINARIES := \- $(GUEST_DIR)/TweakLoader.dylib \- $(GUEST_DIR)/vpregister \- $(GUEST_DIR)/libvcamcaptured.dylib \- $(GUEST_DIR)/libcamfix.dylib \- $(GUEST_DIR)/vphoned+GIT_HASH ?= unknown.PHONY: guest_binaries guest_binaries_clean-guest_binaries: $(GUEST_BINARIES)- @echo " guest binaries → $(GUEST_DIR)"+guest_binaries: $(GUEST_DIR)/vphoned+ @echo " guest daemon → $(GUEST_DIR)/vphoned"$(GUEST_DIR):@mkdir -p $(GUEST_DIR)-# A missing SDK has to be caught before the first rule runs a compiler with an-# empty -isysroot, which fails with a wall of missing-header errors that say-# nothing about the real cause.-$(GUEST_BINARIES): | sdk_check $(GUEST_DIR)--.PHONY: sdk_check-sdk_check:- @test -n "$(IOS_SDK)" -a -n "$(IOS_CC)" || ( \- echo "Error: no iPhoneOS SDK. These are the guest binaries that ship" >&2; \- echo " inside the .app, so they are cross-compiled at build time" >&2; \- echo " and the build machine needs Xcode. Install it, then:" >&2; \- echo " sudo xcode-select -s /Applications/Xcode.app" >&2; \- exit 1)--# The argument order below is the installers' own, framework list included. It-# looks arbitrary and it is load-bearing: `-framework` order decides-# LC_LOAD_DYLIB order, which decides the indirect symbol table's numbering, so-# reordering the list changes the output bytes for no reason. Keeping it means-# these come out byte-identical to what `cfw install` used to compile on the-# user's machine. Verified: vpregister and libvcamcaptured.dylib are identical;-# TweakLoader.dylib differs in exactly two fields per slice —-#-# LC_UUID clang derives it from the content, so any two links differ-# LC_ID_DYLIB it takes no -install_name, so this defaults to the output-# path. It used to be the installer's own-# <vm>/.cfw_temp/TweakLoader.dylib and is now this stable one.-# Nothing reads it: the guest loads the file by absolute path-# from /var/jb/usr/lib, not through its install name.--# TweakLoader — the substrate-style loader injected into guest processes. Fat:-# arm64 for the older bases, arm64e for iOS 27. No -install_name; the installer-# places it at a path the injected LC_LOAD_DYLIB already names.-$(GUEST_DIR)/TweakLoader.dylib: scripts/tweakloader/TweakLoader.m- @echo "=== Building TweakLoader.dylib (arm64 + arm64e, iphoneos) ==="- @$(IOS_CC) -isysroot $(IOS_SDK) \- -arch arm64 -arch arm64e \- $(IOS_MIN) \- -dynamiclib \- -fobjc-arc -O3 \- -framework Foundation \- -o $@ $<--# vpregister — registers JB app bundles through the containerized LaunchServices-# API on iOS 27, where `uicache -a` is a deprecated no-op stub. arm64e only:-# it runs on 27 or not at all. `-undefined dynamic_lookup` because the private-# LaunchServices symbols it calls are resolved by the guest's dyld.-$(GUEST_DIR)/vpregister: scripts/vpregister/vpregister.m- @echo "=== Building vpregister (arm64e, iphoneos) ==="- @$(IOS_CC) -isysroot $(IOS_SDK) \- -arch arm64e \- $(IOS_MIN) \- -fobjc-arc -Os \- -framework Foundation \- -Wl,-undefined,dynamic_lookup \- -o $@ $<--# libvcamcaptured — loaded into /usr/libexec/cameracaptured via an injected-# LC_LOAD_DYLIB, so the -install_name has to be the guest path exactly.-$(GUEST_DIR)/libvcamcaptured.dylib: scripts/vcamcaptured/libvcamcaptured.m- @echo "=== Building libvcamcaptured.dylib (arm64e, iphoneos) ==="- @$(IOS_CC) -isysroot $(IOS_SDK) \- -arch arm64e \- $(IOS_MIN) \- -dynamiclib \- -fobjc-arc -Os \- -install_name /var/jb/usr/lib/libvcamcaptured.dylib \- -framework CoreMedia \- -framework CoreVideo \- -framework Foundation \- -o $@ $<--# libcamfix — the substrate plugin TweakLoader loads into every AVFoundation-# client. Same rule about -install_name.-$(GUEST_DIR)/libcamfix.dylib: scripts/camfix/libcamfix.m- @echo "=== Building libcamfix.dylib (arm64e, iphoneos) ==="- @$(IOS_CC) -isysroot $(IOS_SDK) \- -arch arm64e \- $(IOS_MIN) \- -dynamiclib \- -fobjc-arc -Os \- -install_name /var/jb/Library/MobileSubstrate/DynamicLibraries/libcamfix.dylib \- -framework AVFoundation \- -framework CoreImage \- -framework CoreGraphics \- -framework CoreMedia \- -framework CoreVideo \- -framework Foundation \- -framework ImageIO \- -framework IOSurface \- -framework MobileCoreServices \- -framework Photos \- -framework QuartzCore \- -framework UIKit \- -o $@ $<--# vphoned keeps its own Makefile — it is a multi-file target with a vendored-# libarchive and a commit hash stamped in, and duplicating that here would be-# two places to get it wrong. This rule only puts the result where the others-# are. It used to be compiled a THIRD time, by FirmwarePatcher's buildVphoned(),-# from sources shipped in the .app; that call is gone and the binary staged here-# is what `cfw install` now deploys.-$(GUEST_DIR)/vphoned: $(wildcard scripts/vphoned/*.m) $(wildcard scripts/vphoned/*.h)+$(GUEST_DIR)/vphoned: $(wildcard scripts/vphoned/*.m) $(wildcard scripts/vphoned/*.h) | $(GUEST_DIR)+ @xcrun --sdk iphoneos --show-sdk-path >/dev/null || (echo "Error: iPhoneOS SDK is required on the build machine" >&2; exit 1)@$(MAKE) --no-print-directory -C scripts/vphoned GIT_HASH=$(GIT_HASH)@cp -f scripts/vphoned/vphoned $@diff --git a/scripts/patch_camera_userland.sh b/scripts/patch_camera_userland.shdeleted file mode 100755index 6d2f1996..00000000--- a/scripts/patch_camera_userland.sh+++ /dev/null@@ -1,62 +0,0 @@-#!/bin/zsh-# vphone-tier: dist-# patch_camera_userland.sh — Apply the Camera.app accessibility DSC patches.-#-# Mirrors patch_hv_vmm_userland.sh's shape so the EXP install pipeline can-# call into both via a single entry-point style. The actual work happens-# in FirmwarePatcher's DSCCameraPatcher, invoked through vphone-cli's-# `cfw patch-camera-dsc` subcommand.-#-# Usage:-# patch_camera_userland.sh dsc <chunks_dir> <dsc_header>-#-# <chunks_dir> is the directory containing dyld_shared_cache_arm64e[.NN]-# files (the mounted SystemOS Cryptex's System/Library/Caches/com.apple.dyld).-# <dsc_header> is the dyld_shared_cache_arm64e file itself (sans suffix),-# used by `ipsw dyld symaddr` for per-build symbol resolution.-#-# Used by: cfw_install_exp.sh--set -euo pipefail--SCRIPT_DIR="${0:a:h}"--[[ -n "${_VPHONE_PATH:-}" ]] && export PATH="$_VPHONE_PATH"--# ── vphone-cli resolver — the patcher lives in it ─-# Same order as scripts/cfw_install_host.sh: VPHONE_CLI_BIN when a vphone-cli-# subcommand invoked us, otherwise a dev tree or the .app, where scripts/ sits-# in Contents/Resources and the binaries are one level up in MacOS.-VPHONE_CLI="${VPHONE_CLI_BIN:-}"-if [[ -z "$VPHONE_CLI" ]]; then- for candidate in "${SCRIPT_DIR:h}/.build/release/vphone-cli" "${SCRIPT_DIR:h:h}/MacOS/vphone-cli"; do- [[ -x "$candidate" ]] && { VPHONE_CLI="$candidate"; break }- done-fi-[[ -x "$VPHONE_CLI" ]] || {- echo "[-] cannot find vphone-cli (the camera DSC patcher lives in it) — run 'make build'" >&2- exit 1-}--usage() {- cat <<EOF >&2-Usage:- $0 dsc <chunks_dir> <dsc_header>-EOF- exit 2-}--(( $# >= 1 )) || usage-op="$1"; shift--case "$op" in- dsc)- (( $# >= 2 )) || usage- echo "[*] Patching camera consumers in DSC chunks under: $1"- echo "[*] (symbol resolution against: $2)"- "$VPHONE_CLI" cfw patch-camera-dsc "$1" "$2"- ;;- *)- usage- ;;-esacdiff --git a/scripts/patch_hv_vmm_userland.sh b/scripts/patch_hv_vmm_userland.shdeleted file mode 100755index 43f799f4..00000000--- a/scripts/patch_hv_vmm_userland.sh+++ /dev/null@@ -1,87 +0,0 @@-#!/bin/zsh-# vphone-tier: dist-# patch_hv_vmm_userland.sh — Apply the user-mode hv_vmm_present patch.-#-# Two operations, chosen by the first arg:-#-# dsc <chunks_dir>-# Patch the canonical sysctlbyname("kern.hv_vmm_present", ...) sites-# inside the DSC chunks at <chunks_dir>. <chunks_dir> is the directory-# holding `dyld_shared_cache_arm64e[.NN]` files, typically the-# mounted SystemOS Cryptex's `System/Library/Caches/com.apple.dyld/`.-# Skips the compute/accel dylibs (CoreML, Espresso, ANE, CoreRE,-# RenderBox, WebGPU, caulk, IOSurfaceAccelerator).-#-# watchdogd <binary>-# Surgical 2-instruction patch of /usr/libexec/watchdogd that-# forces its cached "am I a VM?" byte to 1 regardless of the-# sysctl result. Also re-attests the affected CodeDirectory slot-# hash (the binary stays self-consistent for TXM/SHA-256). Do NOT-# re-sign with ldid — the patcher leaves the original Apple-issued-# code-signing identifier intact, which launchd boot-task identity-# checks require.-#-# This script is a thin wrapper around `vphone-cli cfw`. It exists so-# cfw_install_dev.sh and cfw_install_jb.sh can call a single entry point-# without duplicating the binary-resolution logic.-#-# Used by: cfw_install_dev.sh, cfw_install_jb.sh--set -euo pipefail--SCRIPT_DIR="${0:a:h}"--[[ -n "${_VPHONE_PATH:-}" ]] && export PATH="$_VPHONE_PATH"--# ── vphone-cli resolver — both patchers live in it ─-# Same order as scripts/cfw_install_host.sh: VPHONE_CLI_BIN when a vphone-cli-# subcommand invoked us, otherwise a dev tree or the .app, where scripts/ sits-# in Contents/Resources and the binaries are one level up in MacOS.-VPHONE_CLI="${VPHONE_CLI_BIN:-}"-if [[ -z "$VPHONE_CLI" ]]; then- for candidate in "${SCRIPT_DIR:h}/.build/release/vphone-cli" "${SCRIPT_DIR:h:h}/MacOS/vphone-cli"; do- [[ -x "$candidate" ]] && { VPHONE_CLI="$candidate"; break }- done-fi-[[ -x "$VPHONE_CLI" ]] || {- echo "[-] cannot find vphone-cli (the hv_vmm patchers live in it) — run 'make build'" >&2- exit 1-}--usage() {- cat <<EOF >&2-Usage:- $0 dsc <chunks_dir>- $0 watchdogd <binary>-EOF- exit 2-}--(( $# >= 1 )) || usage-op="$1"; shift--case "$op" in- dsc)- (( $# >= 1 )) || usage- echo "[*] Patching hv_vmm_present consumers in DSC chunks under: $1"- "$VPHONE_CLI" cfw patch-hv-vmm-dsc "$1"- ;;- # `standalone <binary>` used to live here and called- # `patch-hv-vmm`, which no longer exists: that subcommand and its backing- # patcher (cfw_patch_hv_vmm_rootfs.py) were removed, so the op had been- # falling through the unknown-command branch and exiting 1. It is- # deleted rather than retargeted because nothing in the repo invokes it and- # there is no honest substitute — `patch-hv-vmm-dsc` takes a directory of- # DSC chunks, not a Mach-O, and `patch-watchdogd` is specific to- # watchdogd's cached byte. EXP now covers user-mode hv_vmm_present with- # `dsc` (every consumer inside the shared cache) plus `watchdogd` (the one- # standalone binary still holding its own copy).- watchdogd)- (( $# >= 1 )) || usage- echo "[*] Patching watchdogd hv_vmm_present cache in: $1"- "$VPHONE_CLI" cfw patch-watchdogd "$1"- ;;- *)- usage- ;;-esacdiff --git a/scripts/payloads/AppleParavirtGPUMetalIOGPUFamily.tar b/scripts/payloads/AppleParavirtGPUMetalIOGPUFamily.tarnew file mode 100644index 00000000..afa44559Binary files /dev/null and b/scripts/payloads/AppleParavirtGPUMetalIOGPUFamily.tar differdiff --git a/scripts/resources b/scripts/resourcesdeleted file mode 160000index 2ef6b06a..00000000--- a/scripts/resources+++ /dev/null@@ -1 +0,0 @@-Subproject commit 2ef6b06a10cdd7a667d337d50cbdb52fd24249c9diff --git a/scripts/vphone_jb_setup.plist b/scripts/vphone_jb_setup.plistdeleted file mode 100644index 2b985991..00000000--- a/scripts/vphone_jb_setup.plist+++ /dev/null@@ -1,23 +0,0 @@-<?xml version="1.0" encoding="UTF-8"?>-<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">-<plist version="1.0">-<dict>- <key>Label</key>- <string>com.vphone.jb-setup</string>- <key>ProgramArguments</key>- <array>- <string>/iosbinpack64/bin/bash</string>- <string>/cores/vphone_jb_setup.sh</string>- </array>- <key>RunAtLoad</key>- <true/>- <key>StandardOutPath</key>- <string>/var/log/vphone_jb_setup.log</string>- <key>StandardErrorPath</key>- <string>/var/log/vphone_jb_setup.log</string>- <key>UserName</key>- <string>root</string>- <key>EnablePressuredExit</key>- <false/>-</dict>-</plist>diff --git a/scripts/vphone_jb_setup.sh b/scripts/vphone_jb_setup.shdeleted file mode 100755index c3f69ece..00000000--- a/scripts/vphone_jb_setup.sh+++ /dev/null@@ -1,313 +0,0 @@-#!/bin/bash-# vphone-tier: guest-# vphone_jb_setup.sh — First-boot JB finalization script.-#-# Deployed to /cores/ during cfw_install_jb.sh.-# Runs automatically via LaunchDaemon on first normal boot.-# Idempotent — safe to re-run on subsequent boots.-#-# Logs to /var/log/vphone_jb_setup.log for host-side monitoring-# via vphoned file browser.--set -uo pipefail--LOG="/var/log/vphone_jb_setup.log"-DONE_MARKER="/var/mobile/.vphone_jb_setup_done"--export TERM=xterm-256color-export DEBIAN_FRONTEND=noninteractive--# Defined here, not next to log(), because the first call below runs before-# log() exists.-rebuild_jb_path() {- P=""- for d in \- /var/jb/usr/bin /var/jb/bin /var/jb/sbin /var/jb/usr/sbin \- /iosbinpack64/bin /iosbinpack64/usr/bin /iosbinpack64/sbin /iosbinpack64/usr/sbin \- /usr/bin /usr/sbin /bin /sbin; do- [ -d "$d" ] && P="$P:$d"- done- export PATH="${P#:}"-}-rebuild_jb_path--# Redirect all output (stdout+stderr) through tee to the log + console.-exec > >(tee -a "$LOG") 2>&1--# NOTE: log() does NOT pipe through tee — stdout is already tee'd to $LOG by the-# exec above, so a second tee here would double every timestamped line.-log() { echo "[$(date '+%H:%M:%S')] $*"; }-die() { log "FATAL: $*"; exit 1; }--log "=== vphone_jb_setup.sh starting ==="-log "PATH=$PATH"--# ── Check done marker ────────────────────────────────────────-if [ -f "$DONE_MARKER" ]; then- log "Already completed (marker exists), exiting."- exit 0-fi--# ── Find boot manifest hash ─────────────────────────────────-BOOT_HASH=""-for d in /private/preboot/*/; do- b="${d%/}"; b="${b##*/}"- if [ "${#b}" = 96 ]; then- BOOT_HASH="$b"- break- fi-done-[ -n "$BOOT_HASH" ] || die "Could not find 96-char boot manifest hash"-log "Boot hash: $BOOT_HASH"--JB_TARGET="/private/preboot/$BOOT_HASH/jb-vphone/procursus"-[ -d "$JB_TARGET" ] || die "Procursus not found at $JB_TARGET"--# ═══════════ 0/8 REPLACE LAUNCHCTL ═════════════════════════════-# Procursus launchctl crashes (missing _launch_active_user_switch symbol).-# iosbinpack64's launchctl talks to launchd fine and always exits 0,-# which is enough for dpkg postinst/prerm script compatibility.-log "[0/8] Linking iosbinpack64 launchctl into procursus..."-IOSBINPACK_LAUNCHCTL=""-for p in /iosbinpack64/bin/launchctl /iosbinpack64/usr/bin/launchctl; do- [ -f "$p" ] && IOSBINPACK_LAUNCHCTL="$p" && break-done--if [ -n "$IOSBINPACK_LAUNCHCTL" ]; then- if [ -f "$JB_TARGET/usr/bin/launchctl" ] && [ ! -L "$JB_TARGET/usr/bin/launchctl" ] && [ ! -f "$JB_TARGET/usr/bin/launchctl.procursus" ]; then- mv "$JB_TARGET/usr/bin/launchctl" "$JB_TARGET/usr/bin/launchctl.procursus"- log " procursus original saved as launchctl.procursus"- fi- ln -sf "$IOSBINPACK_LAUNCHCTL" "$JB_TARGET/usr/bin/launchctl"- mkdir -p "$JB_TARGET/bin"- ln -sf "$IOSBINPACK_LAUNCHCTL" "$JB_TARGET/bin/launchctl"- log " linked usr/bin/launchctl + bin/launchctl -> $IOSBINPACK_LAUNCHCTL"-else- log " WARNING: iosbinpack64 launchctl not found"-fi--# ═══════════ 1/8 SYMLINK /var/jb ═════════════════════════════-log "[1/8] Creating /private/var/jb symlink..."-CURRENT_LINK=$(readlink /private/var/jb 2>/dev/null || true)-if [ "$CURRENT_LINK" = "$JB_TARGET" ]; then- log " Symlink already correct"-else- ln -sf "$JB_TARGET" /private/var/jb- log " /var/jb -> $JB_TARGET"-fi--# ═══════════ 2/8 FIX OWNERSHIP / PERMISSIONS ═════════════════-log "[2/8] Fixing mobile Library ownership..."-mkdir -p /var/jb/var/mobile/Library/Preferences-mkdir -p /var/jb/Library/MobileSubstrate/DynamicLibraries-chown -R 501:501 /var/jb/var/mobile/Library-chmod 0755 /var/jb/var/mobile/Library-chown -R 501:501 /var/jb/var/mobile/Library/Preferences-chmod 0755 /var/jb/var/mobile/Library/Preferences-chown 0:0 /var/jb/Library /var/jb/Library/MobileSubstrate /var/jb/Library/MobileSubstrate/DynamicLibraries-chmod 0755 /var/jb/Library /var/jb/Library/MobileSubstrate /var/jb/Library/MobileSubstrate/DynamicLibraries-log " Ownership set"--log "[2a/8] Preparing dropbear host keys..."-mkdir -p /var/dropbear-DROPBEARKEY=""-for p in /iosbinpack64/usr/local/bin/dropbearkey /iosbinpack64/usr/local/dropbearkey /var/jb/usr/bin/dropbearkey; do- [ -x "$p" ] && DROPBEARKEY="$p" && break-done-if [ -n "$DROPBEARKEY" ]; then- [ -f /var/dropbear/dropbear_rsa_host_key ] || "$DROPBEARKEY" -t rsa -f /var/dropbear/dropbear_rsa_host_key >/dev/null- [ -f /var/dropbear/dropbear_ecdsa_host_key ] || "$DROPBEARKEY" -t ecdsa -f /var/dropbear/dropbear_ecdsa_host_key >/dev/null- if [ -f /var/dropbear/dropbear_rsa_host_key ] && [ -f /var/dropbear/dropbear_ecdsa_host_key ]; then- if chmod 0600 /var/dropbear/dropbear_rsa_host_key /var/dropbear/dropbear_ecdsa_host_key; then- log " dropbear host keys ready"- else- log " WARNING: dropbear host key chmod failed"- fi- else- log " WARNING: dropbear host key generation incomplete"- fi-else- log " WARNING: dropbearkey not found"-fi--# ═══════════ 3/8 RUN prep_bootstrap.sh ═══════════════════════-log "[3/8] Running prep_bootstrap.sh..."-if [ -f /var/jb/prep_bootstrap.sh ]; then- NO_PASSWORD_PROMPT=1 /var/jb/prep_bootstrap.sh || log " prep_bootstrap.sh exited with $?"- log " prep_bootstrap.sh completed"-else- log " prep_bootstrap.sh already ran (deleted itself), skipping"-fi--# Re-discover PATH after prep_bootstrap-rebuild_jb_path-log " PATH=$PATH"--# ═══════════ 4/8 CREATE MARKER FILES ═════════════════════════-log "[4/8] Creating marker files..."-for marker in .procursus_strapped .installed_dopamine; do- if [ -f "/var/jb/$marker" ]; then- log " $marker already exists"- else- : > "/var/jb/$marker"- chown 0:0 "/var/jb/$marker"- chmod 0644 "/var/jb/$marker"- log " $marker created"- fi-done--# ═══════════ 5/8 INSTALL SILEO ═══════════════════════════════-log "[5/8] Installing Sileo..."-SILEO_DEB_PATH="/private/preboot/$BOOT_HASH/org.coolstar.sileo_2.5.1_iphoneos-arm64.deb"--if dpkg -s org.coolstar.sileo >/dev/null 2>&1; then- log " Sileo already installed"-else- if [ -f "$SILEO_DEB_PATH" ]; then- dpkg -i "$SILEO_DEB_PATH" || log " dpkg -i sileo exited with $?"- log " Sileo installed"- else- log " WARNING: Sileo deb not found at $SILEO_DEB_PATH"- fi-fi--# ═══════════ 5b/8 INSTALL EXTRA DEBS ═════════════════════════-log "[5b/8] Installing extra debs..."-DEBS_DIR="/private/preboot/$BOOT_HASH/debs"-if [ -d "$DEBS_DIR" ]; then- to_install=()- for deb in "$DEBS_DIR"/*.deb; do- [ -f "$deb" ] || continue- name="$(basename "$deb")"- pkg="$(dpkg-deb -f "$deb" Package 2>/dev/null)"- ver="$(dpkg-deb -f "$deb" Version 2>/dev/null)"- if [ -z "$pkg" ]; then- log " WARNING: cannot read Package field from $name, will install anyway"- to_install+=("$deb")- continue- fi- cur="$(dpkg-query -W -f='${Version}' "$pkg" 2>/dev/null)"- if [ -n "$cur" ] && dpkg --compare-versions "$cur" ge "$ver" 2>/dev/null; then- log " $pkg $cur already installed (>= $ver), skipping"- else- to_install+=("$deb")- fi- done- if [ "${#to_install[@]}" -gt 0 ]; then- names="$(for d in "${to_install[@]}"; do basename "$d"; done | tr '\n' ' ')"- log " Installing ${#to_install[@]} deb(s): $names"- if dpkg -i "${to_install[@]}"; then- log " Extra debs installed"- else- rc=$?- log " WARNING: dpkg -i exited with $rc (unmet external deps are non-fatal)"- fi- else- log " All extra debs already installed, nothing to do"- fi-else- log " No extra debs staged"-fi--uicache -a 2>/dev/null || true-log " uicache refreshed"--# ═══════════ 6/8 APT SETUP ══════════════════════════════════-log "[6/8] Running apt setup..."--# Determine apt sources directory-HAVOC_LIST="/var/jb/etc/apt/sources.list.d/havoc.list"-if [ -d /etc/apt/sources.list.d ] && [ ! -d /var/jb/etc/apt/sources.list.d ]; then- HAVOC_LIST="/etc/apt/sources.list.d/havoc.list"-fi--if ! grep -rIl 'havoc.app' /etc/apt /var/jb/etc/apt 2>/dev/null | grep -q .; then- mkdir -p "$(dirname "$HAVOC_LIST")"- printf '%s\n' 'deb https://havoc.app/ ./' > "$HAVOC_LIST"- log " Havoc source added: $HAVOC_LIST"-else- log " Havoc source already present"-fi--FRIDA_LIST="$(dirname "$HAVOC_LIST")/frida.list"-if ! grep -rIl 'build.frida.re' /etc/apt /var/jb/etc/apt 2>/dev/null | grep -q .; then- mkdir -p "$(dirname "$FRIDA_LIST")"- printf '%s\n' 'deb https://build.frida.re/ ./' > "$FRIDA_LIST"- log " Frida source added: $FRIDA_LIST"-else- log " Frida source already present"-fi--apt-get -o Acquire::AllowInsecureRepositories=true \- -o Acquire::AllowDowngradeToInsecureRepositories=true \- update -qq 2>&1 || log " apt update exited with $?"-log " apt update done"--apt-get -o APT::Get::AllowUnauthenticated=true \- install -y -qq libkrw0-tfp0 2>/dev/null || true-log " libkrw0-tfp0 done"--apt-get -o APT::Get::AllowUnauthenticated=true \- upgrade -y -qq 2>/dev/null || true-log " apt upgrade done"--# ═══════════ 7/8 INSTALL TROLLSTORE LITE ═════════════════════-log "[7/8] Installing TrollStore Lite..."-TROLLSTORE_READY=0-if dpkg -s com.opa334.trollstorelite >/dev/null 2>&1; then- log " TrollStore Lite already installed"- TROLLSTORE_READY=1-else- apt-get -o APT::Get::AllowUnauthenticated=true \- install -y -qq com.opa334.trollstorelite 2>&1- trollstore_rc=$?- if [ "$trollstore_rc" -ne 0 ]; then- log " WARNING: TrollStore Lite apt install failed with exit code $trollstore_rc"- else- if dpkg -s com.opa334.trollstorelite >/dev/null 2>&1; then- log " TrollStore Lite installed"- TROLLSTORE_READY=1- else- log " WARNING: TrollStore Lite install completed without registering package"- fi- fi-fi--uicache -a 2>/dev/null || true-log " uicache refreshed"--# iOS 27: -[LSApplicationWorkspace registerApplicationDictionary:] (what uicache -a-# uses) is a deprecated no-op stub on 27, so uicache cannot register JB apps. Register-# them via the containerized LS API instead (needs the lsd embedded-reg gate patch from-# cfw_patch_lsd_embedded_reg). The 27 gate is the /cores/vpregister PRESENCE: it is-# deployed only on a 27 base (cfw_install_jb.sh gates the deploy on the mounted-# SystemVersion.plist), so a 26.x/18.x base has no /cores/vpregister and skips this.-# Do NOT re-add a guest-side `sw_vers` version check here — the hybrid guest's sw_vers-# does not reliably report the 27 userland version at first boot, which silently-# skipped this step and left Sileo unregistered.-if [ -x /cores/vpregister ]; then- log " Registering JB apps via containerized LS API (iOS 27 path)..."- /cores/vpregister 2>&1 | while IFS= read -r vpr_line; do log " $vpr_line"; done-fi--# ═══════════ 8/8 SHELL PROFILES FOR SSH ═══════════════════════-log "[8/8] Setting up shell profiles for SSH..."-# .bashrc — non-login interactive shells (dropbear default)-# .bash_profile — login shells (some SSH configurations)-# Both source /var/jb/etc/profile to get the full JB PATH.-for profile in /var/root/.bashrc /var/root/.bash_profile; do- if [ ! -f "$profile" ]; then- printf '%s\n' '# Source JB environment' '[ -r /var/jb/etc/profile ] && . /var/jb/etc/profile' > "$profile"- log " $profile created"- else- log " $profile already exists, skipping"- fi-done--# ═══════════ DONE ════════════════════════════════════════════-if [ "$TROLLSTORE_READY" = "1" ]; then- : > "$DONE_MARKER"- log "=== vphone_jb_setup.sh complete ==="-else- log "=== vphone_jb_setup.sh core steps complete; TrollStore Lite still pending, marker not written ==="-fidiff --git a/scripts/vphoned/signcert.p12 b/scripts/vphoned/signcert.p12deleted file mode 100755index c3f76c5e..00000000Binary files a/scripts/vphoned/signcert.p12 and /dev/null differdiff --git a/sources/FirmwarePatcher/Filesystem/CryptexFilesystemPatcher.swift b/sources/FirmwarePatcher/Filesystem/CryptexFilesystemPatcher.swiftindex 18814190..cf3486a4 100644--- a/sources/FirmwarePatcher/Filesystem/CryptexFilesystemPatcher.swift+++ b/sources/FirmwarePatcher/Filesystem/CryptexFilesystemPatcher.swift@@ -129,40 +129,16 @@ public final class CryptexFilesystemPatcher: Patcher {print("- Fixing dyld cache…")try addDyldSymlinks(targetMount: targetMount)- let cfwInputOgPath = resources.resourceArchivesDir.appendingPathComponent("cfw_input.tar.zst")- let cfwInputPath = try createTmpDir()- // No `--zstd` to pass: VPhoneArchiveExtractor detects the filter, and- // the libzstd it uses is static in the xcframework rather than a- // Homebrew program tar would have gone looking for.- //- // `.ontoGuestVolume` although this lands in a host temp directory.- // The destination is scratch, but the members are the guest's files- // in waiting — several are copied onto the volume verbatim below —- // and this step runs as root, where `/usr/bin/tar -xf` already- // restored modes and numeric owners by default. Keeping them is- // preserving what the tar call did, not tightening it.- try VPhoneArchiveExtractor.extract(- cfwInputOgPath, into: cfwInputPath, options: .ontoGuestVolume- )-print("- Fixing GPU driver…")- try addGpuDriver(targetMount: targetMount, cfwInput: cfwInputPath)+ try addGpuDriver(targetMount: targetMount)print("- Patching mobile activation…")- try patchMobileActivation(targetMount: targetMount, cfwInput: cfwInputPath)+ try patchMobileActivation(targetMount: targetMount)print("- Adding vphoned…")- try addVphoned(targetMount: targetMount, cfwInput: cfwInputPath)- if !noBinpack {- print("- Adding binpack…")- try addExtraServices(targetMount: targetMount, cfwInput: cfwInputPath)- }- try injectLaunchDaemons(- targetMount: targetMount,- cfwInput: cfwInputPath,- cfw: !noBinpack- )- try patchLaunchdCacheLoader(targetMount: targetMount, cfwInput: cfwInputPath)+ try addVphoned(targetMount: targetMount)+ try injectLaunchDaemons(targetMount: targetMount)+ try patchLaunchdCacheLoader(targetMount: targetMount)}print("- Finalizing merged image…")diff --git a/sources/FirmwarePatcher/Filesystem/CryptexFilesystemPatcherGuestPayload.swift b/sources/FirmwarePatcher/Filesystem/CryptexFilesystemPatcherGuestPayload.swiftindex 03d663ed..8253e256 100644--- a/sources/FirmwarePatcher/Filesystem/CryptexFilesystemPatcherGuestPayload.swift+++ b/sources/FirmwarePatcher/Filesystem/CryptexFilesystemPatcherGuestPayload.swift@@ -2,7 +2,7 @@//// Split out of CryptexFilesystemPatcher.swift. These are the steps that write files into the// mounted target volume: dyld symlinks, GPU driver bundle, the mobileactivationd and-// launchd_cache_loader patches, vphoned, the binpack, and the LaunchDaemons that start them.+// launchd_cache_loader patches, vphoned, and its LaunchDaemon.import Foundationimport VPhoneArchive@@ -12,32 +12,21 @@ import VPhoneSignextension CryptexFilesystemPatcher {// MARK: - Signing- /// What the `ldid -S -M -K<cfw_input/signcert.p12>` these steps used to- /// shell out for now asks VPhoneSign for.- ///- /// The `.p12` is opened here because VPhoneSign signs with an already-read- /// identity. There is no longer a second path that opens it elsewhere: the- /// external-ldid escape hatch is gone, so this parse either succeeds or the- /// step fails, and a missing identity can no longer become a silent ad-hoc- /// downgrade.+ /// Preserve a binary's existing entitlements while re-signing without an+ /// embedded certificate. The guest's JB firmware does not need a CMS+ /// identity for these binaries.func guestSigningOptions(- cfwInput: URL,identifier: String? = nil,entitlements: URL? = nil) throws -> VPhoneSignOptions {- let signingCertificatePath = cfwInput.appending(path: "cfw_input/signcert.p12")return VPhoneSignOptions(identifier: identifier,entitlements: try entitlements.map { try Data(contentsOf: $0, options: .mappedIfSafe) },- mergesExisting: true,- identity: try VPhoneSignIdentity(- pkcs12: Data(contentsOf: signingCertificatePath, options: .mappedIfSafe),- password: ""- )+ mergesExisting: true)}- func patchLaunchdCacheLoader(targetMount: String, cfwInput: URL) throws {+ func patchLaunchdCacheLoader(targetMount: String) throws {let target = URL.init(filePath: targetMount)let launchdCacheLoaderPath = target.appending(path: "/usr/libexec/launchd_cache_loader")// Patched in place with no `.bak` to restore from, so this is the call@@ -49,20 +38,18 @@ extension CryptexFilesystemPatcher {try VPhoneSigner.sign(fileAt: launchdCacheLoaderPath,options: try guestSigningOptions(- cfwInput: cfwInput, identifier: "com.apple.launchd_cache_loader"+ identifier: "com.apple.launchd_cache_loader"))}- func injectLaunchDaemons(targetMount: String, cfwInput: URL, cfw: Bool = true) throws {+ func injectLaunchDaemons(targetMount: String) throws {let target = URL.init(filePath: targetMount)let scriptDir = resources.scriptsDirlet tmpDir = try createTmpDir()let launchdPath = tmpDir.appending(path: "launchd.plist")- let launchDaemonsPath = tmpDir.appending(path: "launchDaemons")let launchdOgPath = target.appending(path: "/System/Library/xpc/launchd.plist")- try FileManager.default.createDirectory(at: launchDaemonsPath, withIntermediateDirectories: false)try FileManager.default.moveItem(at: launchdOgPath, to: launchdPath)let vphonedSrc = scriptDir.appendingPathComponent("vphoned")@@ -71,55 +58,13 @@ extension CryptexFilesystemPatcher {at: vphonedLaunchdPlist,to: target.appending(path: "System/Library/LaunchDaemons/vphoned.plist"))- try FileManager.default.copyItem(- at: vphonedLaunchdPlist,- to: launchDaemonsPath.appending(path: vphonedLaunchdPlist.lastPathComponent)- )- if cfw {- let launchDaemonsDir = cfwInput.appending(path: "cfw_input/jb/LaunchDaemons")- let launchDaemons = try FileManager.default.contentsOfDirectory(atPath: launchDaemonsDir.path)- for filename in launchDaemons {- let launchDaemonUrl = launchDaemonsDir.appending(component: filename)- let filename = launchDaemonUrl.lastPathComponent- let fsTarget = target.appending(path: "System/Library/LaunchDaemons/\(filename)")- try FileManager.default.copyItem(at: launchDaemonUrl, to: fsTarget)- try FileManager.default.copyItem(at: launchDaemonUrl, to: launchDaemonsPath.appending(path: filename))- }- }-- // The Python printed one line per daemon as it scanned and the install- // log is read for those lines, so the scan comes back in scan order and- // is logged here in the same words.- let staged = try CFWDaemons.injectDaemons(- into: launchdPath, fromDirectory: launchDaemonsPath- )- for daemon in staged {- switch daemon {- case let .present(daemon):- print(" [+] Injected \(daemon.name)")- case let .absent(source):- print(" [!] Missing \(source), skipping")- }- }+ try CFWDaemons.injectDaemon(into: launchdPath, name: "vphoned", from: vphonedLaunchdPlist)+ print(" [+] Injected vphoned")try FileManager.default.moveItem(at: launchdPath, to: launchdOgPath)try setMode(0o644, at: launchdOgPath)}- func addExtraServices(targetMount: String, cfwInput: URL) throws {- // `.ontoGuestVolume` is `tar --preserve-permissions --no-overwrite-dir`- // with numeric ownership — the preset was written for this archive. The- // `/usr/bin/tar` call it replaces passed only the first of those, so the- // directories iosbinpack64 shares with the system volume had their mode- // and owner taken from the archive; now, as in `cfw_install.sh`, the- // volume keeps its own.- try VPhoneArchiveExtractor.extract(- cfwInput.appending(path: "cfw_input/jb/iosbinpack64.tar"),- into: URL(filePath: targetMount),- options: .ontoGuestVolume- )- }-- func addVphoned(targetMount: String, cfwInput: URL) throws {+ func addVphoned(targetMount: String) throws {let target = URL.init(filePath: targetMount)let scriptDir = resources.scriptsDirlet vphonedSrc = scriptDir.appendingPathComponent("vphoned")@@ -137,7 +82,6 @@ extension CryptexFilesystemPatcher {try VPhoneSigner.sign(fileAt: targetBin,options: try guestSigningOptions(- cfwInput: cfwInput,entitlements: vphonedSrc.appendingPathComponent("entitlements.plist")))@@ -150,20 +94,17 @@ extension CryptexFilesystemPatcher {/// sources shipped inside the .app — which meant installing CFW onto a VM/// required Xcode and the iPhoneOS SDK on a machine whose only job is to run/// that VM. vphoned is cross-compiled at build time now- /// (`scripts/guest_binaries.mk`) and staged into the bundle beside the other- /// four guest binaries; the caller still signs it here, because signing uses- /// the target VM's own certificate.+ /// (`scripts/guest_binaries.mk`) and staged into the bundle.func stageVphoned(to vphonedBin: URL) throws {let prebuilt = try VPhoneGuestBinaries.resolve("vphoned")try FileManager.default.copyItem(at: prebuilt, to: vphonedBin)}- func addGpuDriver(targetMount: String, cfwInput: URL) throws {+ func addGpuDriver(targetMount: String) throws {let target = URL.init(filePath: targetMount)- let gpuTarPath = cfwInput.appending(path: "cfw_input/custom/AppleParavirtGPUMetalIOGPUFamily.tar")try VPhoneArchiveExtractor.extract(- gpuTarPath, into: target, options: .ontoGuestVolume+ resources.gpuDriverArchive, into: target, options: .ontoGuestVolume)let bundle = target.appending(path: "/System/Library/Extensions/AppleParavirtGPUMetalIOGPUFamily.bundle")@@ -186,7 +127,7 @@ extension CryptexFilesystemPatcher {}}- func patchMobileActivation(targetMount: String, cfwInput: URL) throws {+ func patchMobileActivation(targetMount: String) throws {let target = URL.init(filePath: targetMount)let mobileActivationdPath = target.appending(path: "/usr/libexec/mobileactivationd")// `resign: false` because the sign below replaces the signature, and@@ -196,7 +137,7 @@ extension CryptexFilesystemPatcher {try VPhoneSigner.sign(fileAt: mobileActivationdPath,- options: try guestSigningOptions(cfwInput: cfwInput)+ options: try guestSigningOptions())}diff --git a/sources/VPhoneCore/VPhoneGuestBinaries.swift b/sources/VPhoneCore/VPhoneGuestBinaries.swiftindex 5f29e3a7..d53f51a5 100644--- a/sources/VPhoneCore/VPhoneGuestBinaries.swift+++ b/sources/VPhoneCore/VPhoneGuestBinaries.swift@@ -1,17 +1,7 @@// VPhoneGuestBinaries.swift — where the prebuilt iOS binaries live.//-// Five Mach-Os run inside the guest and are built for it, not for this host:-// vphoned, TweakLoader.dylib, vpregister, libvcamcaptured.dylib and-// libcamfix.dylib. Every one of them used to be cross-compiled at CFW-install-// time — three by `scripts/cfw_install*.sh` through `xcrun --sdk iphoneos`, and-// vphoned by `FirmwarePatcher` doing the same thing from Swift. That made Xcode-// and the iPhoneOS SDK a prerequisite for `cfw install`, on a machine whose only-// job is to run a virtual phone.-//-// They are compiled by `scripts/guest_binaries.mk` on the machine that builds-// the .app and shipped in `Contents/Resources/guest`. What is left at install-// time is signing, which cannot move: it uses the target VM's own-// `cfw_input/signcert.p12`, and that does not exist until a VM does.+// vphoned is cross-compiled on the build machine and shipped in the app.+// The runtime installs it with an ad-hoc signature and never needs Xcode.import Foundationdiff --git a/sources/VPhoneCore/VPhoneResources.swift b/sources/VPhoneCore/VPhoneResources.swiftindex f1ea53de..5e9659ec 100644--- a/sources/VPhoneCore/VPhoneResources.swift+++ b/sources/VPhoneCore/VPhoneResources.swift@@ -92,10 +92,11 @@ public struct VPhoneResources: Sendable {// MARK: - Assetspublic var scriptsDir: URL { base.appendingPathComponent("scripts") }- public var resourceArchivesDir: URL { scriptsDir.appendingPathComponent("resources") }+ public var gpuDriverArchive: URL {+ scriptsDir.appendingPathComponent("payloads/AppleParavirtGPUMetalIOGPUFamily.tar")+ }public var cfwInstallHostScript: URL { scriptsDir.appendingPathComponent("cfw_install_host.sh") }public var preflightScript: URL { scriptsDir.appendingPathComponent("boot_host_preflight.sh") }- public var signcert: URL { scriptsDir.appendingPathComponent("vphoned/signcert.p12") }public var vphoned: URL {let bundled = base.appendingPathComponent("vphoned.signed")@@ -108,7 +109,7 @@ public struct VPhoneResources: Sendable {// MARK: - Cache dirs/// The per-user data root: `$VPHONE_ROOT` when set, else `~/.vphone`. Both- /// `VPhoneResources` (ipsws/tools/debs) and `VPhoneLibrary` (VMs) derive+ /// `VPhoneResources` (ipsws/tools) and `VPhoneLibrary` (VMs) derive/// from this so one variable redirects everything vphone-cli creates.public static func userDataRoot() -> URL {if let root = ProcessInfo.processInfo.environment["VPHONE_ROOT"], !root.isEmpty {@@ -119,7 +120,6 @@ public struct VPhoneResources: Sendable {public var ipswCacheDir: URL { Self.userDataRoot().appendingPathComponent("ipsws") }public var sealVolumeCacheDir: URL { Self.userDataRoot().appendingPathComponent("tools") }- public var debsCacheDir: URL { Self.userDataRoot().appendingPathComponent("debs") }// MARK: - No interpreterdiff --git a/sources/VPhoneVMKit/Guest/VPhoneControl.swift b/sources/VPhoneVMKit/Guest/VPhoneControl.swiftindex e2731625..2c6e4ed6 100644--- a/sources/VPhoneVMKit/Guest/VPhoneControl.swift+++ b/sources/VPhoneVMKit/Guest/VPhoneControl.swift@@ -112,11 +112,6 @@ class VPhoneControl {}}- private static func signCertURL() -> URL? {- let signcert = VPhoneResources.resolve().signcert- return FileManager.default.fileExists(atPath: signcert.path) ? signcert : nil- }-// MARK: - Guest Binary Hashprivate func loadGuestBinary() {@@ -459,32 +454,21 @@ class VPhoneControl {let remoteName = "\(UUID().uuidString)-\(localURL.lastPathComponent)"let remotePath = "\(remoteDir)/\(remoteName)"- var cleanupPaths = [remotePath]defer {Task {- for cleanupPath in cleanupPaths {- try? await deleteFile(path: cleanupPath)- }+ try? await deleteFile(path: remotePath)}}try await createDirectory(path: remoteDir)try await uploadFile(path: remotePath, data: data)- var request: [String: Any] = [+ let request: [String: Any] = ["t": "ipa_install","path": remotePath,"registration": "User",]- if let signCertURL = Self.signCertURL() {- let signCertData = try Data(contentsOf: signCertURL, options: .mappedIfSafe)- let certRemotePath = "\(remoteDir)/\(UUID().uuidString)-signcert.p12"- cleanupPaths.append(certRemotePath)- try await uploadFile(path: certRemotePath, data: signCertData)- request["cert_path"] = certRemotePath- }-let (resp, _) = try await sendRequest(request)if let detail = resp["msg"] as? String, !detail.isEmpty {return detaildiff --git a/sources/vphone-cli/VPhoneCreateOrchestrator.swift b/sources/vphone-cli/VPhoneCreateOrchestrator.swiftindex b962adb1..2a5c8b88 100644--- a/sources/vphone-cli/VPhoneCreateOrchestrator.swift+++ b/sources/vphone-cli/VPhoneCreateOrchestrator.swift@@ -431,7 +431,6 @@ public struct VPhoneCreateOrchestrator {let v = options.verbositytry FileManager.default.createDirectory(at: resources.ipswCacheDir, withIntermediateDirectories: true)try FileManager.default.createDirectory(at: resources.sealVolumeCacheDir, withIntermediateDirectories: true)- try FileManager.default.createDirectory(at: resources.debsCacheDir, withIntermediateDirectories: true)// No VPHONE_PYTHON: the CFW installers and cfw-kit run `vphone-cli cfw// <verb>` now, so nothing under this script reads a python. Asking for// one here would only force a venv bootstrap nobody uses.@@ -444,13 +443,11 @@ public struct VPhoneCreateOrchestrator {"VPHONE_CLI_BIN": VPhoneResources.runningExecutable().path,"IPSW_DIR": resources.ipswCacheDir.path,"VPHONE_SEAL_DIR": resources.sealVolumeCacheDir.path,- "VPHONE_DEBS_DIR": resources.debsCacheDir.path,]if options.forceDSCMaxSlide { scriptEnv["FORCE_DSC_MAXSLIDE"] = "1" }if options.enableFrida { scriptEnv["VPHONE_FRIDA"] = "1" }- if options.keepArtifacts { scriptEnv["VPHONE_KEEP_ARTIFACTS"] = "1" }- let args = [resources.cfwInstallHostScript.path, "--variant", "jb", bundleURL.path]+ let args = [resources.cfwInstallHostScript.path, bundleURL.path]// --sudo-password (askpass) wins over --root-popup.let usePopup = options.rootPopup && sudoEnvExtras["SUDO_ASKPASS"] == nillet code: Int32diff --git a/sources/vphone-cli/VPhoneFWCLI.swift b/sources/vphone-cli/VPhoneFWCLI.swiftindex 497a2d3e..272d262d 100644--- a/sources/vphone-cli/VPhoneFWCLI.swift+++ b/sources/vphone-cli/VPhoneFWCLI.swift@@ -9,6 +9,7 @@ struct VPhoneFWCommand: ParsableCommand {abstract: "Firmware pipeline: prepare (download/merge IPSWs) and patch",subcommands: [VPhoneFWCatalogCommand.self,+ VPhoneFWInspectCommand.self,VPhoneFWPrepareCommand.self,VPhoneFWPatchCommand.self,VPhoneFWManifestCommand.self,@@ -22,6 +23,42 @@ struct VPhoneFWCommand: ParsableCommand {])}+/// Check a PCC IPSW's build identities using HTTP ranges before committing+/// space to a full download. The hybrid restore requires both device classes.+struct VPhoneFWInspectCommand: ParsableCommand {+ static let configuration = CommandConfiguration(+ commandName: "inspect",+ abstract: "Inspect a remote IPSW manifest without downloading the archive"+ )++ @Argument(help: "Remote IPSW URL") var source: String++ func run() throws {+ guard let url = URL(string: source), ["https", "http"].contains(url.scheme ?? "") else {+ throw ValidationError("Expected an HTTP(S) IPSW URL")+ }+ let data = try vphoneRunBlocking {+ let zip = try await VPhoneRemoteZip.open(url)+ return try await zip.read(zip.entry(endingWith: "BuildManifest.plist"))+ }+ guard let manifest = try PropertyListSerialization.propertyList(from: data, format: nil)+ as? [String: Any],+ let identities = manifest["BuildIdentities"] as? [[String: Any]] else {+ throw VPhoneRemoteZip.Error.malformed("BuildManifest.plist has no BuildIdentities")+ }+ print("\(manifest["ProductVersion"] ?? "unknown") (\(manifest["ProductBuildVersion"] ?? "unknown"))")+ for deviceClass in ["vresearch101ap", "vphone600ap"] {+ let matches = identities.filter {+ ($0["Info"] as? [String: Any])?["DeviceClass"] as? String == deviceClass+ }+ let variants = matches.compactMap {+ ($0["Info"] as? [String: Any])?["Variant"] as? String+ }+ print("\(deviceClass): \(variants.isEmpty ? "missing" : variants.joined(separator: ", "))")+ }+ }+}+// MARK: - firmware support matrix/// Lists the available firmware using the URLs supplied by AppleDB.diff --git a/sources/vphone-cli/VPhoneRestoreCLI.swift b/sources/vphone-cli/VPhoneRestoreCLI.swiftindex a2a3d7b9..e05a65e2 100644--- a/sources/vphone-cli/VPhoneRestoreCLI.swift+++ b/sources/vphone-cli/VPhoneRestoreCLI.swift@@ -234,7 +234,7 @@ struct VPhoneCFWInstallCommand: ParsableCommand {var rootPopup = false@Flag(name: .customLong("keep-artifacts"),- help: "Keep the extracted CFW input dirs (cfw_input/, cfw_jb_input/) after install (default: removed to save space)"+ help: "Keep the extracted firmware after install (default: removed to save space)")var keepArtifacts = false@Option(name: .shortAndLong, help: "Resource base override (default: inferred from the running binary path)")@@ -252,7 +252,6 @@ struct VPhoneCFWInstallCommand: ParsableCommand {// --root-popup forwards it inline (do shell script's bare env).try FileManager.default.createDirectory(at: resources.ipswCacheDir, withIntermediateDirectories: true)try FileManager.default.createDirectory(at: resources.sealVolumeCacheDir, withIntermediateDirectories: true)- try FileManager.default.createDirectory(at: resources.debsCacheDir, withIntermediateDirectories: true)var scriptEnv: [String: String] = [// The script re-execs under sudo, so it cannot work out where we// live from its own path in the bundled case. Tell it.@@ -262,12 +261,10 @@ struct VPhoneCFWInstallCommand: ParsableCommand {// last Python patcher was deleted."IPSW_DIR": resources.ipswCacheDir.path,"VPHONE_SEAL_DIR": resources.sealVolumeCacheDir.path,- "VPHONE_DEBS_DIR": resources.debsCacheDir.path,]if forceDSCMaxSlide { scriptEnv["FORCE_DSC_MAXSLIDE"] = "1" }- if keepArtifacts { scriptEnv["VPHONE_KEEP_ARTIFACTS"] = "1" }- let args = [resources.cfwInstallHostScript.path, "--variant", "jb", bundle.url.path]+ let args = [resources.cfwInstallHostScript.path, bundle.url.path]let code: Int32if rootPopup {// Forward SUDO_USER (sudo would set it) so the script's chown-back runs.diff --git a/tests/VPhoneCoreTests/ResourcesTests.swift b/tests/VPhoneCoreTests/ResourcesTests.swiftindex 9df21dbc..3223e62f 100644--- a/tests/VPhoneCoreTests/ResourcesTests.swift+++ b/tests/VPhoneCoreTests/ResourcesTests.swift@@ -37,8 +37,8 @@ struct ResourcesTests {let exe = root.appendingPathComponent(".build/release/vphone-cli").pathlet r = VPhoneResources.resolve(executablePath: exe)#expect(r.base.path == root.resolvingSymlinksInPath().path)- #expect(r.resourceArchivesDir.path == root.resolvingSymlinksInPath()- .appendingPathComponent("scripts/resources").path)+ #expect(r.gpuDriverArchive.path == root.resolvingSymlinksInPath()+ .appendingPathComponent("scripts/payloads/AppleParavirtGPUMetalIOGPUFamily.tar").path)}@Test func cacheDirsAreHomeRelative() {@@ -57,7 +57,6 @@ struct ResourcesTests {#expect(VPhoneResources.userDataRoot().path == "/tmp/vphone-test-root")#expect(r.ipswCacheDir.path == "/tmp/vphone-test-root/ipsws")#expect(r.sealVolumeCacheDir.path == "/tmp/vphone-test-root/tools")- #expect(r.debsCacheDir.path == "/tmp/vphone-test-root/debs")}}@@ -71,13 +70,13 @@ struct ResourcesTests {let base = URL(fileURLWithPath: "/x")let r = VPhoneResources(base: base)let rooted = [- r.scriptsDir, r.resourceArchivesDir,- r.cfwInstallHostScript, r.preflightScript, r.signcert, r.vphoned,+ r.scriptsDir, r.gpuDriverArchive,+ r.cfwInstallHostScript, r.preflightScript, r.vphoned,]for url in rooted {#expect(url.path.hasPrefix("/x/"), "\(url.path) escapes the resource base")}- for url in [r.ipswCacheDir, r.sealVolumeCacheDir, r.debsCacheDir] {+ for url in [r.ipswCacheDir, r.sealVolumeCacheDir] {#expect(url.path.hasPrefix("/tmp/vphone-test-root/"))}}diff --git a/tests/VPhoneSignTests/VPhoneSignIdentityTests.swift b/tests/VPhoneSignTests/VPhoneSignIdentityTests.swiftdeleted file mode 100644index 40168207..00000000--- a/tests/VPhoneSignTests/VPhoneSignIdentityTests.swift+++ /dev/null@@ -1,200 +0,0 @@-import Foundation-import Testing-@testable import VPhoneSign--/// `-K`: signing with the repository's own `signcert.p12`.-///-/// The whole file cannot match ldid's, because a CMS carries a signing time.-/// It is only the content that differs: the CMS blob comes out the same-/// length as ldid's on every slice measured (4711 against 4711, 4792 against-/// 4792), and the signed files are the same size to the byte, because both-/// signers reserve `cmsReservation` and pad what is left. What must match is-/// the CodeDirectory, and it is the only part that has to: everything AMFI-/// seals is in there, and the CDHash is computed over it. The CMS is then-/// held to a verifier nobody here wrote.-///-/// So what is frozen from ldid is the part that does not move — the blobs, in-/// `VPhoneSignFixtures.expected`, and the two byte counts, in-/// `expectedLengths`.-@Suite("VPhoneSign signs with a PKCS#12")-struct VPhoneSignIdentityTests {- /// The certificate this repository signs its guest daemon with. It is- /// checked in, wrapped with no password, and expired in 2018 — none of- /// which matters to a device whose AMFI this project patched, and all of- /// which matters to how it has to be read.- static var p12: URL {- URL(fileURLWithPath: #filePath)- .deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent()- .appendingPathComponent("scripts/vphoned/signcert.p12")- }-- private func identity() throws -> VPhoneSignIdentity {- try #require(FileManager.default.fileExists(atPath: Self.p12.path), "signcert.p12 is not in the tree")- return try VPhoneSignIdentity(pkcs12: Data(contentsOf: Self.p12), password: "")- }-- /// `SecPKCS12Import` cannot do this: it answers `errSecAuthFailed` for an- /// empty password. That is the entire reason the container is opened by- /// hand.- @Test("the repository's PKCS#12 opens with no password")- func opensWithoutAPassword() throws {- let identity = try identity()- #expect(identity.teamIdentifier == "DQF6PC5T2P")- #expect(identity.commonName == "iPhone Distribution: jiu de (DQF6PC5T2P)")- }-- @Test("a wrong password is refused, not worked around")- func refusesAWrongPassword() throws {- try #require(FileManager.default.fileExists(atPath: Self.p12.path))- let data = try Data(contentsOf: Self.p12)- #expect(throws: VPhoneSignError.self) {- _ = try VPhoneSignIdentity(pkcs12: data, password: "not the password")- }- }-- /// The hard gate for `-K`: the CodeDirectories are ldid's, byte for byte.- ///- /// Slot 0 and slot 4096 are the two CodeDirectories; slot 2 is in the same- /// claim because under `-K` the designated requirement carries the leaf's- /// common name. A slot the table has no row for must not be written, and a- /// slot it has a row for must be — otherwise a signature missing a- /// CodeDirectory entirely would sail past a loop that only compares what- /// it finds.- @Test("every CodeDirectory matches ldid -K")- func codeDirectoriesMatchLdid() throws {- let identity = try identity()- let corpus = try VPhoneSignFixtures.fixtures- #expect(corpus.count >= 12, "only \(corpus.count) fixtures: too few to say anything")- var compared = 0- for source in corpus {- let directory = try VPhoneSignFixtures.temporaryDirectory()- defer { try? FileManager.default.removeItem(at: directory) }- let name = source.lastPathComponent-- let ours = try VPhoneSignFixtures.sign(- source, in: directory, mergesExisting: true, identity: identity- )- for (index, slice) in try VPhoneSignBlobs(fileAt: ours).slices.enumerated() {- for slot in [UInt32(0), 2, 0x1000] {- let key = "\(name).sealed.\(index).\(slot)"- guard VPhoneSignFixtures.isFrozen(key) else {- #expect(slice[slot] == nil, "\(key): ldid wrote no such blob, this signer did")- continue- }- let blob = try #require(slice[slot], "\(key): ldid wrote this blob, this signer did not")- try VPhoneSignFixtures.expect(key, matches: blob)- compared += 1- }- }- }- // every frozen row has to have been reached, or a corpus that lost a- // fixture — or a signature that lost a slice — compares less and passes- let frozen = VPhoneSignFixtures.expected.keys.count { $0.contains(".sealed.") }- #expect(compared == frozen, "compared \(compared) of the \(frozen) frozen CodeDirectory blobs")- }-- /// The seal, checked by `codesign --verify`, which is an action and not- /// the verbosity flag that `-d -vvv` turns out to be.- ///- /// This signer passes outright, entitlements or not: `codesign --verify`- /// exits 0 and prints "satisfies its Designated Requirement". An earlier- /// note here said the DR clause fails whenever entitlements are present,- /// because ldid compiles a DR naming a leaf that expired in 2018. That- /// does not reproduce in any configuration tried — `--verify` does not- /// build a trust chain, so the expiry never comes into it.- ///- /// `/usr/bin/codesign` is the one system binary this suite still calls,- /// and it is called as a verifier rather than as a source of input.- @Test("codesign --verify accepts the seal, with entitlements and without")- func codesignVerifiesTheSeal() throws {- let identity = try identity()- let codesign = URL(fileURLWithPath: "/usr/bin/codesign")- let corpus = try VPhoneSignFixtures.fixtures- var entitled = 0- for source in corpus {- let directory = try VPhoneSignFixtures.temporaryDirectory()- defer { try? FileManager.default.removeItem(at: directory) }- let name = source.lastPathComponent- if try VPhoneSigner.entitlements(ofFileAt: source).contains(where: { !$0.isEmpty }) {- entitled += 1- }-- let ours = try VPhoneSignFixtures.sign(- source, in: directory, mergesExisting: true, identity: identity- )- let result = try VPhoneSignFixtures.run(codesign, ["--verify", "--no-strict", "-vvv", ours.path])- #expect(result.status == 0, "\(name): \(result.error)")- #expect(result.error.contains("valid on disk"), "\(name): \(result.error)")- #expect(- result.error.contains("satisfies its Designated Requirement"),- "\(name): \(result.error)"- )- }- // the entitlement-carrying half is the case the old note claimed was- // different, so it has to be in the run- #expect(entitled >= 7, "only \(entitled) of the fixtures carried entitlements")- }-- /// The two files are the same size, and their CMS blobs are the same- /// length; only the bytes inside differ, where the signing time lives.- ///- /// This is here because the opposite was written down — that this- /// signer's CMS runs eight bytes longer than ldid's — and a CMS that- /// really was longer would be a real problem: the reservation is fixed,- /// so overflowing it would move the `__LINKEDIT` size in the load- /// commands and change every CDHash.- @Test("the CMS is the same length as ldid's, and so is the file")- func cmsIsTheSameLengthAsLdids() throws {- let identity = try identity()- for source in try VPhoneSignFixtures.fixtures {- let directory = try VPhoneSignFixtures.temporaryDirectory()- defer { try? FileManager.default.removeItem(at: directory) }- let name = source.lastPathComponent-- let ours = try VPhoneSignFixtures.sign(- source, in: directory, mergesExisting: true, identity: identity- )- try VPhoneSignFixtures.expect(- length: "\(name).sealedSize", is: Data(contentsOf: ours).count- )- for (index, slice) in try VPhoneSignBlobs(fileAt: ours).slices.enumerated() {- let cms = try #require(slice[0x10000], "\(name) slice \(index) has no CMS")- try VPhoneSignFixtures.expect(length: "\(name).cms.\(index)", is: cms.count)- }- }- }-- /// The gate that is real evidence rather than a display: a verifier from- /// outside this project, over the bytes this project signed. `-noverify`- /// skips building a trust chain, which would fail on an expired leaf and- /// says nothing about whether the signature is sound.- @Test("openssl cms -verify accepts the signature")- func opensslVerifiesTheCMS() throws {- let openssl = URL(fileURLWithPath: "/usr/bin/openssl")- try #require(FileManager.default.isExecutableFile(atPath: openssl.path), "openssl is not installed")- let identity = try identity()- for source in try VPhoneSignFixtures.fixtures.prefix(6) {- let directory = try VPhoneSignFixtures.temporaryDirectory()- defer { try? FileManager.default.removeItem(at: directory) }- let name = source.lastPathComponent- let ours = try VPhoneSignFixtures.sign(source, in: directory, identity: identity)-- let blobs = try VPhoneSignBlobs(fileAt: ours)- for (index, slice) in blobs.slices.enumerated() {- let cms = try #require(slice[0x10000], "\(name) slice \(index) has no CMS blob")- let directoryBlob = try #require(slice[0], "\(name) slice \(index) has no CodeDirectory")- let cmsFile = directory.appendingPathComponent("cms-\(index).der")- let contentFile = directory.appendingPathComponent("cd-\(index).bin")- // the blob wrapper's own 8-byte header is not part of the CMS- try cms.dropFirst(8).write(to: cmsFile)- try directoryBlob.write(to: contentFile)-- let result = try VPhoneSignFixtures.run(openssl, [- "cms", "-verify", "-inform", "DER", "-in", cmsFile.path,- "-content", contentFile.path, "-noverify", "-binary", "-out", "/dev/null",- ])- #expect(result.status == 0, "\(name) slice \(index): openssl said \(result.error)")- }- }- }-}