Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

[Patchless] Add Binpack (incl SSH)

Maximilian Paßbca4450a6c67
diff --git a/Makefile b/Makefile
index 9a831369..0c52c853 100644
--- a/Makefile
+++ b/Makefile
@@ -50,6 +50,7 @@ help:
@echo " SKIP_PROJECT_SETUP=1 Skip setup_tools/build"
@echo " NONE_INTERACTIVE=1 Auto-continue prompts + boot analysis"
@echo " SUDO_PASSWORD=... Preload sudo credential for setup flow"
+ @echo " NO_BINPACK=1 Excludes the SSH, VNC, ... binaries from being installed (patchless-only, currently)"
@echo ""
@echo "Setup (one-time):"
@echo " make setup_tools Install all tools (brew, trustcache, insert_dylib, venv+pymobiledevice3)"
@@ -87,6 +88,7 @@ help:
@echo " CLOUDOS_SOURCE= URL or local path to cloudOS IPSW"
@echo " make fw_patch Patch boot chain with Swift pipeline (regular variant)"
@echo " make fw_patch_less Patch boot chain with Swift pipeline (less patches)"
+ @echo " Options: NO_BINPACK=1 Excludes the SSH, VNC, ... binaries from being installed"
@echo " make fw_patch_dev Patch boot chain with Swift pipeline (dev mode TXM patches)"
@echo " make fw_patch_jb Patch boot chain with Swift pipeline (dev + JB extensions)"
@echo ""
@@ -122,6 +124,7 @@ setup_machine:
fi
SUDO_PASSWORD="$(SUDO_PASSWORD)" \
NONE_INTERACTIVE="$(NONE_INTERACTIVE)" \
+ NO_BINPACK="$(NO_BINPACK)" \
zsh $(SCRIPTS)/setup_machine.sh \
$(if $(filter 1 true yes YES TRUE,$(JB)),--jb,) \
$(if $(filter 1 true yes YES TRUE,$(DEV)),--dev,) \
@@ -292,12 +295,17 @@ fw_prepare:
fw_patch: patcher_build
"$(CURDIR)/$(PATCHER_BINARY)" patch-firmware --vm-directory "$(CURDIR)/$(VM_DIR)" --variant regular
+UID := $(shell id -u)
+ifeq ($(UID),0)
fw_patch_less: patcher_build
- @sh -c 'if [ "$$(id -u)" -ne 0 ]; then \
- echo "fw_patch_less must be run via sudo" >&2; \
- exit 1; \
- fi; \
- "$(CURDIR)/$(PATCHER_BINARY)" patch-firmware --vm-directory "$(CURDIR)/$(VM_DIR)" --variant less'
+ "$(CURDIR)/$(PATCHER_BINARY)" patch-firmware --vm-directory "$(CURDIR)/$(VM_DIR)" \
+ --variant less \
+ $(if $(filter 1 true yes YES TRUE,$(NO_BINPACK)),--no-binpack,)
+else
+fw_patch_less:
+ @echo "fw_patch_less must be run via sudo"
+ @exit 1
+endif
fw_patch_dev: patcher_build
"$(CURDIR)/$(PATCHER_BINARY)" patch-firmware --vm-directory "$(CURDIR)/$(VM_DIR)" --variant dev
diff --git a/scripts/setup_machine.sh b/scripts/setup_machine.sh
index a92b4b93..7940c96f 100755
--- a/scripts/setup_machine.sh
+++ b/scripts/setup_machine.sh
@@ -56,6 +56,8 @@ BOOT_PANIC_REGEX="${BOOT_PANIC_REGEX:-panic|kernel panic|panic\\.apple\\.com|sta
PMD3_BRIDGE="${PMD3_BRIDGE:-${PROJECT_ROOT}/scripts/pymobiledevice3_bridge.py}"
NONE_INTERACTIVE_RAW="${NONE_INTERACTIVE:-0}"
NONE_INTERACTIVE=0
+NO_BINPACK_RAW="${NO_BINPACK:-0}"
+NO_BINPACK=0
JB_MODE=0
DEV_MODE=0
LESS_MODE=0
@@ -744,9 +746,9 @@ run_make_sudo() {
echo ""
echo "=== ${label} ==="
if [[ -n "${SUDO_PASSWORD:-}" ]]; then
- sudo -A -- make "$@"
+ sudo -A -E -- make "$@"
else
- sudo -- make "$@"
+ sudo -E -- make "$@"
fi
}
@@ -977,6 +979,7 @@ Options:
Environment:
NONE_INTERACTIVE=1 Auto-continue first-boot prompts + run final boot analysis.
SUDO_PASSWORD=... Preload sudo credential via askpass.
+ NO_BINPACK=1 Excludes the SSH, VNC, ... binaries from being installed (patchless-only, currently)
EOF
exit 0
;;
@@ -992,6 +995,9 @@ main() {
if parse_bool "$NONE_INTERACTIVE_RAW"; then
NONE_INTERACTIVE=1
fi
+ if parse_bool "$NO_BINPACK_RAW"; then
+ NO_BINPACK=1
+ fi
setup_sudo_noninteractive
local fw_patch_target="fw_patch"
@@ -1016,7 +1022,7 @@ main() {
mode_label="less"
fi
- echo "[*] setup_machine mode: ${mode_label}, project_setup=$([[ "$SKIP_PROJECT_SETUP" -eq 1 ]] && echo "skip" || echo "run"), non_interactive=${NONE_INTERACTIVE}"
+ echo "[*] setup_machine mode: ${mode_label}, project_setup=$([[ "$SKIP_PROJECT_SETUP" -eq 1 ]] && echo "skip" || echo "run"), non_interactive=${NONE_INTERACTIVE}, no_binpack=${NO_BINPACK}"
if [[ "$SKIP_PROJECT_SETUP" -eq 1 ]]; then
echo ""
@@ -1076,7 +1082,9 @@ main() {
run_make "CFW install" "$cfw_install_target" SSH_PORT="$RAMDISK_SSH_PORT"
stop_boot_dfu
stop_iproxy
+ fi
+ if [[ "$LESS_MODE" -eq 0 || "$NO_BINPACK" -eq 0 ]]; then
echo ""
echo "=== First boot ==="
if [[ "$NONE_INTERACTIVE" -eq 0 ]]; then
diff --git a/sources/FirmwarePatcher/Filesystem/CryptexFilesystemPatcher.swift b/sources/FirmwarePatcher/Filesystem/CryptexFilesystemPatcher.swift
index 79dec7d6..0b93e8dc 100644
--- a/sources/FirmwarePatcher/Filesystem/CryptexFilesystemPatcher.swift
+++ b/sources/FirmwarePatcher/Filesystem/CryptexFilesystemPatcher.swift
@@ -42,6 +42,7 @@ public final class CryptexFilesystemPatcher: Patcher {
public let component = "Filesystem"
public let restoreDir: URL
public let verbose: Bool
+ public let noBinpack: Bool
let vphoneCliDirectory = URL(filePath: "./")
var buildManiest: Data
@@ -50,10 +51,11 @@ public final class CryptexFilesystemPatcher: Patcher {
// MARK: - Init
- public init(buildManiest: Data, restoreDir: URL, verbose: Bool = true) {
+ public init(buildManiest: Data, restoreDir: URL, verbose: Bool = true, noBinpack: Bool = false) {
self.buildManiest = buildManiest
self.restoreDir = restoreDir
self.verbose = verbose
+ self.noBinpack = noBinpack
}
deinit {
@@ -142,6 +144,11 @@ public final class CryptexFilesystemPatcher: Patcher {
print("- Add vphoned")
try addVphoned(targetMount: targetMount, cfwInput: cfwInputPath)
+ if !noBinpack {
+ print("- Add binpack")
+ try addExtraServices(targetMount: targetMount, cfwInput: cfwInputPath)
+ }
+ try injectLaunchDaemons(targetMount: targetMount, cfwInput: cfwInputPath, vphoned: true, cfw: !noBinpack)
try patchLaunchdCacheLoader(targetMount: targetMount, cfwInput: cfwInputPath)
}
@@ -179,6 +186,52 @@ public final class CryptexFilesystemPatcher: Patcher {
])
}
+ func injectLaunchDaemons(targetMount: String, cfwInput: URL, vphoned: Bool = true, cfw: Bool = true) throws {
+ let target = URL.init(filePath: targetMount)
+ let scriptDir = vphoneCliDirectory.appending(path: "scripts")
+
+ let tmpDir = try createTmpDir()
+ let launchdPath = tmpDir.appending(path: "launchd.plist")
+ let launchDaemonsPath = tmpDir.appending(path: "launchDaemons")
+ let launchdOgPath = target.appending(path: "/System/Library/xpc/launchd.plist")
+ try FileManager.default.createDirectory(at: launchDaemonsPath, withIntermediateDirectories: false)
+ try FileManager.default.moveItem(at: launchdOgPath, to: launchdPath)
+
+ if vphoned {
+ let vphonedSrc = scriptDir.appendingPathComponent("vphoned")
+ let vphonedLaunchdPlist = vphonedSrc.appending(path: "vphoned.plist")
+ try FileManager.default.copyItem(at: vphonedLaunchdPlist,
+ to: target.appending(path: "System/Library/LaunchDaemons/vphoned.plist"))
+ try FileManager.default.copyItem(at: vphonedLaunchdPlist, to: launchDaemonsPath.appending(path: vphonedLaunchdPlist.lastPathComponent))
+ }
+ if cfw {
+ let launchDaemonsDir = cfwInput.appending(path: "cfw_input/jb/LaunchDaemons")
+ let launchDaemons = try FileManager.default.contentsOfDirectory(atPath: launchDaemonsDir.path)
+ for filename in launchDaemons {
+ let launchDaemonUrl = launchDaemonsDir.appending(component: filename)
+ let filename = launchDaemonUrl.lastPathComponent
+ let fsTarget = target.appending(path: "System/Library/LaunchDaemons/\(filename)")
+ try FileManager.default.copyItem(at: launchDaemonUrl, to: fsTarget)
+ try FileManager.default.copyItem(at: launchDaemonUrl, to: launchDaemonsPath.appending(path: filename))
+ }
+ }
+
+ _ = try runProcess(vphoneCliDirectory.appending(path: ".venv/bin/python3").path, [
+ vphoneCliDirectory.appending(path: "scripts/patchers/cfw.py").path, "inject-daemons",
+ launchdPath.path, launchDaemonsPath.path
+ ])
+ try FileManager.default.moveItem(at: launchdPath, to: launchdOgPath)
+ _ = try runProcess("/bin/chmod", ["0644", launchdOgPath.path])
+ }
+
+ func addExtraServices(targetMount: String, cfwInput: URL) throws {
+ _ = try runProcess("/usr/bin/tar", [
+ "--preserve-permissions",
+ "-xf", cfwInput.appending(path: "cfw_input/jb/iosbinpack64.tar").path,
+ "-C", targetMount
+ ])
+ }
+
func addVphoned(targetMount: String, cfwInput: URL) throws {
let target = URL.init(filePath: targetMount)
let scriptDir = vphoneCliDirectory.appending(path: "scripts")
@@ -198,24 +251,6 @@ public final class CryptexFilesystemPatcher: Patcher {
targetBin.path
])
_ = try runProcess("/bin/chmod", ["0755", targetBin.path])
-
- // Register Launch Daemon
- let vphonedLaunchdPlist = vphonedSrc.appending(path: "vphoned.plist")
- try FileManager.default.copyItem(at: vphonedLaunchdPlist,
- to: target.appending(path: "System/Library/LaunchDaemons/vphoned.plist"))
- let tmpDir = try createTmpDir()
- let launchdPath = tmpDir.appending(path: "launchd.plist")
- let launchDaemonsPath = tmpDir.appending(path: "launchDaemons")
- let launchdOgPath = target.appending(path: "/System/Library/xpc/launchd.plist")
- try FileManager.default.createDirectory(at: launchDaemonsPath, withIntermediateDirectories: false)
- try FileManager.default.moveItem(at: launchdOgPath, to: launchdPath)
- try FileManager.default.copyItem(at: vphonedLaunchdPlist, to: launchDaemonsPath.appending(path: vphonedLaunchdPlist.lastPathComponent))
- _ = try runProcess(vphoneCliDirectory.appending(path: ".venv/bin/python3").path, [
- vphoneCliDirectory.appending(path: "scripts/patchers/cfw.py").path, "inject-daemons",
- launchdPath.path, launchDaemonsPath.path
- ])
- try FileManager.default.moveItem(at: launchdPath, to: launchdOgPath)
- _ = try runProcess("/bin/chmod", ["0644", launchdOgPath.path])
}
func buildVphoned(vphonedSrc: URL, vphonedBin: URL) throws {
diff --git a/sources/FirmwarePatcher/Pipeline/FirmwarePipeline.swift b/sources/FirmwarePatcher/Pipeline/FirmwarePipeline.swift
index 9dda3a70..4018e98a 100644
--- a/sources/FirmwarePatcher/Pipeline/FirmwarePipeline.swift
+++ b/sources/FirmwarePatcher/Pipeline/FirmwarePipeline.swift
@@ -74,6 +74,7 @@ public final class FirmwarePipeline {
let vmDirectory: URL
let variant: Variant
let verbose: Bool
+ let noBinpack: Bool
let loader: any FirmwareLoader
// MARK: - Init
@@ -82,11 +83,13 @@ public final class FirmwarePipeline {
vmDirectory: URL,
variant: Variant = .regular,
verbose: Bool = true,
+ noBinpack: Bool = false,
loader: (any FirmwareLoader)? = nil
) {
self.vmDirectory = vmDirectory
self.variant = variant
self.verbose = verbose
+ self.noBinpack = noBinpack
self.loader = loader ?? ContainerFirmwareLoader()
}
@@ -301,7 +304,7 @@ public final class FirmwarePipeline {
return switch variant {
case .less:
[{ data, verbose in
- CryptexFilesystemPatcher(buildManiest: data, restoreDir: try! self.findRestoreDirectory(), verbose: verbose)
+ CryptexFilesystemPatcher(buildManiest: data, restoreDir: try! self.findRestoreDirectory(), verbose: verbose, noBinpack: self.noBinpack)
}]
case .regular, .dev, .jb:
[]
diff --git a/sources/vphone-cli/VPhoneCLI.swift b/sources/vphone-cli/VPhoneCLI.swift
index dee09851..94622410 100644
--- a/sources/vphone-cli/VPhoneCLI.swift
+++ b/sources/vphone-cli/VPhoneCLI.swift
@@ -159,12 +159,16 @@ struct PatchFirmwareCLI: ParsableCommand {
@Flag(name: .customLong("quiet"), help: "Suppress per-component progress output.")
var quiet: Bool = false
+
+ @Flag(name: .customLong("no-binpack"), help: "Exclude the SSH, VNC, ... binaries from being installed (patchless-only).")
+ var noBinpack: Bool = false
mutating func run() throws {
let pipeline = FirmwarePipeline(
vmDirectory: vmDirectory,
variant: variant.pipelineVariant,
- verbose: !quiet
+ verbose: !quiet,
+ noBinpack: noBinpack
)
let records = try pipeline.patchAll()