Run a virtual iPhone on an Apple Silicon Mac.
Swift
Add the minimal preset: a restore image instead of patches
Maximilian Paße57eda172ffc
diff --git a/Skills/authoring-patch-sets/SKILL.md b/Skills/authoring-patch-sets/SKILL.mdindex 3ffe49e4..8015957c 100644--- a/Skills/authoring-patch-sets/SKILL.md+++ b/Skills/authoring-patch-sets/SKILL.md@@ -168,7 +168,9 @@ Then:records nothing declares, and undeclared records apply. Leaving the set outhas to mean leaving the patcher out.3. Add the set to both shipped preset plists (both name every set; presets differ- by their selection, not by which sets they draw on).+ by their selection, not by which sets they draw on). The one exception is+ `minimal`, which names only the device tree and the restore image set: it+ customises the system before the restore, the other sets after it.4. Run the catalogue tests.### Capabilities, Requires, Conflicts, Afterdiff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcher.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcher.swiftindex 672a0abc..c115289f 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcher.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcher.swift@@ -28,6 +28,7 @@ public final class CryptexFilesystemPatcher: BufferedPatcher {public let verbose: Boolpublic let noBinpack: Boollet resources = VPhoneResources.resolve()+ public var gate: VPhonePatchGate = .unrestrictedvar buildManiest: Datavar rebuiltData: Data?@@ -63,17 +64,29 @@ public final class CryptexFilesystemPatcher: BufferedPatcher {// MARK: - Patcher+ /// One record per step the gate lets through. The merge itself is the+ /// patcher: the pipeline builds it only when the merge is on.public func findAll() throws -> [PatchRecord] {- [PatchRecord(- patchID: "filesystem.cryptex.merge",- component: "",- fileOffset: 0,- originalBytes: Data(),- patchedBytes: Data(),- description: "Merge the cryptex filesystems inside the OS filesystem",- )]+ Self.steps.filter { gate.isEnabled($0.identifier) }.map { step in+ PatchRecord(+ patchID: step.identifier,+ component: "",+ fileOffset: 0,+ originalBytes: Data(),+ patchedBytes: Data(),+ description: step.description,+ )+ }}+ static let steps: [(identifier: String, description: String)] = [+ (FirmwareRestoreImagePatchSet.cryptexMerge, "Merge the cryptex filesystems inside the OS filesystem"),+ (FirmwareRestoreImagePatchSet.gpuDriver, "Install the paravirtual GPU driver"),+ (FirmwareRestoreImagePatchSet.mobileActivation, "Patch mobileactivationd"),+ (FirmwareRestoreImagePatchSet.vphoned, "Install vphoned and its launch daemon"),+ (FirmwareRestoreImagePatchSet.launchdCacheLoader, "Patch launchd_cache_loader"),+ ]+@discardableResultpublic func apply() throws -> Int {print("Merging filesystems…")@@ -145,16 +158,24 @@ public final class CryptexFilesystemPatcher: BufferedPatcher {print("- Fixing dyld cache…")try addDyldSymlinks(targetMount: targetMount)- print("- Fixing GPU driver…")- try addGpuDriver(targetMount: targetMount)+ if gate.isEnabled(FirmwareRestoreImagePatchSet.gpuDriver) {+ print("- Fixing GPU driver…")+ try addGpuDriver(targetMount: targetMount)+ }- print("- Patching mobile activation…")- try patchMobileActivation(targetMount: targetMount)+ if gate.isEnabled(FirmwareRestoreImagePatchSet.mobileActivation) {+ print("- Patching mobile activation…")+ try patchMobileActivation(targetMount: targetMount)+ }- print("- Adding vphoned…")- try addVphoned(targetMount: targetMount)- try injectLaunchDaemons(targetMount: targetMount)- try patchLaunchdCacheLoader(targetMount: targetMount)+ if gate.isEnabled(FirmwareRestoreImagePatchSet.vphoned) {+ print("- Adding vphoned…")+ try addVphoned(targetMount: targetMount)+ try injectLaunchDaemons(targetMount: targetMount)+ }+ if gate.isEnabled(FirmwareRestoreImagePatchSet.launchdCacheLoader) {+ try patchLaunchdCacheLoader(targetMount: targetMount)+ }}guard attachedDevices.isEmpty else {diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/Manifest/ManifestHashPatcher.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/Manifest/ManifestHashPatcher.swiftindex 0d60cc17..441871c1 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/Manifest/ManifestHashPatcher.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/Manifest/ManifestHashPatcher.swift@@ -35,7 +35,7 @@ public final class ManifestHashPatcher: BufferedPatcher {rebuiltData = try serializePayload(newRoot)patches = [PatchRecord(- patchID: "manifest.hash",+ patchID: FirmwareRestoreImagePatchSet.digestRehash,component: "",fileOffset: 0,originalBytes: Data(),diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwarePatchSetCatalog.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwarePatchSetCatalog.swiftindex fbf6d95e..451b8ba2 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwarePatchSetCatalog.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwarePatchSetCatalog.swift@@ -20,15 +20,21 @@ public enum FirmwarePatchSetCatalog {FirmwareGuestSystemPatchSet.manifest,FirmwareGuestDisplayPatchSet.manifest,FirmwareGuestIdentityPatchSet.manifest,+ FirmwareRestoreImagePatchSet.manifest,]- /// Every bundled set, as a preset references them.+ /// Every bundled set but the restore image, as a preset references them.///- /// Both shipped presets name all of them. A preset picks patches with its- /// selection, not by leaving a set out, so the editor always sees the whole+ /// Every custom-firmware preset names all of them. A preset picks patches with+ /// its selection, not by leaving a set out, so the editor always sees the whole/// catalogue and can turn any patch on or off.+ ///+ /// The restore image is the exception, in both directions: it customises the+ /// system before the restore, which the custom-firmware sets do after it, and+ /// only ``minimalPreset`` names it. See ``FirmwareRestoreImagePatchSet``.public static let bundledReferences: [VPhonePatchSetReference] =- bundled.map { .bundled($0.identifier) }+ bundled.filter { $0.identifier != FirmwareRestoreImagePatchSet.identifier }+ .map { .bundled($0.identifier) }public static func manifest(identifier: String) -> VPhonePatchSetManifest? {bundled.first { $0.identifier == identifier }@@ -303,6 +309,57 @@ public enum FirmwarePatchSetCatalog {),)+ /// The device tree patches ``minimalPreset`` keeps: the board presentation the+ /// guest UI lays out against, and the haptics and microphone array no VM+ /// has. They change no code, so they are no system modification.+ public static let minimalDeviceTreePatches: Set<String> = [+ "devicetree-cfw-serial_number",+ "devicetree-cfw-home_button_type",+ "devicetree-cfw-artwork_device_subtype",+ "devicetree-cfw-island_notch_location",+ "devicetree-cfw-product_haptics_node",+ "devicetree-cfw-product_audio_microphone_array",+ ]++ /// The boot chain patches ``minimalPreset`` keeps: iBEC's and LLB's, which the+ /// old `.less` variant applied too. A stock LLB does not get the restored+ /// guest to its kernel (it restarts after its banner, with Apple's ROMs as+ /// with OpenAVB and OpenSEP). AVPBooter, iBSS, TXM and the restore ramdisk+ /// stay stock.+ public static let minimalBootChainPatches: Set<String> = [+ "ibec-cfw-serial_label",+ "ibec-boot-image4_callback",+ "ibec-boot-boot_args",+ "ibec-boot-bootx_precondition",+ "llb-cfw-serial_label",+ "llb-boot-image4_callback",+ "llb-boot-boot_args",+ "llb-boot-rootfs",+ "llb-boot-panic_bypass",+ "llb-cfw-display_scale",+ ]++ /// A guest on a stock kernel and TXM, with only iBEC and LLB patched: the+ /// system is customised before the restore instead+ /// (``FirmwareRestoreImagePatchSet``), and nothing after it. Names only the+ /// sets it draws on, so no kernel or guest patcher is built.+ /// The shipped `minimal.plist` must match this.+ public static let minimalPreset = VPhonePatchPreset(+ identifier: VPhonePatchPreset.minimalIdentifier,+ title: "Minimal",+ summary: "No kernel or TXM patches and only iBEC and LLB in the boot chain: the restore installs a resealed system with vphoned, the GPU driver and activation, and nothing writes it afterwards.",+ patchSets: [+ .bundled(FirmwareBootChainPatchSet.identifier),+ .bundled(FirmwareDeviceTreePatchSet.identifier),+ .bundled(FirmwareRestoreImagePatchSet.identifier),+ ],+ selection: .allow(+ minimalBootChainPatches+ .union(minimalDeviceTreePatches)+ .union(FirmwareRestoreImagePatchSet.manifest.patches.map(\.identifier)),+ ),+ )+/// The presets the bundle ships.- public static let builtInPresets: [VPhonePatchPreset] = [standardPreset, experimentalPreset, tvOSPreset, tvOS4KPreset]+ public static let builtInPresets: [VPhonePatchPreset] = [standardPreset, experimentalPreset, tvOSPreset, tvOS4KPreset, minimalPreset]}diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareRestoreImagePatchSet.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareRestoreImagePatchSet.swiftnew file mode 100644index 00000000..17ce738e--- /dev/null+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareRestoreImagePatchSet.swift@@ -0,0 +1,80 @@+// FirmwareRestoreImagePatchSet.swift — Manifest for the customised restore image.+//+// The patchless way to a guest: instead of patching the boot chain and kernel to+// accept a modified system, the restore installs one whose digests the boot chain+// already accepts. `fw patch` merges the AppOS and SystemOS cryptexes into the OS+// image, adds what the guest needs to run (GPU driver, activation, vphoned), seals+// the result again, and rehashes every component in the BuildManifest. The boot+// chain, kernel and TXM stay stock, and nothing writes the System volume after the+// restore, because that would break the seal.+//+// Only the `minimal` preset names this set. Every patch in it is boot-essential for+// that preset, and naming it nowhere else keeps `standard` from counting them as+// dropped.++import Foundation+import VPhonePatchKit++public enum FirmwareRestoreImagePatchSet {+ public static let identifier = "com.vphone.patchset.restore.image"++ /// The merge and reseal of the OS image. Every other filesystem patch writes+ /// into the merged image, so they run only with it.+ public static let cryptexMerge = "filesystem-boot-cryptex_merge"+ public static let gpuDriver = "filesystem-boot-gpu_driver"+ public static let mobileActivation = "filesystem-boot-mobileactivationd_should_hactivate"+ public static let vphoned = "filesystem-boot-vphoned"+ public static let launchdCacheLoader = "filesystem-boot-launchd_cache_loader_unsecure_cache_gate"+ public static let digestRehash = "manifest-boot-digest_rehash"++ private static func filesystem(_ identifier: String, _ title: String, _ summary: String) -> VPhonePatchDeclaration {+ VPhonePatchDeclaration(+ identifier: identifier,+ title: title,+ summary: summary,+ target: .firmware(.filesystem),+ bootEssential: true,+ )+ }++ public static let manifest = VPhonePatchSetManifest(+ identifier: identifier,+ name: "Restore Image",+ summary: "A pre-customised, resealed system image restored onto a stock boot chain",+ patches: [+ filesystem(+ cryptexMerge,+ "Cryptex merge",+ "Merges the AppOS and SystemOS cryptexes into the OS image and seals it again, so the stock boot chain mounts a system it has digests for.",+ ),+ filesystem(+ gpuDriver,+ "GPU driver",+ "Installs the paravirtual GPU driver from the cloudOS into the merged image.",+ ),+ filesystem(+ mobileActivation,+ "Activation",+ "Lets mobileactivationd activate the guest without Apple's activation servers.",+ ),+ filesystem(+ vphoned,+ "vphoned",+ "Installs the guest daemon and its launch daemon, which the host talks to.",+ ),+ filesystem(+ launchdCacheLoader,+ "Launch daemon cache",+ "Lets launchd load the launch daemons from the system volume instead of the signed cache, so vphoned starts.",+ ),+ VPhonePatchDeclaration(+ identifier: digestRehash,+ title: "Manifest digests",+ summary: "Rewrites the BuildManifest digests to match the merged image, its trust cache and seal.",+ target: .firmware(.manifest),+ bootEssential: true,+ ),+ ],+ provides: ["vphone.restore.image"],+ )+}diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/Pipeline/FirmwarePipeline.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/Pipeline/FirmwarePipeline.swiftindex 2ef7d6d5..77288f97 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/Pipeline/FirmwarePipeline.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/Pipeline/FirmwarePipeline.swift@@ -33,7 +33,6 @@ public final class FirmwarePipeline {// MARK: - Variantpublic enum Variant: String, Sendable {- case lesscase regularcase devcase jb@@ -85,7 +84,7 @@ public final class FirmwarePipeline {/// Whether the pipeline keeps this component's untouched bytes aside and/// re-patches those on every run — see FirmwarePipelineOriginals.swift.///- /// False for the two `.less` components, and only for them. `Filesystem`+ /// False for the two restore image components, and only for them. `Filesystem`/// and `Manifest` both name `BuildManifest.plist`, but neither is a patcher/// over that one file: `CryptexFilesystemPatcher` rewrites cryptex images/// across the restore tree, and `ManifestHashPatcher` rewrites hashes to@@ -235,7 +234,7 @@ public final class FirmwarePipeline {let sealPatch = RestoreRamDiskSealPatcher.patchIdentifierlet sealSelected = plan?.isEnabled(sealPatch)?? (iOSBase?.major == 27 && cloudOS?.major == 26 && cloudOS?.minor == 4)- guard variant != .less, sealSelected else { return }+ guard sealSelected else { return }let hashType = try RestoreRamDiskSealPatcher.systemVolumeHashType(in: restoreDir)if hashType == RestoreRamDiskSealPatcher.sha256Type {notApplicablePatches.insert(sealPatch)@@ -303,12 +302,11 @@ public final class FirmwarePipeline {for component in components {let baseDir = component.inRestoreDir ? restoreDir : vmDirectory- // `.less` never touches the boot chain: it runs the two whole-tree- // patchers and leaves every other component with no factories at all.- // Keeping it out of this entirely is what stops a `.less` run over an- // already patched VM reading "no patches here" as "put the unpatched- // boot chain back".- let keepsOriginal = variant != .less && component.restorable+ // A plan without the boot chain, kernel and TXM sets (the `minimal`+ // preset) leaves those components with no factories, and the pass+ // below puts back what an earlier preset patched: a stock boot chain+ // is what the restore image patches expect.+ let keepsOriginal = component.restorableguard !component.patcherFactories.isEmpty else {log(" [=] \(component.name): no patches for \(variant.rawValue)")diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/Pipeline/FirmwarePipelineComponents.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/Pipeline/FirmwarePipelineComponents.swiftindex 41564dba..a1cbe9c1 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/Pipeline/FirmwarePipelineComponents.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/Pipeline/FirmwarePipelineComponents.swift@@ -44,6 +44,16 @@ extension FirmwarePipeline {}let includeBootChain = includesSet(FirmwareBootChainPatchSet.identifier)++ // Whether the plan turns on any patch for a boot chain component. A+ // preset that keeps the set for some components only (`minimal`: iBEC and+ // LLB) leaves the others stock, and a patcher built to write nothing+ // would only log that it found nothing.+ func patchesBootChain(_ component: VPhoneFirmwareComponent) -> Bool {+ guard includeBootChain else { return false }+ guard let plan else { return true }+ return plan.declarations.contains { $0.target == .firmware(component) && plan.isEnabled($0.identifier) }+ }let includeKernelBase = includesSet(FirmwareKernelBasePatchSet.identifier)let includeKernelCustomFirmware = includesSet(FirmwareKernelCustomFirmwarePatchSet.identifier)let includeDeviceTree = includesSet(FirmwareDeviceTreePatchSet.identifier)@@ -106,8 +116,8 @@ extension FirmwarePipeline {// mDNSResponder → no DNS). Empty on 26.x bases (stock boot-args).let extraBootArgs = baseIs18 ? "if_attach_nx=0x3" : ""- // 1. AVPBooter — Apple's ROM, in the VM root. Patched for every non-less- // variant (regular/dev/jb/exp). A machine booting OpenAVB has nothing+ // 1. AVPBooter — Apple's ROM, in the VM root. Patched when the plan keeps+ // the boot chain set. A machine booting OpenAVB has nothing// here to patch: OpenAVB checks no image digest, so the digest// bypass the plan selects already holds, and an Apple ROM kept in// the folder beside it is not the one that boots.@@ -117,7 +127,7 @@ extension FirmwarePipeline {inRestoreDir: false,searchPatterns: ["AVPBooter*.bin"],patcherFactories: {- if variant != .less, includeBootChain {+ if patchesBootChain(.avpBooter) {return [{ data, verbose inlet p = AVPBooterPatcher(data: data, verbose: verbose)@@ -138,16 +148,14 @@ extension FirmwarePipeline {searchPatterns: ["Firmware/dfu/iBSS.vresearch101.RELEASE.im4p"],patcherFactories: {switch variant {- case .less:- []case .regular, .dev:- includeBootChain ? [{ data, verbose in+ patchesBootChain(.iBSS) ? [{ data, verbose inlet p = IBootPatcher(data: data, mode: .ibss, verbose: verbose)p.gate = gatereturn p}] : []case .jb, .exp:- includeBootChain ? [+ patchesBootChain(.iBSS) ? [{ data, verbose inlet p = IBootPatcher(data: data, mode: .ibss, verbose: verbose)p.gate = gate@@ -163,12 +171,12 @@ extension FirmwarePipeline {}(),))- // 3. iBEC - Not required by the less variant, still added for the serial logs.+ // 3. iBECcomponents.append(ComponentDescriptor(name: "iBEC",inRestoreDir: true,searchPatterns: ["Firmware/dfu/iBEC.vresearch101.RELEASE.im4p"],- patcherFactories: includeBootChain ? [{ data, verbose in+ patcherFactories: patchesBootChain(.iBEC) ? [{ data, verbose inlet p = IBootPatcher(data: data, mode: .ibec, verbose: verbose)p.extraBootArgs = extraBootArgsp.gate = gate@@ -176,12 +184,12 @@ extension FirmwarePipeline {}] : [],))- // 4. LLB - Not required by the less variant, still added for the serial logs.+ // 4. LLBcomponents.append(ComponentDescriptor(name: "LLB",inRestoreDir: true,searchPatterns: ["Firmware/all_flash/LLB.vresearch101.RELEASE.im4p"],- patcherFactories: includeBootChain ? [{ data, verbose in+ patcherFactories: patchesBootChain(.llb) ? [{ data, verbose inlet p = IBootPatcher(data: data, mode: .llb, verbose: verbose)p.extraBootArgs = extraBootArgs// The boot video word always says 3x, which is already right@@ -199,16 +207,14 @@ extension FirmwarePipeline {searchPatterns: ["Firmware/txm.iphoneos.research.im4p"],patcherFactories: {switch variant {- case .less:- []case .regular:- includeBootChain ? [{ data, verbose in+ patchesBootChain(.txm) ? [{ data, verbose inlet p = TXMPatcher(data: data, verbose: verbose)p.gate = gatereturn p}] : []case .dev, .jb, .exp:- includeBootChain ? [{ data, verbose in+ patchesBootChain(.txm) ? [{ data, verbose inlet p = TXMDevPatcher(data: data, verbose: verbose)p.gate = gatereturn p@@ -219,8 +225,7 @@ extension FirmwarePipeline {// 6. Restore ramdisk and trust cachelet sealPatch = RestoreRamDiskSealPatcher.patchIdentifier- let includeSealPatch = variant != .less- && includeBootChain+ let includeSealPatch = includeBootChain&& isEnabled(sealPatch, fallback: baseIs27 && cloudIs264)&& !notApplicablePatches.contains(sealPatch)let manifestURL = restoreDir.appendingPathComponent("BuildManifest.plist")@@ -271,8 +276,6 @@ extension FirmwarePipeline {searchPatterns: ["kernelcache.research.vphone600"],patcherFactories: {switch variant {- case .less:- []case .regular:includeKernelBase ? [{ data, verbose inlet p = KernelPatcher(@@ -354,49 +357,44 @@ extension FirmwarePipeline {))}- // 9. Filesystem+ // 9. Filesystem — the restore image (`minimal` preset): the merged, resealed+ // OS image the restore installs instead of a patched boot chain.// Not restorable: it reads BuildManifest.plist but writes cryptex images// all over the restore tree, so putting the manifest back on its own// would describe a tree that no longer exists. See ComponentDescriptor.+ let includeRestoreImage = includesSet(FirmwareRestoreImagePatchSet.identifier)+ let applyCryptexMerge = includeRestoreImage+ && isEnabled(FirmwareRestoreImagePatchSet.cryptexMerge, fallback: false)components.append(ComponentDescriptor(name: "Filesystem",inRestoreDir: true,searchPatterns: ["BuildManifest.plist"],- patcherFactories: {- switch variant {- case .less:- [{ data, verbose in- CryptexFilesystemPatcher(- buildManiest: data,- restoreDir: restoreDir,- verbose: verbose,- noBinpack: self.noBinpack,- )- }]- case .regular, .dev, .jb, .exp:- []- }- }(),+ patcherFactories: applyCryptexMerge ? [{ data, verbose in+ let p = CryptexFilesystemPatcher(+ buildManiest: data,+ restoreDir: restoreDir,+ verbose: verbose,+ noBinpack: self.noBinpack,+ )+ p.gate = gate+ return p+ }] : [],restorable: false,))- // 10. Firmware Manifest - Only required when excluding the img4 signature patches.+ // 10. Firmware Manifest — the digests of whatever the restore image changed,+ // so the stock boot chain accepts it.// Not restorable, for the same reason as Filesystem: the hashes it writes// describe files other steps produced, not the manifest's own bytes.+ let applyDigestRehash = includeRestoreImage+ && isEnabled(FirmwareRestoreImagePatchSet.digestRehash, fallback: false)components.append(ComponentDescriptor(name: "Manifest",inRestoreDir: true,searchPatterns: ["BuildManifest.plist"],- patcherFactories: {- switch variant {- case .less:- [{ data, verbose in- ManifestHashPatcher(data: data, restoreDir: restoreDir, verbose: verbose)- }]- case .regular, .dev, .jb, .exp:- []- }- }(),+ patcherFactories: applyDigestRehash ? [{ data, verbose in+ ManifestHashPatcher(data: data, restoreDir: restoreDir, verbose: verbose)+ }] : [],restorable: false,))diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/Core/FirmwarePatcherTests.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/Core/FirmwarePatcherTests.swiftindex 4827b32d..7381adbe 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/Core/FirmwarePatcherTests.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/Core/FirmwarePatcherTests.swift@@ -629,6 +629,29 @@ struct FirmwarePipelineTests {#expect(components.first { $0.name == "Manifest" }?.patcherFactories.isEmpty == true)}+ @Test func `the minimal preset builds no kernel or TXM patcher`() throws {+ let root = URL(fileURLWithPath: NSTemporaryDirectory())+ func patched(_ preset: VPhonePatchPreset) throws -> [String] {+ let plan = try VPhonePatchPlan.resolve(+ preset: preset,+ patchSets: FirmwarePatchSetCatalog.bundled,+ iOSBase: VPhoneVersion("26.4"),+ cloudOS: VPhoneVersion("26.4"),+ )+ let pipeline = FirmwarePipeline(vmDirectory: root, variant: .jb, verbose: false)+ return try pipeline.buildComponentList(restoreDir: root, iOSBase: VPhoneVersion("26.4"), plan: plan)+ .filter { !$0.patcherFactories.isEmpty }+ .map(\.name)+ }+ let minimal = try patched(FirmwarePatchSetCatalog.minimalPreset)+ #expect(!minimal.contains("kernelcache"))+ #expect(!minimal.contains("TXM"))+ #expect(Set(["iBEC", "LLB", "DeviceTree", "Filesystem", "Manifest"]).isSubset(of: Set(minimal)))+ let standard = try patched(FirmwarePatchSetCatalog.standardPreset)+ #expect(!standard.contains("Filesystem"))+ #expect(!standard.contains("Manifest"))+ }+@Test func `standard turns the paravirtual user-client allowlist on before 27`() throws {// The flag the kernel CFW patcher is built with, from the standard plan and// from the no-plan fallback, which has to give the same answer.diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/PatchSets/FirmwarePatchSetCatalogTests.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/PatchSets/FirmwarePatchSetCatalogTests.swiftindex 33d94a98..6bccc0e4 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/PatchSets/FirmwarePatchSetCatalogTests.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/PatchSets/FirmwarePatchSetCatalogTests.swift@@ -136,9 +136,18 @@ struct FirmwarePatchSetCatalogTests {// patch: these are the combinations we claim boot. The tvOS// presets drop exactly the iOS ones an Apple TV has no port of.let tvPresets = [VPhonePatchPreset.tvOSIdentifier, VPhonePatchPreset.tvOS4KIdentifier]- let expected = tvPresets.contains(preset.identifier)- ? Set(plan.droppedBootEssentials).isSubset(of: FirmwarePatchSetCatalog.tvOSBlockedPatches)- : plan.droppedBootEssentials.isEmpty+ // `minimal` drops every boot chain patch but iBEC's and LLB's:+ // its system is customised before the restore instead.+ let expected = if tvPresets.contains(preset.identifier) {+ Set(plan.droppedBootEssentials).isSubset(of: FirmwarePatchSetCatalog.tvOSBlockedPatches)+ } else if preset.identifier == VPhonePatchPreset.minimalIdentifier {+ Set(plan.droppedBootEssentials).isDisjoint(with: FirmwarePatchSetCatalog.minimalBootChainPatches)+ && plan.droppedBootEssentials.allSatisfy {+ FirmwareBootChainPatchSet.manifest.patches.map(\.identifier).contains($0)+ }+ } else {+ plan.droppedBootEssentials.isEmpty+ }#expect(expected,"\(preset.identifier) on \(base)/\(cloud) drops \(plan.droppedBootEssentials)",@@ -162,6 +171,24 @@ struct FirmwarePatchSetCatalogTests {#expect(!plan.skippedByVersion.isEmpty)}+ @Test+ func `Only minimal names the restore image, and patches only iBEC, LLB and the device tree besides`() throws {+ for preset in FirmwarePatchSetCatalog.builtInPresets {+ let namesRestoreImage = preset.patchSets.map(\.identifier).contains(FirmwareRestoreImagePatchSet.identifier)+ #expect(namesRestoreImage == (preset.identifier == VPhonePatchPreset.minimalIdentifier), "\(preset.identifier)")+ }+ let plan = try VPhonePatchPlan.resolve(+ preset: FirmwarePatchSetCatalog.minimalPreset,+ patchSets: FirmwarePatchSetCatalog.bundled,+ iOSBase: VPhoneVersion("26.4"),+ cloudOS: VPhoneVersion("26.4"),+ )+ let restoreImage = Set(FirmwareRestoreImagePatchSet.manifest.patches.map(\.identifier))+ let bootChain = FirmwarePatchSetCatalog.minimalBootChainPatches+ #expect(plan.enabled == restoreImage.union(FirmwarePatchSetCatalog.minimalDeviceTreePatches).union(bootChain))+ #expect(plan.droppedBootEssentials.allSatisfy { !$0.hasPrefix("ibec-") && !$0.hasPrefix("llb-") })+ }+@Testfunc `Standard leaves every manual-only patch off, on every base`() throws {for base in ["18.6.2", "26.4", "27.0"] {diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/Pipeline/FirmwarePipelineOriginalsTests.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/Pipeline/FirmwarePipelineOriginalsTests.swiftindex 89f80cd9..6bee0d25 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/Pipeline/FirmwarePipelineOriginalsTests.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/Pipeline/FirmwarePipelineOriginalsTests.swift@@ -192,25 +192,6 @@ struct FirmwarePipelineOriginalsTests {#expect(vm.componentBytes == Data([0xAA, 0x11, 0x22]))}- @Test func `a less run leaves an already patched boot chain alone`() throws {- let vm = try FakeVM()- defer { vm.remove() }-- _ = try vm.pipeline().patchComponents([vm.descriptor()], restoreDir: vm.restoreDir, plan: nil)- #expect(vm.componentBytes == Data([0xAA, 0x11, 0x22]))-- // `.less` gives every boot-chain component an empty factory list. That must- // not read as "these patches are off, put the firmware back".- let less = FirmwarePipeline(- vmDirectory: vm.root,- variant: .less,- verbose: false,- loader: RawFirmwareLoader(),- )- _ = try less.patchComponents([vm.descriptor(patched: false)], restoreDir: vm.restoreDir, plan: nil)- #expect(vm.componentBytes == Data([0xAA, 0x11, 0x22]))- }-@Test func `the stash never claims a file outside the VM directory or itself`() throws {let vm = try FakeVM()defer { vm.remove() }@@ -224,7 +205,7 @@ struct FirmwarePipelineOriginalsTests {@Test func `only the two whole-tree components opt out of keeping an original`() throws {let root = URL(fileURLWithPath: NSTemporaryDirectory())- let pipeline = FirmwarePipeline(vmDirectory: root, variant: .less, verbose: false)+ let pipeline = FirmwarePipeline(vmDirectory: root, variant: .jb, verbose: false)let components = try pipeline.buildComponentList(restoreDir: root, iOSBase: VPhoneVersion("26.6.2"))let notRestorable = components.filter { !$0.restorable }.map(\.name).sorted()diff --git a/VPhoneExecutable/VPhoneCommand/VPhonePatchKit/PatchSet/VPhonePatchPreset.swift b/VPhoneExecutable/VPhoneCommand/VPhonePatchKit/PatchSet/VPhonePatchPreset.swiftindex 2b1a627d..96ffc1c3 100644--- a/VPhoneExecutable/VPhoneCommand/VPhonePatchKit/PatchSet/VPhonePatchPreset.swift+++ b/VPhoneExecutable/VPhoneCommand/VPhonePatchKit/PatchSet/VPhonePatchPreset.swift@@ -78,6 +78,10 @@ public struct VPhonePatchPreset: Sendable, Hashable, Codable, Identifiable {/// preset: standard without the iOS payloads tvOS has no port of.public static let tvOSIdentifier = "tvos"+ /// The identifier of the preset that patches no boot chain, kernel or TXM and+ /// customises the system before the restore instead.+ public static let minimalIdentifier = "minimal"+/// The preset an Apple TV 4K guest gets: the TV preset for an arm64e/// userland taken from the device's OTA.public static let tvOS4KIdentifier = "tvos-4k"diff --git a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/minimal.plist b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/minimal.plistnew file mode 100644index 00000000..bb848486--- /dev/null+++ b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/minimal.plist@@ -0,0 +1,63 @@+<?xml version="1.0" encoding="UTF-8"?>+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">+<plist version="1.0">+<dict>+ <key>Identifier</key>+ <string>minimal</string>+ <key>PatchSets</key>+ <array>+ <dict>+ <key>Identifier</key>+ <string>com.vphone.patchset.bootchain</string>+ <key>Kind</key>+ <string>Bundled</string>+ </dict>+ <dict>+ <key>Identifier</key>+ <string>com.vphone.patchset.devicetree</string>+ <key>Kind</key>+ <string>Bundled</string>+ </dict>+ <dict>+ <key>Identifier</key>+ <string>com.vphone.patchset.restore.image</string>+ <key>Kind</key>+ <string>Bundled</string>+ </dict>+ </array>+ <key>Selection</key>+ <dict>+ <key>Kind</key>+ <string>Allow</string>+ <key>Patches</key>+ <array>+ <string>devicetree-cfw-artwork_device_subtype</string>+ <string>devicetree-cfw-home_button_type</string>+ <string>devicetree-cfw-island_notch_location</string>+ <string>devicetree-cfw-product_audio_microphone_array</string>+ <string>devicetree-cfw-product_haptics_node</string>+ <string>devicetree-cfw-serial_number</string>+ <string>filesystem-boot-cryptex_merge</string>+ <string>filesystem-boot-gpu_driver</string>+ <string>filesystem-boot-launchd_cache_loader_unsecure_cache_gate</string>+ <string>filesystem-boot-mobileactivationd_should_hactivate</string>+ <string>filesystem-boot-vphoned</string>+ <string>ibec-boot-boot_args</string>+ <string>ibec-boot-bootx_precondition</string>+ <string>ibec-boot-image4_callback</string>+ <string>ibec-cfw-serial_label</string>+ <string>llb-boot-boot_args</string>+ <string>llb-boot-image4_callback</string>+ <string>llb-boot-panic_bypass</string>+ <string>llb-boot-rootfs</string>+ <string>llb-cfw-display_scale</string>+ <string>llb-cfw-serial_label</string>+ <string>manifest-boot-digest_rehash</string>+ </array>+ </dict>+ <key>Summary</key>+ <string>No kernel or TXM patches and only iBEC and LLB in the boot chain: the restore installs a resealed system with vphoned, the GPU driver and activation, and nothing writes it afterwards.</string>+ <key>Title</key>+ <string>Minimal</string>+</dict>+</plist>