Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

feat: guest restore/CFW pipeline updates for the consolidated CLI

zqxwce37ee2943c633
diff --git a/scripts/cfw_install.sh b/scripts/cfw_install.sh
index d492c409..74fcb59a 100755
--- a/scripts/cfw_install.sh
+++ b/scripts/cfw_install.sh
@@ -36,6 +36,10 @@ VM_DIR="$(cd "$VM_DIR" && pwd)"
# `make cfw_install` standalone (without setup_machine.sh exporting PATH)
# still uses the correctly set-up venv interpreter.
_resolve_python3() {
+ if [[ -n "${VPHONE_PYTHON:-}" ]]; then
+ echo "$VPHONE_PYTHON"
+ return
+ fi
local venv_py="${SCRIPT_DIR:h}/.venv/bin/python3"
if [[ -x "$venv_py" ]]; then
echo "$venv_py"
@@ -134,7 +138,7 @@ setup_cfw_input() {
archive="$search_dir/$CFW_ARCHIVE"
if [[ -f "$archive" ]]; then
echo " Extracting $CFW_ARCHIVE..."
- tar --zstd -xf "$archive" -C "$VM_DIR"
+ "$TAR" --zstd --warning=no-unknown-keyword -xf "$archive" -C "$VM_DIR"
return
fi
done
@@ -430,7 +434,7 @@ echo ""
echo "[3/7] Installing AppleParavirtGPUMetalIOGPUFamily..."
cp -R "$INPUT_DIR/custom/AppleParavirtGPUMetalIOGPUFamily.tar" "$MNT1"
-"$TAR" --preserve-permissions --no-overwrite-dir \
+"$TAR" --preserve-permissions --no-overwrite-dir --warning=no-unknown-keyword \
-xf $MNT1/AppleParavirtGPUMetalIOGPUFamily.tar -C $MNT1
BUNDLE="$MNT1/System/Library/Extensions/AppleParavirtGPUMetalIOGPUFamily.bundle"
@@ -452,7 +456,7 @@ echo ""
echo "[4/7] Installing iosbinpack64..."
cp -R "$INPUT_DIR/jb/iosbinpack64.tar" "$MNT1"
-"$TAR" --preserve-permissions --no-overwrite-dir \
+"$TAR" --preserve-permissions --no-overwrite-dir --warning=no-unknown-keyword \
-xf $MNT1/iosbinpack64.tar -C $MNT1
/bin/rm -f $MNT1/iosbinpack64.tar
diff --git a/scripts/cfw_install_dev.sh b/scripts/cfw_install_dev.sh
index 1913e86b..e73ae5a6 100755
--- a/scripts/cfw_install_dev.sh
+++ b/scripts/cfw_install_dev.sh
@@ -31,6 +31,10 @@ VM_DIR="$(cd "$VM_DIR" && pwd)"
# ── Python resolver — prefer project venv over whatever is in PATH ─
_resolve_python3() {
+ if [[ -n "${VPHONE_PYTHON:-}" ]]; then
+ echo "$VPHONE_PYTHON"
+ return
+ fi
local venv_py="${SCRIPT_DIR:h}/.venv/bin/python3"
if [[ -x "$venv_py" ]]; then
echo "$venv_py"
diff --git a/scripts/cfw_install_exp.sh b/scripts/cfw_install_exp.sh
index e6fda8d8..b31f0305 100755
--- a/scripts/cfw_install_exp.sh
+++ b/scripts/cfw_install_exp.sh
@@ -38,6 +38,10 @@ SCRIPT_DIR="${0:a:h}"
# Resolves to .venv/bin/python3 relative to the project root (parent of
# scripts/), falling back to the system python3 when the venv is absent.
_resolve_python3() {
+ if [[ -n "${VPHONE_PYTHON:-}" ]]; then
+ echo "$VPHONE_PYTHON"
+ return
+ fi
local venv_py="${SCRIPT_DIR:h}/.venv/bin/python3"
if [[ -x "$venv_py" ]]; then
echo "$venv_py"
diff --git a/scripts/cfw_install_host.sh b/scripts/cfw_install_host.sh
index 77777a23..2861b527 100755
--- a/scripts/cfw_install_host.sh
+++ b/scripts/cfw_install_host.sh
@@ -45,9 +45,15 @@ IMG="$VM_DIR/Disk.img"
[[ -f "$IMG" ]] || { echo "[-] no Disk.img at $IMG" >&2; exit 1; }
# Host-side install toolchain (gnu-tar/ipsw/aea/ldid/zstd + venv python).
-P="$PROJ/.tools/bin:$PROJ/.venv/bin:/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin"
+# VPHONE_PYTHON overrides the venv python (e.g. a bundled .app has no .venv);
+# unset falls back to the repo venv, unchanged from before.
+if [[ -n "${VPHONE_PYTHON:-}" ]]; then
+ P="$PROJ/.tools/bin:$(dirname "$VPHONE_PYTHON"):/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin"
+else
+ P="$PROJ/.tools/bin:$PROJ/.venv/bin:/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin"
+fi
export PATH="$P"
-PY="$PROJ/.venv/bin/python3"
+PY="${VPHONE_PYTHON:-$PROJ/.venv/bin/python3}"
if lsof "$IMG" >/dev/null 2>&1; then
echo "[-] $IMG is in use — stop the VM first." >&2; exit 1
diff --git a/scripts/cfw_install_jb.sh b/scripts/cfw_install_jb.sh
index b6f0cfb6..5520a47e 100755
--- a/scripts/cfw_install_jb.sh
+++ b/scripts/cfw_install_jb.sh
@@ -22,6 +22,10 @@ SCRIPT_DIR="${0:a:h}"
# Resolves to .venv/bin/python3 relative to the project root (parent of
# scripts/), falling back to the system python3 when the venv is absent.
_resolve_python3() {
+ if [[ -n "${VPHONE_PYTHON:-}" ]]; then
+ echo "$VPHONE_PYTHON"
+ return
+ fi
local venv_py="${SCRIPT_DIR:h}/.venv/bin/python3"
if [[ -x "$venv_py" ]]; then
echo "$venv_py"
@@ -144,7 +148,7 @@ setup_cfw_jb_input() {
archive="$search_dir/$CFW_JB_ARCHIVE"
if [[ -f "$archive" ]]; then
echo " Extracting $CFW_JB_ARCHIVE..."
- tar --zstd -xf "$archive" -C "$VM_DIR"
+ "$TAR" --zstd --warning=no-unknown-keyword -xf "$archive" -C "$VM_DIR"
return
fi
done
@@ -161,7 +165,7 @@ apply_dev_overlay() {
local iosbinpack="$VM_DIR/$CFW_INPUT/jb/iosbinpack64.tar"
local tmpdir="$VM_DIR/.iosbinpack_tmp"
mkdir -p "$tmpdir"
- tar -xf "$iosbinpack" -C "$tmpdir"
+ "$TAR" --warning=no-unknown-keyword -xf "$iosbinpack" -C "$tmpdir"
cp "$dev_bin" "$tmpdir/iosbinpack64/usr/local/bin/rpcserver_ios"
(cd "$tmpdir" && tar -cf "$iosbinpack" iosbinpack64)
rm -rf "$tmpdir"
@@ -256,7 +260,7 @@ echo "[JB-2] Installing iosbinpack64..."
apply_dev_overlay
cp -R "$VM_DIR/$CFW_INPUT/jb/iosbinpack64.tar" "$MNT1"
-"$TAR" --preserve-permissions --no-overwrite-dir \
+"$TAR" --preserve-permissions --no-overwrite-dir --warning=no-unknown-keyword \
-xf $MNT1/iosbinpack64.tar -C $MNT1
/bin/rm -f $MNT1/iosbinpack64.tar
@@ -353,7 +357,7 @@ JB_DIR_NAME="jb-vphone"
/bin/mkdir -p $MNT5/$BOOT_HASH/$JB_DIR_NAME
/bin/chmod 0755 $MNT5/$BOOT_HASH/$JB_DIR_NAME
/usr/sbin/chown 0:0 $MNT5/$BOOT_HASH/$JB_DIR_NAME
-"$TAR" --preserve-permissions -xf $MNT5/$BOOT_HASH/bootstrap-iphoneos-arm64.tar \
+"$TAR" --preserve-permissions --warning=no-unknown-keyword -xf $MNT5/$BOOT_HASH/bootstrap-iphoneos-arm64.tar \
-C $MNT5/$BOOT_HASH/$JB_DIR_NAME/
/bin/mv $MNT5/$BOOT_HASH/$JB_DIR_NAME/var $MNT5/$BOOT_HASH/$JB_DIR_NAME/procursus
mv "$MNT5/$BOOT_HASH/$JB_DIR_NAME/procursus/jb"/*(N) "$MNT5/$BOOT_HASH/$JB_DIR_NAME/procursus" 2>/dev/null || true
diff --git a/scripts/fw_prepare.sh b/scripts/fw_prepare.sh
index 821cc694..dfa2faa2 100755
--- a/scripts/fw_prepare.sh
+++ b/scripts/fw_prepare.sh
@@ -73,7 +73,7 @@ source_hash_suffix() {
elif command -v sha256sum >/dev/null 2>&1; then
printf '%s' "$src" | sha256sum | awk '{print substr($1, 1, 12)}'
else
- python3 - "$src" <<'PY'
+ "$PYTHON3" - "$src" <<'PY'
import hashlib
import sys
@@ -142,7 +142,7 @@ list_firmwares() {
local device="$1" readme_path="$2"
local downloadable_urls
downloadable_urls="$(downloadable_ipsw_urls "$device")"
- DOWNLOADABLE_IPSW_URLS="$downloadable_urls" python3 - "$device" "$readme_path" <<'PY'
+ DOWNLOADABLE_IPSW_URLS="$downloadable_urls" "$PYTHON3" - "$device" "$readme_path" <<'PY'
import os
import re
import sys
@@ -230,7 +230,7 @@ resolve_selector_from_downloads() {
local device="$1" version="$2" build="$3" readme_path="$4"
local downloadable_urls
downloadable_urls="$(downloadable_ipsw_urls "$device")"
- DOWNLOADABLE_IPSW_URLS="$downloadable_urls" python3 - "$device" "$version" "$build" "$readme_path" <<'PY'
+ DOWNLOADABLE_IPSW_URLS="$downloadable_urls" "$PYTHON3" - "$device" "$version" "$build" "$readme_path" <<'PY'
import os
import re
import sys
@@ -426,7 +426,8 @@ download_apfs_sealvolume() {
filename="apfs_sealvolume_${ios_version}"
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
- TOOLS_PREFIX="$PROJECT_DIR/.tools"
+ TOOLS_PREFIX="${VPHONE_SEAL_DIR:-$PROJECT_DIR/.tools}"
+ mkdir -p "$TOOLS_PREFIX"
if [[ -f "$TOOLS_PREFIX/$filename" ]]; then
echo "$filename already present"
@@ -511,6 +512,7 @@ IPHONE_BUILD="${IPHONE_BUILD:-}"
IPHONE_SOURCE="${IPHONE_SOURCE:-}"
CLOUDOS_SOURCE="${CLOUDOS_SOURCE:-}"
IPSW_DIR="${IPSW_DIR:-${SCRIPT_DIR}/../ipsws}"
+PYTHON3="${VPHONE_PYTHON:-python3}"
POSITIONAL=()
while [[ $# -gt 0 ]]; do
@@ -680,7 +682,7 @@ cp -n "${CLOUDOS_DIR}"/Firmware/*.dmg.trustcache "$IPHONE_DIR/Firmware"/ 2>/dev/
cp "$IPHONE_DIR/BuildManifest.plist" "$IPHONE_DIR/iPhone-BuildManifest.plist"
echo "==> Generating hybrid plists ..."
-python3 "$SCRIPT_DIR/fw_manifest.py" "$IPHONE_DIR" "$CLOUDOS_DIR"
+"$PYTHON3" "$SCRIPT_DIR/fw_manifest.py" "$IPHONE_DIR" "$CLOUDOS_DIR"
echo "==> Cleaning up ..."
rm -rf "$CLOUDOS_DIR"
diff --git a/scripts/patch_camera_userland.sh b/scripts/patch_camera_userland.sh
index 933646a1..1a9b5027 100755
--- a/scripts/patch_camera_userland.sh
+++ b/scripts/patch_camera_userland.sh
@@ -23,6 +23,10 @@ SCRIPT_DIR="${0:a:h}"
[[ -n "${_VPHONE_PATH:-}" ]] && export PATH="$_VPHONE_PATH"
_resolve_python3() {
+ if [[ -n "${VPHONE_PYTHON:-}" ]]; then
+ echo "$VPHONE_PYTHON"
+ return
+ fi
local venv_py="${SCRIPT_DIR:h}/.venv/bin/python3"
if [[ -x "$venv_py" ]]; then
echo "$venv_py"
diff --git a/scripts/patch_hv_vmm_userland.sh b/scripts/patch_hv_vmm_userland.sh
index 39793bb2..a6fb49b9 100755
--- a/scripts/patch_hv_vmm_userland.sh
+++ b/scripts/patch_hv_vmm_userland.sh
@@ -37,6 +37,10 @@ SCRIPT_DIR="${0:a:h}"
[[ -n "${_VPHONE_PATH:-}" ]] && export PATH="$_VPHONE_PATH"
_resolve_python3() {
+ if [[ -n "${VPHONE_PYTHON:-}" ]]; then
+ echo "$VPHONE_PYTHON"
+ return
+ fi
local venv_py="${SCRIPT_DIR:h}/.venv/bin/python3"
if [[ -x "$venv_py" ]]; then
echo "$venv_py"
diff --git a/scripts/pymobiledevice3_bridge.py b/scripts/pymobiledevice3_bridge.py
index 52ef3ba6..aad9a83a 100755
--- a/scripts/pymobiledevice3_bridge.py
+++ b/scripts/pymobiledevice3_bridge.py
@@ -23,6 +23,35 @@ from pymobiledevice3.restore.restore import Restore
import typer
+# pymobiledevice3's own CLI installs coloredlogs at INFO (see its __main__) and
+# silences these chatty third-party loggers. Mirror that here so the bridge's
+# restore output is the same colorized log stream when run with -v.
+_NOISY_LOGGERS = (
+ "quic",
+ "asyncio",
+ "parso.cache",
+ "parso.cache.pickle",
+ "parso.python.diff",
+ "humanfriendly.prompts",
+ "blib2to3.pgen2.driver",
+ "urllib3.connectionpool",
+)
+
+
+def install_logging(verbose: int) -> None:
+ import logging
+
+ level = [logging.WARNING, logging.INFO, logging.DEBUG][min(verbose, 2)]
+ try:
+ import coloredlogs
+
+ coloredlogs.install(level=level)
+ except ImportError:
+ logging.basicConfig(level=level)
+ for name in _NOISY_LOGGERS:
+ logging.getLogger(name).disabled = True
+
+
def parse_ecid(value: Optional[str]) -> Optional[int]:
if not value:
return None
@@ -193,7 +222,11 @@ def restore_get_shsh_command(
file_okay=True,
dir_okay=False,
),
+ verbose: int = typer.Option(
+ 0, "--verbose", "-v", count=True, help="Increase log verbosity (-v info, -vv debug)."
+ ),
) -> Awaitable[None]:
+ install_logging(verbose)
return cmd_restore_get_shsh(vm_dir, require_ecid(ecid), udid, out)
@@ -216,7 +249,11 @@ def restore_update_command(
file_okay=True,
dir_okay=False,
),
+ verbose: int = typer.Option(
+ 0, "--verbose", "-v", count=True, help="Increase log verbosity (-v info, -vv debug)."
+ ),
) -> Awaitable[None]:
+ install_logging(verbose)
return cmd_restore_update(vm_dir, require_ecid(ecid), udid, erase=erase, tss_path=tss)