Run a virtual iPhone on an Apple Silicon Mac.
Swift
Merge pull request #53 from zqxwce/feature/ipsw-dir
Lakrfa6540300268
diff --git a/.gitignore b/.gitignoreindex 044828a7..7b403e97 100644--- a/.gitignore+++ b/.gitignore@@ -309,6 +309,7 @@ __marimo__/.streamlit/secrets.toml*.resolved/VM+/ipsws/.limd//.swiftpm*.ipswdiff --git a/Makefile b/Makefileindex deef1ed1..660518a8 100644--- a/Makefile+++ b/Makefile@@ -38,6 +38,8 @@ help:@echo ""@echo "Setup (one-time):"@echo " make setup_machine Full setup through README First Boot"+ @echo " Optional: JB=1 for jailbreak firmware/CFW path"+ @echo " Optional: SKIP_PROJECT_SETUP=1 to skip setup_libimobiledevice/setup_venv/build"@echo " make setup_venv Create Python .venv"@echo " make setup_libimobiledevice Build libimobiledevice toolchain"@echo ""@@ -78,7 +80,9 @@ help:.PHONY: setup_machine setup_venv setup_libimobiledevicesetup_machine:- zsh $(SCRIPTS)/setup_machine.sh+ zsh $(SCRIPTS)/setup_machine.sh \+ $(if $(filter 1 true yes YES TRUE,$(JB)),--jb,) \+ $(if $(filter 1 true yes YES TRUE,$(SKIP_PROJECT_SETUP)),--skip-project-setup,)setup_venv:zsh $(SCRIPTS)/setup_venv.shdiff --git a/scripts/fw_prepare.sh b/scripts/fw_prepare.shindex b53dcd17..0634b7bb 100755--- a/scripts/fw_prepare.sh+++ b/scripts/fw_prepare.sh@@ -3,7 +3,7 @@# Combines cloudOS boot chain with iPhone OS images for vresearch101.## Accepts URLs or local file paths. Local paths are copied instead of downloaded.-# All output goes to the current working directory.+# IPSWs are cached in a project-level directory; extracted firmware output goes to cwd.## Usage:# make fw_prepare@@ -11,11 +11,13 @@# Environment variables (override positional args):# IPHONE_SOURCE — URL or local path to iPhone IPSW# CLOUDOS_SOURCE — URL or local path to cloudOS IPSW+# IPSW_DIR — directory used to cache downloaded/copied IPSWsset -euo pipefailSCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"IPHONE_SOURCE="${IPHONE_SOURCE:-${1:-https://updates.cdn-apple.com/2025FallFCS/fullrestores/089-13864/668EFC0E-5911-454C-96C6-E1063CB80042/iPhone17,3_26.1_23B85_Restore.ipsw}}"CLOUDOS_SOURCE="${CLOUDOS_SOURCE:-${2:-https://updates.cdn-apple.com/private-cloud-compute/399b664dd623358c3de118ffc114e42dcd51c9309e751d43bc949b98f4e31349}}"+IPSW_DIR="${IPSW_DIR:-${SCRIPT_DIR}/../ipsws}"# Derive local filenames from source basenameIPHONE_IPSW="${IPHONE_SOURCE##*/}"@@ -24,10 +26,15 @@ CLOUDOS_IPSW="${CLOUDOS_SOURCE##*/}"# Fallback name if the source basename has no extension (e.g. raw CDN hash URL)[[ "$CLOUDOS_IPSW" == *.ipsw ]] || CLOUDOS_IPSW="pcc-base.ipsw"CLOUDOS_DIR="${CLOUDOS_IPSW%.ipsw}"+IPHONE_IPSW_PATH="${IPSW_DIR}/${IPHONE_IPSW}"+CLOUDOS_IPSW_PATH="${IPSW_DIR}/${CLOUDOS_IPSW}"++mkdir -p "$IPSW_DIR"echo "=== prepare_firmware ==="echo " iPhone: $IPHONE_SOURCE"echo " CloudOS: $CLOUDOS_SOURCE"+echo " IPSWs: $IPSW_DIR"echo " Output: $(pwd)/$IPHONE_DIR/"echo ""@@ -44,7 +51,7 @@ fetch() {echo "==> Copying ${src##*/} ..."cp -- "$src" "$out"else- echo "==> Downloading $out ..."+ echo "==> Downloading ${out##*/} ..."if ! wget --no-check-certificate --show-progress -O "$out" "$src"; thenecho "ERROR: Failed to download '$src'" >&2rm -f "$out"@@ -53,8 +60,8 @@ fetch() {fi}-fetch "$IPHONE_SOURCE" "$IPHONE_IPSW"-fetch "$CLOUDOS_SOURCE" "$CLOUDOS_IPSW"+fetch "$IPHONE_SOURCE" "$IPHONE_IPSW_PATH"+fetch "$CLOUDOS_SOURCE" "$CLOUDOS_IPSW_PATH"# ── Extract ───────────────────────────────────────────────────────────extract() {@@ -66,8 +73,8 @@ extract() {chmod -R u+w "$dir"}-extract "$IPHONE_IPSW" "$IPHONE_DIR"-extract "$CLOUDOS_IPSW" "$CLOUDOS_DIR"+extract "$IPHONE_IPSW_PATH" "$IPHONE_DIR"+extract "$CLOUDOS_IPSW_PATH" "$CLOUDOS_DIR"# ── Merge cloudOS firmware into iPhone restore directory ──────────────echo "==> Importing cloudOS firmware components ..."@@ -92,7 +99,7 @@ echo "==> Generating hybrid plists ..."python3 "$SCRIPT_DIR/fw_manifest.py" "$IPHONE_DIR" "$CLOUDOS_DIR"-# ── Cleanup (keep IPSWs, remove intermediate files) ──────────────────+# ── Cleanup (keep IPSWs in IPSW_DIR, remove intermediate files) ──────echo "==> Cleaning up ..."rm -rf "$CLOUDOS_DIR"diff --git a/scripts/setup_machine.sh b/scripts/setup_machine.shindex c1630f36..e08badc4 100755--- a/scripts/setup_machine.sh+++ b/scripts/setup_machine.sh@@ -3,9 +3,9 @@## Runs README flow up to (but not including) "Subsequent Boots":# 1) Host deps + project setup/build-# 2) vm_new + fw_prepare + fw_patch+# 2) vm_new + fw_prepare + fw_patch (or fw_patch_jb with --jb)# 3) DFU restore (boot_dfu + restore_get_shsh + restore)-# 4) Ramdisk + CFW (boot_dfu + ramdisk_build + ramdisk_send + iproxy + cfw_install)+# 4) Ramdisk + CFW (boot_dfu + ramdisk_build + ramdisk_send + iproxy + cfw_install / cfw_install_jb)# 5) First boot launch (`make boot`) with printed in-guest commandsset -euo pipefail@@ -26,6 +26,8 @@ BOOT_FIFO=""BOOT_FIFO_FD=""VM_DIR="${VM_DIR:-vm}"+JB_MODE=0+SKIP_PROJECT_SETUP=0die() {echo "[-] $*" >&2@@ -261,18 +263,63 @@ stop_iproxy_2222() {IPROXY_PID=""}+parse_args() {+ local arg+ for arg in "$@"; do+ case "$arg" in+ --jb)+ JB_MODE=1+ ;;+ --skip-project-setup)+ SKIP_PROJECT_SETUP=1+ ;;+ -h|--help)+ cat <<'EOF'+Usage: setup_machine.sh [--jb] [--skip-project-setup]++Options:+ --jb Use jailbreak firmware patching + jailbreak CFW install.+ --skip-project-setup Skip setup_libimobiledevice/setup_venv/build stage.+EOF+ exit 0+ ;;+ *)+ die "Unknown argument: $arg"+ ;;+ esac+ done+}+main() {- check_platform- install_brew_deps- ensure_python_linked+ parse_args "$@"- run_make "Project setup" setup_libimobiledevice- run_make "Project setup" setup_venv- run_make "Project setup" build+ local fw_patch_target="fw_patch"+ local cfw_install_target="cfw_install"++ if [[ "$JB_MODE" -eq 1 ]]; then+ fw_patch_target="fw_patch_jb"+ cfw_install_target="cfw_install_jb"+ fi++ echo "[*] setup_machine mode: $([[ "$JB_MODE" -eq 1 ]] && echo "jailbreak" || echo "base"), project_setup=$([[ "$SKIP_PROJECT_SETUP" -eq 1 ]] && echo "skip" || echo "run")"++ if [[ "$SKIP_PROJECT_SETUP" -eq 1 ]]; then+ echo ""+ echo "=== Project setup ==="+ echo "[*] Skipping setup_libimobiledevice/setup_venv/build"+ else+ check_platform+ install_brew_deps+ ensure_python_linked++ run_make "Project setup" setup_libimobiledevice+ run_make "Project setup" setup_venv+ run_make "Project setup" build+ firun_make "Firmware prep" vm_newrun_make "Firmware prep" fw_prepare- run_make "Firmware patch" fw_patch+ run_make "Firmware patch" "$fw_patch_target"echo ""echo "=== Restore phase ==="@@ -292,7 +339,7 @@ main() {sleep 10 # for some reason there is a statistical faiure here if not enough time is given to initialization- run_make "CFW install" cfw_install+ run_make "CFW install" "$cfw_install_target"stop_iproxy_2222stop_boot_dfu