Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Edit an existing machine's patches in Launchpad

Jackya40872995bb8
diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadPreview.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadPreview.swift
index bf992041..581f2fa9 100644
--- a/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadPreview.swift
+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Application/VPhoneLaunchpadPreview.swift
@@ -119,6 +119,13 @@
VPhoneLaunchpadPatchSettingsView(initial: VPhoneLaunchpadPatchSelection()) { _ in }
.environment(model)
}
+ await standalone("09c-patch-settings-machine", suffix, size: NSSize(width: 920, height: 680)) {
+ VPhoneLaunchpadPatchSettingsView(
+ initial: patchCatalog(preset: nil, machine: true)?.selection ?? VPhoneLaunchpadPatchSelection(),
+ machine: labMachine,
+ ) { _ in }
+ .environment(model)
+ }
await sheet(.clone(labMachine), "10-clone", suffix)
await sheet(.export([labMachine]), "11-export", suffix)
await sheet(.console(path("research-01")), "12-console", suffix)
@@ -307,24 +314,32 @@
)
/// Stands in for `fw patches --json`. `preset` moves the Frida patches in
- /// and out of the preset, as the real report does.
- static func patchCatalog(preset: String?) -> VPhoneLaunchpadPatchCatalog? {
+ /// and out of the preset, as the real report does. For a machine it adds
+ /// what a bundle reports about one: two boxes turned off since the guest
+ /// was built, one in the guest and one in the boot chain, both pending.
+ static func patchCatalog(preset: String?, machine: Bool = false) -> VPhoneLaunchpadPatchCatalog? {
let active = preset ?? "standard"
let frida = active == "experimental"
+ let blocked = machine ? #"["kernel-cfw-debugger","dyld-cfw-camera"]"# : "[]"
+ let records = machine ? #""installed":true,"receiptRecorded":true,"pendingPatches":2,"# : ""
+ func pending(_ part: String, _ value: Bool = false) -> String {
+ machine ? #","part":"\#(part)","pending":\#(value)"# : ""
+ }
let json = """
- {"activePreset":"\(active)","blockedPatches":[],"allowedPatches":[],
+ {"activePreset":"\(active)","blockedPatches":\(blocked),"allowedPatches":[],\(records)
"presets":[
{"identifier":"standard","title":"Standard","summary":"The patches every vphone VM needs to boot custom firmware, with a working display and camera.","patchSets":[]},
{"identifier":"experimental","title":"Experimental","summary":"Every patch this bundle declares, including the Frida Stalker relaxations.","patchSets":[]}
],
"patches":[
- {"identifier":"avpbooter-boot-dgst_bypass","title":"AVPBooter digest bypass","summary":"Accepts the resealed boot images instead of the stock digests.","patchSet":"com.vphone.patchset.bootchain","patchSetName":"Boot Chain","target":"AVPBooter","applicability":"any","bootEssential":true,"inPreset":true,"enabled":true},
- {"identifier":"ibss-cfw-serial_label","title":"iBSS serial label","summary":"Tags iBSS serial output so the boot log names its stage.","patchSet":"com.vphone.patchset.bootchain","patchSetName":"Boot Chain","target":"iBSS","applicability":"any","bootEssential":false,"inPreset":true,"enabled":true},
- {"identifier":"kernel-cfw-debugger","title":"Kernel debugger gate","summary":"Lets a debugger attach to any process in the guest.","patchSet":"com.vphone.patchset.kernel.base","patchSetName":"Kernel Base","target":"Kernel","applicability":"any","bootEssential":false,"inPreset":true,"enabled":true},
- {"identifier":"kernel-boot-thread_guard_violation","title":"Thread guard violation","summary":"Stops the guard exception the older kernels raise on first boot.","patchSet":"com.vphone.patchset.kernel.base","patchSetName":"Kernel Base","target":"Kernel","applicability":"iOS 18.x","bootEssential":true,"inPreset":true,"enabled":true},
- {"identifier":"kernel-exp-frida_thread_set_state_entitlement_flag","title":"Frida thread state entitlement","summary":"Lets Stalker set thread state without the entitlement the kernel asks for.","patchSet":"com.vphone.patchset.kernel.frida","patchSetName":"Frida Stalker","target":"Kernel","applicability":"cloudOS 26.4+","bootEssential":false,"inPreset":\(frida),"enabled":\(frida)},
- {"identifier":"kernel-exp-frida_vm_map_delete_immutable_code","title":"Frida immutable code unmap","summary":"Allows Stalker to unmap the immutable code it rewrote.","patchSet":"com.vphone.patchset.kernel.frida","patchSetName":"Frida Stalker","target":"Kernel","applicability":"cloudOS 26.4+","bootEssential":false,"inPreset":\(frida),"enabled":\(frida)},
- {"identifier":"system-vphoned-boot-install","title":"Guest vphoned","summary":"Installs vphoned and its launch daemon into the guest.","patchSet":"com.vphone.patchset.guest.system","patchSetName":"Guest System","target":"Guest filesystem","applicability":"any","bootEssential":true,"inPreset":true,"enabled":true}
+ {"identifier":"avpbooter-boot-dgst_bypass","title":"AVPBooter digest bypass","summary":"Accepts the resealed boot images instead of the stock digests.","patchSet":"com.vphone.patchset.bootchain","patchSetName":"Boot Chain","target":"AVPBooter","applicability":"any","bootEssential":true,"inPreset":true,"enabled":true\(pending("AVPBooter"))},
+ {"identifier":"ibss-cfw-serial_label","title":"iBSS serial label","summary":"Tags iBSS serial output so the boot log names its stage.","patchSet":"com.vphone.patchset.bootchain","patchSetName":"Boot Chain","target":"iBSS","applicability":"any","bootEssential":false,"inPreset":true,"enabled":true\(pending("iBSS"))},
+ {"identifier":"kernel-cfw-debugger","title":"Kernel debugger gate","summary":"Lets a debugger attach to any process in the guest.","patchSet":"com.vphone.patchset.kernel.base","patchSetName":"Kernel Base","target":"kernelcache","applicability":"any","bootEssential":false,"inPreset":true,"enabled":true\(pending("kernelcache", true))},
+ {"identifier":"kernel-boot-thread_guard_violation","title":"Thread guard violation","summary":"Stops the guard exception the older kernels raise on first boot.","patchSet":"com.vphone.patchset.kernel.base","patchSetName":"Kernel Base","target":"kernelcache","applicability":"iOS 18.x","bootEssential":true,"inPreset":true,"enabled":true\(pending("kernelcache"))},
+ {"identifier":"kernel-exp-frida_thread_set_state_entitlement_flag","title":"Frida thread state entitlement","summary":"Lets Stalker set thread state without the entitlement the kernel asks for.","patchSet":"com.vphone.patchset.kernel.frida","patchSetName":"Frida Stalker","target":"kernelcache","applicability":"cloudOS 26.4+","bootEssential":false,"inPreset":\(frida),"enabled":\(frida)\(pending("kernelcache"))},
+ {"identifier":"kernel-exp-frida_vm_map_delete_immutable_code","title":"Frida immutable code unmap","summary":"Allows Stalker to unmap the immutable code it rewrote.","patchSet":"com.vphone.patchset.kernel.frida","patchSetName":"Frida Stalker","target":"kernelcache","applicability":"cloudOS 26.4+","bootEssential":false,"inPreset":\(frida),"enabled":\(frida)\(pending("kernelcache"))},
+ {"identifier":"system-vphoned-boot-install","title":"Guest vphoned","summary":"Installs vphoned and its launch daemon into the guest.","patchSet":"com.vphone.patchset.guest.system","patchSetName":"Guest System","target":"Guest filesystem","applicability":"any","bootEssential":true,"inPreset":true,"enabled":true\(pending("Guest"))},
+ {"identifier":"dyld-cfw-camera","title":"Camera in the shared cache","summary":"Points the camera stack at the virtual camera.","patchSet":"com.vphone.patchset.guest.system","patchSetName":"Guest System","target":"dyld shared cache","applicability":"any","bootEssential":false,"inPreset":true,"enabled":true\(pending("Guest", true))}
]}
"""
return try? JSONDecoder().decode(VPhoneLaunchpadPatchCatalog.self, from: Data(json.utf8))
diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Localizable.xcstrings b/VPhoneLaunchpad/VPhoneLaunchpad/Localizable.xcstrings
index 21d7bc9b..80c141fd 100644
--- a/VPhoneLaunchpad/VPhoneLaunchpad/Localizable.xcstrings
+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Localizable.xcstrings
@@ -13170,15 +13170,97 @@
"zh-Hans" : { "stringUnit" : { "state" : "translated", "value" : "客户机已包含为此虚拟机设定的全部补丁。" } }
}
},
- "The patch choice changed after the guest was built. Run vphone-cli fw patches %@ to see each patch and the step that applies it." : {
+ "Apply to Guest" : {
"localizations" : {
- "en" : { "stringUnit" : { "state" : "translated", "value" : "The patch choice changed after the guest was built. Run vphone-cli fw patches %@ to see each patch and the step that applies it." } },
- "ja" : { "stringUnit" : { "state" : "translated", "value" : "ゲストの構築後にパッチの選択が変更されました。各パッチと適用手順を確認するには、vphone-cli fw patches %@ を実行してください。" } },
- "ko" : { "stringUnit" : { "state" : "translated", "value" : "게스트를 빌드한 뒤 패치 선택이 바뀌었습니다. 각 패치와 적용 단계를 보려면 vphone-cli fw patches %@ 를 실행하십시오." } },
- "vi" : { "stringUnit" : { "state" : "translated", "value" : "Lựa chọn bản vá đã thay đổi sau khi máy khách được dựng. Hãy chạy vphone-cli fw patches %@ để xem từng bản vá và bước áp dụng nó." } },
- "zh-Hans" : { "stringUnit" : { "state" : "translated", "value" : "客户机构建后补丁选择已更改。运行 vphone-cli fw patches %@ 查看每个补丁及应用它的步骤。" } }
+ "en" : { "stringUnit" : { "state" : "translated", "value" : "Apply to Guest" } },
+ "ja" : { "stringUnit" : { "state" : "translated", "value" : "ゲストに適用" } },
+ "ko" : { "stringUnit" : { "state" : "translated", "value" : "게스트에 적용" } },
+ "vi" : { "stringUnit" : { "state" : "translated", "value" : "Áp dụng cho máy khách" } },
+ "zh-Hans" : { "stringUnit" : { "state" : "translated", "value" : "应用到客户机" } }
}
},
+ "Updates the guest environment, which turns guest patches on or off to match this machine’s choice." : {
+ "localizations" : {
+ "en" : { "stringUnit" : { "state" : "translated", "value" : "Updates the guest environment, which turns guest patches on or off to match this machine’s choice." } },
+ "ja" : { "stringUnit" : { "state" : "translated", "value" : "ゲスト環境を更新し、このマシンの選択に合わせてゲストのパッチをオン/オフします。" } },
+ "ko" : { "stringUnit" : { "state" : "translated", "value" : "게스트 환경을 업데이트하여 이 머신의 선택에 맞게 게스트 패치를 켜거나 끕니다." } },
+ "vi" : { "stringUnit" : { "state" : "translated", "value" : "Cập nhật môi trường máy khách, bật hoặc tắt các bản vá máy khách cho khớp với lựa chọn của máy này." } },
+ "zh-Hans" : { "stringUnit" : { "state" : "translated", "value" : "更新客户机环境,按此虚拟机的选择打开或关闭客户机补丁。" } }
+ }
+ },
+ "Stop the machine to apply its patch choice to the guest." : {
+ "localizations" : {
+ "en" : { "stringUnit" : { "state" : "translated", "value" : "Stop the machine to apply its patch choice to the guest." } },
+ "ja" : { "stringUnit" : { "state" : "translated", "value" : "パッチの選択をゲストに適用するには、マシンを停止してください。" } },
+ "ko" : { "stringUnit" : { "state" : "translated", "value" : "패치 선택을 게스트에 적용하려면 머신을 중지하십시오." } },
+ "vi" : { "stringUnit" : { "state" : "translated", "value" : "Hãy dừng máy để áp dụng lựa chọn bản vá cho máy khách." } },
+ "zh-Hans" : { "stringUnit" : { "state" : "translated", "value" : "停止虚拟机后才能把补丁选择应用到客户机。" } }
+ }
+ },
+ "^[%lld guest patch](inflect: true) to apply with Apply to Guest." : {
+ "localizations" : {
+ "en" : { "stringUnit" : { "state" : "translated", "value" : "^[%lld guest patch](inflect: true) to apply with Apply to Guest." } },
+ "ja" : { "stringUnit" : { "state" : "translated", "value" : "「ゲストに適用」で反映するゲストのパッチ:%lld 件。" } },
+ "ko" : { "stringUnit" : { "state" : "translated", "value" : "‘게스트에 적용’으로 반영할 게스트 패치 %lld개." } },
+ "vi" : { "stringUnit" : { "state" : "translated", "value" : "%lld bản vá máy khách sẽ được áp dụng bằng “Áp dụng cho máy khách”." } },
+ "zh-Hans" : { "stringUnit" : { "state" : "translated", "value" : "%lld 个客户机补丁可用“应用到客户机”生效。" } }
+ }
+ },
+ "^[%lld boot chain patch](inflect: true) that only a restore applies." : {
+ "localizations" : {
+ "en" : { "stringUnit" : { "state" : "translated", "value" : "^[%lld boot chain patch](inflect: true) that only a restore applies." } },
+ "ja" : { "stringUnit" : { "state" : "translated", "value" : "復元でのみ反映される起動チェーンのパッチ:%lld 件。" } },
+ "ko" : { "stringUnit" : { "state" : "translated", "value" : "복원으로만 반영되는 부트 체인 패치 %lld개." } },
+ "vi" : { "stringUnit" : { "state" : "translated", "value" : "%lld bản vá chuỗi khởi động chỉ được áp dụng khi khôi phục." } },
+ "zh-Hans" : { "stringUnit" : { "state" : "translated", "value" : "%lld 个启动链补丁只有重新恢复才会生效。" } }
+ }
+ },
+ "vphone-cli fw patches %@ lists each one." : {
+ "localizations" : {
+ "en" : { "stringUnit" : { "state" : "translated", "value" : "vphone-cli fw patches %@ lists each one." } },
+ "ja" : { "stringUnit" : { "state" : "translated", "value" : "各パッチは vphone-cli fw patches %@ で確認できます。" } },
+ "ko" : { "stringUnit" : { "state" : "translated", "value" : "각 패치는 vphone-cli fw patches %@ 로 확인할 수 있습니다." } },
+ "vi" : { "stringUnit" : { "state" : "translated", "value" : "vphone-cli fw patches %@ liệt kê từng bản vá." } },
+ "zh-Hans" : { "stringUnit" : { "state" : "translated", "value" : "运行 vphone-cli fw patches %@ 可逐个查看。" } }
+ }
+ },
+ "No change" : {
+ "localizations" : {
+ "en" : { "stringUnit" : { "state" : "translated", "value" : "No change" } },
+ "ja" : { "stringUnit" : { "state" : "translated", "value" : "変更なし" } },
+ "ko" : { "stringUnit" : { "state" : "translated", "value" : "변경 없음" } },
+ "vi" : { "stringUnit" : { "state" : "translated", "value" : "Không thay đổi" } },
+ "zh-Hans" : { "stringUnit" : { "state" : "translated", "value" : "无更改" } }
+ }
+ },
+ "^[%lld guest patch](inflect: true) to apply with a guest environment update" : {
+ "localizations" : {
+ "en" : { "stringUnit" : { "state" : "translated", "value" : "^[%lld guest patch](inflect: true) to apply with a guest environment update" } },
+ "ja" : { "stringUnit" : { "state" : "translated", "value" : "ゲスト環境の更新で反映するゲストのパッチ:%lld 件" } },
+ "ko" : { "stringUnit" : { "state" : "translated", "value" : "게스트 환경 업데이트로 반영할 게스트 패치 %lld개" } },
+ "vi" : { "stringUnit" : { "state" : "translated", "value" : "%lld bản vá máy khách sẽ áp dụng khi cập nhật môi trường máy khách" } },
+ "zh-Hans" : { "stringUnit" : { "state" : "translated", "value" : "%lld 个客户机补丁在更新客户机环境时生效" } }
+ }
+ },
+ "^[%lld boot chain patch](inflect: true) that only a restore applies" : {
+ "localizations" : {
+ "en" : { "stringUnit" : { "state" : "translated", "value" : "^[%lld boot chain patch](inflect: true) that only a restore applies" } },
+ "ja" : { "stringUnit" : { "state" : "translated", "value" : "復元でのみ反映される起動チェーンのパッチ:%lld 件" } },
+ "ko" : { "stringUnit" : { "state" : "translated", "value" : "복원으로만 반영되는 부트 체인 패치 %lld개" } },
+ "vi" : { "stringUnit" : { "state" : "translated", "value" : "%lld bản vá chuỗi khởi động chỉ áp dụng khi khôi phục" } },
+ "zh-Hans" : { "stringUnit" : { "state" : "translated", "value" : "%lld 个启动链补丁只有重新恢复才会生效" } }
+ }
+ },
+ "Saving patches…" : {
+ "localizations" : {
+ "en" : { "stringUnit" : { "state" : "translated", "value" : "Saving patches…" } },
+ "ja" : { "stringUnit" : { "state" : "translated", "value" : "パッチを保存中…" } },
+ "ko" : { "stringUnit" : { "state" : "translated", "value" : "패치 저장 중…" } },
+ "vi" : { "stringUnit" : { "state" : "translated", "value" : "Đang lưu bản vá…" } },
+ "zh-Hans" : { "stringUnit" : { "state" : "translated", "value" : "正在保存补丁…" } }
+ }
+ },
+
"Unavailable" : {
"localizations" : {
"en" : { "stringUnit" : { "state" : "translated", "value" : "Unavailable" } },
diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineInspector.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineInspector.swift
index 26a811cc..dd9e57fc 100644
--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineInspector.swift
+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineInspector.swift
@@ -83,6 +83,10 @@ struct VPhoneLaunchpadMachineInspector: View {
/// The machine the catalogue above was read for, so another machine's
/// patches never show while its own are read.
@State private var patchCatalogMachine: VPhoneLaunchpadMachinePath?
+ /// The choice the patch editor opens with, set when it is shown.
+ @State private var editedPatches: VPhoneLaunchpadPatchSelection?
+ /// Bumped after a save or an update, so the patches are read again.
+ @State private var patchRevision = 0
private var library: VPhoneLaunchpadMachineLibrary {
model.machines
@@ -173,6 +177,20 @@ struct VPhoneLaunchpadMachineInspector: View {
VPhoneLaunchpadCommandHistoryView()
.environment(model)
}
+ .sheet(item: $editedPatches) { initial in
+ let path = machine.path
+ VPhoneLaunchpadPatchSettingsView(
+ initial: initial,
+ bundleVersion: library.bundleVersion(for: path),
+ machine: path,
+ ) { selection in
+ Task {
+ await library.setPatches(selection, for: path)
+ patchRevision += 1
+ }
+ }
+ .environment(model)
+ }
}
static var mixedHelp: String {
@@ -222,6 +240,7 @@ struct VPhoneLaunchpadMachineInspector: View {
let machine: VPhoneLaunchpadMachinePath
let bundle: String?
let state: VPhoneLaunchpadMachineLibrary.RunState
+ let revision: Int
}
private var patchReadKey: PatchReadKey {
@@ -229,14 +248,16 @@ struct VPhoneLaunchpadMachineInspector: View {
machine: machine.path,
bundle: library.bundleVersion(for: machine.path),
state: library.state(of: machine.path),
+ revision: patchRevision,
)
}
- /// The machine's patch choice, read only. The choice is changed with
- /// `vphone-cli fw set-patches`; this shows the preset, how many boxes
- /// differ from it, and, when the machine's bundle reports it, how many
- /// patches have not reached the guest yet. An older bundle does not
- /// report the last, and the row is left out.
+ /// The machine's patch choice: the preset, how many boxes differ from
+ /// it, and, when the machine's bundle reports it, how many patches have
+ /// not reached the guest yet. An older bundle does not report the last,
+ /// and the row is left out. Edit opens the patch editor on this machine;
+ /// Apply to Guest updates the guest environment, which is what brings
+ /// guest patches in line. Boot-chain patches only a restore changes.
@ViewBuilder
private var patchesSection: some View {
if library.creations[machine.path]?.isRunning != true {
@@ -266,10 +287,24 @@ struct VPhoneLaunchpadMachineInspector: View {
Text("^[\(pending) patch](inflect: true)")
}
}
- .help(pending == 0
- ? String(localized: "The guest has every patch this machine is set to.")
- : String(localized: "The patch choice changed after the guest was built. Run vphone-cli fw patches \(machine.name) to see each patch and the step that applies it."))
+ .help(pendingHelp(catalog, pending: pending))
+ }
+ }
+ HStack {
+ Spacer()
+ if catalog.installed == true, catalog.pendingGuestPatches > 0 {
+ Button("Apply to Guest") {
+ Task {
+ await library.updateGuestEnvironment(machine.path)
+ patchRevision += 1
+ }
+ }
+ .disabled(library.state(of: machine.path) != .stopped)
+ .help(library.state(of: machine.path) == .stopped
+ ? String(localized: "Updates the guest environment, which turns guest patches on or off to match this machine’s choice.")
+ : String(localized: "Stop the machine to apply its patch choice to the guest."))
}
+ Button("Edit…") { editedPatches = catalog.selection }
}
} else if let patchCatalogError {
Text("Unavailable")
@@ -284,6 +319,21 @@ struct VPhoneLaunchpadMachineInspector: View {
}
}
+ private func pendingHelp(_ catalog: VPhoneLaunchpadPatchCatalog, pending: Int) -> String {
+ guard pending > 0 else {
+ return String(localized: "The guest has every patch this machine is set to.")
+ }
+ var lines: [String] = []
+ if catalog.pendingGuestPatches > 0 {
+ lines.append(String(localized: "^[\(catalog.pendingGuestPatches) guest patch](inflect: true) to apply with Apply to Guest."))
+ }
+ if catalog.pendingBootChainPatches > 0 {
+ lines.append(String(localized: "^[\(catalog.pendingBootChainPatches) boot chain patch](inflect: true) that only a restore applies."))
+ }
+ lines.append(String(localized: "vphone-cli fw patches \(machine.name) lists each one."))
+ return lines.joined(separator: "\n")
+ }
+
private func overridesHelp(_ catalog: VPhoneLaunchpadPatchCatalog) -> String {
var lines: [String] = []
if !catalog.blockedPatches.isEmpty {
diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineLibrary.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineLibrary.swift
index f639f2d4..1039511f 100644
--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineLibrary.swift
+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineLibrary.swift
@@ -561,6 +561,18 @@ final class VPhoneLaunchpadMachineLibrary {
await perform(String(localized: "Saving settings…"), on: machine, arguments)
}
+ /// Records a new patch choice for the machine with its own bundle's
+ /// `fw set-patches`. Nothing in the guest changes until the guest
+ /// environment is updated, or, for the boot chain, the machine restored.
+ @discardableResult
+ func setPatches(_ selection: VPhoneLaunchpadPatchSelection, for machine: Path) async -> Bool {
+ await perform(
+ String(localized: "Saving patches…"),
+ on: machine,
+ ["fw", "set-patches", machine.name] + selection.setPatchesArguments + machine.libraryArguments,
+ )
+ }
+
func rename(_ machine: Path, to newName: String) async {
if await perform(String(localized: "Renaming…"), on: machine, ["vm", "rename", machine.name, newName] + machine.libraryArguments) {
selection = [Path(libraryRoot: machine.libraryRoot, name: newName)]
diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadPatchCatalog.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadPatchCatalog.swift
index b31db7f0..74e741f9 100644
--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadPatchCatalog.swift
+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadPatchCatalog.swift
@@ -53,11 +53,26 @@ nonisolated struct VPhoneLaunchpadPatchCatalog: Decodable, Sendable {
/// guest yet. Reported only for a named machine, by a bundle that
/// compares its records; nil otherwise.
let pending: Bool?
+ /// Where the patch lives in a machine: a boot-chain component's name,
+ /// or `Guest`. Reported only for a named machine; nil otherwise.
+ let part: String?
var id: String {
identifier
}
+ /// Whether the patch is in the boot chain, which only a restore
+ /// changes on a machine that exists. Read from `part` when the bundle
+ /// reports it, else from `target`, which names the component the same
+ /// way for a boot-chain patch.
+ var isBootChain: Bool {
+ Self.bootChainParts.contains(part ?? target)
+ }
+
+ private static let bootChainParts: Set<String> = [
+ "AVPBooter", "iBSS", "iBEC", "LLB", "TXM", "kernelcache", "DeviceTree",
+ ]
+
/// False when the patch applies to every version, which is not worth a
/// column entry.
var isVersionGated: Bool {
@@ -125,6 +140,25 @@ nonisolated struct VPhoneLaunchpadPatchCatalog: Decodable, Sendable {
blockedPatches.count + allowedPatches.count
}
+ /// The machine's own choice, as the editor starts from it.
+ var selection: VPhoneLaunchpadPatchSelection {
+ VPhoneLaunchpadPatchSelection(
+ preset: activePreset,
+ blocked: Set(blockedPatches),
+ allowed: Set(allowedPatches),
+ )
+ }
+
+ /// Pending patches a guest environment update brings in line.
+ var pendingGuestPatches: Int {
+ patches.count { $0.pending == true && !$0.isBootChain }
+ }
+
+ /// Pending patches only a restore brings in line.
+ var pendingBootChainPatches: Int {
+ patches.count { $0.pending == true && $0.isBootChain }
+ }
+
func preset(_ identifier: String) -> Preset? {
presets.first { $0.identifier == identifier }
}
@@ -165,7 +199,7 @@ extension VPhoneLaunchpadPatchCatalog {
) async throws -> VPhoneLaunchpadPatchCatalog {
#if DEBUG
if VPhoneLaunchpadPreview.isActive {
- guard let catalog = VPhoneLaunchpadPreview.patchCatalog(preset: preset) else {
+ guard let catalog = VPhoneLaunchpadPreview.patchCatalog(preset: preset, machine: machine != nil) else {
throw VPhoneLaunchpadError(String(localized: "Unable to list the bundle's patches."))
}
return catalog
@@ -271,3 +305,10 @@ nonisolated struct VPhoneLaunchpadPatchSelection: Hashable, Sendable {
catalog.patches.filter { $0.bootEssential && !isOn($0) }
}
}
+
+/// So the inspector can present the editor with the choice it opens on.
+extension VPhoneLaunchpadPatchSelection: Identifiable {
+ var id: Self {
+ self
+ }
+}
diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadPatchSettingsView.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadPatchSettingsView.swift
index f8d251d7..19fc694c 100644
--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadPatchSettingsView.swift
+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadPatchSettingsView.swift
@@ -1,10 +1,13 @@
import SwiftUI
-/// The patch editor New Machine opens: a preset, and a checkmark for every
-/// patch the bundle declares.
+/// The patch editor: a preset, and a checkmark for every patch the bundle
+/// declares. New Machine opens it for a machine that does not exist yet, and
+/// the inspector for one that does.
///
-/// Only a machine that does not exist yet has one. Once installed, its
-/// firmware is patched and the choice is fixed.
+/// For an existing machine the choice is read from and saved to that machine
+/// (`fw patches <vm>`, `fw set-patches <vm>`) with its own Core Bundle, and
+/// the status line says how each change reaches it: guest patches at the next
+/// guest environment update, the boot chain only with a restore.
///
/// The list is never a copy of the catalogue — it is whatever
/// `vphone-cli fw patches --json` reports, so a patch set added to the bundle
@@ -19,7 +22,10 @@ struct VPhoneLaunchpadPatchSettingsView: View {
/// The Core Bundle New Machine creates with; its `vphone-cli` lists the
/// patches. Nil reads the default version's.
let bundleVersion: String?
- /// Hands the edited choice back; New Machine holds it until the VM exists.
+ /// The existing machine being edited, or nil in New Machine.
+ let machine: VPhoneLaunchpadMachinePath?
+ /// Hands the edited choice back; New Machine holds it until the VM exists,
+ /// the inspector saves it to the machine.
let onSave: (VPhoneLaunchpadPatchSelection) -> Void
@Environment(VPhoneLaunchpadModel.self) private var model
@@ -36,14 +42,19 @@ struct VPhoneLaunchpadPatchSettingsView: View {
/// The row whose summary the detail pane reads.
@State private var highlighted: String?
@State private var confirmsBootEssential = false
+ /// What was on when the editor opened, so the status line can count what
+ /// an edit to an existing machine changes. Taken from the first read.
+ @State private var initiallyOn: Set<String>?
init(
initial: VPhoneLaunchpadPatchSelection,
bundleVersion: String? = nil,
+ machine: VPhoneLaunchpadMachinePath? = nil,
onSave: @escaping (VPhoneLaunchpadPatchSelection) -> Void,
) {
self.initial = initial
self.bundleVersion = bundleVersion
+ self.machine = machine
self.onSave = onSave
_selection = State(initialValue: initial)
}
@@ -288,7 +299,22 @@ struct VPhoneLaunchpadPatchSettingsView: View {
if selection.hasOverrides {
parts.append(String(localized: "\(selection.blocked.count) turned off, \(selection.allowed.count) turned on from the preset"))
}
- parts.append(String(localized: "Applied when the machine is installed"))
+ if machine == nil {
+ parts.append(String(localized: "Applied when the machine is installed"))
+ } else if let initiallyOn {
+ let changed = catalog.patches.filter { selection.isOn($0) != initiallyOn.contains($0.identifier) }
+ let bootChain = changed.count(where: \.isBootChain)
+ let guest = changed.count - bootChain
+ if changed.isEmpty {
+ parts.append(String(localized: "No change"))
+ }
+ if guest > 0 {
+ parts.append(String(localized: "^[\(guest) guest patch](inflect: true) to apply with a guest environment update"))
+ }
+ if bootChain > 0 {
+ parts.append(String(localized: "^[\(bootChain) boot chain patch](inflect: true) that only a restore applies"))
+ }
+ }
return parts.joined(separator: " · ")
}
@@ -300,7 +326,7 @@ struct VPhoneLaunchpadPatchSettingsView: View {
do {
let catalog = try await Catalog.read(
using: bundleVersion.map(model.bundles.commandLine(version:)) ?? model.bundles.commandLine(),
- machine: nil,
+ machine: machine,
preset: preset,
)
// A second switch of the picker may have overtaken this read.
@@ -309,6 +335,9 @@ struct VPhoneLaunchpadPatchSettingsView: View {
}
selection.preset = catalog.activePreset
selection.normalize(against: catalog)
+ if initiallyOn == nil {
+ initiallyOn = Set(catalog.patches.filter { selection.isOn($0) }.map(\.identifier))
+ }
self.catalog = catalog
// The detail pane reserves its space either way, so it starts with
// something to read rather than a gap.