Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Offer the LZRAVEN OTAs only on macOS 27 and say why elsewhere

Lakr2330db857666467
diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneFirmwarePreparer.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneFirmwarePreparer.swift
index 869da965..3d635e76 100644
--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneFirmwarePreparer.swift
+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneFirmwarePreparer.swift
@@ -50,6 +50,8 @@ enum VPhoneFirmwarePreparer {
var iPhoneSource = iPhoneSource, otaSource = otaSource, productType = productType
let requestedOTA = VPhoneFirmwareCatalog.otaRelease(source: iPhoneSource)
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.")
}
@@ -310,6 +312,7 @@ enum VPhoneFirmwarePreparer {
// when it is restored over its base's last release.
let release = source.flatMap(VPhoneFirmwareCatalog.otaRelease(source:))
?? VPhoneFirmwareCatalog.otaRelease(for: device.productType, build: build)
+ try release?.checkHost()
let build = release?.build ?? build
guard source != nil || release != nil else {
throw ValidationError("The firmware catalog has no \(device.productType) OTA for build \(build). Pass the device's full OTA of that build with --ota-source, and its key with --ota-key.")
diff --git a/VPhoneKit/VPhoneArchiveKit/Transfer/VPhoneOTAArchive.swift b/VPhoneKit/VPhoneArchiveKit/Transfer/VPhoneOTAArchive.swift
index 73477962..596ff59c 100644
--- a/VPhoneKit/VPhoneArchiveKit/Transfer/VPhoneOTAArchive.swift
+++ b/VPhoneKit/VPhoneArchiveKit/Transfer/VPhoneOTAArchive.swift
@@ -38,6 +38,7 @@ public enum VPhoneOTAArchive {
case existingUserland(URL)
case noSource(String)
case deltaUpdate(URL)
+ case needsNewerMacOS(URL, minimum: Int)
public var errorDescription: String? {
switch self {
@@ -69,6 +70,8 @@ public enum VPhoneOTAArchive {
"The firmware catalog has no OTA for \(productType) at this build. Pass the device's full OTA with --ota-source."
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."
}
}
}
@@ -283,6 +286,7 @@ public enum VPhoneOTAArchive {
}
plain = decrypted
case Data("pbz".utf8):
+ try checkCompression(magic, of: ota)
guard let decompressed = ArchiveByteStream.decompressionStream(readingFrom: file) else {
throw Error.unreadable(ota, "it could not be decompressed")
}
@@ -298,6 +302,23 @@ public enum VPhoneOTAArchive {
return OpenedArchive(archive: archive, streams: plain === file ? [file] : [file, plain])
}
+ /// 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 = 27
+
+ static 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)"
+ }
+
private static func readMagic(_ file: URL) throws -> Data {
guard FileManager.default.fileExists(atPath: file.path) else { throw Error.missingFile(file) }
let handle = try FileHandle(forReadingFrom: file)
@@ -507,6 +528,10 @@ 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)
+ }
chunks.append(name)
progress?(name)
}
diff --git a/VPhoneKit/VPhoneArchiveKitTests/OTAArchiveTests.swift b/VPhoneKit/VPhoneArchiveKitTests/OTAArchiveTests.swift
index 608cc2a3..e2996a11 100644
--- a/VPhoneKit/VPhoneArchiveKitTests/OTAArchiveTests.swift
+++ b/VPhoneKit/VPhoneArchiveKitTests/OTAArchiveTests.swift
@@ -234,6 +234,26 @@ struct OTAArchiveTests {
#expect(!FileManager.default.fileExists(atPath: root.appendingPathComponent("outside").path))
}
+ @Test func `an LZRAVEN payload is refused before macOS 27, by name`() throws {
+ let chunk = URL(fileURLWithPath: "/tmp/payload.000")
+ let lzraven = Data("pbzm".utf8) + Data(repeating: 0, count: 4)
+ if ProcessInfo.processInfo.operatingSystemVersion.majorVersion < 27 {
+ let error = try #require(throws: VPhoneOTAArchive.Error.self) {
+ try VPhoneOTAArchive.checkCompression(lzraven, of: chunk)
+ }
+ guard case .needsNewerMacOS(chunk, minimum: 27) = error else {
+ Issue.record("\(error)")
+ return
+ }
+ #expect(error.localizedDescription.contains("LZRAVEN"))
+ #expect(!error.localizedDescription.contains("Download the OTA again"))
+ } else {
+ try VPhoneOTAArchive.checkCompression(lzraven, of: chunk)
+ }
+ // Every other pbz compression is AppleArchive's on any supported host.
+ try VPhoneOTAArchive.checkCompression(Data("pbzx".utf8), of: chunk)
+ }
+
@Test func `ZIP duplicate metadata is refused`() throws {
let root = try makeRoot()
defer { try? FileManager.default.removeItem(at: root) }
diff --git a/VPhoneKit/VPhoneCoreKit/Firmware/VPhoneFirmwareCatalog.swift b/VPhoneKit/VPhoneCoreKit/Firmware/VPhoneFirmwareCatalog.swift
index 3b65e001..db0ab0ad 100644
--- a/VPhoneKit/VPhoneCoreKit/Firmware/VPhoneFirmwareCatalog.swift
+++ b/VPhoneKit/VPhoneCoreKit/Firmware/VPhoneFirmwareCatalog.swift
@@ -67,8 +67,21 @@ public struct VPhoneOTARelease: Sendable, Equatable {
/// same as `version` while the base still gets releases; a later OTA goes
/// over the base's last one, since only the userland is taken from it.
public let baseVersion: String
+ /// The oldest macOS whose libcompression unpacks the payload: the 27
+ /// releases compress their chunks with LZRAVEN (`pbzm`), which macOS 27
+ /// added. Nil when every supported host unpacks it.
+ public let minimumHostMacOS: Int?
- public init(productType: String, version: String, build: String, url: String, size: Int64, key: String? = nil, baseVersion: String? = nil) {
+ public init(
+ productType: String,
+ version: String,
+ build: String,
+ url: String,
+ size: Int64,
+ key: String? = nil,
+ baseVersion: String? = nil,
+ minimumHostMacOS: Int? = nil,
+ ) {
self.productType = productType
self.version = version
self.build = build
@@ -76,6 +89,29 @@ public struct VPhoneOTARelease: Sendable, Equatable {
self.size = size
self.key = key
self.baseVersion = baseVersion ?? version
+ self.minimumHostMacOS = minimumHostMacOS
+ }
+
+ /// The major version of the macOS this process runs on.
+ public static var hostMacOS: Int {
+ ProcessInfo.processInfo.operatingSystemVersion.majorVersion
+ }
+
+ /// Whether a Mac running `hostMacOS` unpacks the payload.
+ public func unpacks(onMacOS hostMacOS: Int = Self.hostMacOS) -> Bool {
+ minimumHostMacOS.map { hostMacOS >= $0 } ?? true
+ }
+
+ /// Refuses this OTA on a Mac that cannot unpack it, before anything is
+ /// downloaded or restored for it.
+ public func checkHost() throws {
+ guard let minimumHostMacOS, !unpacks() else { return }
+ let name = VPhoneGuestDevice.named(productType)?.family.osName ?? productType
+ let host = ProcessInfo.processInfo.operatingSystemVersion
+ throw 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.",
+ )
}
/// The IPSW cache's folder for OTAs.
@@ -87,6 +123,14 @@ public struct VPhoneOTARelease: Sendable, Equatable {
}
}
+/// An OTA this Mac cannot unpack.
+public struct VPhoneOTAHostError: Error, LocalizedError {
+ public let message: String
+ public var errorDescription: String? {
+ message
+ }
+}
+
// MARK: - VPhoneFirmwareCatalog
/// The known downloadable restore/cloudOS pairings, per guest device. Prompts
@@ -514,7 +558,7 @@ public enum VPhoneFirmwareCatalog {
key: "zm99NLG9ucGRIqHjpHC5BVHS3v55gz7bBmVfeizDMv0=",
),
// tvOS 27 dropped the Apple TV HD, so the 27 userland goes over its
- // last IPSW.
+ // last IPSW. Its chunks are LZRAVEN, which only macOS 27 unpacks.
.init(
productType: "AppleTV14,1",
version: "27.0",
@@ -523,10 +567,12 @@ public enum VPhoneFirmwareCatalog {
size: 4_831_838_208,
key: "L3wZrfSYx2pFDbJSYtEteNDspB26qBv0lxLlkWrKTYk=",
baseVersion: "26.6",
+ minimumHostMacOS: 27,
),
// 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
// and board tree, while the boot chain remains cloudOS 26.4.
+ // Its chunks are LZRAVEN, which only macOS 27 unpacks.
.init(
productType: "AudioAccessory5,1",
version: "27.2",
@@ -534,6 +580,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,
),
]
@@ -565,8 +612,10 @@ public enum VPhoneFirmwareCatalog {
/// device without an IPSW gets one per OTA for it, named for the OTA: the
/// base's IPSW when the OTA is of the same version, else the OTA itself,
/// which `fw prepare` restores over its base's IPSW; an unknown device
- /// gets none.
- public static func pairings(for device: String) -> [VPhoneFirmwarePairing] {
+ /// gets none. An OTA a Mac running `hostMacOS` cannot unpack is left out,
+ /// so the newest pairing, which a creation without sources takes, is one
+ /// this Mac can build.
+ public static func pairings(for device: String, hostMacOS: Int = VPhoneOTARelease.hostMacOS) -> [VPhoneFirmwarePairing] {
guard let guest = VPhoneGuestDevice.named(device) else { return [] }
if guest.notchedArtworkSubtype != nil {
return iOS18ResearchBoardReleases.map { release in
@@ -581,14 +630,15 @@ public enum VPhoneFirmwareCatalog {
}
guard guest.presentsBoard else { return pairings }
let restored = guest.restoreBase ?? guest
+ let otas = otaReleases.filter { $0.productType == guest.productType && $0.unpacks(onMacOS: hostMacOS) }
var releases = (iPhoneReleases + iPadReleases + tvReleases + homePodReleases + watchReleases).first { $0.devices.contains(restored.productType) }?.releases ?? []
if restored != guest {
- releases = otaReleases.filter { $0.productType == guest.productType }.compactMap { ota in
+ releases = otas.compactMap { ota in
guard let base = releases.first(where: { $0.version == ota.baseVersion }) else { return nil }
return (version: ota.version, url: ota.version == base.version ? base.url : ota.url)
}
} else if guest.family == .homePod {
- releases += otaReleases.filter { $0.productType == guest.productType }.compactMap { ota in
+ releases += otas.compactMap { ota in
guard restoreBaseURL(for: ota) != nil else { return nil }
return (version: ota.version, url: ota.url)
}
@@ -631,8 +681,14 @@ public enum VPhoneFirmwareCatalog {
}
/// JSON-friendly projection of the catalog: each build with its recommended
- /// cloudOS, for the iPhone and then per guest device.
+ /// cloudOS, for the iPhone and then per guest device, as this Mac can build
+ /// them.
public static var report: VPhoneFirmwareCatalogReport {
+ report(hostMacOS: VPhoneOTARelease.hostMacOS)
+ }
+
+ /// The report for a Mac running `hostMacOS`.
+ public static func report(hostMacOS: Int) -> VPhoneFirmwareCatalogReport {
func entries(_ pairings: [VPhoneFirmwarePairing]) -> [VPhoneFirmwareCatalogReport.Entry] {
pairings.map {
let ota = otaRelease(source: $0.iosURL)
@@ -653,7 +709,7 @@ public enum VPhoneFirmwareCatalog {
device: device,
pairings: entries(pairings),
devices: VPhoneGuestDevice.known.compactMap { guest in
- let pairings = pairings(for: guest.productType)
+ let pairings = pairings(for: guest.productType, hostMacOS: hostMacOS)
guard !pairings.isEmpty else { return nil }
return .init(
productType: guest.productType,
diff --git a/VPhoneKit/VPhoneCoreKitTests/Firmware/FirmwareCatalogReportTests.swift b/VPhoneKit/VPhoneCoreKitTests/Firmware/FirmwareCatalogReportTests.swift
index ff9a5b2f..b9623d5d 100644
--- a/VPhoneKit/VPhoneCoreKitTests/Firmware/FirmwareCatalogReportTests.swift
+++ b/VPhoneKit/VPhoneCoreKitTests/Firmware/FirmwareCatalogReportTests.swift
@@ -17,7 +17,7 @@ struct FirmwareCatalogReportTests {
}
@Test func `an OTA pairing names its build and the files it needs`() throws {
- let tv4K = try #require(VPhoneFirmwareCatalog.report.devices.first { $0.productType == "AppleTV14,1" })
+ let tv4K = try #require(VPhoneFirmwareCatalog.report(hostMacOS: 27).devices.first { $0.productType == "AppleTV14,1" })
let ipsw = try #require(tv4K.pairings.first { $0.ios.name == "tvOS 26.6" })
let ota = try #require(tv4K.pairings.first { $0.ios.name == "tvOS 27.0" })
#expect(ipsw.ios.build == nil && ipsw.ios.files == nil)
@@ -60,7 +60,7 @@ struct FirmwareCatalogReportTests {
}
@Test func `the Apple TV 4K pairs each OTA with the Apple TV HD IPSW it is restored over`() throws {
- let pairings = VPhoneFirmwareCatalog.pairings(for: "AppleTV14,1")
+ let pairings = VPhoneFirmwareCatalog.pairings(for: "AppleTV14,1", hostMacOS: 27)
#expect(pairings.map(\.iosName) == ["tvOS 26.6", "tvOS 27.0"])
let hd = try #require(VPhoneFirmwareCatalog.pairings(for: "AppleTV5,3").first { $0.iosName == "tvOS 26.6" })
for p in pairings {
@@ -110,7 +110,7 @@ struct FirmwareCatalogReportTests {
}
@Test func `HomePod mini pairs its native 27 IPSW with cloudOS without an OTA base`() throws {
- let pairings = VPhoneFirmwareCatalog.pairings(for: "AudioAccessory5,1")
+ let pairings = VPhoneFirmwareCatalog.pairings(for: "AudioAccessory5,1", hostMacOS: 27)
#expect(pairings.count == 2)
let pairing = try #require(pairings.first)
#expect(pairing.device == "AudioAccessory5,1")
@@ -136,15 +136,32 @@ struct FirmwareCatalogReportTests {
#expect(release.version == "27.2" && release.baseVersion == "27.0")
#expect(release.key == nil && release.size == 3_051_441_612)
#expect(release.fileName == "AudioAccessory5,1_27.2_24K120_OTA.zip")
- let pairings = VPhoneFirmwareCatalog.pairings(for: release.productType)
+ let pairings = VPhoneFirmwareCatalog.pairings(for: release.productType, hostMacOS: 27)
#expect(VPhoneFirmwareCatalog.restoreBaseURL(for: release) == pairings[0].iosURL)
#expect(pairings[1].iosURL == release.url)
#expect(VPhoneFirmwareCatalog.otaRelease(source: "/cache/ota/\(release.fileName)") == release)
- let device = try #require(VPhoneFirmwareCatalog.report.devices.first { $0.productType == release.productType })
+ let device = try #require(VPhoneFirmwareCatalog.report(hostMacOS: 27).devices.first { $0.productType == release.productType })
#expect(device.pairings[1].ios.build == "24K120")
#expect(device.pairings[1].ios.files == ["ota/\(release.fileName)", (pairings[0].iosURL as NSString).lastPathComponent])
}
+ @Test func `a Mac before macOS 27 is offered no OTA it cannot unpack`() throws {
+ // 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"])
+ for release in lzraven {
+ #expect(!release.unpacks(onMacOS: 26) && release.unpacks(onMacOS: 27))
+ }
+ #expect(VPhoneFirmwareCatalog.pairings(for: "AppleTV14,1", hostMacOS: 26).map(\.iosName) == ["tvOS 26.6"])
+ #expect(VPhoneFirmwareCatalog.pairings(for: "AudioAccessory5,1", hostMacOS: 26).map(\.iosName) == ["HomePod Software 27.0"])
+ let report = VPhoneFirmwareCatalog.report(hostMacOS: 26)
+ let tv4K = try #require(report.devices.first { $0.productType == "AppleTV14,1" })
+ #expect(tv4K.pairings.map(\.ios.name) == ["tvOS 26.6"])
+ // Nothing else depends on the host.
+ #expect(VPhoneFirmwareCatalog.pairings(for: "AppleTV5,3", hostMacOS: 26) == VPhoneFirmwareCatalog.pairings(for: "AppleTV5,3", hostMacOS: 27))
+ #expect(VPhoneFirmwareCatalog.pairings(for: "iPhone17,3", hostMacOS: 26) == VPhoneFirmwareCatalog.pairings)
+ }
+
@Test func `i pad pairings come from an IPSW that covers the device`() {
for guest in VPhoneGuestDevice.known where guest.isPad {
let pairings = VPhoneFirmwareCatalog.pairings(for: guest.productType)