Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Format sources with swiftformat for Swift 6.2

Lakra5a553d4183d
diff --git a/VPhoneDaemon/Daemon/APIWire.swift b/VPhoneDaemon/Daemon/APIWire.swift
index 9d2e6e35..ad167fa4 100644
--- a/VPhoneDaemon/Daemon/APIWire.swift
+++ b/VPhoneDaemon/Daemon/APIWire.swift
@@ -48,7 +48,9 @@ enum APIWire {
// generic "command exited with status 1" does not.
if case let .commandFailed(output) = error {
body.merge(output.filter { $0.key != "error" }) { $1 }
- if output["message"] as? String == nil { body["message"] = error.message }
+ if output["message"] as? String == nil {
+ body["message"] = error.message
+ }
}
} else if let error = error as? GuestAPIError {
body = ["code": error.code, "message": error.description]
diff --git a/VPhoneDaemon/Daemon/GuestVirtualAudioProduct.swift b/VPhoneDaemon/Daemon/GuestVirtualAudioProduct.swift
index 2d18f021..e7744283 100644
--- a/VPhoneDaemon/Daemon/GuestVirtualAudioProduct.swift
+++ b/VPhoneDaemon/Daemon/GuestVirtualAudioProduct.swift
@@ -49,7 +49,9 @@ enum GuestVirtualAudioProduct {
/// The same answer as the plugin's `VPGuestProductID`: 8010 on an iPad or
/// iPhone guest, 0 (none) on anything else, unless one was chosen.
static func product(machine: String, chosen: Int?) -> Int {
- if let chosen, chosen >= 0 { return chosen }
+ if let chosen, chosen >= 0 {
+ return chosen
+ }
return machine.hasPrefix("iPad") || machine.hasPrefix("iPhone") ? 8010 : 0
}
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CustomFirmware/CustomFirmwareVirtualAudioGraphConfigurations.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CustomFirmware/CustomFirmwareVirtualAudioGraphConfigurations.swift
index 052742b6..f8c0c4b1 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CustomFirmware/CustomFirmwareVirtualAudioGraphConfigurations.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CustomFirmware/CustomFirmwareVirtualAudioGraphConfigurations.swift
@@ -87,20 +87,20 @@ public enum CustomFirmwareVirtualAudioGraphConfigurations {
guard let plist = parsed as? [String: Any] else {
throw PatcherError.invalidFormat(
- "top-level plist is \(type(of: parsed)), expected dict: \(url.path)"
+ "top-level plist is \(type(of: parsed)), expected dict: \(url.path)",
)
}
guard let configurations = plist[configurationsKey] as? [String: Any] else {
throw PatcherError.invalidFormat(
- "no '\(configurationsKey)' dict present: \(url.path)"
+ "no '\(configurationsKey)' dict present: \(url.path)",
)
}
let speakerNames = configurations.keys.filter { $0.hasPrefix("speaker_") }.sorted()
guard !speakerNames.isEmpty else {
throw PatcherError.invalidFormat(
- "no 'speaker_' configurations in '\(configurationsKey)': \(url.path)"
+ "no 'speaker_' configurations in '\(configurationsKey)': \(url.path)",
)
}
@@ -109,12 +109,12 @@ public enum CustomFirmwareVirtualAudioGraphConfigurations {
let configuration = configurations[name]
guard let entry = configuration as? [String: Any] else {
throw PatcherError.invalidFormat(
- "configuration '\(name)' is \(type(of: configuration)), expected dict: \(url.path)"
+ "configuration '\(name)' is \(type(of: configuration)), expected dict: \(url.path)",
)
}
guard let chainType = entry[chainTypeKey] as? String else {
throw PatcherError.invalidFormat(
- "configuration '\(name)' has no '\(chainTypeKey)' string: \(url.path)"
+ "configuration '\(name)' has no '\(chainTypeKey)' string: \(url.path)",
)
}
switch chainType {
@@ -125,7 +125,7 @@ public enum CustomFirmwareVirtualAudioGraphConfigurations {
default:
throw PatcherError.invalidFormat(
"configuration '\(name)' has chainType '\(chainType)', expected "
- + "'\(speakerChainType)' or '\(graphChainType)': \(url.path)"
+ + "'\(speakerChainType)' or '\(graphChainType)': \(url.path)",
)
}
}
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CustomFirmware/ExecutablePatches/VirtualAudio/CustomFirmwareVirtualAudio.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CustomFirmware/ExecutablePatches/VirtualAudio/CustomFirmwareVirtualAudio.swift
index 69063019..9a8649d0 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CustomFirmware/ExecutablePatches/VirtualAudio/CustomFirmwareVirtualAudio.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CustomFirmware/ExecutablePatches/VirtualAudio/CustomFirmwareVirtualAudio.swift
@@ -207,7 +207,7 @@ public enum CustomFirmwareVirtualAudio {
/// The 33-bit packing mask the handler compares the volume-mode lookup
/// under — a present flag in bit 32 above the mode's low 32 bits. The
/// semantic constant the site is recognised by, beside the strings.
- public static let volumeModePackingMask = 0x1ffffffff
+ public static let volumeModePackingMask = 0x1_FFFF_FFFF
/// Record identity for the volume-gate patch.
public static let volumeGatePatchID = "system-virtualaudio-cfw-volume_mode_precondition"
@@ -355,7 +355,8 @@ public enum CustomFirmwareVirtualAudio {
if let insn = siteInstruction, insn.isJump, !insn.isCall,
let word = wordAt(data, site),
let target = ARM64Encoder.decodeBranchTarget(insn: word, pc: siteVMA),
- target == located.epilogueVMA {
+ target == located.epilogueVMA
+ {
alreadyPatched += 1
continue
}
@@ -485,7 +486,8 @@ public enum CustomFirmwareVirtualAudio {
if let insn = siteInstruction, insn.isJump, !insn.isCall,
let word = wordAt(data, site),
let target = ARM64Encoder.decodeBranchTarget(insn: word, pc: siteVMA),
- target == located.epilogueVMA {
+ target == located.epilogueVMA
+ {
log?(" [=] the mute-set throw already branches to the epilogue")
return MuteSetReport(outcome: .alreadyPatched, anchor: anchor, records: [], slotRehashes: [])
}
@@ -819,9 +821,17 @@ public enum CustomFirmwareVirtualAudio {
let epilogueVMA: UInt64
let sites: [Int]
- var walkerStartVMA: UInt64 { vma(walkerStartOffset) }
- var walkerEndVMA: UInt64 { vma(walkerEndOffset) }
- func vma(_ offset: Int) -> UInt64 { textAddress + UInt64(offset - textStart) }
+ var walkerStartVMA: UInt64 {
+ vma(walkerStartOffset)
+ }
+
+ var walkerEndVMA: UInt64 {
+ vma(walkerEndOffset)
+ }
+
+ func vma(_ offset: Int) -> UInt64 {
+ textAddress + UInt64(offset - textStart)
+ }
}
static func locate(in data: Data) throws -> Plan {
@@ -933,9 +943,17 @@ public enum CustomFirmwareVirtualAudio {
let epilogueVMA: UInt64
let site: Int
- var functionStartVMA: UInt64 { vma(functionStartOffset) }
- var functionEndVMA: UInt64 { vma(functionEndOffset) }
- func vma(_ offset: Int) -> UInt64 { textAddress + UInt64(offset - textStart) }
+ var functionStartVMA: UInt64 {
+ vma(functionStartOffset)
+ }
+
+ var functionEndVMA: UInt64 {
+ vma(functionEndOffset)
+ }
+
+ func vma(_ offset: Int) -> UInt64 {
+ textAddress + UInt64(offset - textStart)
+ }
}
/// Resolve the mute-set throw and the wrapper's epilogue, or say why not.
@@ -1058,9 +1076,17 @@ public enum CustomFirmwareVirtualAudio {
let blockHead: Int
let site: Int
- var functionStartVMA: UInt64 { vma(functionStartOffset) }
- var functionEndVMA: UInt64 { vma(functionEndOffset) }
- func vma(_ offset: Int) -> UInt64 { textAddress + UInt64(offset - textStart) }
+ var functionStartVMA: UInt64 {
+ vma(functionStartOffset)
+ }
+
+ var functionEndVMA: UInt64 {
+ vma(functionEndOffset)
+ }
+
+ func vma(_ offset: Int) -> UInt64 {
+ textAddress + UInt64(offset - textStart)
+ }
}
/// How far above a branch target the format-string reference may sit and
@@ -1086,9 +1112,17 @@ public enum CustomFirmwareVirtualAudio {
/// both gate scans read.
let fileNameVMAs: Set<UInt64>
- var functionStartVMA: UInt64 { vma(functionStartOffset) }
- var functionEndVMA: UInt64 { vma(functionEndOffset) }
- func vma(_ offset: Int) -> UInt64 { textAddress + UInt64(offset - textStart) }
+ var functionStartVMA: UInt64 {
+ vma(functionStartOffset)
+ }
+
+ var functionEndVMA: UInt64 {
+ vma(functionEndOffset)
+ }
+
+ func vma(_ offset: Int) -> UInt64 {
+ textAddress + UInt64(offset - textStart)
+ }
}
/// Resolve the routing handler, or say why not. The anchors are the
@@ -1168,8 +1202,12 @@ public enum CustomFirmwareVirtualAudio {
/// Resolve the SP-gate branch, or say why not.
static func locateSPGate(in data: Data, handler which: SPGateHandler = .playback) throws -> SPGatePlan {
let handler = try locatePlaybackHandler(in: data, file: which.file)
- func vma(_ offset: Int) -> UInt64 { handler.vma(offset) }
- func offset(of address: UInt64) -> Int { handler.textStart + Int(address - handler.textAddress) }
+ func vma(_ offset: Int) -> UInt64 {
+ handler.vma(offset)
+ }
+ func offset(of address: UInt64) -> Int {
+ handler.textStart + Int(address - handler.textAddress)
+ }
// The gate: the one branch in the handler whose target heads the log
// block — a target at or above which, within the window, the format
@@ -1235,7 +1273,7 @@ public enum CustomFirmwareVirtualAudio {
// os_log the head used to open.
guard let above = handler.disasm.disassembleOne(in: data, at: gate.head - 4),
above.mnemonic == "brk" || ["ret", "retab"].contains(above.mnemonic)
- || (above.isJump && !above.isCall && above.detail?.conditionCode == nil)
+ || (above.isJump && !above.isCall && above.detail?.conditionCode == nil)
else {
throw PatcherError.invalidFormat(
"\(component): the log block at 0x\(hex(vma(gate.head))) is reached by "
@@ -1270,9 +1308,17 @@ public enum CustomFirmwareVirtualAudio {
let blockHead: Int
let site: Int
- var functionStartVMA: UInt64 { vma(functionStartOffset) }
- var functionEndVMA: UInt64 { vma(functionEndOffset) }
- func vma(_ offset: Int) -> UInt64 { textAddress + UInt64(offset - textStart) }
+ var functionStartVMA: UInt64 {
+ vma(functionStartOffset)
+ }
+
+ var functionEndVMA: UInt64 {
+ vma(functionEndOffset)
+ }
+
+ func vma(_ offset: Int) -> UInt64 {
+ textAddress + UInt64(offset - textStart)
+ }
}
/// How far above a branch target the precondition block's format and
@@ -1297,8 +1343,12 @@ public enum CustomFirmwareVirtualAudio {
"\(component): the string \"\(volumePreconditionFormat)\" is nowhere in the binary's sections",
)
}
- func vma(_ offset: Int) -> UInt64 { handler.vma(offset) }
- func offset(of address: UInt64) -> Int { handler.textStart + Int(address - handler.textAddress) }
+ func vma(_ offset: Int) -> UInt64 {
+ handler.vma(offset)
+ }
+ func offset(of address: UInt64) -> Int {
+ handler.textStart + Int(address - handler.textAddress)
+ }
// The comparison: the one branch in the handler whose target heads a
// precondition log block — both the format and the handler's own
@@ -1372,7 +1422,7 @@ public enum CustomFirmwareVirtualAudio {
// expecting the os_log the head used to open.
guard let above = handler.disasm.disassembleOne(in: data, at: gate.head - 4),
above.mnemonic == "brk" || ["ret", "retab"].contains(above.mnemonic)
- || (above.isJump && !above.isCall && above.detail?.conditionCode == nil)
+ || (above.isJump && !above.isCall && above.detail?.conditionCode == nil)
else {
throw PatcherError.invalidFormat(
"\(component): the precondition block at 0x\(hex(vma(gate.head))) is reached by "
@@ -1409,7 +1459,9 @@ public enum CustomFirmwareVirtualAudio {
while cursor >= branch - 24 {
defer { cursor -= 4 }
guard let insn = disasm.disassembleOne(in: data, at: cursor) else { return false }
- if insn.mnemonic == "cmp" { sawCompare = true }
+ if insn.mnemonic == "cmp" {
+ sawCompare = true
+ }
guard insn.mnemonic == "and",
let operands = insn.detail?.operands, operands.count >= 3,
operands[2].type == .immediate,
@@ -1490,7 +1542,8 @@ public enum CustomFirmwareVirtualAudio {
if insn.mnemonic == "str",
let operands = insn.detail?.operands, operands.count >= 2,
operands[0].type == .register,
- operands[1].type == .memory, operands[1].mem.base == ARM64Register.x(0) {
+ operands[1].type == .memory, operands[1].mem.base == ARM64Register.x(0)
+ {
sawObjectStore = true
}
if insn.isCall, sawObjectStore {
@@ -1501,7 +1554,8 @@ public enum CustomFirmwareVirtualAudio {
// to its `brk`) or at the `brk` the compiler plants after a call
// it knows never returns.
if insn.mnemonic == "brk"
- || (insn.isJump && !insn.isCall && insn.detail?.conditionCode == nil) {
+ || (insn.isJump && !insn.isCall && insn.detail?.conditionCode == nil)
+ {
return sawObjectStore && sawThrowCall
}
}
@@ -1546,7 +1600,9 @@ public enum CustomFirmwareVirtualAudio {
.sorted { lhs, rhs in
let l = lhs.sectionName == "__cstring"
let r = rhs.sectionName == "__cstring"
- if l != r { return l }
+ if l != r {
+ return l
+ }
return lhs.fileOffset < rhs.fileOffset
}
var addresses: Set<UInt64> = []
@@ -1555,7 +1611,8 @@ public enum CustomFirmwareVirtualAudio {
let end = start + Int(section.size)
var searchFrom = start
while searchFrom + bytes.count <= end,
- let match = range(of: bytes, in: data, start: searchFrom, end: end) {
+ let match = range(of: bytes, in: data, start: searchFrom, end: end)
+ {
let stringStart = cStringStart(in: data, containing: match, notBefore: start)
addresses.insert(section.address + UInt64(stringStart - start))
searchFrom = match + 1
@@ -1572,8 +1629,8 @@ public enum CustomFirmwareVirtualAudio {
in data: Data,
disasm: ARM64Disassembler,
sections: [String: MachOSectionInfo],
- textStart: Int,
- textEnd: Int,
+ textStart _: Int,
+ textEnd _: Int,
walkerStart: Int,
walkerEnd: Int,
epilogueVMA: UInt64,
@@ -1581,7 +1638,8 @@ public enum CustomFirmwareVirtualAudio {
let needle = Array((terminateFault + "\0").utf8)
var faultVMA: UInt64?
for section in sections.values
- where section.fileOffset > 0 && Int(section.fileOffset) + Int(section.size) <= data.count {
+ where section.fileOffset > 0 && Int(section.fileOffset) + Int(section.size) <= data.count
+ {
let start = Int(section.fileOffset)
let end = start + Int(section.size)
if let match = range(of: needle, in: data, start: start, end: end) {
@@ -1615,8 +1673,9 @@ public enum CustomFirmwareVirtualAudio {
break
}
if insn.isJump, !insn.isCall, insn.detail?.conditionCode == nil,
- let target = branchTarget(insn, at: cursor), target >= walkerStart, target < walkerEnd {
- cursor = Int(target) - 4 // the defer moves past it
+ let target = branchTarget(insn, at: cursor), target >= walkerStart, target < walkerEnd
+ {
+ cursor = Int(target) - 4 // the defer moves past it
continue
}
}
@@ -1644,7 +1703,8 @@ public enum CustomFirmwareVirtualAudio {
after.isJump, !after.isCall,
let word = wordAtCache(data: after.bytes, offset: 0),
let target = ARM64Encoder.decodeBranchTarget(insn: word, pc: UInt64(site + 4)),
- target == epilogueVMA {
+ target == epilogueVMA
+ {
return nil
}
return site
@@ -1655,7 +1715,7 @@ public enum CustomFirmwareVirtualAudio {
return ARM64Encoder.decodeBranchTarget(insn: word, pc: UInt64(offset))
}
- private static func wordAtCache(data bytes: [UInt8], offset: Int) -> UInt32? {
+ private static func wordAtCache(data bytes: [UInt8], offset _: Int) -> UInt32? {
guard bytes.count >= 4 else { return nil }
return UInt32(bytes[0]) | UInt32(bytes[1]) << 8 | UInt32(bytes[2]) << 16 | UInt32(bytes[3]) << 24
}
@@ -1705,10 +1765,12 @@ public enum CustomFirmwareVirtualAudio {
guard let insn = disasm.disassembleOne(in: data, at: cursor) else { return false }
if insn.mnemonic == "adrp",
let operands = insn.detail?.operands, operands.count >= 2,
- operands[0].reg == ARM64Register.x(1) {
+ operands[0].reg == ARM64Register.x(1)
+ {
if let low = disasm.disassembleOne(in: data, at: cursor + 4), low.mnemonic == "add",
let lowOps = low.detail?.operands, lowOps.count >= 3,
- lowOps[0].reg == ARM64Register.x(1), lowOps[1].reg == ARM64Register.x(1) {
+ lowOps[0].reg == ARM64Register.x(1), lowOps[1].reg == ARM64Register.x(1)
+ {
sawMessageLoad = true
}
}
@@ -1720,7 +1782,8 @@ public enum CustomFirmwareVirtualAudio {
// a tail-called throw) or at the `brk` the compiler plants after
// a call it knows never returns.
if insn.mnemonic == "brk"
- || (insn.isJump, !insn.isCall, insn.detail?.conditionCode == nil) == (true, true, true) {
+ || (insn.isJump, !insn.isCall, insn.detail?.conditionCode == nil) == (true, true, true)
+ {
return sawMessageLoad && sawConstructorCall
}
}
@@ -1736,7 +1799,7 @@ public enum CustomFirmwareVirtualAudio {
in data: Data,
sections: [String: MachOSectionInfo],
textStart: Int,
- textEnd: Int,
+ textEnd _: Int,
before offset: Int,
window: Int = 0x100,
) -> (adrp: Int, add: Int)? {
@@ -1772,7 +1835,9 @@ public enum CustomFirmwareVirtualAudio {
.sorted { lhs, rhs in
let l = lhs.sectionName == "__cstring"
let r = rhs.sectionName == "__cstring"
- if l != r { return l }
+ if l != r {
+ return l
+ }
return lhs.fileOffset < rhs.fileOffset
}
for section in searchable {
@@ -1800,7 +1865,7 @@ public enum CustomFirmwareVirtualAudio {
/// The same pairs, matching any target in a set.
private static func adrpAddReferences(
- to placeholder: UInt64,
+ to _: UInt64,
formingAnyOf targets: Set<UInt64>,
in data: Data,
textStart: Int,
@@ -1841,7 +1906,9 @@ public enum CustomFirmwareVirtualAudio {
scanned += 1
}
guard let insn = disasm.disassembleOne(in: data, at: cursor) else { return nil }
- if insn.isCall { continue }
+ if insn.isCall {
+ continue
+ }
if insn.mnemonic == "brk" || (insn.isJump && insn.detail?.conditionCode == nil) {
return cursor
}
@@ -1876,7 +1943,8 @@ public enum CustomFirmwareVirtualAudio {
while cursor + 4 <= textEnd {
defer { cursor += 4 }
if let insn = disasm.disassembleOne(in: data, at: cursor),
- insn.mnemonic == "retab" {
+ insn.mnemonic == "retab"
+ {
retabOffset = cursor
break
}
@@ -1921,7 +1989,8 @@ public enum CustomFirmwareVirtualAudio {
var index = retab - 8
var sawFramePair = false
while let insn = instruction(index), insn.mnemonic == "ldp",
- let operands = insn.detail?.operands, operands.count >= 2 {
+ let operands = insn.detail?.operands, operands.count >= 2
+ {
if operands[0].reg == ARM64Register.x(29), operands[1].reg == ARM64Register.x(30) {
sawFramePair = true
}
@@ -1947,7 +2016,8 @@ public enum CustomFirmwareVirtualAudio {
let canary = instruction(index - 20), canary.mnemonic == "ldur",
let canaryOps = canary.detail?.operands, canaryOps.count >= 2,
canaryOps[1].type == .memory,
- canaryOps[1].mem.base == ARM64Register.x(29) {
+ canaryOps[1].mem.base == ARM64Register.x(29)
+ {
return index - 20
}
return firstPop
@@ -1981,7 +2051,9 @@ public enum CustomFirmwareVirtualAudio {
matched = false
break
}
- if matched { return offset }
+ if matched {
+ return offset
+ }
}
return nil
}
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareDeviceTreePatchSet.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareDeviceTreePatchSet.swift
index 894fbf5a..62cc226e 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareDeviceTreePatchSet.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareDeviceTreePatchSet.swift
@@ -168,6 +168,7 @@ public enum FirmwareDeviceTreePatchSet {
),
// MARK: Removed Nodes
+
//
// Written to every guest's tree, iPhone and iPad, whatever the variant.
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift
index 7a3c38fd..e8924318 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift
@@ -178,6 +178,7 @@ public enum FirmwareGuestSystemPatchSet {
target: .guestFile(path: "/Library/LaunchDaemons"),
bootEssential: true,
),
+
// MARK: Audio
VPhonePatchDeclaration(
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareVirtualAudioGraphConfigurationsTests.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareVirtualAudioGraphConfigurationsTests.swift
index 8cf43e41..2ede5894 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareVirtualAudioGraphConfigurationsTests.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareVirtualAudioGraphConfigurationsTests.swift
@@ -8,9 +8,9 @@
// file's format survives, a re-run writes nothing, and anything unexpected
// refuses rather than half-patches.
+@testable import FirmwarePatcher
import Foundation
import Testing
-@testable import FirmwarePatcher
import VPhonePatchKit
@Suite("CustomFirmwareVirtualAudioGraphConfigurations")
@@ -47,8 +47,8 @@ struct CustomFirmwareVirtualAudioGraphConfigurationsTests {
return url
}
- @Test("flips every speaker chain and leaves the rest of the file alone")
- func flipsSpeakerChains() throws {
+ @Test
+ func `flips every speaker chain and leaves the rest of the file alone`() throws {
let url = try writeTemporary(Self.tuningSet())
let outcome = try CustomFirmwareVirtualAudioGraphConfigurations.patch(at: url, verbose: false)
#expect(outcome == .rewritten(changed: ["speaker_general", "speaker_raw", "speaker_ringtone"]))
@@ -65,9 +65,9 @@ struct CustomFirmwareVirtualAudioGraphConfigurationsTests {
// The only difference from the input is the flipped chainTypes.
var expected = Self.tuningSet()
- var expectedConfigurations = expected["Configurations"] as! [String: Any]
+ var expectedConfigurations = try #require(expected["Configurations"] as? [String: Any])
for name in ["speaker_ringtone", "speaker_general", "speaker_raw"] {
- var entry = expectedConfigurations[name] as! [String: Any]
+ var entry = try #require(expectedConfigurations[name] as? [String: Any])
entry["chainType"] = "dflt"
expectedConfigurations[name] = entry
}
@@ -76,8 +76,8 @@ struct CustomFirmwareVirtualAudioGraphConfigurationsTests {
#expect(difference == nil, "unexpected differences beyond the flipped chainTypes: \(difference ?? "")")
}
- @Test("keeps the plist's format — binary in, binary out")
- func preservesFormat() throws {
+ @Test
+ func `keeps the plist's format — binary in, binary out`() throws {
for format in [PropertyListSerialization.PropertyListFormat.binary, .xml] {
let url = try writeTemporary(Self.tuningSet(), format: format)
try CustomFirmwareVirtualAudioGraphConfigurations.patch(at: url, verbose: false)
@@ -86,8 +86,8 @@ struct CustomFirmwareVirtualAudioGraphConfigurationsTests {
}
}
- @Test("is idempotent and honours dry run")
- func idempotentAndDryRun() throws {
+ @Test
+ func `is idempotent and honours dry run`() throws {
let url = try writeTemporary(Self.tuningSet())
let dry = try CustomFirmwareVirtualAudioGraphConfigurations.patch(at: url, dryRun: true, verbose: false)
#expect(dry == .dryRun(changed: ["speaker_general", "speaker_raw", "speaker_ringtone"]))
@@ -102,12 +102,13 @@ struct CustomFirmwareVirtualAudioGraphConfigurationsTests {
#expect(try Data(contentsOf: url) == written)
}
- @Test("refuses plists it does not understand, not searched past",
- arguments: [
- "not a plist at all",
- "{\"Configurations\": {\"speaker_ringtone\": {\"chainType\": \"sprt\"}}}",
- ])
- func refusesUnexpectedInput(_ text: String) throws {
+ @Test(
+ arguments: [
+ "not a plist at all",
+ "{\"Configurations\": {\"speaker_ringtone\": {\"chainType\": \"sprt\"}}}",
+ ],
+ )
+ func `refuses plists it does not understand, not searched past`(_ text: String) throws {
let url = try writeTemporary(["placeholder": true])
try Data(text.utf8).write(to: url)
#expect(throws: PatcherError.self) {
@@ -115,10 +116,10 @@ struct CustomFirmwareVirtualAudioGraphConfigurationsTests {
}
}
- @Test("refuses a speaker chain on an unknown chainType")
- func refusesUnknownChainType() throws {
+ @Test
+ func `refuses a speaker chain on an unknown chainType`() throws {
var plist = Self.tuningSet()
- var configurations = plist["Configurations"] as! [String: Any]
+ var configurations = try #require(plist["Configurations"] as? [String: Any])
configurations["speaker_siri"] = ["chainType": "sprt", "graph": "speaker_general"]
plist["Configurations"] = configurations
let url = try writeTemporary(plist)
@@ -127,8 +128,8 @@ struct CustomFirmwareVirtualAudioGraphConfigurationsTests {
}
}
- @Test("refuses a plist with no speaker configurations")
- func refusesNoSpeakerConfigurations() throws {
+ @Test
+ func `refuses a plist with no speaker configurations`() throws {
let micOnly: [String: Any] = [
"CommonData": ["tuningPath": "/Library/Audio/Tunings/AID2029/VAD"],
"Configurations": ["beamformed_mic_general": ["chainType": "dflt", "graph": "beam_mic_general"]],
@@ -139,16 +140,16 @@ struct CustomFirmwareVirtualAudioGraphConfigurationsTests {
}
}
- @Test("refuses a plist without the Configurations dict")
- func refusesMissingConfigurations() throws {
+ @Test
+ func `refuses a plist without the Configurations dict`() throws {
let url = try writeTemporary(["CommonData": ["tuningPath": "/x"]])
#expect(throws: PatcherError.self) {
try CustomFirmwareVirtualAudioGraphConfigurations.patch(at: url, verbose: false)
}
}
- @Test("the anchor keys are the ones the tuning set ships")
- func keysAreStable() {
+ @Test
+ func `the anchor keys are the ones the tuning set ships`() {
#expect(CustomFirmwareVirtualAudioGraphConfigurations.speakerChainType == "clhs")
#expect(CustomFirmwareVirtualAudioGraphConfigurations.graphChainType == "dflt")
#expect(CustomFirmwareVirtualAudioGraphConfigurations.configurationsKey == "Configurations")
@@ -206,7 +207,7 @@ struct CustomFirmwareVirtualAudioGraphConfigurationsTests {
#expect(patched[name]?["chainType"] as? String == "dflt")
}
for name in ["speaker_raw", "speaker_measurement", "bottom_mic_general"] {
- #expect(NSDictionary(dictionary: try #require(patched[name])) == NSDictionary(dictionary: try #require(original[name])))
+ #expect(try NSDictionary(dictionary: #require(patched[name])) == NSDictionary(dictionary: #require(original[name])))
}
}
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareVirtualAudioMicrophoneChainsTests.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareVirtualAudioMicrophoneChainsTests.swift
index 914258d1..d64e9768 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareVirtualAudioMicrophoneChainsTests.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareVirtualAudioMicrophoneChainsTests.swift
@@ -6,9 +6,9 @@
// configurations `graph_configurations.plist` pairs, and a measurement strip
// whose second AUNBandEQ carries +18 dB as parameter 0 of its saved state.
+@testable import FirmwarePatcher
import Foundation
import Testing
-@testable import FirmwarePatcher
import VPhonePatchKit
@Suite("CustomFirmwareVirtualAudioMicrophoneChains")
@@ -119,7 +119,7 @@ struct CustomFirmwareVirtualAudioMicrophoneChainsTests {
let patched = try Self.configurations(url)
let original = try #require(Self.tuningSet()["Configurations"] as? [String: [String: Any]])
for name in ["bottom_mic_measurement", "bottom_mic_voice_messages", "speaker_general", "speaker_measurement"] {
- #expect(NSDictionary(dictionary: try #require(patched[name])) == NSDictionary(dictionary: try #require(original[name])))
+ #expect(try NSDictionary(dictionary: #require(patched[name])) == NSDictionary(dictionary: #require(original[name])))
}
#expect(try Self.read(url)["CommonData"] != nil)
}
@@ -177,7 +177,7 @@ struct CustomFirmwareVirtualAudioMicrophoneChainsTests {
let url = try Self.write(Self.tuningSet(), format: format)
defer { try? FileManager.default.removeItem(at: url) }
try Patcher.patch(at: url, verbose: false)
- #expect(CustomFirmwareBuildVersion.detectFormat(try Data(contentsOf: url)) == format)
+ #expect(try CustomFirmwareBuildVersion.detectFormat(Data(contentsOf: url)) == format)
}
@Test func `a plist of another shape is refused`() throws {
@@ -264,7 +264,7 @@ struct CustomFirmwareVirtualAudioMicrophoneChainsTests {
defer { try? FileManager.default.removeItem(at: url) }
#expect(try Patcher.neutralizeGain(at: url, verbose: false).isEmpty)
- #expect(Self.data(try Self.effects(url)[0]) == foreign)
+ #expect(try Self.data(Self.effects(url)[0]) == foreign)
}
@Test func `parameter data that is not whole records is refused`() throws {
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareVirtualAudioTests.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareVirtualAudioTests.swift
index 71cb1f27..edda2d8b 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareVirtualAudioTests.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcherTests/CustomFirmware/CustomFirmwareVirtualAudioTests.swift
@@ -10,9 +10,9 @@
// recorded in `Research/Guest/virtio_sound.md` — that covers the mute-set
// patch this suite's second half names.
+@testable import FirmwarePatcher
import Foundation
import Testing
-@testable import FirmwarePatcher
import VPhonePatchKit
@Suite("CustomFirmwareVirtualAudio")
@@ -20,9 +20,10 @@ struct CustomFirmwareVirtualAudioTests {
/// Not a Mach-O at all.
static let junk = Data(repeating: 0x41, count: 4096)
- @Test("a binary without the message is refused, not searched past",
- arguments: [Self.junk, Data()])
- func refusesBinariesWithoutTheSite(_ input: Data) throws {
+ @Test(
+ arguments: [Self.junk, Data()],
+ )
+ func `a binary without the message is refused, not searched past`(_ input: Data) throws {
var data = input
#expect(throws: PatcherError.self) {
try CustomFirmwareVirtualAudio.patch(
@@ -34,15 +35,16 @@ struct CustomFirmwareVirtualAudioTests {
}
}
- @Test("the message string is the anchor the records name")
- func messageIsStable() {
+ @Test
+ func `the message string is the anchor the records name`() {
#expect(CustomFirmwareVirtualAudio.message == "No default VAD present")
#expect(CustomFirmwareVirtualAudio.patchID == "system-virtualaudio-cfw-speaker_route_throws")
}
- @Test("a binary without the mute-set log is refused, not searched past",
- arguments: [Self.junk, Data()])
- func refusesBinariesWithoutTheMuteSetSite(_ input: Data) throws {
+ @Test(
+ arguments: [Self.junk, Data()],
+ )
+ func `a binary without the mute-set log is refused, not searched past`(_ input: Data) throws {
var data = input
#expect(throws: PatcherError.self) {
try CustomFirmwareVirtualAudio.patchMuteSet(
@@ -54,16 +56,17 @@ struct CustomFirmwareVirtualAudioTests {
}
}
- @Test("the mute-set anchor strings and record identity are stable")
- func muteSetIdentityIsStable() {
+ @Test
+ func `the mute-set anchor strings and record identity are stable`() {
#expect(CustomFirmwareVirtualAudio.muteSetMessage == "Set mute value of %u on HAL device")
#expect(CustomFirmwareVirtualAudio.muteSetException == "Unable to set property data.")
#expect(CustomFirmwareVirtualAudio.muteSetPatchID == "system-virtualaudio-cfw-mute_set_throw")
}
- @Test("a binary without the decline log is refused, not searched past",
- arguments: [Self.junk, Data()])
- func refusesBinariesWithoutTheSPGateSite(_ input: Data) throws {
+ @Test(
+ arguments: [Self.junk, Data()],
+ )
+ func `a binary without the decline log is refused, not searched past`(_ input: Data) throws {
var data = input
#expect(throws: PatcherError.self) {
try CustomFirmwareVirtualAudio.patchSpeakerProtectionGate(
@@ -75,15 +78,15 @@ struct CustomFirmwareVirtualAudioTests {
}
}
- @Test("the SP-gate anchor strings and record identity are stable")
- func spGateIdentityIsStable() {
+ @Test
+ func `the SP-gate anchor strings and record identity are stable`() {
#expect(CustomFirmwareVirtualAudio.spGateMessage == "HAL Speaker Protection is missing. Failing route")
#expect(CustomFirmwareVirtualAudio.spGateFile == "RoutingHandler_Playback_GenericConfig1.cpp")
#expect(CustomFirmwareVirtualAudio.spGatePatchID == "system-virtualaudio-cfw-speaker_protection_gate")
}
- @Test("each SP-gate handler has its own file anchor and a record the declaration covers")
- func spGateHandlersAreDistinct() {
+ @Test
+ func `each SP-gate handler has its own file anchor and a record the declaration covers`() {
typealias Handler = CustomFirmwareVirtualAudio.SPGateHandler
#expect(Handler.allCases == [.playback, .playbackAndRecord])
#expect(Handler.playback.file == CustomFirmwareVirtualAudio.spGateFile)
@@ -98,9 +101,10 @@ struct CustomFirmwareVirtualAudioTests {
#expect(!Handler.playback.file.contains(Handler.playbackAndRecord.file))
}
- @Test("a binary without the play-and-record decline is refused, not searched past",
- arguments: [Self.junk, Data()])
- func refusesBinariesWithoutTheRecordSPGateSite(_ input: Data) throws {
+ @Test(
+ arguments: [Self.junk, Data()],
+ )
+ func `a binary without the play-and-record decline is refused, not searched past`(_ input: Data) throws {
var data = input
#expect(throws: PatcherError.self) {
try CustomFirmwareVirtualAudio.patchSpeakerProtectionGate(
@@ -113,9 +117,10 @@ struct CustomFirmwareVirtualAudioTests {
}
}
- @Test("a binary without the precondition decline is refused, not searched past",
- arguments: [Self.junk, Data()])
- func refusesBinariesWithoutTheVolumeGateSite(_ input: Data) throws {
+ @Test(
+ arguments: [Self.junk, Data()],
+ )
+ func `a binary without the precondition decline is refused, not searched past`(_ input: Data) throws {
var data = input
#expect(throws: PatcherError.self) {
try CustomFirmwareVirtualAudio.patchVolumeModePrecondition(
@@ -127,18 +132,18 @@ struct CustomFirmwareVirtualAudioTests {
}
}
- @Test("the volume-gate anchor strings and record identity are stable")
- func volumeGateIdentityIsStable() {
+ @Test
+ func `the volume-gate anchor strings and record identity are stable`() {
#expect(CustomFirmwareVirtualAudio.volumePreconditionFormat == "PRECONDITION FAILURE (std::logic_error)")
- #expect(CustomFirmwareVirtualAudio.volumeModePackingMask == 0x1ffffffff)
+ #expect(CustomFirmwareVirtualAudio.volumeModePackingMask == 0x1_FFFF_FFFF)
#expect(CustomFirmwareVirtualAudio.volumeGatePatchID == "system-virtualaudio-cfw-volume_mode_precondition")
}
/// `tbz w21, #0, 0x136878` at 0x136620 — the real gate branch, read off
/// the iPadOS 26.6.2 plugin binary this patch was written against (bytes
/// d5 12 00 36 at that offset).
- @Test("the conditional-branch decoder reads the real gate's target")
- func decodesTheGatesTBZ() {
+ @Test
+ func `the conditional-branch decoder reads the real gate's target`() {
#expect(
CustomFirmwareVirtualAudio.decodeConditionalBranchTarget(
insn: 0x3600_12D5,
@@ -151,9 +156,9 @@ struct CustomFirmwareVirtualAudioTests {
/// up to 512 KB ahead instead of up to 256 KB back. The word is built
/// from its fields — `b.eq` with every immediate bit set, i.e. −1 — not
/// taken as a literal.
- @Test("the 19-bit immediate sign-extends")
- func signExtendsTheImmediate19() {
- let word: UInt32 = 0x5400_0000 | (0x7FFFF << 5) // b.eq, imm19 = −1
+ @Test
+ func `the 19-bit immediate sign-extends`() {
+ let word: UInt32 = 0x5400_0000 | (0x7FFFF << 5) // b.eq, imm19 = −1
#expect(
CustomFirmwareVirtualAudio.decodeConditionalBranchTarget(
insn: word,
@@ -165,8 +170,8 @@ struct CustomFirmwareVirtualAudioTests {
/// `tbz` reaches ±32 KB through a 14-bit immediate at bits 18-5, and a
/// 64-bit `cbnz` proves the leading sf/b5 bit is not mistaken for part
/// of the family. Both words are built from their fields.
- @Test("the 14-bit and 64-bit families decode")
- func decodesTheImmediate14And64BitFamilies() {
+ @Test
+ func `the 14-bit and 64-bit families decode`() {
// tbz w21, #0, imm14 = −1 (bits 30-25 = 011011, bit 24 = 0)
let tbz: UInt32 = 0x3600_0000 | (0x3FFF << 5) | 21
#expect(CustomFirmwareVirtualAudio.decodeConditionalBranchTarget(insn: tbz, pc: 0x1000) == 0x0FFC)
@@ -175,8 +180,8 @@ struct CustomFirmwareVirtualAudioTests {
#expect(CustomFirmwareVirtualAudio.decodeConditionalBranchTarget(insn: cbnz, pc: 0x2000) == 0x2040)
}
- @Test("the conditional-branch decoder refuses words outside its families")
- func refusesNonBranchWords() {
+ @Test
+ func `the conditional-branch decoder refuses words outside its families`() {
#expect(CustomFirmwareVirtualAudio.decodeConditionalBranchTarget(insn: 0xD503_201F, pc: 0) == nil)
// A `b` — the family `ARM64Encoder.decodeBranchTarget` owns.
#expect(CustomFirmwareVirtualAudio.decodeConditionalBranchTarget(insn: 0x1400_0002, pc: 0) == nil)
diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift
index 41117af4..241c869c 100644
--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift
+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift
@@ -1194,10 +1194,10 @@ struct VPhoneCustomFirmwareInstaller {
includeIdentity: Bool,
boardDeviceTree: URL?,
) throws {
- // Like every guest patch, a VM with no plan still gets it — except the
- // identity rewrite on an iPad guest, whose installed tree already
- // carries its own identity from `fw patch`; the rewrite would turn it
- // back into an iPhone17,3.
+ /// Like every guest patch, a VM with no plan still gets it — except the
+ /// identity rewrite on an iPad guest, whose installed tree already
+ /// carries its own identity from `fw patch`; the rewrite would turn it
+ /// back into an iPhone17,3.
func on(_ identifier: String) -> Bool {
let enabled = plan?.isEnabled(identifier) ?? true
if let plan, !enabled {
@@ -1214,7 +1214,7 @@ struct VPhoneCustomFirmwareInstaller {
rewriteIdentity = on(identity)
}
}
- let spoofBuild = includeIdentity ? self.spoofBuild : nil
+ let spoofBuild = includeIdentity ? spoofBuild : nil
var repairs: [(verb: String, arguments: [String])] = []
if let boardDeviceTree, on(FirmwareGuestSystemPatchSet.prebootBoardAudio) {
repairs.append(("patch-dt-board-audio", [boardDeviceTree.path]))
@@ -1432,7 +1432,7 @@ struct VPhoneCustomFirmwareInstaller {
// No --identifier: codesign keeps the one the bundle already carries.
_ = try tool("/usr/bin/codesign", [
"-f", "-s", "-", "--timestamp=none",
- try system.directory(bundle).path,
+ system.directory(bundle).path,
])
}
diff --git a/VPhoneLaunchpad/Tests/LauncherPolicyTests.swift b/VPhoneLaunchpad/Tests/LauncherPolicyTests.swift
index 451d6f22..8daa2e9e 100644
--- a/VPhoneLaunchpad/Tests/LauncherPolicyTests.swift
+++ b/VPhoneLaunchpad/Tests/LauncherPolicyTests.swift
@@ -81,14 +81,16 @@ struct LauncherPolicyTests {
// Only `vm launch <machine>`.
for arguments in [[], ["vm"], ["vm", "launch"], ["vm", "stop", "research-01"],
["launch", "vm", "research-01"], ["--headless", "vm", "launch"],
- ["cfw", "install", "research-01"]] {
+ ["cfw", "install", "research-01"]]
+ {
expectRefused("only `vphone-cli vm launch <machine>`", cli, arguments)
}
// Only the vphone-cli of a bundle directly in the store.
for path in [base + "/outside/VPhone.bundle/Contents/MacOS/vphone-cli", macOS + "/vphone-vm",
store + "/2.4.0/vphone-cli", store + "/a/b/VPhone.bundle/Contents/MacOS/vphone-cli",
- store + "/2.5.0/VPhone.bundle/Contents/MacOS/vphone-cli", "/bin/sh"] {
+ store + "/2.5.0/VPhone.bundle/Contents/MacOS/vphone-cli", "/bin/sh"]
+ {
expectRefused("is not the vphone-cli of a bundle in \(store)", path)
}
expectRefused("is not a regular file", store + "/dir/VPhone.bundle/Contents/MacOS/vphone-cli")
@@ -117,7 +119,7 @@ struct LauncherPolicyTests {
for version in installed.sorted() {
let path = VPhoneLaunchpadBundleStore.executable(version: version, named: "vphone-cli").path
do {
- print("accepted \(try Policy.check(executable: path, arguments: launch))")
+ try print("accepted \(Policy.check(executable: path, arguments: launch))")
} catch {
print("refused \(version): \(error.message)")
}
diff --git a/VPhoneLaunchpad/Tests/LauncherProcessTests.swift b/VPhoneLaunchpad/Tests/LauncherProcessTests.swift
index ac8bb9fc..07571520 100644
--- a/VPhoneLaunchpad/Tests/LauncherProcessTests.swift
+++ b/VPhoneLaunchpad/Tests/LauncherProcessTests.swift
@@ -133,7 +133,7 @@ final class Relay {
}
}
-// /var is a symlink to /private/var; the child reports the physical path.
+/// /var is a symlink to /private/var; the child reports the physical path.
func realPath(_ path: String) -> String {
guard let resolved = realpath(path, nil) else {
return path
diff --git a/VPhoneLaunchpad/VPhoneLaunchpadLauncher/main.swift b/VPhoneLaunchpad/VPhoneLaunchpadLauncher/main.swift
index 24ae3dbe..e64adef3 100644
--- a/VPhoneLaunchpad/VPhoneLaunchpadLauncher/main.swift
+++ b/VPhoneLaunchpad/VPhoneLaunchpadLauncher/main.swift
@@ -46,4 +46,5 @@ do {
} catch {
fail(failedStatus, error.message)
}
+
VPhoneLaunchpadLauncherProcess.exit(withStatusOf: status)