Run a virtual iPhone on an Apple Silicon Mac.
Swift
Allow use of default / unpatched AVPBooter
Maximilian Paß210d58823d49
diff --git a/sources/vphone-cli/VPhoneAppDelegate.swift b/sources/vphone-cli/VPhoneAppDelegate.swiftindex d4747c35..2ce70dde 100644--- a/sources/vphone-cli/VPhoneAppDelegate.swift+++ b/sources/vphone-cli/VPhoneAppDelegate.swift@@ -47,12 +47,12 @@ class VPhoneAppDelegate: NSObject, NSApplicationDelegate {private func startVirtualMachine() async throws {let options = try cli.resolveOptions()- guard FileManager.default.fileExists(atPath: options.romURL.path) else {- throw VPhoneError.romNotFound(options.romURL.path)+ guard options.romURL == nil || FileManager.default.fileExists(atPath: options.romURL!.path) else {+ throw VPhoneError.romNotFound(options.romURL!.path)}print("=== vphone-cli ===")- print("ROM : \(options.romURL.path)")+ print("ROM : \(options.romURL?.path ?? "None")")print("Disk : \(options.diskURL.path)")print("NVRAM : \(options.nvramURL.path)")print("Config: \(options.configURL.path)")@@ -68,7 +68,7 @@ class VPhoneAppDelegate: NSObject, NSApplicationDelegate {}print("SEP : enabled")print(" storage : \(options.sepStorageURL.path)")- print(" rom : \(options.sepRomURL.path)")+ print(" rom : \(options.sepRomURL?.path ?? "None")")print("")let vm = try VPhoneVirtualMachine(options: options)diff --git a/sources/vphone-cli/VPhoneCLI.swift b/sources/vphone-cli/VPhoneCLI.swiftindex 520153fa..be65f7c5 100644--- a/sources/vphone-cli/VPhoneCLI.swift+++ b/sources/vphone-cli/VPhoneCLI.swift@@ -88,13 +88,13 @@ struct VPhoneBootCLI: ParsableCommand {return VPhoneVirtualMachine.Options(configURL: config,- romURL: manifest.resolve(path: manifest.romImages.avpBooter, in: vmDir),+ romURL: manifest.romImages != nil ? manifest.resolve(path: manifest.romImages!.avpBooter, in: vmDir) : nil,nvramURL: manifest.resolve(path: manifest.nvramStorage, in: vmDir),diskURL: manifest.resolve(path: manifest.diskImage, in: vmDir),cpuCount: Int(manifest.cpuCount),memorySize: manifest.memorySize,sepStorageURL: manifest.resolve(path: manifest.sepStorage, in: vmDir),- sepRomURL: manifest.resolve(path: manifest.romImages.avpSEPBooter, in: vmDir),+ sepRomURL: manifest.romImages != nil ? manifest.resolve(path: manifest.romImages!.avpSEPBooter, in: vmDir) : nil,screenWidth: manifest.screenConfig.width,screenHeight: manifest.screenConfig.height,screenPPI: manifest.screenConfig.pixelsPerInch,diff --git a/sources/vphone-cli/VPhoneVirtualMachine.swift b/sources/vphone-cli/VPhoneVirtualMachine.swiftindex b6d6086d..fd51c17a 100644--- a/sources/vphone-cli/VPhoneVirtualMachine.swift+++ b/sources/vphone-cli/VPhoneVirtualMachine.swift@@ -15,13 +15,13 @@ class VPhoneVirtualMachine: NSObject, VZVirtualMachineDelegate {struct Options {var configURL: URL- var romURL: URL+ var romURL: URL?var nvramURL: URLvar diskURL: URLvar cpuCount: Int = 8var memorySize: UInt64 = 8 * 1024 * 1024 * 1024var sepStorageURL: URL- var sepRomURL: URL+ var sepRomURL: URL?var screenWidth: Int = 1290var screenHeight: Int = 2796var screenPPI: Int = 460@@ -134,7 +134,9 @@ class VPhoneVirtualMachine: NSObject, VZVirtualMachineDelegate {// --- Boot loader with custom ROM ---let bootloader = VZMacOSBootLoader()- Dynamic(bootloader)._setROMURL(options.romURL)+ if let romURL = options.romURL {+ Dynamic(bootloader)._setROMURL(romURL)+ }// --- VM Configuration ---let config = VZVirtualMachineConfiguration()@@ -250,7 +252,9 @@ class VPhoneVirtualMachine: NSObject, VZVirtualMachineDelegate {// Coprocessorslet sepConfig = Dynamic._VZSEPCoprocessorConfiguration(storageURL: options.sepStorageURL)- sepConfig.setRomBinaryURL(options.sepRomURL)+ if let sepRomURL = options.sepRomURL {+ sepConfig.setRomBinaryURL(sepRomURL)+ }sepConfig.setDebugStub(Dynamic._VZGDBDebugStubConfiguration().asObject)if let sepObj = sepConfig.asObject {Dynamic(config)._setCoprocessors([sepObj])diff --git a/sources/vphone-cli/VPhoneVirtualMachineManifest.swift b/sources/vphone-cli/VPhoneVirtualMachineManifest.swiftindex 588fa18c..0d8d81b6 100644--- a/sources/vphone-cli/VPhoneVirtualMachineManifest.swift+++ b/sources/vphone-cli/VPhoneVirtualMachineManifest.swift@@ -44,7 +44,7 @@ struct VPhoneVirtualMachineManifest: Codable {// MARK: - ROMs/// ROM image paths- let romImages: ROMImages+ let romImages: ROMImages?// MARK: - SEP@@ -107,7 +107,7 @@ struct VPhoneVirtualMachineManifest: Codable {networkConfig: NetworkConfig = .default,diskImage: String = "Disk.img",nvramStorage: String = "nvram.bin",- romImages: ROMImages,+ romImages: ROMImages?,sepStorage: String = "SEPStorage") {self.platformType = platformType