Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

[Patchless] Add vphoned

Maximilian Paßecf1c327fcec
diff --git a/Makefile b/Makefile
index 8ddd112d..8983fe1a 100644
--- a/Makefile
+++ b/Makefile
@@ -73,6 +73,7 @@ help:
@echo " make amfidont_allow_vphone Start amfidont for the signed vphone-cli binary"
@echo " make boot_host_preflight Diagnose whether host can launch signed PV=3 binary"
@echo " make boot Boot VM (reads from config.plist)"
+ @echo " make boot_less Boot VM in vphoned patchless compatibility"
@echo " make boot_dfu Boot VM in DFU mode (reads from config.plist)"
@echo ""
@echo "Firmware pipeline:"
@@ -84,6 +85,7 @@ help:
@echo " IPHONE_SOURCE= URL or local path to iPhone IPSW"
@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 " 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 ""
@@ -192,7 +194,7 @@ vphoned:
# VM management
# ═══════════════════════════════════════════════════════════════════
-.PHONY: vm_new vm_backup vm_restore vm_switch vm_list amfidont_allow_vphone boot_host_preflight boot boot_dfu boot_binary_check
+.PHONY: vm_new vm_backup vm_restore vm_switch vm_list amfidont_allow_vphone boot_host_preflight boot boot_less boot_dfu boot_binary_check
vm_new:
CPU="$(CPU)" MEMORY="$(MEMORY)" \
@@ -261,6 +263,10 @@ boot: bundle vphoned boot_binary_check
cd $(VM_DIR) && "$(CURDIR)/$(BUNDLE_BIN)" \
--config ./config.plist
+boot_less: bundle vphoned boot_binary_check
+ cd $(VM_DIR) && "$(CURDIR)/$(BUNDLE_BIN)" \
+ --config ./config.plist --variant less
+
boot_dfu: build boot_binary_check
cd $(VM_DIR) && "$(CURDIR)/$(BINARY)" \
--config ./config.plist \
diff --git a/README.md b/README.md
index 3e9f903f..565f348e 100644
--- a/README.md
+++ b/README.md
@@ -19,12 +19,12 @@ Boot a virtual iPhone (iOS 26) via Apple's Virtualization.framework using PCC re
Four patch variants are available with increasing levels of security bypass:
-| Variant | Boot Chain | CFW | Make Targets |
-| --------------- | :---------: | :-------: | ---------------------------------- |
-| **Patchless** | 2 patches | 2 phases | `fw_patch_less` (sudo) |
-| **Regular** | 41 patches | 10 phases | `fw_patch` + `cfw_install` |
-| **Development** | 52 patches | 12 phases | `fw_patch_dev` + `cfw_install_dev` |
-| **Jailbreak** | 112 patches | 14 phases | `fw_patch_jb` + `cfw_install_jb` |
+| Variant | Boot Chain | CFW | Make Targets |
+| --------------- | :---------: | :-------: | ----------------------------------- |
+| **Patchless** | 3 patches | 2 phases | `fw_patch_less` (root) + `boot_less`|
+| **Regular** | 41 patches | 10 phases | `fw_patch` + `cfw_install` |
+| **Development** | 52 patches | 12 phases | `fw_patch_dev` + `cfw_install_dev` |
+| **Jailbreak** | 112 patches | 14 phases | `fw_patch_jb` + `cfw_install_jb` |
> JB finalization (symlinks, Sileo, apt, TrollStore) runs automatically on first boot via `/cores/vphone_jb_setup.sh` LaunchDaemon. Monitor progress: `/var/log/vphone_jb_setup.log`.
diff --git a/scripts/setup_machine.sh b/scripts/setup_machine.sh
index f0fde09f..e87b1119 100755
--- a/scripts/setup_machine.sh
+++ b/scripts/setup_machine.sh
@@ -1116,7 +1116,7 @@ main() {
if [[ "$LESS_MODE" -eq 0 ]]; then
run_boot_analysis
else
- run_make "Start VM" boot
+ run_make "Start VM" boot_less
fi
}
diff --git a/scripts/vphoned/vphoned.m b/scripts/vphoned/vphoned.m
index c31049cc..30166096 100644
--- a/scripts/vphoned/vphoned.m
+++ b/scripts/vphoned/vphoned.m
@@ -413,6 +413,9 @@ int main(int argc, char *argv[]) {
// Bootstrap: if running from install path and a cached update exists, exec
// it
const char *selfPath = self_executable_path();
+ NSLog(@"vphoned: starting (pid=%d, path=%s)", getpid(), selfPath ?: "?");
+
+#if !LESS
if (selfPath && strcmp(selfPath, INSTALL_PATH) == 0 &&
access(CACHE_PATH, X_OK) == 0) {
NSLog(@"vphoned: found cached binary at %s, exec'ing", CACHE_PATH);
@@ -421,8 +424,7 @@ int main(int argc, char *argv[]) {
strerror(errno));
unlink(CACHE_PATH);
}
-
- NSLog(@"vphoned: starting (pid=%d, path=%s)", getpid(), selfPath ?: "?");
+#endif
if (!vp_hid_load())
return 1;
diff --git a/sources/FirmwarePatcher/Filesystem/CryptexFilesystemPatcher.swift b/sources/FirmwarePatcher/Filesystem/CryptexFilesystemPatcher.swift
index 65e40e3a..a4c7592f 100644
--- a/sources/FirmwarePatcher/Filesystem/CryptexFilesystemPatcher.swift
+++ b/sources/FirmwarePatcher/Filesystem/CryptexFilesystemPatcher.swift
@@ -127,6 +127,10 @@ public final class CryptexFilesystemPatcher: Patcher {
print("- Patch Mobile Activation")
try patchMobileActivation(targetMount: targetMount, cfwInput: cfwInputPath)
+
+ print("- Add vphoned")
+ try addVphoned(targetMount: targetMount, cfwInput: cfwInputPath)
+ try patchLaunchdCacheLoader(targetMount: targetMount, cfwInput: cfwInputPath)
}
print("- Finalizing merged image")
@@ -143,6 +147,98 @@ public final class CryptexFilesystemPatcher: Patcher {
return (newDmgPath, finalDestination)
}
+ func patchLaunchdCacheLoader(targetMount: String, cfwInput: URL) throws {
+ let target = URL.init(filePath: targetMount)
+ let launchdCacheLoaderPath = target.appending(path: "/usr/libexec/launchd_cache_loader")
+ let pythonPath = vphoneCliDirectory.appending(path: ".venv/bin/python3")
+ let patcherPath = vphoneCliDirectory.appending(path: "scripts/patchers/cfw.py")
+ _ = try runProcess(pythonPath.path, [
+ patcherPath.path, "patch-launchd-cache-loader",
+ launchdCacheLoaderPath.path
+ ])
+ _ = try runProcess("/bin/chmod", ["0755", launchdCacheLoaderPath.path])
+
+ let signingCertificatePath = cfwInput.appending(path: "cfw_input/signcert.p12")
+ _ = try runProcess("/opt/homebrew/bin/ldid", [
+ "-S", "-M", "-K\(signingCertificatePath.path)",
+ "-Icom.apple.launchd_cache_loader",
+ launchdCacheLoaderPath.path
+ ])
+ }
+
+ func addVphoned(targetMount: String, cfwInput: URL) throws {
+ let target = URL.init(filePath: targetMount)
+ let scriptDir = vphoneCliDirectory.appending(path: "scripts")
+ let vphonedSrc = scriptDir.appendingPathComponent("vphoned")
+ let vphonedBin = vphonedSrc.appendingPathComponent("vphoned")
+
+ try buildVphoned(vphonedSrc: vphonedSrc, vphonedBin: vphonedBin)
+
+ // Sign
+ let targetBin = target.appending(path: "/usr/bin/vphoned")
+ try FileManager.default.copyItem(at: vphonedBin, to: targetBin)
+ let signingCertificatePath = cfwInput.appending(path: "cfw_input/signcert.p12")
+ _ = try runProcess("/opt/homebrew/bin/ldid", [
+ "-S\(vphonedSrc.appendingPathComponent("entitlements.plist").path)",
+ "-M", "-K\(signingCertificatePath.path)",
+ targetBin.path
+ ])
+ _ = try runProcess("/bin/chmod", ["0755", targetBin.path])
+
+ let signedCopyPath = self.restoreDir.deletingLastPathComponent().appending(path: ".vphoned.signed")
+ if FileManager.default.fileExists(atPath: signedCopyPath.path) {
+ try FileManager.default.removeItem(at: signedCopyPath)
+ }
+ try FileManager.default.copyItem(at: targetBin, to: signedCopyPath)
+
+ // 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 {
+ let srcURLs = try FileManager.default.contentsOfDirectory(
+ at: vphonedSrc,
+ includingPropertiesForKeys: [.contentModificationDateKey],
+ options: [.skipsHiddenFiles]
+ ).filter { $0.pathExtension == "m" }
+
+ var args = [
+ "-sdk", "iphoneos", "clang",
+ "-arch", "arm64",
+ "-Os",
+ "-fobjc-arc",
+ "-I\(vphonedSrc.path)",
+ "-I\(vphonedSrc.appendingPathComponent("vendor/libarchive").path)",
+ "-DLESS=1",
+ "-o", vphonedBin.path
+ ]
+ args.append(contentsOf: srcURLs.map { $0.path })
+ args.append(contentsOf: [
+ "-larchive",
+ "-lsqlite3",
+ "-framework", "Foundation",
+ "-framework", "Security",
+ "-framework", "CoreServices"
+ ])
+
+ _ = try runProcess("/usr/bin/xcrun", args)
+ }
+
func addGpuDriver(targetMount: String, cfwInput: URL) throws {
let target = URL.init(filePath: targetMount)
diff --git a/sources/vphone-cli/VPhoneAppDelegate.swift b/sources/vphone-cli/VPhoneAppDelegate.swift
index 2ce70dde..34f65490 100644
--- a/sources/vphone-cli/VPhoneAppDelegate.swift
+++ b/sources/vphone-cli/VPhoneAppDelegate.swift
@@ -52,12 +52,13 @@ class VPhoneAppDelegate: NSObject, NSApplicationDelegate {
}
print("=== vphone-cli ===")
- print("ROM : \(options.romURL?.path ?? "None")")
- print("Disk : \(options.diskURL.path)")
- print("NVRAM : \(options.nvramURL.path)")
- print("Config: \(options.configURL.path)")
- print("CPU : \(options.cpuCount)")
- print("Memory: \(options.memorySize / 1024 / 1024) MB")
+ print("Variant : \(options.variant)")
+ print("ROM : \(options.romURL?.path ?? "None")")
+ print("Disk : \(options.diskURL.path)")
+ print("NVRAM : \(options.nvramURL.path)")
+ print("Config : \(options.configURL.path)")
+ print("CPU : \(options.cpuCount)")
+ print("Memory : \(options.memorySize / 1024 / 1024) MB")
print(
"Screen: \(options.screenWidth)x\(options.screenHeight) @ \(options.screenPPI) PPI (scale \(options.screenScale)x)"
)
@@ -76,7 +77,7 @@ class VPhoneAppDelegate: NSObject, NSApplicationDelegate {
try await vm.start(forceDFU: cli.dfu)
- let control = VPhoneControl()
+ let control = VPhoneControl(variant: options.variant)
self.control = control
if !cli.dfu {
let vphonedURL = URL(fileURLWithPath: cli.vphonedBin)
diff --git a/sources/vphone-cli/VPhoneCLI.swift b/sources/vphone-cli/VPhoneCLI.swift
index f4da9fbf..dee09851 100644
--- a/sources/vphone-cli/VPhoneCLI.swift
+++ b/sources/vphone-cli/VPhoneCLI.swift
@@ -43,6 +43,9 @@ struct VPhoneBootCLI: ParsableCommand {
@Option(help: "Path to signed vphoned binary for guest auto-update")
var vphonedBin: String = ".vphoned.signed"
+
+ @Option(help: "Firmware variant to execute.")
+ var variant: PatchFirmwareCLI.VariantOption = .regular
@Option(
help: "Automatically install the given IPA/TIPA after the guest control channel connects. Unavailable with --dfu.",
@@ -99,7 +102,8 @@ struct VPhoneBootCLI: ParsableCommand {
screenHeight: manifest.screenConfig.height,
screenPPI: manifest.screenConfig.pixelsPerInch,
screenScale: manifest.screenConfig.scale,
- kernelDebugPort: kernelDebugPort
+ kernelDebugPort: kernelDebugPort,
+ variant: variant.virtualMachineVariant
)
}
@@ -121,6 +125,15 @@ struct PatchFirmwareCLI: ParsableCommand {
case .jb: .jb
}
}
+
+ var virtualMachineVariant: VPhoneVirtualMachine.Variant {
+ switch self {
+ case .less: .less
+ case .regular: .regular
+ case .dev: .dev
+ case .jb: .jb
+ }
+ }
}
static let configuration = CommandConfiguration(
diff --git a/sources/vphone-cli/VPhoneControl.swift b/sources/vphone-cli/VPhoneControl.swift
index aa23fbf9..c9844156 100644
--- a/sources/vphone-cli/VPhoneControl.swift
+++ b/sources/vphone-cli/VPhoneControl.swift
@@ -41,7 +41,12 @@ class VPhoneControl {
private var nextRequestId: UInt64 = 0
private var connectionAttemptToken: UInt64 = 0
private var reconnectWorkItem: DispatchWorkItem?
+ public var variant: VPhoneVirtualMachine.Variant = .regular
+ init(variant: VPhoneVirtualMachine.Variant) {
+ self.variant = variant
+ }
+
// MARK: - Pending Requests
/// Callback for a pending request. Called on the read-loop queue.
@@ -211,7 +216,7 @@ class VPhoneControl {
self.isConnected = true
print("[control] connected to \(name) v\(version), caps: \(caps)")
- if needUpdate {
+ if needUpdate && self.variant != .less {
self.pushUpdate(fd: fd)
} else {
self.startReadLoop(fd: fd, attemptToken: attemptToken)
diff --git a/sources/vphone-cli/VPhoneVirtualMachine.swift b/sources/vphone-cli/VPhoneVirtualMachine.swift
index fd51c17a..428fae16 100644
--- a/sources/vphone-cli/VPhoneVirtualMachine.swift
+++ b/sources/vphone-cli/VPhoneVirtualMachine.swift
@@ -13,6 +13,13 @@ class VPhoneVirtualMachine: NSObject, VZVirtualMachineDelegate {
/// Synthetic battery source for runtime charge/connectivity updates.
private var batterySource: AnyObject?
+ public enum Variant: String, Sendable {
+ case less
+ case regular
+ case dev
+ case jb
+ }
+
struct Options {
var configURL: URL
var romURL: URL?
@@ -27,6 +34,7 @@ class VPhoneVirtualMachine: NSObject, VZVirtualMachineDelegate {
var screenPPI: Int = 460
var screenScale: Double = 3.0
var kernelDebugPort: Int?
+ var variant: Variant
}
private struct DeviceIdentity {