Run a virtual iPhone on an Apple Silicon Mac.
Swift
Refuse an LZRAVEN OTA before any download, however it is named
Lakr233007b48feb5da
diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneFirmwarePreparer.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneFirmwarePreparer.swiftindex 3d635e76..14e57da2 100644--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneFirmwarePreparer.swift+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneFirmwarePreparer.swift@@ -49,9 +49,10 @@ enum VPhoneFirmwarePreparer {// got, restores the OTA's base IPSW and stages that OTA.var iPhoneSource = iPhoneSource, otaSource = otaSource, productType = productTypelet requestedOTA = VPhoneFirmwareCatalog.otaRelease(source: iPhoneSource)+ // An OTA this Mac cannot unpack is refused before any IPSW is+ // downloaded for it, whether it comes as the iPhone source or on its own.+ try (requestedOTA ?? otaSource.flatMap(VPhoneFirmwareCatalog.otaRelease(source:)))?.checkHost()if let release = requestedOTA {- // Before any IPSW is downloaded or restored for it.- try release.checkHost()guard let base = VPhoneFirmwareCatalog.restoreBaseURL(for: release) else {throw ValidationError("The firmware catalog has no \(release.baseVersion) IPSW to restore the \(release.productType) OTA \(release.version) over.")}@@ -264,6 +265,8 @@ enum VPhoneFirmwarePreparer {if let ota, let productType, ota.productType != productType {throw Error.deviceNotInSource(productType, available: [ota.productType])}+ // Before its base IPSW is downloaded (`fw ota` and template builds come here first).+ try ota?.checkHost()let iPhoneSource = ota.flatMap(VPhoneFirmwareCatalog.restoreBaseURL(for:)) ?? iPhoneSourcelet productType = productType ?? ota?.productType// Remote IPSWs go to one cache shared by every machine; keeping themdiff --git a/VPhoneKit/VPhoneArchiveKit/Transfer/VPhoneOTAArchive.swift b/VPhoneKit/VPhoneArchiveKit/Transfer/VPhoneOTAArchive.swiftindex 596ff59c..e87cd25c 100644--- a/VPhoneKit/VPhoneArchiveKit/Transfer/VPhoneOTAArchive.swift+++ b/VPhoneKit/VPhoneArchiveKit/Transfer/VPhoneOTAArchive.swift@@ -71,7 +71,7 @@ public enum VPhoneOTAArchive {case let .deltaUpdate(file):"\(file.lastPathComponent) requires a pristine prerequisite build. A modified vphone system needs a full OTA, without PrerequisiteBuild."case let .needsNewerMacOS(file, minimum):- "\(file.lastPathComponent) is compressed with LZRAVEN, which macOS \(minimum) and later unpack; this Mac runs macOS \(hostVersion). Create this machine on macOS \(minimum) or later, or choose an earlier release."+ "\(file.lastPathComponent) is compressed with LZRAVEN, which macOS \(minimum) and later unpack; this Mac runs macOS \(VPhoneOTARelease.hostMacOSVersion). Create this machine on macOS \(minimum) or later, or choose an earlier release."}}}@@ -305,18 +305,11 @@ public enum VPhoneOTAArchive {/// LZRAVEN (`pbzm`) came with macOS 27's libcompression: an older Mac/// cannot unpack a payload compressed with it.static let lzravenMagic = Data("pbzm".utf8)- static let lzravenMinimumMacOS = 27static func checkCompression(_ magic: Data, of file: URL) throws {- guard magic.prefix(4) == lzravenMagic,- ProcessInfo.processInfo.operatingSystemVersion.majorVersion < lzravenMinimumMacOS- else { return }- throw Error.needsNewerMacOS(file, minimum: lzravenMinimumMacOS)- }-- static var hostVersion: String {- let version = ProcessInfo.processInfo.operatingSystemVersion- return "\(version.majorVersion).\(version.minorVersion)"+ let minimum = VPhoneOTARelease.lzravenMinimumMacOS+ guard magic.prefix(4) == lzravenMagic, VPhoneOTARelease.hostMacOS < minimum else { return }+ throw Error.needsNewerMacOS(file, minimum: minimum)}private static func readMagic(_ file: URL) throws -> Data {@@ -528,10 +521,9 @@ public enum VPhoneOTAArchive {linkList = data} else {let name = String(path.dropFirst(payloadPrefix.count))- // Before the rest of the payload is written.- if chunks.isEmpty {- try checkCompression(readMagic(pending.appendingPathComponent(name)), of: ota)- }+ // Each chunk as it lands, so an LZRAVEN payload is refused at+ // its first chunk, before the rest is written.+ try checkCompression(readMagic(pending.appendingPathComponent(name)), of: ota)chunks.append(name)progress?(name)}diff --git a/VPhoneKit/VPhoneCoreKit/Firmware/VPhoneFirmwareCatalog.swift b/VPhoneKit/VPhoneCoreKit/Firmware/VPhoneFirmwareCatalog.swiftindex db0ab0ad..bd35c907 100644--- a/VPhoneKit/VPhoneCoreKit/Firmware/VPhoneFirmwareCatalog.swift+++ b/VPhoneKit/VPhoneCoreKit/Firmware/VPhoneFirmwareCatalog.swift@@ -97,6 +97,16 @@ public struct VPhoneOTARelease: Sendable, Equatable {ProcessInfo.processInfo.operatingSystemVersion.majorVersion}+ /// The macOS this process runs on, as `major.minor`.+ public static var hostMacOSVersion: String {+ let host = ProcessInfo.processInfo.operatingSystemVersion+ return "\(host.majorVersion).\(host.minorVersion)"+ }++ /// The first macOS whose libcompression decodes LZRAVEN (`pbzm`), the+ /// compression of the 27-series OTAs' payload.+ public static let lzravenMinimumMacOS = 27+/// Whether a Mac running `hostMacOS` unpacks the payload.public func unpacks(onMacOS hostMacOS: Int = Self.hostMacOS) -> Bool {minimumHostMacOS.map { hostMacOS >= $0 } ?? true@@ -107,10 +117,9 @@ public struct VPhoneOTARelease: Sendable, Equatable {public func checkHost() throws {guard let minimumHostMacOS, !unpacks() else { return }let name = VPhoneGuestDevice.named(productType)?.family.osName ?? productType- let host = ProcessInfo.processInfo.operatingSystemVersionthrow VPhoneOTAHostError(message: "\(name) \(version) (\(build)) compresses its userland with LZRAVEN, which macOS \(minimumHostMacOS) and later unpack; "- + "this Mac runs macOS \(host.majorVersion).\(host.minorVersion). Choose an earlier release, or create this machine on macOS \(minimumHostMacOS) or later.",+ + "this Mac runs macOS \(Self.hostMacOSVersion). Choose an earlier release, or create this machine on macOS \(minimumHostMacOS) or later.",)}@@ -567,7 +576,7 @@ public enum VPhoneFirmwareCatalog {size: 4_831_838_208,key: "L3wZrfSYx2pFDbJSYtEteNDspB26qBv0lxLlkWrKTYk=",baseVersion: "26.6",- minimumHostMacOS: 27,+ minimumHostMacOS: VPhoneOTARelease.lzravenMinimumMacOS,),// HomePod's newer software ships as a full ZIP OTA. Keep its own// 27.0 restore IPSW as the base; the OTA supplies only the userland@@ -580,7 +589,7 @@ public enum VPhoneFirmwareCatalog {url: "https://updates.cdn-apple.com/2026FallFCS/b191c01c-8e6e-4b74-8b84-015131f696b8/com_apple_MobileAsset_SoftwareUpdate/861a9e7426795ddb3eac86cd0b089e5bf7939258.zip",size: 3_051_441_612,baseVersion: "27.0",- minimumHostMacOS: 27,+ minimumHostMacOS: VPhoneOTARelease.lzravenMinimumMacOS,),]diff --git a/VPhoneKit/VPhoneCoreKitTests/Firmware/FirmwareCatalogReportTests.swift b/VPhoneKit/VPhoneCoreKitTests/Firmware/FirmwareCatalogReportTests.swiftindex b9623d5d..1a72790d 100644--- a/VPhoneKit/VPhoneCoreKitTests/Firmware/FirmwareCatalogReportTests.swift+++ b/VPhoneKit/VPhoneCoreKitTests/Firmware/FirmwareCatalogReportTests.swift@@ -149,6 +149,11 @@ struct FirmwareCatalogReportTests {// tvOS 27.0 and HomePod Software 27.2 compress their chunks with LZRAVEN.let lzraven = VPhoneFirmwareCatalog.otaReleases.filter { $0.minimumHostMacOS == 27 }#expect(Set(lzraven.map(\.build)) == ["24J361", "24K120"])+ // Every 27-series OTA is LZRAVEN so far: a new one must say so, or an+ // older Mac would be offered it and fail only after its downloads.+ for release in VPhoneFirmwareCatalog.otaReleases where Int(release.version.split(separator: ".")[0]) ?? 0 >= 27 {+ #expect(release.minimumHostMacOS == VPhoneOTARelease.lzravenMinimumMacOS, "\(release.productType) \(release.version)")+ }for release in lzraven {#expect(!release.unpacks(onMacOS: 26) && release.unpacks(onMacOS: 27))}