Run a virtual iPhone on an Apple Silicon Mac.
Swift
fw prepare --device: look up iPad IPSWs by version or build
Jackyc6fec70b5f30
diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneFirmwareCommand.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneFirmwareCommand.swiftindex c356be8b..993f3783 100644--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneFirmwareCommand.swift+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneFirmwareCommand.swift@@ -208,6 +208,8 @@ struct VPhoneFirmwarePrepareCommand: ParsableCommand {var ipswCache: String?@Option(help: "iPhone version to resolve to an IPSW") var iphoneVersion: String?@Option(help: "iPhone build to resolve to an IPSW") var iphoneBuild: String?+ @Option(help: "Device whose IPSWs --list, --iphone-version and --iphone-build look up: iPhone17,3 or iPad16,1")+ var device: String = VPhoneFirmwareCatalog.device@Flag(help: "List downloadable IPSWs and exit") var list = false@Option(name: .shortAndLong, help: "Resource base override (default: inferred from the running binary path)")var projectRoot: String?@@ -220,9 +222,13 @@ struct VPhoneFirmwarePrepareCommand: ParsableCommand {let bundleGuide = resources.base.appendingPathComponent("docs/guides/compatibility.md")let readme = FileManager.default.fileExists(atPath: sourceGuide.path) ? sourceGuide.path : bundleGuide.pathlet needsCatalog = list || iphoneVersion != nil || iphoneBuild != nil+ guard VPhoneGuestDevice.named(device) != nil else {+ throw ValidationError("vphone runs \(VPhoneGuestDevice.known.map(\.productType).joined(separator: " and ")) guests, not \(device).")+ }+ let device = devicelet urls = if needsCatalog {try vphoneRunBlocking {- try await VPhoneFirmwareIndex.restoreURLs(forDevice: "iPhone17,3")+ try await VPhoneFirmwareIndex.restoreURLs(forDevice: device)}.joined(separator: "\n")} else {""@@ -230,7 +236,7 @@ struct VPhoneFirmwarePrepareCommand: ParsableCommand {if list {let code = VPhoneFirmwareMatrixCommandLine.list(- device: "iPhone17,3",+ device: device,readmePath: readme,downloadURLs: urls,)@@ -246,7 +252,7 @@ struct VPhoneFirmwarePrepareCommand: ParsableCommand {throw ValidationError("Use either --iphone-source or --iphone-version/--iphone-build.")}let selection = VPhoneFirmwareMatrix.selection(- device: "iPhone17,3",+ device: device,version: iphoneVersion ?? "",build: iphoneBuild ?? "",readme: try? String(contentsOfFile: readme, encoding: .utf8),diff --git a/VPhoneKit/VPhoneCoreKit/Firmware/VPhoneFirmwareIndex.swift b/VPhoneKit/VPhoneCoreKit/Firmware/VPhoneFirmwareIndex.swiftindex 6cb9706f..d6ca8acf 100644--- a/VPhoneKit/VPhoneCoreKit/Firmware/VPhoneFirmwareIndex.swift+++ b/VPhoneKit/VPhoneCoreKit/Firmware/VPhoneFirmwareIndex.swift@@ -59,8 +59,10 @@ public enum VPhoneFirmwareIndex {// MARK: - Queries/// Every released iOS restore URL for one device identifier, newest first.+ /// AppleDB files an iPad's releases under iPadOS.public static func restoreURLs(forDevice device: String) async throws -> [String] {- try await releases(os: "iOS", device: device).map(\.url.absoluteString)+ try await releases(os: device.hasPrefix("iPad") ? "iPadOS" : "iOS", device: device)+ .map(\.url.absoluteString)}/// The released macOS restore image for a marketing version like "26.1".diff --git a/VPhoneKit/VPhoneCoreKit/Firmware/VPhoneFirmwareMatrix.swift b/VPhoneKit/VPhoneCoreKit/Firmware/VPhoneFirmwareMatrix.swiftindex 2e737134..752998c5 100644--- a/VPhoneKit/VPhoneCoreKit/Firmware/VPhoneFirmwareMatrix.swift+++ b/VPhoneKit/VPhoneCoreKit/Firmware/VPhoneFirmwareMatrix.swift@@ -195,10 +195,11 @@ public enum VPhoneFirmwareMatrix {////// A line counts when it *ends* with `/<device>_<version>_<build>_Restore.ipsw`,/// so the surrounding CDN path — which differs per release and is sometimes- /// a bare UUID — is ignored.+ /// a bare UUID — is ignored. An IPSW shared by several models names them+ /// all, comma-separated (`iPad16,1,iPad16,2_…`); `device` may be any of them.public static func releases(downloadURLs: String, device: String) -> [VPhoneFirmwareRelease] {- let pattern = "/(" + NSRegularExpression.escapedPattern(for: device)- + "_([^_]+)_([A-Za-z0-9]+)_Restore\\.ipsw)$"+ let pattern = "/((?:[^/_]*,)?" + NSRegularExpression.escapedPattern(for: device)+ + "(?:,[^/_]*)?_([^_]+)_([A-Za-z0-9]+)_Restore\\.ipsw)$"guard let name = try? NSRegularExpression(pattern: pattern) else { return [] }var seen: Set<VPhoneFirmwareRelease> = []diff --git a/VPhoneKit/VPhoneCoreKitTests/Firmware/FirmwareMatrixTests.swift b/VPhoneKit/VPhoneCoreKitTests/Firmware/FirmwareMatrixTests.swiftindex d7078ac8..41846daa 100644--- a/VPhoneKit/VPhoneCoreKitTests/Firmware/FirmwareMatrixTests.swift+++ b/VPhoneKit/VPhoneCoreKitTests/Firmware/FirmwareMatrixTests.swift@@ -719,4 +719,18 @@ struct FirmwareMatrixCommandLineTests {#expect(err == "Unsupported: no downloadable IPSW matched device=iPhone17,3 version=99.9\n")#expect(!err.contains("\u{1B}["))}++ @Test func `an IPSW naming several models matches each of them`() {+ let urls = """+ https://updates.cdn-apple.com/2026SummerFCS/cf7db64d-5866-4bf2-bfff-50a32f58bec3/iPad16,1,iPad16,2_26.6.2_23G90_Restore.ipsw+ https://updates.cdn-apple.com/2026SummerFCS/x/iPad16,10,iPad16,11_26.6.2_23G90_Restore.ipsw+ """+ let wifi = VPhoneFirmwareMatrix.releases(downloadURLs: urls, device: "iPad16,1")+ #expect(wifi.map(\.build) == ["23G90"])+ #expect(wifi.first?.version == "26.6.2")+ #expect(wifi.first?.url.contains("iPad16,1,iPad16,2_") == true)+ #expect(VPhoneFirmwareMatrix.releases(downloadURLs: urls, device: "iPad16,2").count == 1)+ // A longer model number is a different device.+ #expect(VPhoneFirmwareMatrix.releases(downloadURLs: urls, device: "iPad16,11").count == 1)+ }}