Run a virtual iPhone on an Apple Silicon Mac.
Swift
refactor: remove legacy setup workflows and clean up release CI
Lakr4def115630e2
diff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex 8b4f508f..7b8021c5 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -1,10 +1,8 @@name: release# Build the portable, signed vphone-cli.app and attach it to a published-# GitHub Release. Uses ./scripts/build.sh (the canonical build) so the .app-# ships self-contained — bundled scripts/resources/requirements.txt/-# vphoned/.tools — not the lean `make bundle` output. Signing is ad-hoc-# (codesign --sign -) with sources/vphone.entitlements; no secrets required.+# GitHub Release. Validate the actual application bundle; no Homebrew+# packages or separately provisioned runtime tools are required.on:release:@@ -19,64 +17,30 @@ jobs:steps:- name: Checkoutuses: actions/checkout@v4+ with:+ lfs: true- name: Init submodules- # vendor/* (--recursive: libcapstone-spm builds capstone from its own- # nested submodule) for the Swift build; scripts/resources is the CFW- # asset storage that build.sh bundles into the .app; scripts/repos/trustcache- # provides the trustcache tool source. scripts/repos/insert_dylib is- # deliberately NOT initialised: nothing in the product runs it, it is only- # the local parity reference for CFWMachOTests.matchesInsertDylib.- run: |- git submodule update --init --recursive --depth 1 \- vendor/swift-argument-parser \- vendor/Dynamic \- vendor/libcapstone-spm \- vendor/libimg4-spm \- vendor/MachOKit \- scripts/resources \- scripts/repos/trustcache+ # 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: |swift --versionxcodebuild -version- - name: Install build deps- run: brew install ldid-procursus openssl@3-- - name: Build .tools/bin/trustcache- # The one runtime tool build.sh still bundles into the .app; it errors- # if absent. Mirrors scripts/setup_tools.sh step [2/4]; its venv ([4/4])- # and sshpass ([1/4]) steps aren't needed to build.- # insert_dylib ([3/4]) is deliberately not built here: `cfw inject-dylib`- # writes the load command in process, so the binary is only the parity- # reference CFWMachOTests compares against — a test this job never runs.- run: |- set -euo pipefail- mkdir -p .tools/bin- openssl_prefix="$(brew --prefix openssl@3)"- make -C scripts/repos/trustcache \- OPENSSL=1 \- CFLAGS="-I${openssl_prefix}/include -DOPENSSL -w" \- LDFLAGS="-L${openssl_prefix}/lib" \- -j"$(sysctl -n hw.logicalcpu)"- cp scripts/repos/trustcache/trustcache .tools/bin/trustcache-- name: Build and bundle (portable .app)+ env:+ SWIFT_JOBS: "4"run: ./scripts/build.sh- - name: Verify the bundle is portable-complete and entitled+ - name: Verify application bundlerun: |set -euo pipefail- res=.build/vphone-cli.app/Contents/Resources- for p in scripts/fw_prepare.sh scripts/cfw_install.sh scripts/resources \- requirements.txt vphoned.signed .tools/bin/trustcache; do- [ -e "$res/$p" ] || { echo "::error::bundle is missing $p — not portable"; exit 1; }- done- bin=.build/vphone-cli.app/Contents/MacOS/vphone-cli- codesign -d --entitlements - "$bin" 2>&1 | grep -q 'com.apple.private.virtualization' \- || { echo "::error::required virtualization entitlement missing from signed app"; exit 1; }+ codesign --verify --strict .build/vphone-cli.app+ test -x .build/vphone-cli.app/Contents/Resources/guest/vphoned+ zsh scripts/check_aux.sh- name: Package appenv:diff --git a/AGENTS.md b/AGENTS.mdindex a04da40a..3e3c2548 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -184,10 +184,8 @@ scripts/ # Shell only — the CFW patchers are `vphone-├── 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)├── check_aux.sh [b] # The self-containment admission gates — `make check-aux`-├── setup_machine.sh [b] # Full automation (setup → first boot)├── 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-├── vm_{create,backup,restore,switch}.sh [b]├── fw_prepare.sh [d] # Download IPSWs, merge cloudOS into iPhone├── cfw_install.sh [d] # Install CFW (regular)├── cfw_install_dev.sh [d] # Regular + rpcserver daemon@@ -204,12 +202,6 @@ scripts/ # Shell only — the CFW patchers are `vphone-├── tweakloader/ vpregister/ vcamcaptured/ camfix/ # The other four guest sources; same deal└── repos/ # Toolchain source (git submodule: insert_dylib)-cfw-kit/ # Variant-layered CFW installer, vendored as-is. ALL BUILD TIER:-├── run.sh # it still reaches for ldid/gtar/zstd/ipsw the way-├── lib/ # scripts/cfw_install*.sh did before they were cleaned out, so it-├── vanilla/ jb/ # does not ship and a dist user cannot run it. P3 decides whether-└── docs/phase-matrix.md # it gets the same treatment or stays a development tool.-research/ # Detailed firmware/patch documentation```@@ -252,7 +244,7 @@ research/ # Detailed firmware/patch documentationEvery patcher is Swift, in `sources/FirmwarePatcher`. The boot chain and kernelrun through `patch-firmware`; the CFW/DSC patchers are `vphone-cli cfw <verb>`,-one verb per patch, driven by `scripts/cfw_install*.sh` and `cfw-kit/`.+one verb per patch, driven by `scripts/cfw_install*.sh` only.- Disassembly is Capstone via `ARM64Disassembler` (the `libcapstone-spm` package). Assembly is `ARM64Encoder` plus the pre-encoded constants in `ARM64` (`ARM64Constants.swift`) — together they replace keystone's `asm()` / `asm_at()`, and `ARM64.nop` / `ARM64.movW0_0` are the old `NOP` / `MOV_W0_0`. IM4P containers go through `IM4PHandler` (the `libimg4-spm` package), which replaces pyimg4. Both resolve by URL; there is no `vendor/` directory to check out first.- Dynamic pattern finding (string anchors, ADRP+ADD xrefs, BL frequency) — no hardcoded offsets.diff --git a/Makefile b/Makefileindex bbd6af0c..23ef4e7d 100644--- a/Makefile+++ b/Makefile@@ -8,16 +8,7 @@ VM_DIR ?= vm# (e.g. external SSD) VM_DIR values. `abspath` leaves absolute paths intact# and joins relative ones against CURDIR — use this for the VM directory arg.VM_DIR_ABS := $(abspath $(VM_DIR))-# CPU cores, memory (MB), disk size (GB) — used only during vm_new.-# NB: no inline comments on these `?=` lines — make would fold the trailing-# whitespace into the value (e.g. CPU="8 ") and break numeric consumers.-CPU ?= 8-MEMORY ?= 8192-DISK_SIZE ?= 64-BACKUPS_DIR ?= vm.backups-NAME ?=-BACKUP_INCLUDE_IPSW ?= 0-FORCE ?= 0+SWIFT_JOBS ?= 4# UDID and ECID for restore operationsRESTORE_UDID ?=RESTORE_ECID ?=@@ -77,23 +68,6 @@ export PATH := $(CURDIR)/$(TOOLS_PREFIX)/bin:$(CURDIR)/.build/release:$(PATH)help:@echo "vphone-cli — Virtual iPhone boot tool"@echo ""- @echo "LazyCat (AIO):"- @echo " make setup_machine Full setup through First Boot"- @echo " Options: JB=1 Jailbreak firmware/CFW path"- @echo " DEV=1 Dev firmware/CFW path (dev TXM + cfw_install_dev)"- @echo " EXP=1 Experimental firmware/CFW path (JB + EXP-only patches:"- @echo " kernel hv_vmm rename, DSC byte-5 mangle, surgical watchdogd patch,"- @echo " DT identity properties, post-restore DT rewrite, opt-in build spoof)"- @echo " LESS=1 Build, keeping iOS security mitigations enabled."- @echo " SKIP_PROJECT_SETUP=1 Skip setup_tools/build"- @echo " INTERACTIVE=1 Prompt at first-boot stages (default: non-interactive)"- @echo " SUDO_PASSWORD=... Preload sudo credential for setup flow"- @echo " NO_BINPACK=1 Skip installing the SSH, VNC and other bundled binaries (patchless only)"- @echo " NO_VPHONED=1 Skip installing vphoned (patchless only)"- @echo " SPOOF_BUILD=<id> (EXP only) Rewrite ProductBuildVersion in SystemVersion.plist to <id>"- @echo " e.g. SPOOF_BUILD=23F77 makes Settings → About show that build."- @echo " Unset or empty keeps the build version that ships in the IPSW."- @echo ""@echo "Setup (one-time):"@echo " make setup_tools Build insert_dylib (a test reference; optional)"@echo ""@@ -105,17 +79,10 @@ help:@echo " CLEAN_IPSW=1 Also remove ipsws/ after confirmation"@echo ""@echo "VM management:"- @echo " make vm_new Create VM directory with manifest (config.plist)"- @echo " Options: VM_DIR=vm VM directory name"- @echo " CPU=8 CPU cores (stored in manifest)"- @echo " MEMORY=8192 Memory in MB (stored in manifest)"- @echo " DISK_SIZE=64 Disk size in GB (stored in manifest)"- @echo " make vm_backup NAME=<name> Save current VM as a named backup"- @echo " make vm_restore NAME=<name> Restore a named backup into vm/"- @echo " make vm_switch NAME=<name> Save current + restore target (one step)"- @echo " make vm_list List available backups"- @echo " Options: BACKUP_INCLUDE_IPSW=1 Include *_Restore* IPSW directories in the backup"- @echo " FORCE=1 Skip overwrite prompt on restore"+ @echo " vphone-cli vm new <name> Create a VM bundle"+ @echo " vphone-cli vm list List VM bundles"+ @echo " vphone-cli vm export <name> --out <archive> Back up a VM"+ @echo " vphone-cli vm import <archive> --name <name> Restore into a new VM"@echo " make check-aux Run the self-containment admission gates"@echo " make amfi_allow Allow THIS build's vphone-vm past amfid (asks for root)"@echo " Re-run after every build — it allowlists cdhashes"@@ -170,35 +137,13 @@ help:@echo " make cfw_install_exp Install CFW + JB + EXP experimental (hv_vmm rename, post-restore DT, build spoof)"@echo " make cfw_install_host Select variant: VARIANT=regular|dev|jb|exp (default exp) SPOOF_BUILD=<id> (exp)"@echo ""- @echo "Variables: VM_DIR=$(VM_DIR) CPU=$(CPU) MEMORY=$(MEMORY) DISK_SIZE=$(DISK_SIZE)"+ @echo "Variables: VM_DIR=$(VM_DIR) SWIFT_JOBS=$(SWIFT_JOBS)"# ═══════════════════════════════════════════════════════════════════# Setup# ═══════════════════════════════════════════════════════════════════-.PHONY: setup_machine setup_tools--setup_machine:- @if count=0; \- [ -n "$(call truthy,$(JB))" ] && count=$$((count+1)); \- [ -n "$(call truthy,$(DEV))" ] && count=$$((count+1)); \- [ -n "$(call truthy,$(EXP))" ] && count=$$((count+1)); \- [ -n "$(call truthy,$(LESS))" ] && count=$$((count+1)); \- [ $$count -gt 1 ]; then \- echo "Error: use only one of JB=1, DEV=1, EXP=1 or LESS=1."; \- exit 1; \- fi- SUDO_PASSWORD="$(SUDO_PASSWORD)" \- INTERACTIVE="$(INTERACTIVE)" \- NO_BINPACK="$(NO_BINPACK)" \- NO_VPHONED="$(NO_VPHONED)" \- SPOOF_BUILD="$(SPOOF_BUILD)" \- zsh $(SCRIPTS)/setup_machine.sh \- $(if $(call truthy,$(JB)),--jb,) \- $(if $(call truthy,$(DEV)),--dev,) \- $(if $(call truthy,$(EXP)),--exp,) \- $(if $(call truthy,$(LESS)),--less,) \- $(if $(call truthy,$(SKIP_PROJECT_SETUP)),--skip-project-setup,)+.PHONY: setup_toolssetup_tools:VARIANT=$(VARIANT) zsh $(SCRIPTS)/setup_tools.sh@@ -261,7 +206,7 @@ endef$(PATCHER_BINARY): $(SWIFT_SOURCES) Package.swift@echo "=== Building vphone-cli patcher ($(GIT_HASH)) ==="$(WRITE_BUILD_INFO)- @set -o pipefail; swift build 2>&1 | tail -5+ @set -o pipefail; swift build --jobs $(SWIFT_JOBS) 2>&1 | tail -5# One recipe produces all three host binaries — `swift build` builds every# target anyway. Grouped targets (`&:`) would say this more precisely but need@@ -274,7 +219,7 @@ $(PATCHER_BINARY): $(SWIFT_SOURCES) Package.swift$(BINARY): $(SWIFT_SOURCES) Package.swift $(ENTITLEMENTS)@echo "=== Building vphone-cli ($(GIT_HASH)) ==="$(WRITE_BUILD_INFO)- @set -o pipefail; swift build -c release 2>&1 | tail -5+ @set -o pipefail; swift build -c release --jobs $(SWIFT_JOBS) 2>&1 | tail -5sign: $(BINARY)@echo "=== Signing ==="@@ -383,46 +328,10 @@ vphoned: $(GUEST_DIR)/vphoned $(BINARY)# VM management# ═══════════════════════════════════════════════════════════════════-.PHONY: vm_new vm_backup vm_restore vm_switch vm_list amfi_allow amfi_status amfi_off boot_host_preflight boot boot_less boot_dfu boot_binary_check boot_binary_check_less--vm_new:- CPU="$(CPU)" MEMORY="$(MEMORY)" \- zsh $(SCRIPTS)/vm_create.sh --dir "$(VM_DIR)" --disk-size $(DISK_SIZE)--vm_backup:- VM_DIR="$(VM_DIR)" BACKUPS_DIR="$(BACKUPS_DIR)" NAME="$(NAME)" BACKUP_INCLUDE_IPSW="$(BACKUP_INCLUDE_IPSW)" \- zsh $(SCRIPTS)/vm_backup.sh--vm_restore:- VM_DIR="$(VM_DIR)" BACKUPS_DIR="$(BACKUPS_DIR)" NAME="$(NAME)" FORCE="$(FORCE)" \- zsh $(SCRIPTS)/vm_restore.sh--vm_switch:- VM_DIR="$(VM_DIR)" BACKUPS_DIR="$(BACKUPS_DIR)" NAME="$(NAME)" BACKUP_INCLUDE_IPSW="$(BACKUP_INCLUDE_IPSW)" \- zsh $(SCRIPTS)/vm_switch.sh--vm_list:- @found=0; \- if [ -d "$(BACKUPS_DIR)" ]; then \- current=""; \- [ -f "$(VM_DIR)/.vm_name" ] && current="$$(cat "$(VM_DIR)/.vm_name")"; \- for d in "$(BACKUPS_DIR)"/*/; do \- [ -f "$${d}config.plist" ] || continue; \- name="$$(basename "$$d")"; \- size="$$(du -sh "$$d" 2>/dev/null | cut -f1)"; \- if [ "$$name" = "$$current" ]; then \- echo " * $$name ($$size) [active]"; \- else \- echo " $$name ($$size)"; \- fi; \- found=1; \- done; \- fi; \- if [ "$$found" = "0" ]; then echo " (no backups yet — run: make vm_backup NAME=<name>)"; fi+.PHONY: amfi_allow amfi_status amfi_off boot_host_preflight boot boot_less boot_dfu boot_binary_check boot_binary_check_less-# The self-containment admission gates. Expected to FAIL today: the bundled-# ldid is Homebrew's and links /opt/homebrew. That is the gate working, and it-# clears when VPhoneSign replaces ldid. CHECK_AUX_FAST=1 skips the smoke test.+# Self-containment checks over the complete application bundle.+# CHECK_AUX_FAST=1 skips smoke checks for local source checks only..PHONY: check-auxcheck-aux: bundle@zsh $(SCRIPTS)/check_aux.shdiff --git a/cfw-kit/README.md b/cfw-kit/README.mddeleted file mode 100644index 90a3ba69..00000000--- a/cfw-kit/README.md+++ /dev/null@@ -1,118 +0,0 @@-# custom-firmware-kit--Two independently buildable CFW environments for vphone-cli guests, sharing one-base install path.--| | vanilla | jb |-| --- | --- | --- |-| goal | boots to SpringBoard, nothing else | jailbroken kernel, empty userland |-| boot chain | `make fw_patch` (52 patches) | `make fw_patch_jb` (**127 patches**) |-| SSH / VNC / RPC | none | none (slot's job) |-| daemons added | none | none |-| `launchd.plist` | untouched | untouched |-| userland | yours to design | slot: `rootless` / `roothide`, both empty |--The kit does **not** fork the patchers. It calls the repo's built-`vphone-cli cfw <verb>`, so patch behaviour cannot drift from upstream.-It does not modify the vphone-cli repo at all.--## Use--```sh-# boot chain first — the kit only does the filesystem layer-cd ~/Documents/GitHub/Lakr233/vphone-cli && make fw_patch # or fw_patch_jb--# then, with the VM restored and POWERED OFF-~/Desktop/custom-firmware-kit/run.sh --variant vanilla /path/to/vm-~/Desktop/custom-firmware-kit/run.sh --variant jb /path/to/vm-```--`run.sh` re-execs itself under `sudo` (owners-honoured mounts need root),-attaches `Disk.img`, runs the variant installer against the mounted volumes,-then flips the boot snapshot offline via the repo's `vphone-cli cfw-flip-snapshot`.--Check what would happen without touching anything — **no root, no attach, no-writes**:--```sh-KIT_CHECK_ONLY=1 ./run.sh --variant jb-```--### Knobs--| variable | default | effect |-| --- | --- | --- |-| `JB_USERLAND` | `none` | `rootless` \| `roothide`; jb only. Both slots are empty, so anything but `none` is currently a hard error *before* the image is attached |-| `VANILLA_LSD_EMBEDDED_REG` | `0` | vanilla, 27 bases: open lsd's JB app-registration path |-| `FORCE_DSC_MAXSLIDE` | `0` | zero maxSlide on non-27 bases (normally self-gated to a no-op) |-| `KIT_CHECK_ONLY` | `0` | preflight and stop |-| `VPHONE_REPO` / `--repo` | auto | vphone-cli checkout to take the built `vphone-cli` and the resources from |-| `VPHONE_DROP_ARTIFACTS` | `0` | delete the extracted `cfw_input/` afterwards |--## Layout--```-run.sh host driver: attach, dispatch, snapshot flip-lib/common.sh helpers lifted from upstream cfw_install.sh + preflight-lib/base_stages.sh the stages both variants need-vanilla/install.sh minimal boot-jb/install.sh + jetsam guard, debugserver, Campo, two slot hooks-jb/userland/ empty slots (rootless, roothide) + how to fill them-docs/phase-matrix.md every upstream phase → variant, with evidence-```--`../paravirt-gpu-provenance-kit/` is separate and unchanged. It documents where-the two binaries in the GPU bundle come from; this kit only installs them.--## Design notes--**Preflight is the only safety net.** The installer streams onto a mounted-volume with no snapshot to roll back to, so everything that can fail is checked-before the first write: tools, the built binary, and every `cfw` subcommand this-variant *and its userland slot* will call — each one asked of the binary itself-(`vphone-cli cfw <sub> --help`), not pattern-matched out of a source file. A-userland flavour is sourced before preflight precisely so its requirements get-checked too.--**`umount` is never forced.** If something still holds a file on the volume the-kit wants to hear about it, not paper over it with `umount -f`-(`lib/base_stages.sh`).--**Why vanilla drops `launchd_cache_loader`.** That patch exists only to let-launchd accept a modified `launchd.plist`, and upstream's phase 7/7-(`inject-daemons`) is the only thing that modifies it. Vanilla installs no-daemons, so the patch has nothing to enable and stock validation passes-untouched. A userland flavour that *does* rewrite `launchd.plist` must declare-`USERLAND_MODIFIES_LAUNCHD_PLIST=1`, which re-arms the patch automatically.-Full reasoning in `docs/phase-matrix.md`.--## Verification status — read this before trusting the kit--Done, and repeatable:--- `zsh -n` on all five scripts-- payload paths confirmed present: `cfw_input/signcert.p12`,- `cfw_input/custom/AppleParavirtGPUMetalIOGPUFamily.tar`-- slot contract exercised with a throwaway flavour: `REQUIRED_CFW_SUBCOMMANDS`- appends reach preflight, `USERLAND_MODIFIES_LAUNCHD_PLIST=1` pulls in- `patch-launchd-cache-loader`, and a flavour demanding a nonexistent- subcommand is rejected with nothing written-- `run.sh` error paths: missing `--variant`, unknown variant, unknown- `JB_USERLAND`, empty slot--**Not re-run since the patchers moved into `vphone-cli`:**--- the `KIT_CHECK_ONLY=1` preflight. It no longer greps a Python file for verb- names; it asks the binary (`vphone-cli cfw <sub> --help`). Run it for both- variants, and for vanilla with the lsd flag on, before trusting the kit again.--**Not done — no VM was available on the authoring host:**--- no real install has ever run-- **no guest has ever booted from either variant**-- whether vanilla actually reaches SpringBoard is a static inference from- upstream's code and the research docs, not a measurement--Treat the phase matrix as a reviewed argument, not a test result. The first real-run should be vanilla on a 26.x base, where the fewest version gates fire.diff --git a/cfw-kit/docs/phase-matrix.md b/cfw-kit/docs/phase-matrix.mddeleted file mode 100644index eb3439fa..00000000--- a/cfw-kit/docs/phase-matrix.md+++ /dev/null@@ -1,101 +0,0 @@-# Phase matrix — what each variant installs, and why--Every row of upstream's installers, mapped onto this kit's two variants with the-evidence for the decision. This table is the only auditable form of the claim-"vanilla still boots".--Derived against:--| file | sha256 |-| --- | --- |-| `scripts/cfw_install.sh` | `7d71137763c47e9ac19a1199a97132f0e8990d4c9e8ff0f82e9719cd10e0373b` |-| `scripts/cfw_install_jb.sh` | `5c6c064b2aacce540a4dac15660cb3ec709e07f85d62a0ab49c331a91b062c74` |-| `scripts/cfw_install_host.sh` | `6c84d50b65c37404ca6ab423b6d22b5a69aba27d063da37d7ae0fc682175aa78` |--vphone-cli HEAD `6d5ce7d49b4574859c57c66dff26c5c02bcae6ba`, branch-`qof-update-26-fall`, 2026-09-23. **If any hash has moved, re-diff before-trusting this table.**--Note `cfw_install_jb.sh:43` runs `cfw_install.sh` first, so upstream "jb" means-regular + the JB phases. This kit does not chain; both variants call the same-stage functions in `lib/base_stages.sh` directly.-------## `cfw_install.sh` (regular, 7 phases)--| upstream | vanilla | jb | why |-| --- | :-: | :-: | --- |-| Cryptex SystemOS + AppOS + dyld symlinks (`:214`) | ✅ | ✅ | the hybrid firmware has a boot chain and no userland without it |-| IOMFB SwapEnd 0x560 — 26.0/18.x (`:331`) | ✅ | ✅ | version-gated; without it the VZ view is black |-| IOMFB force-kern — 27.x (`:336`) | ✅ | ✅ | same, 27's path |-| DSC maxSlide — 27.x (`:364`) | ✅ | ✅ | 27's cache + 512 MiB slide overflows the 6 GiB shared region → dyld cannot map libSystem → **pid 1 panics** |-| lsd embedded-reg — 27.x (`:366`) | ⬜ opt-in | ✅ | upstream `:348-351`: exists so the **`vpregister` first-boot tool** can register JB apps, because 27's `registerApplicationDictionary` is a stub. Nothing walks that path without such a tool. `VANILLA_LSD_EMBEDDED_REG=1` to force. |-| libxpc LWCR self-check — 27.x (`:368`) | ✅ | ✅ | 27's libxpc brk-aborts on the (matched=0, MATCH) pair our signing produces → every entitlement-pinning daemon crash-loops |-| `os_lockdown_mode_enabled` — 27.x (`:370`) | ✅ | ✅ | missing MAC sysctl → launchd abort |-| **2/7** seputil (`:383`) | ✅ | ✅ | SEP rejects the volume without the gigalocker UUID rename |-| diskimagesiod DDI gate — 27.x (`:407`) | ✅ | ✅ | **applied by upstream's regular variant too**, not a JB extra: `waitForDAMount` otherwise hangs forever on the 26.4 hybrid. Version-gated exactly as upstream. |-| gigalocker rename (`:423`) | ✅ | ✅ | part of the same SEP requirement |-| **3/7** AppleParavirtGPU bundle (`:431`) | ✅ | ✅ | backboardd crash loop / black SpringBoard without it. Provenance: `../paravirt-gpu-provenance-kit` |-| **4/7** iosbinpack64 (`:453`) | ❌ | ❌ | this is where bash/dropbear/SSH live. vanilla: explicitly excluded ("不给 ssh"). jb: belongs to the userland slot |-| **5/7** launchd_cache_loader (`:468`) | ❌ | ⬜ slot | **proven dead, not merely unnecessary.** `research/0_binary_patch_comparison.md:183` states its purpose is "Allow modified `launchd.plist`", and `cfw_install.sh:567` (`inject-daemons`) is the **only** writer of that file in the whole installer. Drop 7/7 and the patch has nothing to enable. Re-armed automatically when a slot sets `USERLAND_MODIFIES_LAUNCHD_PLIST=1`. |-| **6/7** mobileactivationd (`:486`) | ✅ | ✅ | otherwise the guest sits on the activation screen forever |-| **7/7** vphoned + 4 daemon plists + `launchd.plist` injection (`:504-569`) | ❌ | ⬜ slot | vphoned is host↔guest control, not a boot requirement. The plists are bash/dropbear/trollvnc/rpcserver_ios — exactly the "什么都不给" list |--## `cfw_install_jb.sh` (JB phases)--| upstream | vanilla | jb | why |-| --- | :-: | :-: | --- |-| **JB-1** launchd jetsam guard (`:244`) | ❌ | ✅ | without it pid 1 panics on boot under the JB kernel patches. Flavour-independent |-| **JB-1** launchdhook `/b` injection (`:237-242`) | ❌ | ⬜ slot | BaseBin-specific → `userland_launchd_hook` |-| **JB-2** iosbinpack64 (`:259`) | ❌ | ❌ | same as 4/7 |-| **JB-3** debugserver entitlements (`:271`) | ❌ | ✅ | flavour-independent, and a debugger is the point of a research JB |-| **JB-3b** Campo mach-lookup, 27 only (`:293`) | ❌ | ✅ | flavour-independent sandbox fix |-| **JB-4** procursus bootstrap (`:317`) | ❌ | ⬜ slot | rootless and roothide disagree on the prefix — this IS the divergence |-| **JB-4** BaseBin → `/cores` (`:378`) | ❌ | ⬜ slot | flavour-specific dylibs |-| **JB-4** TweakLoader (`:411`) | ❌ | ⬜ slot | flavour-specific |-| **JB-5** first-boot setup + `launchd.plist` injection (`:423-471`) | ❌ | ⬜ slot | Sileo/apt/TrollStore finalization; also the thing that makes launchd_cache_loader necessary again |--Legend: ✅ installed · ❌ not installed · ⬜ left to the userland slot or an opt-in flag-------## Divergences from upstream worth knowing--1. **No chaining.** Upstream jb re-runs the whole regular installer. Here both- variants call shared stage functions, so the base path cannot drift between- them — but it also means this kit's jb is *not* byte-identical to upstream's- jb even before the empty slot is accounted for.--2. **`patch_rootfs_binary` helper.** Upstream open-codes the- backup → patch → sign → copy → chmod sequence in four places. Same- semantics, one helper (`lib/common.sh`). diskimagesiod and launchd still- open-code it because their entitlements must survive the re-sign.--3. **`detect_ios_version` is explicit.** Upstream sets `IOS_VERSION` as a side- effect of the display-fix block, which makes the stage order silently- load-bearing. Here it is set once, on purpose, right after the Cryptex lands- (`SystemVersion.plist` does not exist before that).--4. **Preflight before any write.** Upstream discovers a missing `zstd` or a- stale `vphone-cli` partway through a streaming install onto a volume with no- snapshot to roll back to. `preflight()` checks tools, the built binary and- every `cfw` subcommand the selected variant *and its userland slot* will- call — each asked of the binary itself with `--help`, which exits 0 only for- a verb it really has — then refuses with nothing written.--5. **`run.sh` requires `--variant`.** Upstream `cfw_install_host.sh` defaults to- `exp`. Defaulting to either variant here would hand someone a firmware they- did not ask for.--6. **`cfw_input/` is kept.** Upstream deletes it for `make` idempotence; opt in- with `VPHONE_DROP_ARTIFACTS=1`.--## What this table does not tell you--Nothing here was verified by booting a guest. Every ✅ and ❌ is read off-upstream's code and comments plus the research docs. The two rows most likely to-be wrong in practice are the two where this kit *removes* something upstream-always installs — 4/7 and 7/7 — and their failure mode is a guest that boots to-a black screen or a login-less shell you cannot reach, because vanilla-deliberately ships no way in.diff --git a/cfw-kit/jb/install.sh b/cfw-kit/jb/install.shdeleted file mode 100755index e37578a9..00000000--- a/cfw-kit/jb/install.sh+++ /dev/null@@ -1,247 +0,0 @@-#!/bin/zsh-# vphone-tier: build (see cfw-kit/run.sh)-# jb/install.sh — fully patched firmware, empty userland.-#-# The firmware layer is jailbroken all the way: run `make fw_patch_jb` first and-# all 127 JB boot-chain patches (iBoot / kernel / TXM / DSC) are already in the-# images this installs onto. This script then applies the FILESYSTEM-layer JB-# work that does not depend on which userland flavour you eventually pick.-#-# The userland is deliberately EMPTY. No BaseBin hooks, no procursus bootstrap,-# no Sileo, no TweakLoader, no first-boot setup. Two flavours are planned —-# rootless and roothide — and they disagree about where things live, so the kit-# ships the interface and neither implementation. See userland/README.md.-#-# installed here left empty (slot)-# ───────────────────────────────── ──────────────────────────────-# everything vanilla installs BaseBin hooks -> /cores-# launchd jetsam guard /b launchdhook alias + injection-# debugserver entitlements procursus bootstrap-# Campo mach-lookup fix (iOS 27) Sileo / apt / TrollStore-# iOS-27 JB DSC + DDI patches TweakLoader-# first-boot setup daemon-#-# Usage: ../run.sh --variant jb [vm_dir]-# JB_USERLAND=rootless|roothide|none (default: none)-# Contract: root, VM off, CFW_HOST_CONTAINER set, $1 = VM dir.-set -euo pipefail--KIT_DIR="${0:a:h:h}"-source "$KIT_DIR/lib/common.sh"-source "$KIT_DIR/lib/base_stages.sh"--VM_DIR="$(cd "${1:-.}" && pwd)"-CFW_INPUT="cfw_input"-CFW_ARCHIVE="cfw_input.tar.zst"-TEMP_DIR="$VM_DIR/.cfw_temp"--JB_USERLAND="${JB_USERLAND:-none}"-FORCE_DSC_MAXSLIDE="${FORCE_DSC_MAXSLIDE:-0}"--REQUIRED_CFW_SUBCOMMANDS=(- cryptex-paths- patch-seputil- patch-mobileactivationd- patch-iomfb-swapend- patch-iomfb-force-kern- patch-dsc-maxslide- patch-xpc-lwcr- patch-lockdown-mode- patch-lsd-embedded-reg- patch-diskimagesiod- patch-launchd-jetsam- # J3's Campo fix. It was a standalone Python script outside the preflight's- # reach; as a cfw verb it is checked with the rest.- patch-campo-entitlements-)--REPO_DIR="$(resolve_repo)"-VPHONE_CLI="$(resolve_vphone_cli)"-init_paths--cleanup_on_exit() {- safe_detach "$TEMP_DIR/mnt_sysos" 2>/dev/null || true- safe_detach "$TEMP_DIR/mnt_appos" 2>/dev/null || true-}-trap cleanup_on_exit EXIT--echo "[*] custom-firmware-kit — variant: jb (all firmware patches, empty userland)"-echo "[+] repo: $REPO_DIR"-echo "[+] vm: $VM_DIR"--# ── Userland slot ───────────────────────────────────────────────-# Loaded BEFORE anything is written so a flavour can register hooks and so a-# missing/broken slot fails before the volume is touched.-USERLAND_DIR=""-if [[ "$JB_USERLAND" != "none" ]]; then- USERLAND_DIR="$KIT_DIR/jb/userland/$JB_USERLAND"- [[ -d "$USERLAND_DIR" ]] || die "unknown JB_USERLAND '$JB_USERLAND' (expected a dir at $USERLAND_DIR)"- if [[ -f "$USERLAND_DIR/install.sh" ]]; then- echo "[+] userland flavour: $JB_USERLAND"- source "$USERLAND_DIR/install.sh"- else- die "JB_USERLAND=$JB_USERLAND but $USERLAND_DIR/install.sh does not exist yet.- The userland slots are intentionally empty in this kit — see jb/userland/README.md.- Use JB_USERLAND=none to install the firmware layer only."- fi-else- echo "[+] userland flavour: none (slot left empty — firmware layer only)"-fi--# A flavour that rewrites launchd.plist needs the cache-validation NOP too;-# fold it into the preflight list so a missing subcommand is caught before any-# write rather than halfway through the install.-if [[ "${USERLAND_MODIFIES_LAUNCHD_PLIST:-0}" == "1" ]]; then- echo "[+] slot declares it modifies launchd.plist — launchd_cache_loader patch enabled"- REQUIRED_CFW_SUBCOMMANDS+=(patch-launchd-cache-loader)-fi--preflight-[[ "${KIT_CHECK_ONLY:-0}" == "1" ]] && { echo "[+] check-only: stopping before any write"; exit 0; }--RESTORE_DIR=$(find_restore_dir)-echo "[+] Restore directory: $RESTORE_DIR"--setup_cfw_input-INPUT_DIR="$VM_DIR/$CFW_INPUT"-echo "[+] Input resources: $INPUT_DIR"-require_signing_tools--mkdir -p "$TEMP_DIR"--echo ""-echo "[*] Parsing iPhone BuildManifest for Cryptex paths..."-CRYPTEX_PATHS=$(cfw_cli 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"--# ── Base (same code path as vanilla) ────────────────────────────-# The only difference from vanilla's base is the lsd embedded-registration-# gate, on here because a JB userland is what needs it.-stage_cryptex-detect_ios_version-stage_display_and_boot_fixes 1-stage_seputil-stage_gpu-stage_mobileactivationd--# Only needed if the userland slot rewrites launchd.plist. See the stage's-# comment in lib/base_stages.sh for why this is not unconditional.-if [[ "${USERLAND_MODIFIES_LAUNCHD_PLIST:-0}" == "1" ]]; then- stage_launchd_cache_loader-else- echo ""- echo "[base] skip launchd_cache_loader (nothing modifies launchd.plist)"-fi--# ═══════════ J1 PATCH LAUNCHD (JETSAM GUARD) ══════════════════-# The jetsam guard patch is flavour-independent: without it pid 1 panics on-# boot under the JB kernel patches. The launchdhook dylib injection that-# upstream also does here belongs to BaseBin, so it is exposed as a hook the-# userland slot may implement instead of being done unconditionally.-echo ""-echo "[J1] 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"--# Original entitlements must survive the re-sign or spawn breaks.-echo " Extracting original entitlements..."-ldid -e "$TEMP_DIR/launchd" > "$TEMP_DIR/launchd.entitlements" 2>/dev/null || true-if [[ -s "$TEMP_DIR/launchd.entitlements" ]]; then- echo " [+] Preserved launchd entitlements"-else- warn "No entitlements found on original launchd"-fi--# ── slot hook: dylib injection into pid 1 ──-if typeset -f userland_launchd_hook >/dev/null; then- echo " Running userland launchd hook ($JB_USERLAND)..."- userland_launchd_hook "$TEMP_DIR/launchd"-else- echo " [*] No userland launchd hook — pid 1 gets no injected dylib"-fi--cfw_cli patch-launchd-jetsam "$TEMP_DIR/launchd"--if [[ -s "$TEMP_DIR/launchd.entitlements" ]]; then- ldid -S"$TEMP_DIR/launchd.entitlements" -M "-K$VM_DIR/$CFW_INPUT/signcert.p12" "$TEMP_DIR/launchd"-else- ldid_sign "$TEMP_DIR/launchd"-fi-cp -R "$TEMP_DIR/launchd" "$MNT1/sbin/launchd"-/bin/chmod 0755 $MNT1/sbin/launchd--echo " [+] launchd patched"--# ═══════════ J2 DEBUGSERVER ENTITLEMENTS ══════════════════════-echo ""-echo "[J2] Patching debugserver entitlements..."--if [[ -f "$MNT1/usr/libexec/debugserver" ]]; then- cp "$MNT1/usr/libexec/debugserver" "$TEMP_DIR/debugserver"- ldid -e "$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- ldid_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"-else- warn "debugserver not present in this OS image; skipping"-fi--# ═══════════ J3 CAMPO SANDBOX FIX (iOS 27 only) ═══════════════-# Grants Campo the backboard/frontboard mach-lookups the 26.4 temporary sandbox-# denies. 27-gated on the mounted rootfs SystemVersion.plist.-CAMPO_BIN="$MNT1/Applications/Campo.app/Campo"-case "$IOS_VERSION" in-27.*)- if [[ -f "$CAMPO_BIN" ]]; then- echo ""- echo "[J3] Granting Campo backboard/frontboard mach-lookup exceptions (iOS $IOS_VERSION)..."- cp "$CAMPO_BIN" "$TEMP_DIR/Campo"- ldid -e "$TEMP_DIR/Campo" > "$TEMP_DIR/Campo.entitlements" 2>/dev/null || true- if [[ -s "$TEMP_DIR/Campo.entitlements" ]]; then- cfw_cli patch-campo-entitlements "$TEMP_DIR/Campo.entitlements"- ldid_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"- else- warn "Could not read Campo entitlements; skipping Campo sandbox fix"- fi- else- echo "[J3] Campo.app not present in this OS image; skipping"- fi- ;;-*)- echo "[J3] skip Campo sandbox fix (base iOS ${IOS_VERSION:-unknown} — 27-only)"- ;;-esac--# ═══════════ J4 USERLAND SLOT ═════════════════════════════════-echo ""-if typeset -f userland_install >/dev/null; then- echo "[J4] Installing userland flavour: $JB_USERLAND..."- userland_install- echo " [+] userland installed"-else- echo "[J4] Userland slot is empty — nothing installed."- echo " No /cores hooks, no bootstrap, no package manager, no tweak loader."- echo " Fill jb/userland/{rootless,roothide}/install.sh to change that."-fi--stage_unmount--echo ""-echo "[+] jb CFW installation complete (firmware layer fully patched)."-if ! typeset -f userland_install >/dev/null; then- echo " Userland slot empty: the guest boots a jailbroken KERNEL with a"- echo " stock userland. That is expected for JB_USERLAND=none."-fidiff --git a/cfw-kit/jb/userland/README.md b/cfw-kit/jb/userland/README.mddeleted file mode 100644index 543a91c4..00000000--- a/cfw-kit/jb/userland/README.md+++ /dev/null@@ -1,63 +0,0 @@-# JB userland slot--Both flavour directories here are **empty on purpose**. `jb/install.sh` installs-the firmware and filesystem layers; everything above that — BaseBin hooks, the-procursus bootstrap, a package manager, a tweak loader, a first-boot setup-daemon — is left to a flavour, because rootless and roothide disagree about-where any of it lives.--With no flavour selected the guest boots a **jailbroken kernel under a stock-userland**. That is a valid, deliberate end state, not a half-finished install.--> The authoritative hook contract — exact call sites, variables in scope,-> available helpers, and the two declarations a flavour must make — is-> **§10 of `~/Desktop/vphone-cli-migration-plan.md`**. This page is only how to-> drive it. If the two ever disagree, the plan wins.--## Selecting a flavour--```sh-JB_USERLAND=rootless ../../run.sh --variant jb /path/to/vm-```--`JB_USERLAND` is `none` by default. Naming a flavour whose directory has no-`install.sh` is a hard error raised **before the disk image is attached**, so a-half-built flavour cannot leave a half-modified volume behind.--## Adding one--Drop an `install.sh` in `rootless/` or `roothide/`. It is **sourced**, not-executed, so it must define functions rather than run work at the top level.-Two optional hooks:--| function | when it runs |-| --- | --- |-| `userland_launchd_hook <workfile>` | on the launchd work copy, after its entitlements are saved and before the jetsam patch and re-sign |-| `userland_install` | after J3, with the volumes still mounted, just before unmount |--Top-level statements run at source time — before `preflight`, before anything is-written. That is where a flavour declares what it needs:--```zsh-# checked by preflight, before the first write-REQUIRED_CFW_SUBCOMMANDS+=(inject-dylib)--# if you rewrite /System/Library/xpc/launchd.plist you MUST set this, or-# launchd will refuse the modified plist and the guest will not boot-USERLAND_MODIFIES_LAUNCHD_PLIST=1-```--## Payloads already in the repo--`scripts/resources/cfw_jb_input.tar.zst` carries a rootless-shaped set:--- `basebin/launchdhook.dylib`, `basebin/libellekit.dylib`, `basebin/systemhook.dylib`-- `jb/bootstrap-iphoneos-arm64.tar.zst`-- `jb/org.coolstar.sileo_2.5.1_iphoneos-arm64.deb`--None of these are Apple binaries — they are ElleKit/Dopamine-derived, so the-provenance question that applies to the GPU bundle does not apply here.--**roothide has no payload in this repo.** A roothide flavour has to bring its-own BaseBin; the dylibs above are built for rootless path assumptions and-will not work unmodified.diff --git a/cfw-kit/jb/userland/roothide/.gitkeep b/cfw-kit/jb/userland/roothide/.gitkeepdeleted file mode 100644index e6b96d95..00000000--- a/cfw-kit/jb/userland/roothide/.gitkeep+++ /dev/null@@ -1,3 +0,0 @@-# Empty slot. Add install.sh here to implement the roothide flavour.-# Hook contract: ../README.md, and §10 of vphone-cli-migration-plan.md.-# Note: no roothide BaseBin ships in the repo; bring your own.diff --git a/cfw-kit/jb/userland/rootless/.gitkeep b/cfw-kit/jb/userland/rootless/.gitkeepdeleted file mode 100644index 2b635298..00000000--- a/cfw-kit/jb/userland/rootless/.gitkeep+++ /dev/null@@ -1,2 +0,0 @@-# Empty slot. Add install.sh here to implement the rootless flavour.-# Hook contract: ../README.md, and §10 of vphone-cli-migration-plan.md.diff --git a/cfw-kit/lib/base_stages.sh b/cfw-kit/lib/base_stages.shdeleted file mode 100644index 32f337e2..00000000--- a/cfw-kit/lib/base_stages.sh+++ /dev/null@@ -1,268 +0,0 @@-#!/bin/zsh-# vphone-tier: build (see cfw-kit/run.sh)-# base_stages.sh — the stages BOTH variants need, as functions.-#-# This is the "what does it take to boot at all" set. Nothing here installs a-# daemon, opens a port, or touches launchd.plist. Both vanilla and jb call-# these; jb then layers its own stages on top.-#-# Every function assumes lib/common.sh is already sourced and init_paths ran.--# ── Version detection ───────────────────────────────────────────-# Sets IOS_VERSION and DSC_DIR once, explicitly. Several stages key off-# IOS_VERSION; having one of them set it as a side effect made the stage order-# load-bearing in a way nothing enforced. Call this right after stage_cryptex —-# SystemVersion.plist only exists on the volume once the Cryptex is in place.-detect_ios_version() {- IOS_VERSION=$(read_ios_version)- DSC_DIR="$MNT1/System/Cryptexes/OS/System/Library/Caches/com.apple.dyld"- echo " [*] userland version: ${IOS_VERSION:-unknown}"- [[ -n "$IOS_VERSION" ]] \- || warn "could not read ProductVersion — every version-gated fix below will be skipped"-}--# ── Cryptex SystemOS + AppOS ────────────────────────────────────-# Without this the hybrid firmware has a boot chain and no userland.-stage_cryptex() {- echo ""- echo "[base] Installing Cryptex (SystemOS + AppOS)..."-- echo " Mounting rootfs rw..."- mount_vol s1 "$MNT1"-- local os_count=0 app_count=0- [[ -d "$MNT1/System/Cryptexes/OS" ]] && os_count=$(/bin/ls "$MNT1/System/Cryptexes/OS/" | /usr/bin/wc -l | tr -d ' ')- [[ -d "$MNT1/System/Cryptexes/App" ]] && app_count=$(/bin/ls "$MNT1/System/Cryptexes/App/" | /usr/bin/wc -l | tr -d ' ')-- if [[ "${os_count:-0}" -gt 0 && "${app_count:-0}" -gt 0 ]]; then- echo " [*] Cryptexes already installed (OS=${os_count}, App=${app_count}), skipping copy"- _link_dyld- echo " [+] Cryptex skipped (already present)"- return- fi-- local sysos_dmg="$TEMP_DIR/CryptexSystemOS.dmg"- local appos_dmg="$TEMP_DIR/CryptexAppOS.dmg"- local mnt_sysos="$TEMP_DIR/mnt_sysos"- local mnt_appos="$TEMP_DIR/mnt_appos"-- if [[ ! -f "$sysos_dmg" ]]; then- echo " Extracting AEA key..."- local aea_key- aea_key=$(ipsw fw aea --key "$RESTORE_DIR/$CRYPTEX_SYSOS")- echo " Decrypting SystemOS..."- aea decrypt -i "$RESTORE_DIR/$CRYPTEX_SYSOS" -o "$sysos_dmg" -key-value "$aea_key"- else- echo " Using cached SystemOS DMG"- fi-- if [[ ! -f "$appos_dmg" ]]; then- cp "$RESTORE_DIR/$CRYPTEX_APPOS" "$appos_dmg"- else- echo " Using cached AppOS DMG"- fi-- 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..."- host_hdiutil attach -mountpoint "$mnt_sysos" "$sysos_dmg" -nobrowse -owners off \- || die "Failed to mount SystemOS DMG. Run 'sudo -v' in a terminal and retry."- echo " Mounting AppOS..."- host_hdiutil attach -mountpoint "$mnt_appos" "$appos_dmg" -nobrowse -owners off \- || die "Failed to mount AppOS DMG. Run 'sudo -v' in a terminal and retry."-- /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-- echo " Copying Cryptexes..."- cp -R "$mnt_sysos/." "$MNT1/System/Cryptexes/OS"- cp -R "$mnt_appos/." "$MNT1/System/Cryptexes/App"-- echo " Creating dyld symlinks..."- _link_dyld-- echo " Unmounting Cryptex DMGs..."- safe_detach "$mnt_sysos"- safe_detach "$mnt_appos"-- echo " [+] Cryptex installed"-}--_link_dyld() {- /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-}--# ── Version-gated display / boot fixes ──────────────────────────-# NOT optional extras. Without the matching one the guest either shows a black-# screen on the host VZ view or panics at pid 1. Keyed off the installed-# userland version, exactly as upstream does.-#-# $1 = "1" to also apply the lsd embedded-registration gate. That one is the-# only genuinely JB-only patch in this stage: upstream's own comment-# (cfw_install.sh:348-351) says it exists so the iOS-27 `vpregister` first-boot-# tool can register JB app bundles, because uicache's-# registerApplicationDictionary is a no-op stub on 27. With no such tool-# installed it opens a path nothing walks.-#-# Reads IOS_VERSION / DSC_DIR; detect_ios_version must have run.-stage_display_and_boot_fixes() {- local want_lsd_reg="${1:-0}"- : "${IOS_VERSION?detect_ios_version has not run}"- : "${DSC_DIR:?detect_ios_version has not run}"-- case "$IOS_VERSION" in- 26.0*|18.*)- echo " [*] Patching IOMobileFramebuffer SwapEnd payload size (-> 0x560)..."- [[ -d "$DSC_DIR" ]] || die "dyld cache dir missing: $DSC_DIR"- cfw_cli patch-iomfb-swapend "$DSC_DIR" --target-size 0x560- ;;- 27.*)- echo " [*] Forcing IOMobileFramebuffer present onto the kern (method-5) path..."- [[ -d "$DSC_DIR" ]] || die "dyld cache dir missing: $DSC_DIR"- cfw_cli patch-iomfb-force-kern "$DSC_DIR"- ;;- esac-- case "$IOS_VERSION" in- 27.*)- if [[ -d "$DSC_DIR" ]]; then- # 27's cache + 512 MiB maxSlide overflows the 6 GiB shared region- # -> dyld cannot map libSystem -> launchd (pid 1) panics.- echo " [*] Checking dyld cache maxSlide vs kernel shared region..."- cfw_cli patch-dsc-maxslide "$DSC_DIR"- # libxpc LWCR self-check crash-loops every daemon that pins an- # entitlement peer-requirement under our code-signing setup.- echo " [*] Patching libxpc LWCR self-check..."- cfw_cli patch-xpc-lwcr "$DSC_DIR"- # missing MAC sysctl -> launchd abort.- echo " [*] Patching os_lockdown_mode_enabled..."- cfw_cli patch-lockdown-mode "$DSC_DIR"-- if [[ "$want_lsd_reg" == "1" ]]; then- echo " [*] Patching lsd embedded-registration gate..."- cfw_cli patch-lsd-embedded-reg "$DSC_DIR"- else- echo " [*] skip lsd embedded-registration gate (no JB registration tool)"- fi- fi- ;;- *)- if [[ "${FORCE_DSC_MAXSLIDE:-0}" == "1" && -d "$DSC_DIR" ]]; then- echo " [*] Forcing dyld cache maxSlide=0 (opt-in FORCE_DSC_MAXSLIDE=1)..."- cfw_cli patch-dsc-maxslide "$DSC_DIR" --force- fi- ;;- esac-}--# ── seputil + gigalocker ────────────────────────────────────────-stage_seputil() {- echo ""- echo "[base] Patching seputil..."- patch_rootfs_binary "usr/libexec/seputil" patch-seputil "com.apple.seputil"-- # diskimagesiod DDI mount-gate. NOT an extra and NOT jailbreak-specific:- # upstream applies it in the plain regular variant too (cfw_install.sh:407),- # because on a 27 userland MobileStorageMounter's waitForDAMount otherwise- # hangs forever on the 26.4 hybrid. Version-gated exactly as upstream: on a- # version-matched userland the native wait completes and forcing it to- # return early could race the real mount.- #- # Entitlements (embedded sandbox profile + private DA/apfs) must survive the- # re-sign, so this cannot use patch_rootfs_binary.- case "$IOS_VERSION" in- 27.*)- echo " Patching diskimagesiod (DDI auto-mount, iOS $IOS_VERSION)..."- if ! [[ -e "$MNT1/usr/libexec/diskimagesiod.bak" ]]; then- /bin/cp "$MNT1/usr/libexec/diskimagesiod" "$MNT1/usr/libexec/diskimagesiod.bak"- fi- ldid -e "$MNT1/usr/libexec/diskimagesiod.bak" > "$TEMP_DIR/diskimagesiod.ent.plist"- cp "$MNT1/usr/libexec/diskimagesiod.bak" "$TEMP_DIR/diskimagesiod"- cfw_cli patch-diskimagesiod "$TEMP_DIR/diskimagesiod"- ldid_sign_ent "$TEMP_DIR/diskimagesiod" "$TEMP_DIR/diskimagesiod.ent.plist" "com.apple.diskimagesiod"- cp -R "$TEMP_DIR/diskimagesiod" "$MNT1/usr/libexec/diskimagesiod"- /bin/chmod 0755 "$MNT1/usr/libexec/diskimagesiod"- ;;- esac-- echo " Renaming gigalocker..."- mount_vol s3 "$MNT3"- mv "$MNT3"/*.gl(N) "$MNT3/AA.gl" 2>/dev/null || true-- echo " [+] seputil patched"-}--# ── Paravirtual GPU bundle ──────────────────────────────────────-# Without it: backboardd crash loop / black SpringBoard.-# Provenance of the two binaries in here: see ../paravirt-gpu-provenance-kit.-stage_gpu() {- echo ""- echo "[base] Installing AppleParavirtGPUMetalIOGPUFamily..."-- local gpu_tar="$INPUT_DIR/custom/AppleParavirtGPUMetalIOGPUFamily.tar"- [[ -f "$gpu_tar" ]] || die "GPU bundle missing: $gpu_tar"-- cp -R "$gpu_tar" "$MNT1"- "$TAR" --preserve-permissions --no-overwrite-dir --warning=no-unknown-keyword \- -xf $MNT1/AppleParavirtGPUMetalIOGPUFamily.tar -C $MNT1-- local bundle="$MNT1/System/Library/Extensions/AppleParavirtGPUMetalIOGPUFamily.bundle"- 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"-}--# ── Activation bypass ───────────────────────────────────────────-# Without it the guest sits on the activation screen forever.-stage_mobileactivationd() {- echo ""- echo "[base] Patching mobileactivationd..."- patch_rootfs_binary "usr/libexec/mobileactivationd" patch-mobileactivationd- echo " [+] mobileactivationd patched"-}--# ── launchd cache validation ────────────────────────────────────-# NOPs the cache validation check in launchd_cache_loader. Its ONLY purpose is-# to let launchd accept a MODIFIED /System/Library/xpc/launchd.plist-# (research/0_binary_patch_comparison.md row 2: "Allow modified launchd.plist").-#-# So it is NOT part of the base set: neither vanilla nor jb-with-an-empty-slot-# touches launchd.plist, and on a stock plist the stock validation passes.-# A userland flavour that injects a daemon into launchd.plist — which is what-# upstream cfw_install_jb.sh:459-471 does — MUST declare-# USERLAND_MODIFIES_LAUNCHD_PLIST=1, or the guest will boot with a plist-# launchd refuses to load.-stage_launchd_cache_loader() {- echo ""- echo "[base] Patching launchd_cache_loader (modified launchd.plist allowed)..."- patch_rootfs_binary "usr/libexec/launchd_cache_loader" \- patch-launchd-cache-loader "com.apple.launchd_cache_loader"- echo " [+] launchd_cache_loader patched"-}--# ── Teardown ────────────────────────────────────────────────────-stage_unmount() {- echo ""- echo "[*] Unmounting image volumes..."- # Deliberately NOT umount -f: if something still holds a file on the volume- # we want to hear about it, not paper over it.- umount "$MNT1" 2>/dev/null || warn "could not unmount $MNT1 (still busy?)"- umount "$MNT3" 2>/dev/null || true- /bin/rm -rf "$TEMP_DIR/mnt_sysos" "$TEMP_DIR/mnt_appos"-}diff --git a/cfw-kit/lib/common.sh b/cfw-kit/lib/common.shdeleted file mode 100644index f4b813ec..00000000--- a/cfw-kit/lib/common.sh+++ /dev/null@@ -1,242 +0,0 @@-#!/bin/zsh-# vphone-tier: build (see cfw-kit/run.sh for why the whole kit is build tier)-# common.sh — shared helpers for the custom-firmware-kit variant installers.-#-# Every function here is lifted from vphone-cli's scripts/cfw_install.sh so the-# two variants behave identically to the upstream installer on the code paths-# they keep. Do not "improve" them here — if upstream changes, re-sync.-#-# Contract expected by the callers (same as upstream cfw_install.sh):-# - running as root, VM powered off-# - CFW_HOST_CONTAINER set to the attached APFS container (e.g. disk4)-# - cwd = the VM directory, $1 = the VM directory-# - VPHONE_REPO points at a vphone-cli checkout (for the built binary and-# the resources/ archives)--# ── Restore caller's PATH — Nix /etc/zshenv resets PATH on zsh startup ─-[[ -n "${_VPHONE_PATH:-}" ]] && export PATH="$_VPHONE_PATH"--die() {- echo "[-] $*" >&2- exit 1-}--warn() { echo "[!] $*" >&2; }--# ── Repo location ───────────────────────────────────────────────-# The kit does not fork the patchers; it calls the repo's `vphone-cli cfw`.-# The checkout marker is scripts/cfw_install.sh — the upstream installer this-# kit is derived from, and the one file whose absence really does mean "not a-# vphone-cli checkout". It is deliberately not the built binary: a fresh clone-# has no .build yet, and "run make build" is a better error than "wrong path".-resolve_repo() {- local candidate="${VPHONE_REPO:-}"- if [[ -z "$candidate" ]]; then- # The kit now lives inside the checkout, so the enclosing directory is- # the answer in the normal case. The other two are kept for running it- # from outside a checkout, which is how it was developed.- for c in "${KIT_DIR:h}" "$HOME/Documents/GitHub/Lakr233/vphone-cli" "${KIT_DIR:h}/vphone-cli"; do- [[ -f "$c/scripts/cfw_install.sh" ]] && candidate="$c" && break- done- fi- [[ -n "$candidate" ]] || die "VPHONE_REPO unset and no vphone-cli checkout found. Pass --repo <path>."- [[ -f "$candidate/scripts/cfw_install.sh" ]] \- || die "Not a vphone-cli checkout (no scripts/cfw_install.sh): $candidate"- echo "${candidate:a}"-}--# ── vphone-cli resolver — every CFW patcher lives in the binary ─-# Same order as scripts/cfw_install_host.sh and run.sh: VPHONE_CLI_BIN when a-# vphone-cli subcommand invoked us, otherwise the repo's dev build or the .app,-# where the kit sits beside Contents/Resources and the binaries are one level-# up in MacOS. Never `command -v` — it has to be the binary built from this-# checkout, not whatever else is on PATH.-resolve_vphone_cli() {- if [[ -n "${VPHONE_CLI_BIN:-}" ]]; then- echo "$VPHONE_CLI_BIN"- return- fi- local c- for c in "$REPO_DIR/.build/release/vphone-cli" "${REPO_DIR:h}/MacOS/vphone-cli"; do- [[ -x "$c" ]] && { echo "$c"; return }- done- echo "$REPO_DIR/.build/release/vphone-cli" # report the expected path-}--cfw_cli() { "$VPHONE_CLI" cfw "$@"; }--# ── Signing ─────────────────────────────────────────────────────-require_signing_tools() {- command -v ldid &>/dev/null \- || die "ldid not found (brew install ldid-procursus). Run: make setup_tools"-}--ldid_sign() {- local file="$1" bundle_id="${2:-}"- local args=(-S -M "-K$VM_DIR/$CFW_INPUT/signcert.p12")- [[ -n "$bundle_id" ]] && args+=("-I$bundle_id")- ldid "${args[@]}" "$file"-}--# Like ldid_sign but re-applies an entitlements plist (for binaries whose-# entitlements must survive the re-sign).-ldid_sign_ent() {- local file="$1" ent="$2" bundle_id="${3:-}"- local args=("-S$ent" -M "-K$VM_DIR/$CFW_INPUT/signcert.p12")- [[ -n "$bundle_id" ]] && args+=("-I$bundle_id")- ldid "${args[@]}" "$file"-}--# ── Host image helpers ──────────────────────────────────────────-host_hdiutil() {- local rc- [[ -n "${SUDO_ASKPASS:-}" ]] && { sudo -A hdiutil "$@"; return; }- hdiutil "$@" && return 0- rc=$?- if sudo -n true 2>/dev/null; then- sudo hdiutil "$@"- return- fi- return "$rc"-}--safe_detach() {- local mnt="$1"- if mount | grep -Fq " on $mnt "; then- host_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-}--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"-}--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_cfw_input() {- [[ -d "$VM_DIR/$CFW_INPUT" ]] && return- local archive- for search_dir in "$REPO_DIR/scripts/resources" "$REPO_DIR/scripts" "$VM_DIR"; do- archive="$search_dir/$CFW_ARCHIVE"- if [[ -f "$archive" ]]; then- echo " Extracting $CFW_ARCHIVE..."- "$TAR" --zstd --warning=no-unknown-keyword -xf "$archive" -C "$VM_DIR"- return- fi- done- die "Neither $CFW_INPUT/ nor $CFW_ARCHIVE found"-}--# ── Preflight ───────────────────────────────────────────────────-# Everything that can fail is checked BEFORE the first write to the volume.-# This is the only cheap protection against a half-modified guest volume:-# the installer is streaming and there is no snapshot to roll back to.-preflight() {- local fatal=0-- command -v ipsw >/dev/null 2>&1 \- || { warn "'ipsw' not found. Install: brew install blacktop/tap/ipsw"; fatal=1; }- command -v aea >/dev/null 2>&1 \- || { warn "'aea' not found (requires macOS 12+)"; fatal=1; }- command -v ldid >/dev/null 2>&1 \- || { warn "'ldid' not found. Install: brew install ldid-procursus"; fatal=1; }-- # GNU tar: macOS bsdtar lacks --no-overwrite-dir / --warning=.- if [[ ! -x "$TAR" ]]; then- warn "GNU tar not found at '$TAR'. Install: brew install gnu-tar"; fatal=1- fi- # --zstd in GNU tar spawns an external zstd(1); it is NOT linked in.- if [[ -x "$TAR" ]] && ! command -v zstd >/dev/null 2>&1; then- warn "'zstd' not found — GNU tar's --zstd shells out to it. Install: brew install zstd"- fatal=1- fi-- if [[ ! -x "$VPHONE_CLI" ]]; then- warn "vphone-cli not found (tried: $VPHONE_CLI) — build it with 'make build' in $REPO_DIR"- fatal=1- else- # Every cfw subcommand this variant will call must exist up front. Ask- # the binary, not a source file, by reading the verb list out of its own- # help. Probing `cfw <sub> --help` looks tidier and is WRONG: swift- # argument-parser intercepts --help anywhere in argv and prints the group- # help with exit 0, so every name on earth "passes". And `cfw <sub>` with- # no arguments cannot be used either — it exits 64 for a real verb- # (missing argument) and 64 for a typo, and would actually RUN any verb- # that happens to need no arguments.- local -a have- # (@f) on empty output yields one empty element, not an empty array, so- # a count test never fires. Drop empties first — that is what makes the- # "could not read the list" branch below reachable at all.- have=(${(@f)"$("$VPHONE_CLI" cfw --help 2>&1 |- awk '/^SUBCOMMANDS:/ {f = 1; next} f && /^ [a-z]/ {print $1}')"})- have=(${have:#})- if (( ${#have} == 0 )); then- warn "could not read the subcommand list from '$VPHONE_CLI cfw --help'"- fatal=1- else- local sub- for sub in "${REQUIRED_CFW_SUBCOMMANDS[@]}"; do- (( ${have[(I)$sub]} )) \- || { warn "vphone-cli has no 'cfw $sub' subcommand — binary too old or too new for this kit"; fatal=1; }- done- fi- fi-- (( fatal == 0 )) || die "Preflight failed — nothing was written."- echo "[+] preflight OK"-}--# ── Volume layout (set by the caller after sourcing) ────────────-init_paths() {- : "${CFW_HOST_CONTAINER:?CFW_HOST_CONTAINER unset — run via run.sh or cfw_install_host.sh}"- HOST_MNT="${CFW_HOST_MNT:-/private/tmp/cfwhost}"- MNT1="$HOST_MNT/mnt1" # disk1s1 (System / rootfs)- MNT3="$HOST_MNT/mnt3" # disk1s3- TAR="$(command -v gtar 2>/dev/null || echo /opt/homebrew/bin/gtar)"- mkdir -p "$HOST_MNT"-}--# Read the installed userland version off the mounted rootfs. Every-# version-gated patch below keys off this, exactly as upstream does.-read_ios_version() {- /usr/bin/plutil -extract ProductVersion raw -o - \- "$MNT1/System/Library/CoreServices/SystemVersion.plist" 2>/dev/null || true-}--# Patch a rootfs binary from its pristine .bak, sign it, put it back.-# Upstream does this inline in four places; same semantics, one helper.-patch_rootfs_binary() { # <relpath> <cfw subcommand> [bundle_id]- local rel="$1" sub="$2" bundle_id="${3:-}"- local live="$MNT1/$rel" bak="$MNT1/$rel.bak" work="$TEMP_DIR/${rel:t}"-- [[ -e "$live" || -e "$bak" ]] || die "missing on volume: /$rel"- if ! [[ -e "$bak" ]]; then- echo " Creating backup of /$rel..."- /bin/cp "$live" "$bak"- fi- /bin/cp "$bak" "$work"- cfw_cli "$sub" "$work"- ldid_sign "$work" "$bundle_id"- /bin/cp -R "$work" "$live"- /bin/chmod 0755 "$live"-}diff --git a/cfw-kit/run.sh b/cfw-kit/run.shdeleted file mode 100755index 2fc6efe8..00000000--- a/cfw-kit/run.sh+++ /dev/null@@ -1,184 +0,0 @@-#!/bin/zsh-# vphone-tier: build-#-# BUILD, not dist, and that is a decision rather than an oversight: cfw-kit is-# vendored as-is from an external tree and still reaches for ldid, gnu-tar, zstd-# and ipsw the way scripts/cfw_install*.sh did before they were cleaned out. It-# does not ship in the .app, so none of that reaches a user — but it also means-# a dist user cannot run this variant installer. Whether cfw-kit becomes a dist-# path (by getting the same treatment the cfw_install*.sh family got) or stays a-# development tool is a P3 question, deliberately left open. Until it is-# answered, do not add it to scripts/dist_manifest.sh.-#-# run.sh — host driver for the custom-firmware-kit variant installers.-#-# Attaches the VM's Disk.img on the host, hands the APFS container to the-# variant installer (vanilla/ or jb/), then flips the boot snapshot offline so-# the VM boots the live volume.-#-# Derived from vphone-cli's scripts/cfw_install_host.sh. Everything to do with-# root, attach and the snapshot flip is kept verbatim — those are the parts-# that are easy to get subtly wrong and impossible to notice until a guest-# fails to boot. Upstream at the time of derivation:-# scripts/cfw_install_host.sh-# sha256 6c84d50b65c37404ca6ab423b6d22b5a69aba27d063da37d7ae0fc682175aa78-# vphone-cli HEAD 6d5ce7d49b4574859c57c66dff26c5c02bcae6ba (2026-09-23)-# If upstream's hash has moved, diff it before trusting this script.-#-# Prereqs: VM restored and POWERED OFF; for the jb variant the boot chain must-# already carry the 127 JB patches (`make fw_patch_jb`). Host needs gnu-tar,-# zstd, ipsw, aea, ldid (`make setup_tools`) and a built vphone-cli-# (`make build`) — every CFW patcher the kit calls lives in that binary.-#-# Usage:-# ./run.sh --variant vanilla|jb [--repo <vphone-cli>] [vm_dir]-#-# JB_USERLAND=rootless|roothide|none jb only; default none (empty slot)-# VANILLA_LSD_EMBEDDED_REG=1 vanilla only; opens lsd's JB app-# registration path on a 27 base-# FORCE_DSC_MAXSLIDE=1 force maxSlide=0 on non-27 bases-# KIT_CHECK_ONLY=1 preflight only; never attaches the image-# VPHONE_KEEP_ARTIFACTS=1 keep the extracted cfw_input/ (default: kept)-set -euo pipefail--KIT_DIR="${0:a:h}"--VARIANT=""-VM_DIR=""-REPO_ARG="${VPHONE_REPO:-}"--usage() {- /bin/cat >&2 <<'USAGE'-usage: run.sh --variant vanilla|jb [--repo <vphone-cli checkout>] [vm_dir]-- vanilla minimal boot: Cryptex, dyld links, display/boot fixes, seputil,- GPU bundle, activation bypass. No daemons, no SSH, no jailbreak.- jb the above plus the filesystem-layer jailbreak work. Userland slot- is empty unless JB_USERLAND names a flavour.-USAGE- exit 2-}--while (( $# )); do- case "$1" in- --variant) [[ $# -ge 2 ]] || usage; VARIANT="$2"; shift 2 ;;- --repo) [[ $# -ge 2 ]] || usage; REPO_ARG="$2"; shift 2 ;;- -h|--help) usage ;;- -*) echo "[-] unknown option: $1" >&2; usage ;;- *) VM_DIR="$1"; shift ;;- esac-done--# No default variant. Upstream defaults to `exp`; defaulting to either of ours-# would silently give someone a firmware they did not ask for.-[[ -n "$VARIANT" ]] || { echo "[-] --variant is required (vanilla|jb)" >&2; usage; }-case "$VARIANT" in- vanilla|jb) ;;- *) echo "[-] unknown variant: $VARIANT (vanilla|jb)" >&2; exit 1 ;;-esac--INSTALLER="$KIT_DIR/$VARIANT/install.sh"-[[ -f "$INSTALLER" ]] || { echo "[-] missing installer: $INSTALLER" >&2; exit 1; }--# resolve_repo/die live in the shared lib; don't duplicate the search order.-source "$KIT_DIR/lib/common.sh"-export VPHONE_REPO="$REPO_ARG"-REPO_DIR="$(resolve_repo)" # die() inside -> non-zero -> errexit aborts here-PROJ="$REPO_DIR"--[[ -n "$VM_DIR" ]] || VM_DIR="$PROJ/vm"-VM_DIR="${VM_DIR:a}"--# Host-side install toolchain (gnu-tar/ipsw/aea/ldid/zstd). No python entry:-# the installers call `vphone-cli cfw <verb>` for every patch, and nothing they-# run comes out of the venv.-P="$PROJ/.tools/bin:/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin"-export PATH="$P"--# Variables the installers read, forwarded explicitly. An expansion-produced-# ${VAR:+NAME=val} is not parsed as a shell assignment, hence `env`.-kit_env=(- CFW_HOST_CONTAINER="__unset__"- _VPHONE_PATH="$P"- VPHONE_REPO="$PROJ"- ${VPHONE_CLI_BIN:+VPHONE_CLI_BIN="$VPHONE_CLI_BIN"}- ${JB_USERLAND:+JB_USERLAND="$JB_USERLAND"}- ${VANILLA_LSD_EMBEDDED_REG:+VANILLA_LSD_EMBEDDED_REG="$VANILLA_LSD_EMBEDDED_REG"}- ${FORCE_DSC_MAXSLIDE:+FORCE_DSC_MAXSLIDE="$FORCE_DSC_MAXSLIDE"}-)--# ── check-only: never touch the image, never ask for root ───────-# Deliberately placed BEFORE the sudo re-exec. The installers stop right after-# preflight — before find_restore_dir and before the first mount — so nothing-# here needs privileges, and a preflight that prompts for a password is a-# preflight nobody runs. The container sentinel only has to satisfy-# init_paths' :? guard; nothing dereferences it on this path.-if [[ "${KIT_CHECK_ONLY:-0}" == "1" ]]; then- echo "[*] check-only: $VARIANT preflight only — no root, no attach, no writes"- [[ -d "$VM_DIR" ]] || { echo "[!] $VM_DIR does not exist; using it as a label only" >&2; VM_DIR="$PWD"; }- ( cd "$VM_DIR" && env "${kit_env[@]}" KIT_CHECK_ONLY=1 zsh "$INSTALLER" . )- echo "[+] check-only passed for variant=$VARIANT"- exit 0-fi--# 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" --repo "$PROJ" "$VM_DIR"-fi-unset SUDO_ASKPASS # already root: host_hdiutil/pre-step use plain sudo/hdiutil--IMG="$VM_DIR/Disk.img"-[[ -f "$IMG" ]] || { echo "[-] no Disk.img at $IMG" >&2; exit 1; }--if lsof "$IMG" >/dev/null 2>&1; then- echo "[-] $IMG is in use — stop the VM first." >&2; exit 1-fi--echo "[*] custom-firmware-kit: variant=$VARIANT vm=$VM_DIR"-echo "[*] repo=$PROJ"-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)-SYS=$(diskutil apfs list "$CONT" 2>/dev/null | awk '/APFS Volume Disk \(Role\):/{for(i=1;i<=NF;i++) if($i ~ /^disk[0-9]+s[0-9]+$/) dev=$i} /Name:.*System \(Case-sensitive\)/{print dev; exit}')-[[ -n "$CONT" && -n "$SYS" ]] || { echo "[-] System volume not found in $IMG" >&2; hdiutil detach "$BASEDISK" 2>/dev/null; exit 1; }-echo "[*] attached: container=$CONT system=$SYS"--cleanup() {- for m in /private/tmp/cfwhost/mnt1 /private/tmp/cfwhost/mnt3 /private/tmp/cfwhost/mnt5; do- umount "$m" 2>/dev/null || true- done- hdiutil detach "$BASEDISK" 2>/dev/null || diskutil eject "$BASEDISK" 2>/dev/null || true-}-trap cleanup EXIT--kit_env[1]="CFW_HOST_CONTAINER=$CONT"--echo "[*] running $VARIANT/install.sh (files placed on host mounts)..."-( cd "$VM_DIR" && env "${kit_env[@]}" zsh "$INSTALLER" . )--cleanup-trap - EXIT--echo "[*] flipping boot snapshot offline (com.apple.os.update -> live volume)..."-# Was `python3 tools/apfs_snap_rename.py`. Same resolver the installers use for-# the CFW patchers (lib/common.sh), so there is one search order in the kit.-VPHONE_CLI="$(resolve_vphone_cli)"-[[ -x "$VPHONE_CLI" ]] || { echo "[-] cannot find vphone-cli — snapshot NOT flipped; the VM will boot the stock snapshot." >&2; exit 1; }-"$VPHONE_CLI" cfw flip-snapshot "$IMG"--# Upstream removes the extracted cfw_input/ here for `make` idempotence. The kit-# keeps it: re-running a variant is the normal case while designing a userland,-# and re-extracting 7 MB every time is pure waste. Opt in to the cleanup.-if [[ "${VPHONE_DROP_ARTIFACTS:-0}" == "1" ]]; then- rm -rf "${VM_DIR:?}/cfw_input"-fi--# The whole install ran as root. Hand the host-side artifacts back to the-# invoking user so subsequent user-run steps (make boot) don't hit EPERM.-if [[ -n "${SUDO_USER:-}" ]]; then- chown -R "$SUDO_USER" "$VM_DIR" 2>/dev/null || true- echo "[*] restored ownership of host-side artifacts to $SUDO_USER"-fi--echo "[+] $VARIANT install complete. Boot with: make boot"diff --git a/cfw-kit/vanilla/install.sh b/cfw-kit/vanilla/install.shdeleted file mode 100755index 1ffb0567..00000000--- a/cfw-kit/vanilla/install.sh+++ /dev/null@@ -1,110 +0,0 @@-#!/bin/zsh-# vphone-tier: build (see cfw-kit/run.sh)-# vanilla/install.sh — the smallest CFW that boots.-#-# Installs nothing you did not ask for: no SSH, no VNC, no RPC server, no-# iosbinpack64, no vphoned, no LaunchDaemon injection, no jailbreak. The guest-# boots to SpringBoard with working graphics, and that is the whole contract.-# Everything else is yours to design.-#-# Installed, and why none of it is optional:-# Cryptex SystemOS + AppOS the hybrid firmware has no userland without it-# dyld symlinks dyld cannot find the shared cache otherwise-# version-gated display fixes black screen (IOMFB) / pid-1 panic (27.x) without-# seputil gigalocker UUID SEP rejects the volume otherwise-# diskimagesiod (27 only) MobileStorageMounter hangs forever otherwise-# AppleParavirtGPU bundle backboardd crash loop / black SpringBoard without-# mobileactivationd bypass stuck on the activation screen otherwise-#-# Deliberately NOT installed (upstream cfw_install.sh does all of these):-# iosbinpack64 jailbreak tool pack — bash/dropbear/SSH live here-# launchd_cache_loader patch its ONLY purpose is to allow a MODIFIED-# launchd.plist. We never modify it, so stock cache-# validation passes untouched and the patch is moot.-# launchd.plist injection no daemons -> nothing to inject-# vphoned host<->guest control daemon; not needed to boot-# bash / dropbear / trollvnc / rpcserver_ios plists-#-# Usage: ../run.sh --variant vanilla [vm_dir]-# Contract: root, VM off, CFW_HOST_CONTAINER set, $1 = VM dir.-set -euo pipefail--KIT_DIR="${0:a:h:h}"-source "$KIT_DIR/lib/common.sh"-source "$KIT_DIR/lib/base_stages.sh"--VM_DIR="$(cd "${1:-.}" && pwd)"-CFW_INPUT="cfw_input"-CFW_ARCHIVE="cfw_input.tar.zst"-TEMP_DIR="$VM_DIR/.cfw_temp"--# The lsd embedded-registration gate is the one iOS-27 DSC patch upstream-# applies that has no effect without a jailbreak tool to use it (see-# lib/base_stages.sh). Off here. Turn it on only if you add your own app-# registration tool to a 27 guest.-#-# Note this is NOT the diskimagesiod DDI patch — that one is applied-# unconditionally on 27, because upstream's regular variant applies it too and-# without it MobileStorageMounter hangs.-VANILLA_LSD_EMBEDDED_REG="${VANILLA_LSD_EMBEDDED_REG:-0}"-FORCE_DSC_MAXSLIDE="${FORCE_DSC_MAXSLIDE:-0}"--REQUIRED_CFW_SUBCOMMANDS=(- cryptex-paths- patch-seputil- patch-mobileactivationd- patch-iomfb-swapend- patch-iomfb-force-kern- patch-dsc-maxslide- patch-xpc-lwcr- patch-lockdown-mode- patch-diskimagesiod-)-[[ "$VANILLA_LSD_EMBEDDED_REG" == "1" ]] && REQUIRED_CFW_SUBCOMMANDS+=(patch-lsd-embedded-reg)--REPO_DIR="$(resolve_repo)"-VPHONE_CLI="$(resolve_vphone_cli)"-init_paths--cleanup_on_exit() {- safe_detach "$TEMP_DIR/mnt_sysos" 2>/dev/null || true- safe_detach "$TEMP_DIR/mnt_appos" 2>/dev/null || true-}-trap cleanup_on_exit EXIT--echo "[*] custom-firmware-kit — variant: vanilla (minimal boot)"-echo "[+] repo: $REPO_DIR"-echo "[+] vm: $VM_DIR"--preflight-[[ "${KIT_CHECK_ONLY:-0}" == "1" ]] && { echo "[+] check-only: stopping before any write"; exit 0; }--RESTORE_DIR=$(find_restore_dir)-echo "[+] Restore directory: $RESTORE_DIR"--setup_cfw_input-INPUT_DIR="$VM_DIR/$CFW_INPUT"-echo "[+] Input resources: $INPUT_DIR"-require_signing_tools--mkdir -p "$TEMP_DIR"--echo ""-echo "[*] Parsing iPhone BuildManifest for Cryptex paths..."-CRYPTEX_PATHS=$(cfw_cli 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"--stage_cryptex-detect_ios_version-stage_display_and_boot_fixes "$VANILLA_LSD_EMBEDDED_REG"-stage_seputil-stage_gpu-stage_mobileactivationd-stage_unmount--echo ""-echo "[+] vanilla CFW installation complete."-echo " No daemons, no SSH, no jailbreak were installed — by design."diff --git a/scripts/build.sh b/scripts/build.shindex 94e822ec..a2cd43c5 100755--- a/scripts/build.sh+++ b/scripts/build.sh@@ -59,7 +59,7 @@ doneecho "=== Building vphone-cli (${GIT_HASH}) ==="echo '// Auto-generated — do not edit' > "$BUILD_INFO"echo "enum VPhoneBuildInfo { static let commitHash = \"${GIT_HASH}\" }" >> "$BUILD_INFO"-swift build -c release+swift build -c release --jobs "${SWIFT_JOBS:-4}"# vphone-amfi-allow, which SwiftPM cannot produce: it reads amfid's ObjC runtime# and so must match amfid's own slice, which is arm64e. Plain clang, two systemdiff --git a/scripts/check_aux.sh b/scripts/check_aux.shindex 6b312983..64fbde40 100755--- a/scripts/check_aux.sh+++ b/scripts/check_aux.sh@@ -415,7 +415,7 @@ check_sources() {# check_aux.sh excludes itself, because a scanner that looks for a word# necessarily contains it.hits=$( { grep -rnE 'python[0-9.]*' --include='*.sh' --include='*.mk' \- scripts/ cfw-kit/ tests/ 2>/dev/null+ scripts/ tests/ 2>/dev/nullgrep -HnE 'python[0-9.]*' Makefile 2>/dev/null } \| grep -vE '^[^:]+:[0-9]+:[[:space:]]*#' \| grep -vE '^scripts/check_aux\.sh:' \diff --git a/scripts/dist_manifest.sh b/scripts/dist_manifest.shindex 51ada22f..62390161 100755--- a/scripts/dist_manifest.sh+++ b/scripts/dist_manifest.sh@@ -44,11 +44,6 @@ tier_of() {if [[ "${1:-}" == "--tiers" ]]; thenfor f in *.sh; do print -r -- "$f $(tier_of "$f")"; done- # cfw-kit is a separate tree, vendored as-is and never bundled; it declares- # its tier the same way so gate 0 can see it too.- for f in ../cfw-kit/**/*.sh(N); do- print -r -- "${f#../} $(tier_of "$f")"- doneexit 0fidiff --git a/scripts/setup_machine.sh b/scripts/setup_machine.shdeleted file mode 100755index 32a8db68..00000000--- a/scripts/setup_machine.sh+++ /dev/null@@ -1,782 +0,0 @@-#!/bin/zsh-# vphone-tier: build-# setup_machine.sh — Full vphone machine bootstrap through "First Boot".-#-# Runs README flow up to (but not including) "Subsequent Boots":-# 1) Host deps + project setup/build-# 2) vm_new + fw_prepare + fw_patch (or fw_patch_dev/ fw_patch_jb with --dev/--jb)-# 3) DFU restore (boot_dfu + restore_get_shsh + restore)-# 4) CFW install — host-mount install + offline snapshot flip-# (cfw_install_host, VM off)-# 5) First boot launch (`make boot`) with printed in-guest commands--set -euo pipefail--SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"-PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"--cd "$PROJECT_ROOT"--LOG_DIR="${PROJECT_ROOT}/setup_logs"-DFU_LOG="${LOG_DIR}/boot_dfu.log"-BOOT_LOG="${LOG_DIR}/boot.log"--DFU_PID=""-BOOT_PID=""-BOOT_FIFO=""-BOOT_FIFO_FD=""-SUDO_ASKPASS_SCRIPT=""--VM_DIR="${VM_DIR:-vm}"-VM_DIR_ABS="${VM_DIR:A}"-AUTO_KILL_VM_LOCKS="${AUTO_KILL_VM_LOCKS:-1}"-POST_RESTORE_KILL_DELAY="${POST_RESTORE_KILL_DELAY:-30}"-POST_KILL_SETTLE_DELAY="${POST_KILL_SETTLE_DELAY:-5}"--DEVICE_UDID=""-DEVICE_ECID=""-BOOT_ANALYSIS_TIMEOUT="${BOOT_ANALYSIS_TIMEOUT:-300}"-BOOT_PROMPT_FALLBACK_TIMEOUT="${BOOT_PROMPT_FALLBACK_TIMEOUT:-60}"-BOOT_BASH_PROMPT_REGEX="${BOOT_BASH_PROMPT_REGEX:-bash-[0-9]+(\.[0-9]+)+#|:/[^ ]* root#}"-BOOT_PANIC_REGEX="${BOOT_PANIC_REGEX:-(^|[^p])(panic|kernel panic|panic\\.apple\\.com|stackshot succeeded)}"-# The restore backend, built by `make build` a few steps before it is needed.-# It replaces the pymobiledevice3 bridge script and the interpreter that ran it.-VPHONE_CLI="${VPHONE_CLI:-${PROJECT_ROOT}/.build/release/vphone-cli}"-NON_INTERACTIVE=1-JB_MODE=0-DEV_MODE=0-EXP_MODE=0-LESS_MODE=0-SKIP_PROJECT_SETUP=0--die() {- echo "[-] $*" >&2- exit 1-}--require_cmd() {- local cmd="$1"- command -v "$cmd" >/dev/null 2>&1 || die "Missing required command: $cmd"-}--normalize_ecid() {- local ecid="$1"- ecid="${ecid#0x}"- ecid="${ecid#0X}"- [[ "$ecid" =~ ^[0-9A-Fa-f]{1,16}$ ]] || return 1- printf "%016s" "${ecid:u}" | tr ' ' '0'-}--load_device_identity() {- local prediction_file="${VM_DIR_ABS}/udid-prediction.txt"- local timeout=30- local waited=0- local key value- local udid_ecid-- while [[ ! -f "$prediction_file" && "$waited" -lt "$timeout" ]]; do- if [[ -n "$DFU_PID" ]] && ! kill -0 "$DFU_PID" 2>/dev/null; then- break- fi- sleep 1- waited=$(( waited + 1 ))- done-- [[ -f "$prediction_file" ]] || die "Missing ${prediction_file}. Rebuild and run make boot_dfu to generate it."-- DEVICE_UDID=""- DEVICE_ECID=""- while IFS='=' read -r key value; do- case "$key" in- UDID)- DEVICE_UDID="${value:u}"- ;;- ECID)- DEVICE_ECID="$(normalize_ecid "$value" || true)"- ;;- esac- done < "$prediction_file"-- [[ "$DEVICE_UDID" =~ ^[0-9A-F]{8}-[0-9A-F]{16}$ ]] \- || die "Invalid UDID in ${prediction_file}: ${DEVICE_UDID}"-- if [[ -z "$DEVICE_ECID" ]]; then- DEVICE_ECID="${DEVICE_UDID#*-}"- fi- [[ "$DEVICE_ECID" =~ ^[0-9A-F]{16}$ ]] \- || die "Invalid ECID in ${prediction_file}: ${DEVICE_ECID}"-- udid_ecid="${DEVICE_UDID#*-}"- [[ "$udid_ecid" == "$DEVICE_ECID" ]] \- || die "UDID/ECID mismatch in ${prediction_file}: ${DEVICE_UDID} vs 0x${DEVICE_ECID}"-- echo "[+] Device identity loaded: UDID=${DEVICE_UDID} ECID=0x${DEVICE_ECID}"-}--parse_bool() {- local raw="${1:-0}"- # zsh `${var:l}` lowercases value for tolerant bool parsing.- case "${raw:l}" in- 1|true|yes|on) return 0 ;;- *) return 1 ;;- esac-}--setup_sudo_noninteractive() {- [[ -n "${SUDO_PASSWORD:-}" ]] || return 0-- SUDO_ASKPASS_SCRIPT="$(mktemp "${TMPDIR:-/tmp}/vphone-sudo-askpass.XXXXXX")"- cat >"$SUDO_ASKPASS_SCRIPT" <<'EOF'-#!/bin/sh-printf '%s\n' "${SUDO_PASSWORD:-}"-EOF- chmod 700 "$SUDO_ASKPASS_SCRIPT"- export SUDO_ASKPASS="$SUDO_ASKPASS_SCRIPT"-- if sudo -A -v >/dev/null 2>&1; then- echo "[+] sudo credential preloaded via SUDO_PASSWORD"- else- echo "[!] SUDO_PASSWORD provided but sudo -A validation failed; continuing without preload"- fi-}--collect_vm_lock_pids() {- local -a paths pids- local path pid- typeset -U pids-- paths=(- "${VM_DIR_ABS}/nvram.bin"- "${VM_DIR_ABS}/machineIdentifier.bin"- "${VM_DIR_ABS}/Disk.img"- "${VM_DIR_ABS}/SEPStorage"- )-- for path in "${paths[@]}"; do- [[ -e "$path" ]] || continue- while IFS= read -r pid; do- [[ "$pid" == <-> ]] || continue- [[ "$pid" == "$$" ]] && continue- pids+=("$pid")- done < <(lsof -t -- "$path" 2>/dev/null || true)- done-- (( ${#pids[@]} > 0 )) && print -l -- "${pids[@]}" || true-}--check_vm_storage_locks() {- if ! command -v lsof >/dev/null 2>&1; then- echo "[!] lsof not found; skipping VM lock preflight."- return- fi-- local -a lock_pids- lock_pids=(${(@f)$(collect_vm_lock_pids)})- (( ${#lock_pids[@]} == 0 )) && return-- echo "[-] VM storage files are currently in use: ${VM_DIR_ABS}"- echo " This usually means another vphone process is still running."-- local pid proc_info- for pid in "${lock_pids[@]}"; do- [[ -z "$pid" || "$pid" == "$$" ]] && continue- proc_info="$(ps -o pid=,ppid=,command= -p "$pid" 2>/dev/null || true)"- [[ -n "$proc_info" ]] && echo " $proc_info" || echo " pid=$pid"- done-- if [[ "$AUTO_KILL_VM_LOCKS" == "1" ]]; then- echo "[*] AUTO_KILL_VM_LOCKS=1 set; terminating lock holder processes..."- for pid in "${lock_pids[@]}"; do- [[ -z "$pid" || "$pid" == "$$" ]] && continue- stop_process_tree "$pid"- done- sleep 1-- lock_pids=(${(@f)$(collect_vm_lock_pids)})- (( ${#lock_pids[@]} == 0 )) && { echo "[+] Cleared VM storage locks"; return; }- echo "[-] VM storage locks still present after AUTO_KILL_VM_LOCKS attempt."- fi-- die "Stop those processes and retry. You can also set AUTO_KILL_VM_LOCKS=1."-}--list_descendants() {- local pid- local -a children-- children=("${(@f)$(pgrep -P "$1" 2>/dev/null || true)}")- for pid in "${children[@]}"; do- [[ -z "$pid" ]] && continue- list_descendants "$pid"- print -r -- "$pid"- done-}--kill_descendants() {- local -a descendants- descendants=("${(@f)$(list_descendants "$1")}")- [[ ${#descendants[@]} -gt 0 ]] && kill -9 "${descendants[@]}" >/dev/null 2>&1 || true-}--stop_process_tree() {- local pid="$1"- [[ -n "$pid" && "$pid" == <-> ]] || return 0- kill -0 "$pid" 2>/dev/null || return 0-- kill_descendants "$pid"- kill "$pid" >/dev/null 2>&1 || true- sleep 1- if kill -0 "$pid" 2>/dev/null; then- kill -9 "$pid" >/dev/null 2>&1 || true- fi- wait "$pid" 2>/dev/null || true-}--kill_stale_vphone_procs() {- # A stale guest is a vphone-vm, not a vphone-cli: vphone-cli only forwards a- # boot and exits when the guest it started does, so it is never the thing- # left behind holding a VM.- local vphone_bin="${PROJECT_ROOT}/.build/release/vphone-vm"- local -a stale_pids- stale_pids=(${(@f)$(pgrep -f "$vphone_bin" 2>/dev/null || true)})- (( ${#stale_pids[@]} == 0 )) && return-- echo "[*] Found stale vphone-cli process(es) (pids: ${stale_pids[*]}); terminating..."- for pid in "${stale_pids[@]}"; do- [[ "$pid" == "$$" ]] && continue- stop_process_tree "$pid"- done-- # Wait up to 8s for VZ file locks to clear (flock/fcntl locks may lag behind process exit)- local waited=0- while (( waited < 8 )); do- local -a remaining- remaining=(${(@f)$(collect_vm_lock_pids)})- (( ${#remaining[@]} == 0 )) && break- sleep 1- waited=$(( waited + 1 ))- done- echo "[+] Stale vphone-cli processes cleared"-}--force_release_vm_locks() {- local -a lock_pids- local pid-- lock_pids=(${(@f)$(collect_vm_lock_pids)})- (( ${#lock_pids[@]} == 0 )) && return-- echo "[*] Releasing lingering VM lock holders..."- for pid in "${lock_pids[@]}"; do- [[ -z "$pid" || "$pid" == "$$" ]] && continue- stop_process_tree "$pid"- done-- sleep 1-}--cleanup() {- if [[ -n "$BOOT_FIFO_FD" ]]; then- exec {BOOT_FIFO_FD}>&- || true- BOOT_FIFO_FD=""- fi-- if [[ -n "$BOOT_PID" ]] && kill -0 "$BOOT_PID" 2>/dev/null; then- stop_process_tree "$BOOT_PID"- BOOT_PID=""- fi-- if [[ -n "$BOOT_FIFO" && -p "$BOOT_FIFO" ]]; then- rm -f "$BOOT_FIFO" || true- BOOT_FIFO=""- fi-- if [[ -n "$DFU_PID" ]]; then- stop_process_tree "$DFU_PID"- DFU_PID=""- fi-- if [[ -n "$SUDO_ASKPASS_SCRIPT" && -f "$SUDO_ASKPASS_SCRIPT" ]]; then- rm -f "$SUDO_ASKPASS_SCRIPT" || true- SUDO_ASKPASS_SCRIPT=""- fi-}--start_first_boot() {- check_vm_storage_locks- mkdir -p "$LOG_DIR"- : > "$BOOT_LOG"-- local target="boot"- if [ "$1" -eq 1 ]; then- target="boot_less"- fi-- BOOT_FIFO="$(mktemp -u "${TMPDIR:-/tmp}/vphone-first-boot.XXXXXX")"- mkfifo "$BOOT_FIFO"-- (make "$target" <"$BOOT_FIFO" >"$BOOT_LOG" 2>&1) &- BOOT_PID=$!-- exec {BOOT_FIFO_FD}>"$BOOT_FIFO"-- sleep 2- if ! kill -0 "$BOOT_PID" 2>/dev/null; then- die "make $target exited early during first boot stage"- fi-}--send_first_boot_commands() {- [[ -n "$BOOT_FIFO_FD" ]] || die "First boot command channel is not open"-- local commands=(- "export PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games:/iosbinpack64/usr/local/sbin:/iosbinpack64/usr/local/bin:/iosbinpack64/usr/sbin:/iosbinpack64/usr/bin:/iosbinpack64/sbin:/iosbinpack64/bin'"- "cp /iosbinpack64/etc/profile /var/profile"- "cp /iosbinpack64/etc/motd /var/motd"- "mkdir -p /var/dropbear"- "dropbearkey -t rsa -f /var/dropbear/dropbear_rsa_host_key"- "dropbearkey -t ecdsa -f /var/dropbear/dropbear_ecdsa_host_key"- "shutdown -h now"- )-- local cmd- for cmd in "${commands[@]}"; do- print -r -- "$cmd" >&${BOOT_FIFO_FD}- done-}--monitor_boot_log_until() {- local timeout="$1"- local waited=0-- [[ "$timeout" == <-> ]] || die "monitor timeout must be integer seconds"- (( timeout > 0 )) || die "monitor timeout must be > 0"-- while (( waited < timeout )); do- if [[ -f "$BOOT_LOG" ]] && grep -Eiq "$BOOT_PANIC_REGEX" "$BOOT_LOG"; then- echo "panic"- return 0- fi- if [[ -f "$BOOT_LOG" ]] && grep -Eq "$BOOT_BASH_PROMPT_REGEX" "$BOOT_LOG"; then- echo "bash"- return 0- fi- if [[ -n "$BOOT_PID" ]] && ! kill -0 "$BOOT_PID" 2>/dev/null; then- echo "exited"- return 0- fi- sleep 1- waited=$(( waited + 1 ))- done-- echo "timeout"-}--wait_for_first_boot_prompt_auto() {- local boot_state- boot_state="$(monitor_boot_log_until "$BOOT_PROMPT_FALLBACK_TIMEOUT")"- case "$boot_state" in- panic)- echo "[-] Panic detected while waiting for first-boot shell prompt."- tail -n 80 "$BOOT_LOG" 2>/dev/null || true- die "First boot panicked before command injection."- ;;- bash)- echo "[+] First-boot shell prompt detected"- ;;- exited)- echo "[-] make boot exited before first-boot command injection."- tail -n 80 "$BOOT_LOG" 2>/dev/null || true- die "First boot exited before command injection."- ;;- timeout)- echo "[!] Shell prompt not detected within ${BOOT_PROMPT_FALLBACK_TIMEOUT}s; fallback to timed continue."- ;;- esac-}--run_boot_analysis() {- local boot_state-- check_vm_storage_locks- mkdir -p "$LOG_DIR"- : > "$BOOT_LOG"- (make boot >"$BOOT_LOG" 2>&1) &- BOOT_PID=$!-- sleep 2- if ! kill -0 "$BOOT_PID" 2>/dev/null; then- echo "[-] make boot exited early during boot analysis."- tail -n 80 "$BOOT_LOG" 2>/dev/null || true- die "Boot analysis failed: process exited early."- fi-- boot_state="$(monitor_boot_log_until "$BOOT_ANALYSIS_TIMEOUT")"- case "$boot_state" in- panic)- echo "[-] Boot analysis: panic detected, stopping VM."- stop_process_tree "$BOOT_PID"- BOOT_PID=""- tail -n 80 "$BOOT_LOG" 2>/dev/null || true- die "Boot analysis failed: panic detected."- ;;- bash)- echo "[+] Boot analysis: bash prompt detected, boot success."- stop_process_tree "$BOOT_PID"- BOOT_PID=""- ;;- exited)- echo "[-] Boot analysis: VM process exited before success marker."- BOOT_PID=""- tail -n 80 "$BOOT_LOG" 2>/dev/null || true- die "Boot analysis failed: process exited."- ;;- timeout)- echo "[-] Boot analysis timeout (${BOOT_ANALYSIS_TIMEOUT}s); stopping VM."- stop_process_tree "$BOOT_PID"- BOOT_PID=""- tail -n 80 "$BOOT_LOG" 2>/dev/null || true- die "Boot analysis timeout."- ;;- esac-}--trap cleanup EXIT INT TERM--check_platform() {- [[ "$(uname -s)" == "Darwin" ]] || die "This script supports macOS only"-- local major- major="$(sw_vers -productVersion | cut -d. -f1)"- if [[ -z "$major" || "$major" -lt 15 ]]; then- die "macOS 15+ required (detected: $(sw_vers -productVersion))"- fi-- xcrun -sdk iphoneos --show-sdk-path >/dev/null 2>&1 \- || die "iOS SDK not found. Full Xcode is required (Command Line Tools alone does not include the iOS SDK).\n Install Xcode from the App Store, then run:\n sudo xcode-select -s /Applications/Xcode.app/Contents/Developer"-}--install_brew_deps() {- require_cmd brew-- # One formula, and it is not a tool this project runs — it is what `git clone`- # needs to check out scripts/resources, whose archives are LFS objects.- #- # The other eight are gone, and each for its own reason: wget and the- # gnu-tar/zstd pair and ldid-procursus were replaced by vphone-archive and- # `vphone-cli sign`; ipsw by `vphone-cli fw aea-key` / `fw urls` /- # `fw seal-tool`; openssl@3 was only ever linked into a trustcache build for a- # binary nothing invoked; libusb has not been in the link since- # MobileRecoveryCore took upstream's IOKit backend; and sshpass was installed- # for years without a single caller. No python formula either — the restore- # backend is linked into vphone-cli and the patchers are Swift.- local deps=(git-lfs)-- echo "=== Installing Homebrew dependencies ==="- for pkg in "${deps[@]}"; do- if brew list --formula "$pkg" >/dev/null 2>&1; then- echo " $pkg: already installed"- else- echo " $pkg: installing"- brew install "$pkg"- fi- done- echo ""-}--run_make() {- local label="$1"- shift-- echo ""- echo "=== ${label} ==="- if [[ -n "${SUDO_PASSWORD:-}" ]]; then- sudo -A -v >/dev/null 2>&1 || true- fi- make "$@"-}--run_make_sudo() {- local label="$1"- shift-- echo ""- echo "=== ${label} ==="- if [[ -n "${SUDO_PASSWORD:-}" ]]; then- sudo -A -E -- make "$@"- else- sudo -E -- make "$@"- fi-}--start_boot_dfu() {- mkdir -p "$LOG_DIR"-- if [[ -n "$DFU_PID" ]] && kill -0 "$DFU_PID" 2>/dev/null; then- return- fi-- kill_stale_vphone_procs- check_vm_storage_locks-- # Remove stale prediction file so load_device_identity waits for the fresh- # one written by this boot, avoiding an ECID mismatch race.- rm -f "${VM_DIR_ABS}/udid-prediction.txt"-- : > "$DFU_LOG"- echo "[*] Starting DFU boot in background..."- (make boot_dfu >"$DFU_LOG" 2>&1) &- DFU_PID=$!-- sleep 2- if ! kill -0 "$DFU_PID" 2>/dev/null; then- echo "[-] make boot_dfu exited early. Last log lines:"- tail -n 40 "$DFU_LOG" || true- exit 1- fi-- echo "[+] boot_dfu running (pid=$DFU_PID, log=$DFU_LOG)"-}--stop_boot_dfu() {- if [[ -n "$DFU_PID" ]] && kill -0 "$DFU_PID" 2>/dev/null; then- echo "[*] Stopping background DFU boot (pid=$DFU_PID)..."- stop_process_tree "$DFU_PID"- fi- DFU_PID=""- force_release_vm_locks-}--wait_for_post_restore_reboot() {- local remaining="${POST_RESTORE_KILL_DELAY}"- local panic_seen=0-- echo "[*] Restore complete; waiting up to ${POST_RESTORE_KILL_DELAY}s for reboot/panic before stopping DFU..."- while (( remaining > 0 )); do- if [[ -f "$DFU_LOG" ]] && grep -Eiq 'panic|kernel panic' "$DFU_LOG"; then- panic_seen=1- break- fi- if [[ -n "$DFU_PID" ]] && ! kill -0 "$DFU_PID" 2>/dev/null; then- echo "[*] DFU process exited during post-restore reboot window."- return- fi- sleep 1- remaining=$(( remaining - 1 ))- done-- if (( panic_seen == 1 )); then- echo "[+] Panic marker observed; stopping DFU now."- else- echo "[*] No panic marker observed in ${POST_RESTORE_KILL_DELAY}s; stopping DFU anyway."- fi-}--wait_for_recovery() {- [[ -x "$VPHONE_CLI" ]] || die "Missing vphone-cli: $VPHONE_CLI (run: make build)"-- echo "[*] Waiting for recovery/DFU endpoint..."- local i- for i in {1..90}; do- if "$VPHONE_CLI" recovery-probe --ecid "0x${DEVICE_ECID}" --timeout 2 >/dev/null 2>&1; then- echo "[+] Device endpoint is reachable"- return- fi- sleep 2- done-- echo "[-] Timed out waiting for device endpoint. Last DFU log lines:"- tail -n 60 "$DFU_LOG" || true- exit 1-}--parse_args() {- local arg- for arg in "$@"; do- case "$arg" in- --jb)- JB_MODE=1- ;;- --dev)- DEV_MODE=1- ;;- --exp)- EXP_MODE=1- ;;- --less)- LESS_MODE=1- ;;- --skip-project-setup)- SKIP_PROJECT_SETUP=1- ;;- -h|--help)- cat <<'EOF'-Usage: setup_machine.sh [--jb] [--dev] [--exp] [--less] [--skip-project-setup]--Options:- --jb Use jailbreak firmware patching + jailbreak CFW install.- --dev Use dev firmware patching + dev CFW install.- --exp Use experimental firmware patching + EXP CFW install- (JB + kernel hv_vmm rename, DSC byte-5 mangle, watchdogd- surgical patch, DT identity properties, post-restore DT- rewrite, opt-in build-version spoof via SPOOF_BUILD).- --less Use patchless firmware patching + CFW install.- --skip-project-setup Skip setup_tools/build stage.--Environment:- INTERACTIVE=1 Prompt at first-boot stages (default: non-interactive — auto-continue + boot analysis).- SUDO_PASSWORD=... Preload sudo credential via askpass.- NO_BINPACK=1 Skip installing the bundled binaries (SSH, VNC, and others).- Patchless variant only.- NO_VPHONED=1 Skip installing vphoned. Patchless variant only.- SPOOF_BUILD=<id> (EXP only) Rewrite SystemVersion.plist ProductBuildVersion- to <id> (e.g. 23F77). Leave unset to skip.-EOF- exit 0- ;;- *)- die "Unknown argument: $arg"- ;;- esac- done-}--main() {- parse_args "$@"- if parse_bool "${INTERACTIVE:-0}"; then- NON_INTERACTIVE=0- fi- if parse_bool "${NO_BINPACK:-0}"; then- NO_BINPACK=1- else- NO_BINPACK=0- fi- if parse_bool "${NO_VPHONED:-0}"; then- NO_VPHONED=1- else- NO_VPHONED=0- fi- setup_sudo_noninteractive-- local fw_patch_target="fw_patch"- local cfw_variant="regular" # variant for `cfw_install_host`- local mode_label="base"-- if (( JB_MODE + DEV_MODE + EXP_MODE + LESS_MODE > 1 )); then- die "--jb, --dev, --exp, and --less are mutually exclusive"- fi-- if [[ "$JB_MODE" -eq 1 ]]; then- fw_patch_target="fw_patch_jb"- cfw_variant="jb"- mode_label="jailbreak"- elif [[ "$DEV_MODE" -eq 1 ]]; then- fw_patch_target="fw_patch_dev"- cfw_variant="dev"- mode_label="dev"- elif [[ "$EXP_MODE" -eq 1 ]]; then- fw_patch_target="fw_patch_exp"- cfw_variant="exp"- mode_label="experimental"- elif [[ "$LESS_MODE" -eq 1 ]]; then- fw_patch_target="fw_patch_less"- cfw_variant=""- mode_label="less"- fi-- echo "[*] setup_machine mode: ${mode_label}, project_setup=$([[ "$SKIP_PROJECT_SETUP" -eq 1 ]] && echo "skip" || echo "run"), non_interactive=${NON_INTERACTIVE}, no_binpack=${NO_BINPACK}, no_vphoned=${NO_VPHONED}"-- if [[ "$SKIP_PROJECT_SETUP" -eq 1 ]]; then- echo ""- echo "=== Project setup ==="- echo "[*] Skipping setup_tools/build"- else- check_platform- install_brew_deps-- run_make "Project setup" setup_tools- run_make "Project setup" build- fi-- run_make "Firmware prep" vm_new- if [[ "$LESS_MODE" -eq 0 ]]; then- run_make "Firmware prep" fw_prepare- run_make "Firmware patch" "$fw_patch_target"- else- VARIANT=less run_make "Firmware prep" fw_prepare- run_make_sudo "Firmware patch" "$fw_patch_target"- fi-- echo ""- echo "=== Restore phase ==="- start_boot_dfu- load_device_identity- wait_for_recovery- run_make "Restore" restore_get_shsh RESTORE_UDID="$DEVICE_UDID" RESTORE_ECID="0x$DEVICE_ECID"- run_make "Restore" restore RESTORE_UDID="$DEVICE_UDID" RESTORE_ECID="0x$DEVICE_ECID"- wait_for_post_restore_reboot- stop_boot_dfu-- if [[ "$LESS_MODE" -eq 0 ]]; then- echo "[*] Waiting ${POST_KILL_SETTLE_DELAY}s for cleanup before CFW install..."- sleep "$POST_KILL_SETTLE_DELAY"-- # Host-mount CFW install + offline snapshot flip. The VM is off after the- # restore phase, so we attach Disk.img on the host, place all CFW files, and- # rename the boot snapshot offline. cfw_install_host re-execs under sudo- # (SUDO_ASKPASS from setup_sudo_noninteractive when SUDO_PASSWORD is set).- echo ""- echo "=== CFW install (host-mount) ==="- check_vm_storage_locks- run_make "CFW install" cfw_install_host VARIANT="$cfw_variant" SPOOF_BUILD="${SPOOF_BUILD:-}"- fi-- if [[ "$LESS_MODE" -eq 0 || "$NO_BINPACK" -eq 0 ]]; then- echo ""- echo "=== First boot ==="- if [[ "$NON_INTERACTIVE" -eq 0 ]]; then- read -r "?[*] Press Enter to start the VM. After it boots, press Enter again for the final stage."- else- echo "[*] Non-interactive mode. Starting the first boot automatically…"- fi-- start_first_boot "$LESS_MODE"-- if [[ "$NON_INTERACTIVE" -eq 0 ]]; then- read -r "?[*] Press Enter once the VM is fully booted"- else- wait_for_first_boot_prompt_auto- fi- send_first_boot_commands-- echo "[*] Commands sent. Waiting for VM shutdown..."- wait "$BOOT_PID"- BOOT_PID=""-- exec {BOOT_FIFO_FD}>&- || true- BOOT_FIFO_FD=""- rm -f "$BOOT_FIFO" || true- BOOT_FIFO=""- fi-- if [[ "$JB_MODE" -eq 1 || "$EXP_MODE" -eq 1 ]]; then- echo ""- echo "=== JB Finalize ==="- echo "[*] JB finalization will run automatically on first normal boot"- echo " via /cores/vphone_jb_setup.sh (LaunchDaemon)."- echo " Monitor progress via vphoned file browser: /var/log/vphone_jb_setup.log"- fi-- echo ""- echo "=== Done ==="- echo "Setup completed."-- echo "=== Boot analysis ==="- if [[ "$LESS_MODE" -eq 0 ]]; then- run_boot_analysis- else- run_make "Start VM" boot_less- fi-}--main "$@"diff --git a/scripts/vm_backup.sh b/scripts/vm_backup.shdeleted file mode 100755index 10544860..00000000--- a/scripts/vm_backup.sh+++ /dev/null@@ -1,113 +0,0 @@-#!/bin/zsh-# vphone-tier: build-# vm_backup.sh — Save the current VM as a named backup.-#-# Backups are stored under vm.backups/<name>/.-# The active VM remembers its name in vm/.vm_name for use by vm_switch.-#-# Usage:-# make vm_backup NAME=ios17-# make vm_backup NAME=ios18-jb BACKUP_INCLUDE_IPSW=1-set -euo pipefail--# Try cp -c for APFS clone/COW first; fall back to cp -a where -c is unsupported.-_vphone_cp() {- cp -a -c "$@" 2>/dev/null || cp -a "$@"-}--VM_DIR="${VM_DIR:-vm}"-BACKUPS_DIR="${BACKUPS_DIR:-vm.backups}"-NAME="${NAME:-}"-BACKUP_INCLUDE_IPSW="${BACKUP_INCLUDE_IPSW:-0}"--# --- Parse args ----while [[ $# -gt 0 ]]; do- case "$1" in- --name) NAME="$2"; shift 2 ;;- --include-ipsw) BACKUP_INCLUDE_IPSW=1; shift ;;- -h|--help)- echo "Usage: $0 --name <name> [--include-ipsw]"- exit 0- ;;- *) echo "Unknown option: $1"; exit 1 ;;- esac-done--if [[ -z "${NAME}" ]]; then- echo "ERROR: NAME is required."- echo " Usage: make vm_backup NAME=ios17"- exit 1-fi--# Reject names with slashes or dots to keep the backups dir clean-if [[ "${NAME}" == */* || "${NAME}" == .* ]]; then- echo "ERROR: NAME must be a simple identifier (no slashes or leading dots)."- exit 1-fi--# --- Validate source ----if [[ ! -d "${VM_DIR}" ]]; then- echo "ERROR: VM directory not found: ${VM_DIR}"- exit 1-fi--if [[ ! -f "${VM_DIR}/config.plist" ]]; then- echo "ERROR: ${VM_DIR} is not a valid VM directory (config.plist is missing)."- exit 1-fi--# --- Check for running VM ----if pgrep -f "vphone-cli.*--config.*${VM_DIR}" >/dev/null 2>&1; then- echo "WARNING: vphone-cli appears to be running against ${VM_DIR}."- echo " Backing up a live VM may produce an inconsistent snapshot."- printf "Continue anyway? [y/N] "- read -r answer- [[ "${answer}" =~ ^[Yy]$ ]] || exit 1-fi--DEST="${BACKUPS_DIR}/${NAME}"--echo "=== vphone vm_backup ==="-echo "Name : ${NAME}"-echo "Source : ${VM_DIR}/"-echo "Dest : ${DEST}/"-src_size="$(du -sh "${VM_DIR}" 2>/dev/null | cut -f1)"-echo "Size : ${src_size} (on disk)"--if [[ "${BACKUP_INCLUDE_IPSW}" != "1" ]]; then- echo "IPSW : excluded (use BACKUP_INCLUDE_IPSW=1 to include)"-else- echo "IPSW : included"-fi-echo ""--# --- Sync ----mkdir -p "${DEST}"--# Use cp for speed.-# On APFS, cp -c can create an instant copy-on-write clone.-# If -c is unsupported, _vphone_cp falls back to cp -a.-while IFS= read -r -d '' item; do- base="$(basename "${item}")"-- # Skip IPSW restore dirs if excluded.- if [[ "${BACKUP_INCLUDE_IPSW}" != "1" && "${base}" == *_Restore* ]]; then- continue- fi-- if [[ -d "${item}" || -f "${item}" ]]; then- _vphone_cp "${item}" "${DEST}/"- fi-done < <(find "${VM_DIR}" -mindepth 1 -maxdepth 1 -print0)--# Tag the active VM with this name-echo "${NAME}" > "${VM_DIR}/.vm_name"--echo ""-echo "=== Saved as '${NAME}' ==="-backup_size="$(du -sh "${DEST}" 2>/dev/null | cut -f1)"-echo "Backup size : ${backup_size}"-echo ""-echo "To restore : make vm_restore NAME=${NAME}"-echo "To switch : make vm_switch NAME=${NAME}"-echo "List all : make vm_list"diff --git a/scripts/vm_create.sh b/scripts/vm_create.shdeleted file mode 100755index 5456ed27..00000000--- a/scripts/vm_create.sh+++ /dev/null@@ -1,186 +0,0 @@-#!/bin/zsh-# vphone-tier: build-# vm_create.sh — Create a new vphone VM directory with all required files.-#-# Mirrors the vrevm VM creation process:-# 1. Create VM directory structure-# 2. Create sparse disk image (default 64 GB)-# 3. Create SEP storage (512 KB flat file)-# 4. Copy AVPBooter and AVPSEPBooter ROMs-# 5. Generate config.plist manifest-#-# machineIdentifier and NVRAM are auto-created on first boot by vphone-cli.-#-# Usage:-# make vm_new # Create VM/ with framework ROMs-# make vm_new VM_DIR=MyVM # Custom directory name-# make vm_new DISK_SIZE=32 # 32 GB disk-set -euo pipefail--# --- Defaults ----VM_DIR="${VM_DIR:-vm}"-DISK_SIZE_GB="${DISK_SIZE:-64}"-CPU_COUNT="${CPU:-8}"-MEMORY_MB="${MEMORY:-8192}"-SEP_STORAGE_SIZE=$((512 * 1024)) # 512 KB (same as vrevm)--# Script directory-SCRIPT_DIR="${0:A:h}"--# Framework-bundled ROMs (vresearch1 / research1 chip)-FW_ROM_DIR="/System/Library/Frameworks/Virtualization.framework/Versions/A/Resources"-ROM_SRC="${FW_ROM_DIR}/AVPBooter.vresearch1.bin"-SEPROM_SRC="${FW_ROM_DIR}/AVPSEPBooter.vresearch1.bin"--# --- Parse args ----while [[ $# -gt 0 ]]; do- case "$1" in- --dir)- VM_DIR="$2"- shift 2- ;;- --disk-size)- DISK_SIZE_GB="$2"- shift 2- ;;- --rom)- ROM_SRC="$2"- shift 2- ;;- --seprom)- SEPROM_SRC="$2"- shift 2- ;;- -h | --help)- echo "Usage: $0 [--dir VM] [--disk-size 64] [--rom path] [--seprom path]"- echo ""- echo "Options:"- echo " --dir VM directory name (default: VM)"- echo " --disk-size Disk image size in GB (default: 64)"- echo " --rom Path to AVPBooter ROM (default: framework built-in)"- echo " --seprom Path to AVPSEPBooter ROM (default: framework built-in)"- exit 0- ;;- *)- echo "Unknown option: $1"- exit 1- ;;- esac-done--DISK_SIZE_BYTES=$((DISK_SIZE_GB * 1024 * 1024 * 1024))--echo "=== vphone vm_new ==="-echo "Directory : ${VM_DIR}"-echo "Disk size : ${DISK_SIZE_GB} GB"-echo "AVPBooter : ${ROM_SRC}"-echo "AVPSEPBooter: ${SEPROM_SRC}"-echo ""--# --- Validate ROM sources ----if [[ ! -f "${ROM_SRC}" ]]; then- echo "ERROR: AVPBooter ROM not found: ${ROM_SRC}"- echo " On Apple Internal macOS, this should be at:"- echo " ${FW_ROM_DIR}/AVPBooter.vresearch1.bin"- exit 1-fi--if [[ ! -f "${SEPROM_SRC}" ]]; then- echo "ERROR: AVPSEPBooter ROM not found: ${SEPROM_SRC}"- echo " On Apple Internal macOS, this should be at:"- echo " ${FW_ROM_DIR}/AVPSEPBooter.vresearch1.bin"- exit 1-fi--# --- Create VM directory ----if [[ -d "${VM_DIR}" ]]; then- echo "WARNING: ${VM_DIR}/ already exists"- # Check for existing disk to avoid accidental overwrite- if [[ -f "${VM_DIR}/Disk.img" ]]; then- echo " Disk.img already exists — skipping disk creation"- echo " Delete ${VM_DIR}/Disk.img manually to recreate"- fi-else- echo "[1/5] Creating ${VM_DIR}/"- mkdir -p "${VM_DIR}"-fi--# --- Create sparse disk image ----if [[ ! -f "${VM_DIR}/Disk.img" ]]; then- echo "[2/5] Creating sparse disk image (${DISK_SIZE_GB} GB)"- # Use dd with seek to create a sparse file (same approach as vrevm)- dd if=/dev/zero of="${VM_DIR}/Disk.img" bs=1 count=0 seek="${DISK_SIZE_BYTES}" 2>/dev/null- echo " -> ${VM_DIR}/Disk.img ($(du -h "${VM_DIR}/Disk.img" | cut -f1) on disk)"-else- echo "[2/5] Disk.img exists — skipping"-fi--# --- Create SEP storage ----if [[ ! -f "${VM_DIR}/SEPStorage" ]]; then- echo "[3/5] Creating SEP storage (512 KB)"- dd if=/dev/zero of="${VM_DIR}/SEPStorage" bs=1 count="${SEP_STORAGE_SIZE}" 2>/dev/null-else- echo "[3/5] SEPStorage exists — skipping"-fi--# --- Copy ROMs ----echo "[4/5] Copying ROMs"--ROM_DST="${VM_DIR}/AVPBooter.vresearch1.bin"-SEPROM_DST="${VM_DIR}/AVPSEPBooter.vresearch1.bin"--if [[ -f "${ROM_DST}" ]] && cmp -s "${ROM_SRC}" "${ROM_DST}"; then- echo " AVPBooter.vresearch1.bin — up to date"-else- cp "${ROM_SRC}" "${ROM_DST}"- echo " AVPBooter.vresearch1.bin — copied ($(wc -c <"${ROM_DST}" | tr -d ' ') bytes)"-fi--if [[ -f "${SEPROM_DST}" ]] && cmp -s "${SEPROM_SRC}" "${SEPROM_DST}"; then- echo " AVPSEPBooter.vresearch1.bin — up to date"-else- cp "${SEPROM_SRC}" "${SEPROM_DST}"- echo " AVPSEPBooter.vresearch1.bin — copied ($(wc -c <"${SEPROM_DST}" | tr -d ' ') bytes)"-fi--# --- Create .gitkeep ----touch "${VM_DIR}/.gitkeep"--# --- Generate VM manifest ----echo "[5/5] Generating VM manifest (config.plist)"-# VPHONE_CLI_BIN is set when a vphone-cli subcommand invokes this script; the-# fallbacks cover being run by hand from a dev tree or from inside the .app,-# where scripts/ sits in Contents/Resources and the binaries are in MacOS.-PROJ_ROOT="${SCRIPT_DIR:h}"-VPHONE_CLI="${VPHONE_CLI_BIN:-}"-if [[ -z "$VPHONE_CLI" ]]; then- for candidate in "${PROJ_ROOT}/.build/release/vphone-cli" "${PROJ_ROOT:h}/MacOS/vphone-cli"; do- [[ -x "$candidate" ]] && { VPHONE_CLI="$candidate"; break }- done-fi-[[ -x "$VPHONE_CLI" ]] || {- echo "ERROR: cannot find vphone-cli to generate the VM manifest"- exit 1-}-"$VPHONE_CLI" vm write-manifest \- --vm-dir "${VM_DIR}" \- --cpu "${CPU_COUNT}" \- --memory "${MEMORY_MB}" || {- echo "ERROR: Failed to generate VM manifest"- exit 1-}--echo ""-echo "=== VM created at ${VM_DIR}/ ==="-echo ""-echo "Contents:"-ls -lh "${VM_DIR}/"-echo ""-echo "Configuration saved to ${VM_DIR}/config.plist."-echo "Future boots read the VM configuration from this file."-echo ""-echo "Next steps:"-echo " 1. Prepare firmware: make fw_prepare"-echo " 2. Patch firmware: make fw_patch"-echo " 3. Boot DFU: make boot_dfu"-echo " 4. Boot normal: make boot"diff --git a/scripts/vm_restore.sh b/scripts/vm_restore.shdeleted file mode 100755index e606b47e..00000000--- a/scripts/vm_restore.sh+++ /dev/null@@ -1,150 +0,0 @@-#!/bin/zsh-# vphone-tier: build-# vm_restore.sh — Restore a named backup into the active VM directory.-#-# Usage:-# make vm_restore NAME=ios17-# make vm_restore NAME=ios17 FORCE=1--set -euo pipefail--# Try cp -c for APFS clone/COW first; fall back to cp -a where -c is unsupported.-_vphone_cp() {- cp -a -c "$@" 2>/dev/null || cp -a "$@"-}--VM_DIR="${VM_DIR:-vm}"-BACKUPS_DIR="${BACKUPS_DIR:-vm.backups}"-NAME="${NAME:-}"-FORCE="${FORCE:-0}"--validate_backup_name() {- local name="$1"- local label="${2:-NAME}"-- if [[ -z "${name}" ]]; then- echo "ERROR: ${label} is required."- exit 1- fi-- if [[ "$name" == */* || "$name" == .* ]]; then- echo "ERROR: ${label} must be a simple identifier (no slashes or leading dots)."- exit 1- fi-}--list_backups() {- if [[ ! -d "${BACKUPS_DIR}" ]]; then- echo " (none)"- return- fi-- local found=0-- while IFS= read -r -d '' d; do- if [[ -f "${d}/config.plist" ]]; then- echo " - $(basename "${d}")"- found=1- fi- done < <(find "${BACKUPS_DIR}" -mindepth 1 -maxdepth 1 -type d -print0)-- if [[ "${found}" != "1" ]]; then- echo " (none)"- fi-}--safe_clear_vm_dir() {- if [[ -z "${VM_DIR}" || "${VM_DIR}" == "/" || "${VM_DIR}" == "." ]]; then- echo "ERROR: Refusing to clear unsafe VM_DIR: '${VM_DIR}'"- exit 1- fi-- mkdir -p "${VM_DIR}"-- # Delete all direct contents, including hidden files.- find "${VM_DIR}" -mindepth 1 -maxdepth 1 -exec rm -rf -- {} +-}--# --- Parse args ----while [[ $# -gt 0 ]]; do- case "$1" in- --name) NAME="$2"; shift 2 ;;- --force) FORCE=1; shift ;;- -h|--help)- echo "Usage: $0 --name <name> [--force]"- exit 0- ;;- *) echo "Unknown option: $1"; exit 1 ;;- esac-done--if [[ -z "${NAME}" ]]; then- echo "ERROR: NAME is required."- echo " Usage: make vm_restore NAME=ios17"- echo ""- echo "Available backups:"- list_backups- exit 1-fi--validate_backup_name "${NAME}"--SRC="${BACKUPS_DIR}/${NAME}"--# --- Validate backup ----if [[ ! -d "${SRC}" ]]; then- echo "ERROR: Backup '${NAME}' not found at ${SRC}/"- echo ""- echo "Available backups:"- list_backups- exit 1-fi--if [[ ! -f "${SRC}/config.plist" ]]; then- echo "ERROR: Backup '${NAME}' is incomplete (config.plist is missing from ${SRC}/)."- exit 1-fi--# --- Check for running VM ----if pgrep -f "vphone-cli.*--config.*${VM_DIR}" >/dev/null 2>&1; then- echo "ERROR: vphone-cli appears to be running against ${VM_DIR}."- echo " Stop the VM before restoring."- exit 1-fi--# --- Confirm overwrite ----if [[ -d "${VM_DIR}" && "${FORCE}" != "1" ]]; then- current=""- [[ -f "${VM_DIR}/.vm_name" ]] && current="$(< "${VM_DIR}/.vm_name")"- echo "WARNING: ${VM_DIR}/ already exists${current:+ (current: '${current}')}."- echo " This will replace it with backup '${NAME}'."- echo " Existing files in ${VM_DIR}/ will be deleted first."- echo " Back up first with: make vm_backup NAME=<name>"- printf "Continue? [y/N] "- read -r answer- [[ "${answer}" =~ ^[Yy]$ ]] || exit 1-fi--echo "=== vphone vm_restore ==="-echo "Name : ${NAME}"-echo "Source : ${SRC}/"-echo "Dest : ${VM_DIR}/"-backup_size="$(du -sh "${SRC}" 2>/dev/null | cut -f1)"-echo "Size : ${backup_size} (on disk)"-echo ""--# --- Restore ----safe_clear_vm_dir--while IFS= read -r -d '' item; do- if [[ -d "${item}" || -f "${item}" ]]; then- _vphone_cp "${item}" "${VM_DIR}/"- fi-done < <(find "${SRC}" -mindepth 1 -maxdepth 1 -print0)--# Tag the active VM.-echo "${NAME}" > "${VM_DIR}/.vm_name"--echo ""-echo "=== Restored '${NAME}' ==="-echo "Next: make boot"diff --git a/scripts/vm_switch.sh b/scripts/vm_switch.shdeleted file mode 100755index 4c039f45..00000000--- a/scripts/vm_switch.sh+++ /dev/null@@ -1,210 +0,0 @@-#!/bin/zsh-# vphone-tier: build-# vm_switch.sh — Switch the active VM to a different named backup.-#-# Saves the current VM under its name (from vm/.vm_name), then restores-# the target backup. If the current VM has no name yet, prompts for one.-#-# Usage:-# make vm_switch NAME=ios18-# make vm_switch NAME=ios18 BACKUP_INCLUDE_IPSW=1--set -euo pipefail--# Try cp -c for APFS clone/COW first; fall back to cp -a where -c is unsupported.-_vphone_cp() {- cp -a -c "$@" 2>/dev/null || cp -a "$@"-}--VM_DIR="${VM_DIR:-vm}"-BACKUPS_DIR="${BACKUPS_DIR:-vm.backups}"-NAME="${NAME:-}"-BACKUP_INCLUDE_IPSW="${BACKUP_INCLUDE_IPSW:-0}"--validate_backup_name() {- local name="$1"- local label="${2:-NAME}"-- if [[ -z "${name}" ]]; then- echo "ERROR: ${label} is required."- exit 1- fi-- if [[ "${name}" == */* || "${name}" == .* ]]; then- echo "ERROR: ${label} must be a simple identifier (no slashes or leading dots)."- exit 1- fi-}--validate_safe_path() {- local path="$1"- local label="$2"-- if [[ -z "${path}" || "${path}" == "/" || "${path}" == "." || "${path}" == ".." ]]; then- echo "ERROR: Refusing unsafe ${label}: '${path}'"- exit 1- fi-}--list_backups() {- if [[ ! -d "${BACKUPS_DIR}" ]]; then- echo " (none)"- return- fi-- local found=0-- while IFS= read -r -d '' d; do- if [[ -f "${d}/config.plist" ]]; then- echo " - $(basename "${d}")"- found=1- fi- done < <(find "${BACKUPS_DIR}" -mindepth 1 -maxdepth 1 -type d -print0)-- if [[ "${found}" != "1" ]]; then- echo " (none)"- fi-}--copy_children() {- local src="$1"- local dst="$2"- local include_ipsw="${3:-1}"-- mkdir -p "${dst}"-- while IFS= read -r -d '' item; do- base="$(basename "${item}")"-- if [[ "${include_ipsw}" != "1" && "${base}" == *_Restore* ]]; then- continue- fi-- _vphone_cp "${item}" "${dst}/"- done < <(find "${src}" -mindepth 1 -maxdepth 1 \( -type f -o -type d -o -type l \) -print0)-}--replace_dir_with_tmp() {- local tmp="$1"- local dest="$2"- local old="${dest}.old.$$"-- rm -rf -- "${old}"-- if [[ -e "${dest}" || -L "${dest}" ]]; then- mv -- "${dest}" "${old}"- fi-- if ! mv -- "${tmp}" "${dest}"; then- if [[ -e "${old}" || -L "${old}" ]]; then- mv -- "${old}" "${dest}"- fi- echo "ERROR: Failed to replace ${dest}"- exit 1- fi-- rm -rf -- "${old}"-}--# --- Parse args ----while [[ $# -gt 0 ]]; do- case "$1" in- --name) NAME="$2"; shift 2 ;;- --include-ipsw) BACKUP_INCLUDE_IPSW=1; shift ;;- -h|--help)- echo "Usage: $0 --name <target> [--include-ipsw]"- exit 0- ;;- *) echo "Unknown option: $1"; exit 1 ;;- esac-done--if [[ -z "${NAME}" ]]; then- echo "ERROR: NAME is required (the backup to switch to)."- echo " Usage: make vm_switch NAME=ios18"- echo ""- echo "Available backups:"- list_backups- exit 1-fi--validate_backup_name "${NAME}"-validate_safe_path "${VM_DIR}" "VM_DIR"-validate_safe_path "${BACKUPS_DIR}" "BACKUPS_DIR"--TARGET="${BACKUPS_DIR}/${NAME}"--if [[ ! -d "${TARGET}" || ! -f "${TARGET}/config.plist" ]]; then- echo "ERROR: Backup '${NAME}' not found."- echo ""- echo "Available backups:"- list_backups- exit 1-fi--# --- Check for running VM ----if pgrep -f "vphone-cli.*--config.*${VM_DIR}" >/dev/null 2>&1; then- echo "ERROR: vphone-cli appears to be running against ${VM_DIR}."- echo " Stop the VM before switching."- exit 1-fi--mkdir -p "${BACKUPS_DIR}"--# --- Determine current VM name ----CURRENT=""-if [[ -d "${VM_DIR}" && -f "${VM_DIR}/config.plist" ]]; then- if [[ -f "${VM_DIR}/.vm_name" ]]; then- CURRENT="$(< "${VM_DIR}/.vm_name")"- fi-- if [[ -z "${CURRENT}" ]]; then- echo "Current VM has no name. Give it one to save before switching."- printf "Name for current VM: "- read -r CURRENT || CURRENT=""-- if [[ -z "${CURRENT}" ]]; then- echo "ERROR: Cannot switch without saving the current VM."- exit 1- fi- fi-- validate_backup_name "${CURRENT}" "Current VM name"-- if [[ "${CURRENT}" == "${NAME}" ]]; then- echo "'${NAME}' is already the active VM."- exit 0- fi-- echo "=== Saving current VM as '${CURRENT}' ==="-- CURRENT_DEST="${BACKUPS_DIR}/${CURRENT}"- TMP_CURRENT_DEST="${BACKUPS_DIR}/.${CURRENT}.tmp.$$"-- rm -rf -- "${TMP_CURRENT_DEST}"- mkdir -p "${TMP_CURRENT_DEST}"-- copy_children "${VM_DIR}" "${TMP_CURRENT_DEST}" "${BACKUP_INCLUDE_IPSW}"- echo "${CURRENT}" > "${TMP_CURRENT_DEST}/.vm_name"-- replace_dir_with_tmp "${TMP_CURRENT_DEST}" "${CURRENT_DEST}"-- echo ""-fi--# --- Restore target ----echo "=== Restoring '${NAME}' ==="--TMP_VM_DIR="${VM_DIR}.restore.$$"--rm -rf -- "${TMP_VM_DIR}"-mkdir -p "${TMP_VM_DIR}"--copy_children "${TARGET}" "${TMP_VM_DIR}" "1"-echo "${NAME}" > "${TMP_VM_DIR}/.vm_name"--replace_dir_with_tmp "${TMP_VM_DIR}" "${VM_DIR}"--echo ""-echo "=== Switched: ${CURRENT:+${CURRENT} → }${NAME} ==="-echo "Next: make boot"diff --git a/sources/VPhoneCore/VPhoneBundleOps.swift b/sources/VPhoneCore/VPhoneBundleOps.swiftindex a09db6d8..780d7ca6 100644--- a/sources/VPhoneCore/VPhoneBundleOps.swift+++ b/sources/VPhoneCore/VPhoneBundleOps.swift@@ -65,7 +65,7 @@ public enum VPhoneBundleOps {throw error}- // SEP storage: 512 KB of zeros (real bytes, matches vm_create.sh).+ // SEP storage: 512 KB of initialized zero bytes.try Data(count: 512 * 1024).write(to: dir.appendingPathComponent("SEPStorage"))// ROMs.diff --git a/sources/vphone-cli/VPhoneVMCLI.swift b/sources/vphone-cli/VPhoneVMCLI.swiftindex 889e4feb..16ffc907 100644--- a/sources/vphone-cli/VPhoneVMCLI.swift+++ b/sources/vphone-cli/VPhoneVMCLI.swift@@ -26,10 +26,8 @@ struct VPhoneVMCommand: ParsableCommand {)}-/// Replaces `scripts/vm_manifest.py`, called from `vm_create.sh` as its last-/// step. Deliberately takes a directory rather than a library name: it runs-/// while the bundle is still being assembled, before it is something the-/// library would list.+/// Writes configuration for an existing bundle directory. New bundles should+/// normally use `vm new`, which owns all initial storage files.struct VPhoneVMWriteManifestCommand: ParsableCommand {static let configuration = CommandConfiguration(commandName: "write-manifest",