Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Fetch the seal tool for iOS 18 from macOS 15

Maximilian Paß9e400447dbee
diff --git a/Research/0_binary_patch_comparison.md b/Research/0_binary_patch_comparison.md
index 6c327ca5..40b99398 100644
--- a/Research/0_binary_patch_comparison.md
+++ b/Research/0_binary_patch_comparison.md
@@ -3313,7 +3313,8 @@ seal. So for a VM whose plan enables `filesystem-boot-cryptex_merge`:
from the receipt-checked store bundle; that flag refuses any selection that
does not merge the restore image.
- `fw prepare` stages `apfs_sealvolume_<iOS version>` into `<restore>/.tools`
- (the `fw seal-tool` fetch) and the GPU driver for
+ (the `fw seal-tool` fetch; iOS 18.x.y takes macOS 15.x.y, or without a twin
+ the newest macOS 15 below it) and the GPU driver for
`filesystem-boot-gpu_driver` as for `system-extensions-boot-gpu_bundle`.
`vm create` and Launchpad now record the preset before `fw prepare`, which
read `standard` before: the GPU staging followed the wrong selection for any
diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneFirmwareDownloadCommand.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneFirmwareDownloadCommand.swift
index a8afa748..f8e278bf 100644
--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneFirmwareDownloadCommand.swift
+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneFirmwareDownloadCommand.swift
@@ -54,7 +54,9 @@ struct VPhoneFirmwareSealToolCommand: ParsableCommand {
`apfs_sealvolume` is what turns a rebuilt system volume into a sealed
one, and it is not in an iPhone restore image — only in a macOS one. The
two have shared a marketing version since 2025, so "the tool for iOS
- 26.1" means "the one in macOS 26.1".
+ 26.1" means "the one in macOS 26.1"; iOS 18.x.y goes with macOS 15.x.y.
+ Without an exact match, the newest macOS of that major below it is
+ taken.
The macOS IPSW is about 18 GB and two files in it are wanted, so nothing
is downloaded whole: the archive is read over HTTP range requests, the
@@ -120,7 +122,7 @@ struct VPhoneFirmwareSealToolCommand: ParsableCommand {
/// Resolve the macOS release, then take BuildManifest.plist and the restore
/// ramdisk out of its IPSW without downloading the IPSW.
private static func fetchRamdisk(version: String, in output: URL) async throws -> URL {
- let release = try await VPhoneFirmwareIndex.macOSRelease(version: version)
+ let release = try await VPhoneFirmwareIndex.sealToolRelease(forOSVersion: version)
print(" macOS \(release.version) (\(release.build))")
let zip = try await VPhoneRemoteZip.open(release.url)
diff --git a/VPhoneKit/VPhoneCoreKit/Firmware/VPhoneFirmwareIndex.swift b/VPhoneKit/VPhoneCoreKit/Firmware/VPhoneFirmwareIndex.swift
index d6ca8acf..a02096a6 100644
--- a/VPhoneKit/VPhoneCoreKit/Firmware/VPhoneFirmwareIndex.swift
+++ b/VPhoneKit/VPhoneCoreKit/Firmware/VPhoneFirmwareIndex.swift
@@ -65,11 +65,34 @@ public enum VPhoneFirmwareIndex {
.map(\.url.absoluteString)
}
- /// The released macOS restore image for a marketing version like "26.1".
- public static func macOSRelease(version: String) async throws -> Release {
- let matches = try await releases(os: "macOS", device: nil)
- .filter { $0.version == version }
- guard let release = matches.first else { throw Error.noRelease("macOS", version) }
+ /// The macOS whose `apfs_sealvolume` seals a system of iOS `version`.
+ ///
+ /// Before 2025 the two did not share a marketing version: iOS 18.x.y goes
+ /// with macOS 15.x.y. Not every iOS release has a macOS twin (18.2.1 has
+ /// only 15.2), and the catalogue misses some releases, so without an exact
+ /// match the newest release of the same major below it is taken.
+ public static func sealToolRelease(forOSVersion version: String) async throws -> Release {
+ let macOS = try await releases(os: "macOS", device: nil)
+ return try sealToolRelease(forOSVersion: version, in: macOS)
+ }
+
+ /// ``sealToolRelease(forOSVersion:)`` over a given list of macOS releases.
+ static func sealToolRelease(forOSVersion version: String, in macOS: [Release]) throws -> Release {
+ func numbers(_ version: String) -> [Int] {
+ version.split(separator: ".").compactMap { Int($0) }
+ }
+ var target = numbers(version)
+ if target.first == 18 {
+ target[0] = 15
+ }
+ // The same major, and not newer than the target.
+ let candidates = macOS.filter {
+ let other = numbers($0.version)
+ return other.first == target.first && !target.lexicographicallyPrecedes(other)
+ }
+ guard let release = candidates.max(by: { numbers($0.version).lexicographicallyPrecedes(numbers($1.version)) }) else {
+ throw Error.noRelease("macOS", target.map(String.init).joined(separator: "."))
+ }
return release
}
diff --git a/VPhoneKit/VPhoneCoreKitTests/Firmware/SealToolReleaseTests.swift b/VPhoneKit/VPhoneCoreKitTests/Firmware/SealToolReleaseTests.swift
new file mode 100644
index 00000000..bae6e9f9
--- /dev/null
+++ b/VPhoneKit/VPhoneCoreKitTests/Firmware/SealToolReleaseTests.swift
@@ -0,0 +1,41 @@
+import Foundation
+import Testing
+@testable import VPhoneCoreKit
+
+struct SealToolReleaseTests {
+ private let macOS = ["15.2", "15.6.1", "15.7.1", "26.1", "26.4"].map {
+ VPhoneFirmwareIndex.Release(
+ os: "macOS",
+ version: $0,
+ build: "",
+ url: URL(string: "https://example.invalid/\($0).ipsw")!,
+ )
+ }
+
+ private func sealTool(_ version: String) throws -> String {
+ try VPhoneFirmwareIndex.sealToolRelease(forOSVersion: version, in: macOS).version
+ }
+
+ @Test func `iOS 26 takes the macOS of the same version`() throws {
+ #expect(try sealTool("26.1") == "26.1")
+ #expect(try sealTool("26.4") == "26.4")
+ }
+
+ @Test func `iOS 18 takes the macOS 15 of the same minor`() throws {
+ #expect(try sealTool("18.2") == "15.2")
+ #expect(try sealTool("18.7.1") == "15.7.1")
+ }
+
+ @Test func `without a twin, the newest macOS of the major below it`() throws {
+ // 18.2.1 has no macOS 15.2.1, and 15.6 is not in this list.
+ #expect(try sealTool("18.2.1") == "15.2")
+ #expect(try sealTool("18.6") == "15.2")
+ #expect(try sealTool("18.7.2") == "15.7.1")
+ #expect(try sealTool("26.5") == "26.4")
+ }
+
+ @Test func `nothing of the major at or below it is an error`() {
+ #expect(throws: VPhoneFirmwareIndex.Error.self) { try sealTool("18.1") }
+ #expect(throws: VPhoneFirmwareIndex.Error.self) { try sealTool("27.0") }
+ }
+}