Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

refactor: spell out firmware patcher names

Lakrdd1b9c664c42
diff --git a/sources/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcherGuestPayload.swift b/sources/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcherGuestPayload.swift
index 707552b8..dc723aa7 100644
--- a/sources/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcherGuestPayload.swift
+++ b/sources/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcherGuestPayload.swift
@@ -146,7 +146,7 @@ extension CryptexFilesystemPatcher {
let mobileActivationdPath = target.appending(path: "/usr/libexec/mobileactivationd")
// `resign: false` because the sign below replaces the signature, and
// re-attesting would refuse an unsigned input the Python accepted.
- try CustomFirmwareMobileactivationd.patch(fileAt: mobileActivationdPath, resign: false)
+ try CustomFirmwareMobileActivation.patch(fileAt: mobileActivationdPath, resign: false)
try setMode(0o755, at: mobileActivationdPath)
try VPhoneSigner.sign(
diff --git a/sources/FirmwarePatcher/CustomFirmware/ExecutablePatches/CustomFirmwareDiskimagesiod+ObjCMetadata.swift b/sources/FirmwarePatcher/CustomFirmware/ExecutablePatches/CustomFirmwareDiskimagesiod+ObjCMetadata.swift
index 6d4d75db..a1053d0f 100644
--- a/sources/FirmwarePatcher/CustomFirmware/ExecutablePatches/CustomFirmwareDiskimagesiod+ObjCMetadata.swift
+++ b/sources/FirmwarePatcher/CustomFirmware/ExecutablePatches/CustomFirmwareDiskimagesiod+ObjCMetadata.swift
@@ -1,6 +1,6 @@
import Foundation
-extension CustomFirmwareDiskimagesiod {
+extension CustomFirmwareDiskImage {
// MARK: - ObjC metadata
/// selector cstring → selref → method-list entry → IMP.
diff --git a/sources/FirmwarePatcher/CustomFirmware/ExecutablePatches/CustomFirmwareDiskimagesiod.swift b/sources/FirmwarePatcher/CustomFirmware/ExecutablePatches/CustomFirmwareDiskimagesiod.swift
index 30521d76..2b9f693d 100644
--- a/sources/FirmwarePatcher/CustomFirmware/ExecutablePatches/CustomFirmwareDiskimagesiod.swift
+++ b/sources/FirmwarePatcher/CustomFirmware/ExecutablePatches/CustomFirmwareDiskimagesiod.swift
@@ -77,7 +77,7 @@ import Foundation
/// Forces `-[DIDiskArb isMountCompleteWithExpectedCount:diskTracker:]` to
/// return YES so MobileStorageMounter stops waiting on a mount that will never
/// be reported.
-public enum CustomFirmwareDiskimagesiod {
+public enum CustomFirmwareDiskImage {
// MARK: - Identity
/// The component name the Python records this write under.
@@ -135,7 +135,7 @@ public enum CustomFirmwareDiskimagesiod {
/// True when the site already holds this patch's own output.
public var isAlreadyPatched: Bool {
- original == CustomFirmwareDiskimagesiod.replacement
+ original == CustomFirmwareDiskImage.replacement
}
}
diff --git a/sources/FirmwarePatcher/CustomFirmware/ExecutablePatches/CustomFirmwareMobileactivationd+Anchoring.swift b/sources/FirmwarePatcher/CustomFirmware/ExecutablePatches/CustomFirmwareMobileactivationd+Anchoring.swift
index 0bd45a63..bead1c93 100644
--- a/sources/FirmwarePatcher/CustomFirmware/ExecutablePatches/CustomFirmwareMobileactivationd+Anchoring.swift
+++ b/sources/FirmwarePatcher/CustomFirmware/ExecutablePatches/CustomFirmwareMobileactivationd+Anchoring.swift
@@ -1,6 +1,6 @@
import Foundation
-extension CustomFirmwareMobileactivationd {
+extension CustomFirmwareMobileActivation {
// MARK: - Anchoring
/// Resolve the IMP of ``method``, by symbol and by ObjC metadata.
diff --git a/sources/FirmwarePatcher/CustomFirmware/ExecutablePatches/CustomFirmwareMobileactivationd.swift b/sources/FirmwarePatcher/CustomFirmware/ExecutablePatches/CustomFirmwareMobileactivationd.swift
index 0e6be07c..9cff59a1 100644
--- a/sources/FirmwarePatcher/CustomFirmware/ExecutablePatches/CustomFirmwareMobileactivationd.swift
+++ b/sources/FirmwarePatcher/CustomFirmware/ExecutablePatches/CustomFirmwareMobileactivationd.swift
@@ -57,7 +57,7 @@ import Foundation
/// Forces `-[DeviceType should_hactivate]` to return YES, so the guest
/// self-activates instead of waiting on Apple's activation service.
-public enum CustomFirmwareMobileactivationd {
+public enum CustomFirmwareMobileActivation {
// MARK: - Identity
/// The ObjC method whose result is forced.
diff --git a/sources/FirmwarePatcher/CustomFirmware/ExecutablePatches/CustomFirmwareWatchdogd.swift b/sources/FirmwarePatcher/CustomFirmware/ExecutablePatches/CustomFirmwareWatchdogd.swift
index cbdd0dc9..f21d957f 100644
--- a/sources/FirmwarePatcher/CustomFirmware/ExecutablePatches/CustomFirmwareWatchdogd.swift
+++ b/sources/FirmwarePatcher/CustomFirmware/ExecutablePatches/CustomFirmwareWatchdogd.swift
@@ -93,7 +93,7 @@
import Capstone
import Foundation
-public enum CustomFirmwareWatchdogd {
+public enum CustomFirmwareWatchDog {
// MARK: - Anchors
/// Component name carried by every ``PatchRecord`` this patcher emits.
diff --git a/sources/FirmwarePatcher/CustomFirmware/ExecutablePatches/CustomFirmwareWatchdogdDiscovery.swift b/sources/FirmwarePatcher/CustomFirmware/ExecutablePatches/CustomFirmwareWatchdogdDiscovery.swift
index 9d72f5c9..01cd8fb0 100644
--- a/sources/FirmwarePatcher/CustomFirmware/ExecutablePatches/CustomFirmwareWatchdogdDiscovery.swift
+++ b/sources/FirmwarePatcher/CustomFirmware/ExecutablePatches/CustomFirmwareWatchdogdDiscovery.swift
@@ -3,7 +3,7 @@
import Capstone
import Foundation
-extension CustomFirmwareWatchdogd {
+extension CustomFirmwareWatchDog {
// MARK: - Site discovery
/// Every VM-presence cache site in `data`, pristine or already patched, in
@@ -24,7 +24,7 @@ extension CustomFirmwareWatchdogd {
log?(" [.] cstring at va:0x\(hex(literal.address)) "
+ "(foff:0x\(hex(UInt64(literal.fileOffset))), sect=\(literal.section))")
- guard let symbols = CustomFirmwareWatchdogdSymbolTargets(data: data) else {
+ guard let symbols = CustomFirmwareWatchDogSymbolTargets(data: data) else {
throw PatcherError.invalidFormat(
"no LC_SYMTAB/LC_DYSYMTAB — \(sysctlFunction) cannot be resolved",
)
@@ -105,7 +105,7 @@ extension CustomFirmwareWatchdogd {
literalVMA: UInt64,
text: MachOSectionInfo,
segments: [MachOSegmentInfo],
- symbols: CustomFirmwareWatchdogdSymbolTargets,
+ symbols: CustomFirmwareWatchDogSymbolTargets,
) -> Site? {
// Layer 3: the call, and the import it resolves to.
guard let callIndex = firstIndex(
diff --git a/sources/FirmwarePatcher/CustomFirmware/ExecutablePatches/CustomFirmwareWatchdogdSymbolTargets.swift b/sources/FirmwarePatcher/CustomFirmware/ExecutablePatches/CustomFirmwareWatchdogdSymbolTargets.swift
index 90f786ed..9640d113 100644
--- a/sources/FirmwarePatcher/CustomFirmware/ExecutablePatches/CustomFirmwareWatchdogdSymbolTargets.swift
+++ b/sources/FirmwarePatcher/CustomFirmware/ExecutablePatches/CustomFirmwareWatchdogdSymbolTargets.swift
@@ -19,7 +19,7 @@ import Foundation
/// which that shared parser exposes. It carries this patcher's name because
/// this patcher is its only caller — the first time a second one needs the same
/// lookup, move it to `Binary/` under a neutral name rather than growing a copy.
-struct CustomFirmwareWatchdogdSymbolTargets {
+struct CustomFirmwareWatchDogSymbolTargets {
/// A section of branch-island stubs, one per imported symbol.
struct StubSection {
let address: UInt64
diff --git a/sources/FirmwarePatcher/DyldSharedCache/Patchers/DyldSharedCacheHVVMMPatcher+MachOStringSites.swift b/sources/FirmwarePatcher/DyldSharedCache/Patchers/DyldSharedCacheHVVMMPatcher+MachOStringSites.swift
index 53197418..0878bf65 100644
--- a/sources/FirmwarePatcher/DyldSharedCache/Patchers/DyldSharedCacheHVVMMPatcher+MachOStringSites.swift
+++ b/sources/FirmwarePatcher/DyldSharedCache/Patchers/DyldSharedCacheHVVMMPatcher+MachOStringSites.swift
@@ -1,6 +1,6 @@
import Foundation
-extension DyldSharedCacheHVVMMPatcher {
+extension DyldSharedCacheHypervisorVirtualMachinePatcher {
/// One occurrence of the pristine cstring in a standalone Mach-O.
public struct MachOStringSite: Sendable, Equatable {
/// Address the literal is mapped at.
diff --git a/sources/FirmwarePatcher/DyldSharedCache/Patchers/DyldSharedCacheHVVMMPatcher.swift b/sources/FirmwarePatcher/DyldSharedCache/Patchers/DyldSharedCacheHVVMMPatcher.swift
index b65561c1..e4ed20a8 100644
--- a/sources/FirmwarePatcher/DyldSharedCache/Patchers/DyldSharedCacheHVVMMPatcher.swift
+++ b/sources/FirmwarePatcher/DyldSharedCache/Patchers/DyldSharedCacheHVVMMPatcher.swift
@@ -75,7 +75,7 @@ import Foundation
/// The user-mode `kern.hv_vmm_present` cstring mangle, over a chunked dyld
/// shared cache and over standalone Mach-Os.
-public enum DyldSharedCacheHVVMMPatcher {
+public enum DyldSharedCacheHypervisorVirtualMachinePatcher {
// MARK: - The cstring and its mangle
//
diff --git a/sources/vphone-cli/VPhoneCustomFirmwareDyldSharedCacheVerbsCLI.swift b/sources/vphone-cli/VPhoneCustomFirmwareDyldSharedCacheVerbsCLI.swift
index dffd3dea..2964618b 100644
--- a/sources/vphone-cli/VPhoneCustomFirmwareDyldSharedCacheVerbsCLI.swift
+++ b/sources/vphone-cli/VPhoneCustomFirmwareDyldSharedCacheVerbsCLI.swift
@@ -24,7 +24,7 @@ import Foundation
enum VPhoneCustomFirmwareDyldSharedCacheVerbs {
/// Registered into `vphone-cli cfw` by `VPhoneCustomFirmwareCommand`.
static let all: [ParsableCommand.Type] = [
- VPhoneCustomFirmwarePatchHVVMMDyldSharedCacheCommand.self,
+ VPhoneCustomFirmwarePatchHypervisorVirtualMachineDyldSharedCacheCommand.self,
VPhoneCustomFirmwarePatchIOMFBSwapEndCommand.self,
VPhoneCustomFirmwarePatchIOMFBForceKernCommand.self,
VPhoneCustomFirmwarePatchDyldSharedCacheMaxSlideCommand.self,
@@ -64,7 +64,7 @@ enum VPhoneCustomFirmwareDyldSharedCacheVerbs {
// MARK: - patch-hv-vmm-dsc
-struct VPhoneCustomFirmwarePatchHVVMMDyldSharedCacheCommand: ParsableCommand {
+struct VPhoneCustomFirmwarePatchHypervisorVirtualMachineDyldSharedCacheCommand: ParsableCommand {
static let configuration = CommandConfiguration(
commandName: "patch-hv-vmm-dsc",
abstract: "Mangle the \"kern.hv_vmm_present\" sysctl name in the userland dyld cache",
@@ -100,7 +100,7 @@ struct VPhoneCustomFirmwarePatchHVVMMDyldSharedCacheCommand: ParsableCommand {
var dryRun = false
func run() throws {
- try DyldSharedCacheHVVMMPatcher.patch(
+ try DyldSharedCacheHypervisorVirtualMachinePatcher.patch(
chunksDirectory: chunksDirectory,
dryRun: dryRun,
log: VPhoneCustomFirmwareDyldSharedCacheVerbs.stdout,
diff --git a/sources/vphone-cli/VPhoneCustomFirmwareMachOVerbsCLI.swift b/sources/vphone-cli/VPhoneCustomFirmwareMachOVerbsCLI.swift
index fb11f28a..bb412e4e 100644
--- a/sources/vphone-cli/VPhoneCustomFirmwareMachOVerbsCLI.swift
+++ b/sources/vphone-cli/VPhoneCustomFirmwareMachOVerbsCLI.swift
@@ -189,7 +189,7 @@ struct VPhoneCustomFirmwarePatchMobileactivationdCommand: ParsableCommand {
func run() throws {
try requireUntruncatedMachO(at: binary)
// resign: false — the Python's bytes, for the `ldid_sign` that follows.
- try CustomFirmwareMobileactivationd.patch(fileAt: binary, resign: false, log: machOVerbLog)
+ try CustomFirmwareMobileActivation.patch(fileAt: binary, resign: false, log: machOVerbLog)
}
}
@@ -260,7 +260,7 @@ struct VPhoneCustomFirmwarePatchWatchdogdCommand: ParsableCommand {
func run() throws {
try requireUntruncatedMachO(at: binary)
- try CustomFirmwareWatchdogd.patch(at: binary, dryRun: dryRun, log: machOVerbLog)
+ try CustomFirmwareWatchDog.patch(at: binary, dryRun: dryRun, log: machOVerbLog)
}
}
@@ -291,7 +291,7 @@ struct VPhoneCustomFirmwarePatchDiskimagesiodCommand: ParsableCommand {
try requireUntruncatedMachO(at: binary)
// Off in the library and off in the Python: cfw_install.sh re-signs
// with the extracted com.apple.diskimagesiod entitlements right after.
- try CustomFirmwareDiskimagesiod.patch(fileAt: binary, reattest: false, log: machOVerbLog)
+ try CustomFirmwareDiskImage.patch(fileAt: binary, reattest: false, log: machOVerbLog)
}
}
diff --git a/tests/FirmwarePatcherTests/CustomFirmwareDiskimagesiodTests.swift b/tests/FirmwarePatcherTests/CustomFirmwareDiskimagesiodTests.swift
index 72515f3b..8822611e 100644
--- a/tests/FirmwarePatcherTests/CustomFirmwareDiskimagesiodTests.swift
+++ b/tests/FirmwarePatcherTests/CustomFirmwareDiskimagesiodTests.swift
@@ -302,7 +302,7 @@ private enum DiskImagesComparison {
// MARK: - The replacement bytes
@Suite("diskimagesiod replacement encoding")
-struct CustomFirmwareDiskimagesiodEncodingTests {
+struct CustomFirmwareDiskImageEncodingTests {
@Test
func `mov x0, #1 built from ISA fields is the keystone-verified constant`() throws {
let encoded = try #require(ARM64Encoder.encodeMovzX(rd: 0, imm16: 1))
@@ -313,10 +313,10 @@ struct CustomFirmwareDiskimagesiodEncodingTests {
@Test
func `the patch writes exactly mov x0, #1 ; ret`() {
- #expect(CustomFirmwareDiskimagesiod.replacement.count == 8)
- #expect(CustomFirmwareDiskimagesiod.replacement == ARM64.movX0_1 + ARM64.ret)
+ #expect(CustomFirmwareDiskImage.replacement.count == 8)
+ #expect(CustomFirmwareDiskImage.replacement == ARM64.movX0_1 + ARM64.ret)
#expect(
- CustomFirmwareDiskimagesiod.disassemblyText(of: CustomFirmwareDiskimagesiod.replacement, at: nil)
+ CustomFirmwareDiskImage.disassemblyText(of: CustomFirmwareDiskImage.replacement, at: nil)
== "mov x0, #1; ret",
)
}
@@ -329,17 +329,17 @@ struct CustomFirmwareDiskimagesiodEncodingTests {
.enabled(if: DiskImagesFixture.runs, DiskImagesFixture.missing),
.serialized,
)
-struct CustomFirmwareDiskimagesiodAnchorTests {
+struct CustomFirmwareDiskImageAnchorTests {
@Test
func `the IMP resolves through the relative method list, into __TEXT,__text`() throws {
let pristine = try #require(DiskImagesFixture.pristine, DiskImagesFixture.missing)
let data = try Data(contentsOf: pristine)
- let site = try CustomFirmwareDiskimagesiod.locate(in: data)
+ let site = try CustomFirmwareDiskImage.locate(in: data)
// Shipped diskimagesiod is stripped, so the symbol-table anchor misses
// and the ObjC metadata walk is what answers.
#expect(site.anchor == .relativeMethodList)
- #expect(MachOParser.findSymbol(containing: CustomFirmwareDiskimagesiod.symbolFragment, in: data) == nil)
+ #expect(MachOParser.findSymbol(containing: CustomFirmwareDiskImage.symbolFragment, in: data) == nil)
let sections = MachOParser.parseSections(from: data)
let text = try #require(sections["__TEXT,__text"])
@@ -353,7 +353,7 @@ struct CustomFirmwareDiskimagesiodAnchorTests {
// A real ObjC method prologue, not yet patched.
#expect(!site.isAlreadyPatched)
- #expect(CustomFirmwareDiskimagesiod.disassemblyText(of: site.original, at: va)
+ #expect(CustomFirmwareDiskImage.disassemblyText(of: site.original, at: va)
.hasPrefix("pacibsp; stp"))
}
@@ -373,7 +373,7 @@ struct CustomFirmwareDiskimagesiodAnchorTests {
@Test
func `the reference's own anchor walk agreed on the same offset`() throws {
let pristine = try #require(DiskImagesFixture.pristine, DiskImagesFixture.missing)
- let site = try CustomFirmwareDiskimagesiod.locate(in: Data(contentsOf: pristine))
+ let site = try CustomFirmwareDiskImage.locate(in: Data(contentsOf: pristine))
// The offset the Python printed; both walks must land on it.
#expect(site.fileOffset == DiskImagesGolden.impFileOffset)
@@ -387,24 +387,24 @@ struct CustomFirmwareDiskimagesiodAnchorTests {
let sections = MachOParser.parseSections(from: data)
let selectorVA = try #require(
- CustomFirmwareDiskimagesiod.selectorStringVA(in: data, sections: sections),
+ CustomFirmwareDiskImage.selectorStringVA(in: data, sections: sections),
)
let selrefs = try #require(sections["__DATA,__objc_selrefs"])
- let selrefVA = try #require(CustomFirmwareDiskimagesiod.selectorReferenceVA(
+ let selrefVA = try #require(CustomFirmwareDiskImage.selectorReferenceVA(
in: data,
selrefs: selrefs,
selectorVA: selectorVA,
- imageBase: CustomFirmwareDiskimagesiod.imageBase(sections),
+ imageBase: CustomFirmwareDiskImage.imageBase(sections),
))
let methlist = try #require(sections["__TEXT,__objc_methlist"])
- let imps = CustomFirmwareDiskimagesiod.relativeMethodListIMPs(
+ let imps = CustomFirmwareDiskImage.relativeMethodListIMPs(
in: data,
section: methlist,
naming: [selectorVA, selrefVA],
)
#expect(imps.count == 1)
- #expect(try imps.first == (CustomFirmwareDiskimagesiod.locate(in: data)).virtualAddress)
+ #expect(try imps.first == (CustomFirmwareDiskImage.locate(in: data)).virtualAddress)
}
@Test
@@ -414,14 +414,14 @@ struct CustomFirmwareDiskimagesiodAnchorTests {
let sections = MachOParser.parseSections(from: data)
let selectorVA = try #require(
- CustomFirmwareDiskimagesiod.selectorStringVA(in: data, sections: sections),
+ CustomFirmwareDiskImage.selectorStringVA(in: data, sections: sections),
)
let selrefs = try #require(sections["__DATA,__objc_selrefs"])
- let selrefVA = try #require(CustomFirmwareDiskimagesiod.selectorReferenceVA(
+ let selrefVA = try #require(CustomFirmwareDiskImage.selectorReferenceVA(
in: data,
selrefs: selrefs,
selectorVA: selectorVA,
- imageBase: CustomFirmwareDiskimagesiod.imageBase(sections),
+ imageBase: CustomFirmwareDiskImage.imageBase(sections),
))
let methlist = try #require(sections["__TEXT,__objc_methlist"])
let targets: Set<UInt64> = [selectorVA, selrefVA]
@@ -430,12 +430,12 @@ struct CustomFirmwareDiskimagesiodAnchorTests {
// section have to name the same single implementation, or the two
// implementations would have diverged on some other firmware even
// though they agreed on this one.
- let structural = CustomFirmwareDiskimagesiod.relativeMethodListIMPs(
+ let structural = CustomFirmwareDiskImage.relativeMethodListIMPs(
in: data,
section: methlist,
naming: targets,
)
- let strided = CustomFirmwareDiskimagesiod.scanRelativeMethodEntryIMPs(
+ let strided = CustomFirmwareDiskImage.scanRelativeMethodEntryIMPs(
in: data,
section: methlist,
naming: targets,
@@ -449,7 +449,7 @@ struct CustomFirmwareDiskimagesiodAnchorTests {
let unrelated = try #require(DiskImagesFixture.unrelated, DiskImagesFixture.missing)
let data = try Data(contentsOf: unrelated)
#expect(throws: PatcherError.self) {
- try CustomFirmwareDiskimagesiod.locate(in: data)
+ try CustomFirmwareDiskImage.locate(in: data)
}
}
}
@@ -461,13 +461,13 @@ struct CustomFirmwareDiskimagesiodAnchorTests {
.enabled(if: DiskImagesFixture.runs, DiskImagesFixture.missing),
.serialized,
)
-struct CustomFirmwareDiskimagesiodParityTests {
+struct CustomFirmwareDiskImageParityTests {
@Test
func `Swift reproduces the reference's bytes, one site each`() throws {
let swiftClone = try DiskImagesFixture.clone(named: "swift")
defer { DiskImagesFixture.discard(swiftClone) }
- let report = try CustomFirmwareDiskimagesiod.patch(fileAt: swiftClone, log: nil)
+ let report = try CustomFirmwareDiskImage.patch(fileAt: swiftClone, log: nil)
#expect(report.outcome == .patched)
#expect(report.sitesWritten == 1)
// Off by default: `cfw_install.sh` re-signs with ldid straight after,
@@ -486,7 +486,7 @@ struct CustomFirmwareDiskimagesiodParityTests {
let clone = try DiskImagesFixture.clone(named: "record")
defer { DiskImagesFixture.discard(clone) }
- let report = try CustomFirmwareDiskimagesiod.patch(fileAt: clone, log: nil)
+ let report = try CustomFirmwareDiskImage.patch(fileAt: clone, log: nil)
let record = try #require(report.record)
#expect(record.patchID == "diskimagesiod.is_mount_complete")
@@ -494,7 +494,7 @@ struct CustomFirmwareDiskimagesiodParityTests {
#expect(record.fileOffset == report.site.fileOffset)
#expect(record.virtualAddress == report.site.virtualAddress)
#expect(record.originalBytes == report.site.original)
- #expect(record.patchedBytes == CustomFirmwareDiskimagesiod.replacement)
+ #expect(record.patchedBytes == CustomFirmwareDiskImage.replacement)
#expect(record.afterDisasm == "mov x0, #1; ret")
#expect(record.beforeDisasm.hasPrefix("pacibsp"))
#expect(record.patchDescription.contains("isMountCompleteWithExpectedCount:diskTracker:"))
@@ -511,7 +511,7 @@ struct CustomFirmwareDiskimagesiodParityTests {
defer { DiskImagesFixture.discard(clone) }
let pristine = try #require(DiskImagesFixture.pristine, DiskImagesFixture.missing)
- let report = try CustomFirmwareDiskimagesiod.patch(fileAt: clone, log: nil)
+ let report = try CustomFirmwareDiskImage.patch(fileAt: clone, log: nil)
let differences = try DiskImagesComparison.differences(
between: pristine,
and: clone,
@@ -531,7 +531,7 @@ struct CustomFirmwareDiskimagesiodParityTests {
.enabled(if: DiskImagesFixture.runs, DiskImagesFixture.missing),
.serialized,
)
-struct CustomFirmwareDiskimagesiodReattestTests {
+struct CustomFirmwareDiskImageReattestTests {
@Test
func `the fixture really does have the short tail slot this path regressed on`() throws {
let pristine = try #require(DiskImagesFixture.pristine, DiskImagesFixture.missing)
@@ -554,10 +554,10 @@ struct CustomFirmwareDiskimagesiodReattestTests {
let attested = try DiskImagesFixture.clone(named: "attested")
defer { DiskImagesFixture.discard(bare, attested) }
- try CustomFirmwareDiskimagesiod.patch(fileAt: bare, log: nil)
+ try CustomFirmwareDiskImage.patch(fileAt: bare, log: nil)
#expect(try DiskImagesFixture.codesignVerify(bare).status != 0)
- let report = try CustomFirmwareDiskimagesiod.patch(fileAt: attested, reattest: true, log: nil)
+ let report = try CustomFirmwareDiskImage.patch(fileAt: attested, reattest: true, log: nil)
#expect(report.outcome == .patched)
#expect(report.rehashes.count == 1)
@@ -575,7 +575,7 @@ struct CustomFirmwareDiskimagesiodReattestTests {
let swiftClone = try DiskImagesFixture.clone(named: "swift-attested")
defer { DiskImagesFixture.discard(swiftClone) }
- let report = try CustomFirmwareDiskimagesiod.patch(fileAt: swiftClone, reattest: true, log: nil)
+ let report = try CustomFirmwareDiskImage.patch(fileAt: swiftClone, reattest: true, log: nil)
#expect(report.rehashes.first?.pageIndex == DiskImagesGolden.reattestedSlot)
#expect(
try DiskImagesFixture.digest(of: swiftClone) == DiskImagesGolden.patchedAndReattested,
@@ -624,17 +624,17 @@ struct CustomFirmwareDiskimagesiodReattestTests {
.enabled(if: DiskImagesFixture.runs, DiskImagesFixture.missing),
.serialized,
)
-struct CustomFirmwareDiskimagesiodIdempotenceTests {
+struct CustomFirmwareDiskImageIdempotenceTests {
@Test
func `a second Swift run recognises its own output and writes nothing`() throws {
let clone = try DiskImagesFixture.clone(named: "twice")
defer { DiskImagesFixture.discard(clone) }
- try CustomFirmwareDiskimagesiod.patch(fileAt: clone, log: nil)
+ try CustomFirmwareDiskImage.patch(fileAt: clone, log: nil)
let afterFirst = try Data(contentsOf: clone)
let attributes = try FileManager.default.attributesOfItem(atPath: clone.path)
- let second = try CustomFirmwareDiskimagesiod.patch(fileAt: clone, log: nil)
+ let second = try CustomFirmwareDiskImage.patch(fileAt: clone, log: nil)
#expect(second.outcome == .alreadyPatched)
#expect(second.sitesWritten == 0)
#expect(second.record == nil)
@@ -651,10 +651,10 @@ struct CustomFirmwareDiskimagesiodIdempotenceTests {
let clone = try DiskImagesFixture.clone(named: "twice-attested")
defer { DiskImagesFixture.discard(clone) }
- try CustomFirmwareDiskimagesiod.patch(fileAt: clone, reattest: true, log: nil)
+ try CustomFirmwareDiskImage.patch(fileAt: clone, reattest: true, log: nil)
let afterFirst = try Data(contentsOf: clone)
- let second = try CustomFirmwareDiskimagesiod.patch(fileAt: clone, reattest: true, log: nil)
+ let second = try CustomFirmwareDiskImage.patch(fileAt: clone, reattest: true, log: nil)
#expect(second.outcome == .alreadyPatched)
#expect(second.sitesWritten == 0)
#expect(second.rehashes.isEmpty, "the stored slot hashes were already current")
@@ -677,13 +677,13 @@ struct CustomFirmwareDiskimagesiodIdempotenceTests {
defer { DiskImagesFixture.discard(referenceOutput) }
// Reproduce the reference's output, and prove it is that, by digest.
- try CustomFirmwareDiskimagesiod.patch(fileAt: referenceOutput, log: nil)
+ try CustomFirmwareDiskImage.patch(fileAt: referenceOutput, log: nil)
try #require(
try DiskImagesFixture.digest(of: referenceOutput) == DiskImagesGolden.patched,
)
#expect(DiskImagesGolden.patchedTwice == DiskImagesGolden.patched)
- let report = try CustomFirmwareDiskimagesiod.patch(fileAt: referenceOutput, log: nil)
+ let report = try CustomFirmwareDiskImage.patch(fileAt: referenceOutput, log: nil)
#expect(report.outcome == .alreadyPatched)
#expect(try DiskImagesFixture.digest(of: referenceOutput) == DiskImagesGolden.patched)
}
@@ -694,7 +694,7 @@ struct CustomFirmwareDiskimagesiodIdempotenceTests {
defer { DiskImagesFixture.discard(clone) }
let pristine = try #require(DiskImagesFixture.pristine, DiskImagesFixture.missing)
- let report = try CustomFirmwareDiskimagesiod.patch(fileAt: clone, reattest: true, dryRun: true, log: nil)
+ let report = try CustomFirmwareDiskImage.patch(fileAt: clone, reattest: true, dryRun: true, log: nil)
#expect(report.outcome == .wouldPatch)
#expect(report.sitesWritten == 0)
#expect(report.rehashes.isEmpty)
diff --git a/tests/FirmwarePatcherTests/CustomFirmwareMobileactivationdTests.swift b/tests/FirmwarePatcherTests/CustomFirmwareMobileactivationdTests.swift
index 3ea205e0..d7ae8281 100644
--- a/tests/FirmwarePatcherTests/CustomFirmwareMobileactivationdTests.swift
+++ b/tests/FirmwarePatcherTests/CustomFirmwareMobileactivationdTests.swift
@@ -158,14 +158,14 @@ enum MobileactivationdGolden {
/// `VPHONE_PATCH_RESIGN=0` skips re-attestation, which is what reproduces
/// ``MobileactivationdGolden/patched`` exactly.
@Suite("mobileactivationd should_hactivate — shell runner")
-struct CustomFirmwareMobileactivationdRunnerTests {
+struct CustomFirmwareMobileActivationRunnerTests {
@Test(.enabled(if: ProcessInfo.processInfo.environment["VPHONE_PATCH_FILE"] != nil))
func `run patcher from environment`() throws {
let environment = ProcessInfo.processInfo.environment
let path = try #require(environment["VPHONE_PATCH_FILE"])
let resign = environment["VPHONE_PATCH_RESIGN"] != "0"
- let report = try CustomFirmwareMobileactivationd.patch(fileAt: URL(filePath: path), resign: resign)
+ let report = try CustomFirmwareMobileActivation.patch(fileAt: URL(filePath: path), resign: resign)
print(
"RUNNER outcome=\(report.outcome.rawValue)"
@@ -187,7 +187,7 @@ struct CustomFirmwareMobileactivationdRunnerTests {
// MARK: - Anchoring
@Suite("mobileactivationd should_hactivate — anchoring")
-struct CustomFirmwareMobileactivationdAnchorTests {
+struct CustomFirmwareMobileActivationAnchorTests {
/// The two routes are independent — `LC_SYMTAB` on one side, the
/// `__objc_methname` -> `__objc_selrefs` -> relative method list walk on the
/// other — and they agree. That agreement is the evidence the anchor is the
@@ -198,16 +198,16 @@ struct CustomFirmwareMobileactivationdAnchorTests {
let segments = MachOParser.parseSegments(from: data)
let bySymbol = try #require(
- CustomFirmwareMobileactivationd.symbolVirtualAddress(in: data),
+ CustomFirmwareMobileActivation.symbolVirtualAddress(in: data),
"LC_SYMTAB should carry -[DeviceType should_hactivate]",
)
let byMetadata = try #require(
- CustomFirmwareMobileactivationd.objcMetadataVirtualAddress(in: data, segments: segments),
+ CustomFirmwareMobileActivation.objcMetadataVirtualAddress(in: data, segments: segments),
"the ObjC method lists should carry the same IMP",
)
#expect(bySymbol == byMetadata)
- let anchor = try CustomFirmwareMobileactivationd.locateIMP(in: data)
+ let anchor = try CustomFirmwareMobileActivation.locateIMP(in: data)
#expect(anchor.source == .symbolTableAndObjCMetadata)
#expect(anchor.virtualAddress == bySymbol)
#expect(anchor.section == "__TEXT,__text", "the IMP must be code, not data")
@@ -229,7 +229,7 @@ struct CustomFirmwareMobileactivationdAnchorTests {
let data = try Data(contentsOf: MobileactivationdFixture.pristine)
let sections = MachOParser.parseSections(from: data)
let selectorVA = try #require(
- CustomFirmwareMobileactivationd.selectorVirtualAddress(in: data, sections: sections),
+ CustomFirmwareMobileActivation.selectorVirtualAddress(in: data, sections: sections),
)
let methname = try #require(sections["__TEXT,__objc_methname"])
@@ -239,7 +239,7 @@ struct CustomFirmwareMobileactivationdAnchorTests {
// That naive search finds an earlier, wrong offset on this binary — so
// this is not an assertion that passes either way.
- let needle = Data(CustomFirmwareMobileactivationd.selector.utf8) + Data([0])
+ let needle = Data(CustomFirmwareMobileActivation.selector.utf8) + Data([0])
let naive = try #require(data.range(of: needle)?.lowerBound)
#expect(naive < offset)
#expect(data[naive - 1] == UInt8(ascii: "_"))
@@ -251,7 +251,7 @@ struct CustomFirmwareMobileactivationdAnchorTests {
func `missing method throws`() throws {
let data = try Data(contentsOf: MobileactivationdFixture.launchd)
#expect(throws: PatcherError.self) {
- try CustomFirmwareMobileactivationd.locateIMP(in: data)
+ try CustomFirmwareMobileActivation.locateIMP(in: data)
}
}
@@ -260,7 +260,7 @@ struct CustomFirmwareMobileactivationdAnchorTests {
/// patch asks it for the right instruction, and that the pair reads back as
/// `mov x0, #1 ; ret`.
@Test func `replacement is mov X 0 one then ret`() throws {
- let bytes = try CustomFirmwareMobileactivationd.replacementBytes()
+ let bytes = try CustomFirmwareMobileActivation.replacementBytes()
#expect(bytes.count == 8)
#expect(bytes == ARM64.movX0_1 + ARM64.ret)
@@ -278,14 +278,14 @@ struct CustomFirmwareMobileactivationdAnchorTests {
/// Both words of the getter are re-hashed, so a getter that straddles a
/// page boundary does not leave the second page's slot stale.
@Test func `touched offsets cover both words`() throws {
- let anchor = CustomFirmwareMobileactivationd.Anchor(
+ let anchor = CustomFirmwareMobileActivation.Anchor(
virtualAddress: 0x1_0000_0FFC,
fileOffset: 0xFFC,
source: .symbolTable,
section: "__TEXT,__text",
)
- let bytes = try CustomFirmwareMobileactivationd.replacementBytes()
- let offsets = CustomFirmwareMobileactivationd.touchedOffsets(anchor, bytes)
+ let bytes = try CustomFirmwareMobileActivation.replacementBytes()
+ let offsets = CustomFirmwareMobileActivation.touchedOffsets(anchor, bytes)
#expect(offsets == [0xFFC, 0x1000])
#expect(Set(offsets.map { $0 / 4096 }).count == 2, "the two words are on different pages")
}
@@ -294,7 +294,7 @@ struct CustomFirmwareMobileactivationdAnchorTests {
// MARK: - Byte parity with the frozen reference
@Suite("mobileactivationd should_hactivate — parity and idempotence")
-struct CustomFirmwareMobileactivationdParityTests {
+struct CustomFirmwareMobileActivationParityTests {
/// The fixture the frozen digests were taken over. Without this a digest
/// mismatch below would read as a patcher bug when the real cause is a
/// different firmware's `mobileactivationd`.
@@ -320,7 +320,7 @@ struct CustomFirmwareMobileactivationdParityTests {
func `matches the frozen reference bytes`() throws {
let swiftFile = try MobileactivationdFixture.copyOfPristine(named: "swift.bin")
- let report = try CustomFirmwareMobileactivationd.patch(fileAt: swiftFile, resign: false, log: nil)
+ let report = try CustomFirmwareMobileActivation.patch(fileAt: swiftFile, resign: false, log: nil)
#expect(report.outcome == .patched)
#expect(report.sitesWritten == 1)
@@ -354,7 +354,7 @@ struct CustomFirmwareMobileactivationdParityTests {
func `reattested output matches the frozen reference and verifies`() throws {
let swiftFile = try MobileactivationdFixture.copyOfPristine(named: "swift-resigned.bin")
- let report = try CustomFirmwareMobileactivationd.patch(fileAt: swiftFile, resign: true, log: nil)
+ let report = try CustomFirmwareMobileActivation.patch(fileAt: swiftFile, resign: true, log: nil)
let rehash = try #require(report.slotRehashes.first)
#expect(report.slotRehashes.count == 1)
#expect(rehash.pageIndex == MobileactivationdGolden.reattestedSlot)
@@ -376,7 +376,7 @@ struct CustomFirmwareMobileactivationdParityTests {
// The contrast: without re-attestation it is rejected.
let unsigned = try MobileactivationdFixture.copyOfPristine(named: "swift-unsigned.bin")
- try CustomFirmwareMobileactivationd.patch(fileAt: unsigned, resign: false, log: nil)
+ try CustomFirmwareMobileActivation.patch(fileAt: unsigned, resign: false, log: nil)
let rejected = try MobileactivationdFixture.run(
MobileactivationdFixture.codesign, ["-v", unsigned.path],
)
@@ -390,11 +390,11 @@ struct CustomFirmwareMobileactivationdParityTests {
func `second run changes nothing`() throws {
let file = try MobileactivationdFixture.copyOfPristine(named: "swift-idempotent.bin")
- let first = try CustomFirmwareMobileactivationd.patch(fileAt: file, log: nil)
+ let first = try CustomFirmwareMobileActivation.patch(fileAt: file, log: nil)
#expect(first.outcome == .patched)
let afterFirst = try Data(contentsOf: file)
- let second = try CustomFirmwareMobileactivationd.patch(fileAt: file, log: nil)
+ let second = try CustomFirmwareMobileActivation.patch(fileAt: file, log: nil)
#expect(second.outcome == .alreadyPatched)
#expect(second.sitesWritten == 0)
#expect(second.record == nil)
@@ -402,7 +402,7 @@ struct CustomFirmwareMobileactivationdParityTests {
#expect(second.anchor == first.anchor)
#expect(try Data(contentsOf: file) == afterFirst)
- let third = try CustomFirmwareMobileactivationd.patch(fileAt: file, log: nil)
+ let third = try CustomFirmwareMobileActivation.patch(fileAt: file, log: nil)
#expect(third.outcome == .alreadyPatched)
#expect(try Data(contentsOf: file) == afterFirst)
}
@@ -414,9 +414,9 @@ struct CustomFirmwareMobileactivationdParityTests {
@Test(.enabled(if: MobileactivationdFixture.hasPristine))
func `rerun repairs A stale slot`() throws {
let file = try MobileactivationdFixture.copyOfPristine(named: "swift-stale-slot.bin")
- try CustomFirmwareMobileactivationd.patch(fileAt: file, resign: false, log: nil)
+ try CustomFirmwareMobileActivation.patch(fileAt: file, resign: false, log: nil)
- let repaired = try CustomFirmwareMobileactivationd.patch(fileAt: file, resign: true, log: nil)
+ let repaired = try CustomFirmwareMobileActivation.patch(fileAt: file, resign: true, log: nil)
#expect(repaired.outcome == .alreadyPatched)
#expect(repaired.slotRehashes.count == 1, "the stale slot must be recomputed")
#expect(repaired.record == nil, "no code bytes changed the second time")
@@ -428,7 +428,7 @@ struct CustomFirmwareMobileactivationdParityTests {
let file = try MobileactivationdFixture.copyOfPristine(named: "swift-dry-run.bin")
let before = try Data(contentsOf: file)
- let report = try CustomFirmwareMobileactivationd.patch(fileAt: file, dryRun: true, log: nil)
+ let report = try CustomFirmwareMobileActivation.patch(fileAt: file, dryRun: true, log: nil)
#expect(report.outcome == .wouldPatch)
#expect(report.sitesWritten == 0)
#expect(report.anchor.section == "__TEXT,__text")
diff --git a/tests/FirmwarePatcherTests/CustomFirmwareWatchdogdTests.swift b/tests/FirmwarePatcherTests/CustomFirmwareWatchdogdTests.swift
index 0cd189c8..3ef40267 100644
--- a/tests/FirmwarePatcherTests/CustomFirmwareWatchdogdTests.swift
+++ b/tests/FirmwarePatcherTests/CustomFirmwareWatchdogdTests.swift
@@ -6,7 +6,7 @@
// * `scripts/patchers/cfw_patch_watchdogd.py`, driven exactly as
// `cfw_install_exp.sh` drove it (`cfw.py patch-watchdogd <binary>`). That
// Python is gone; what it wrote over the pristine binary is frozen in
-// ``WatchdogdGolden`` below, and the central test grades `CustomFirmwareWatchdogd`
+// ``WatchdogdGolden`` below, and the central test grades `CustomFirmwareWatchDog`
// against it byte for byte — patched instructions and re-attested code
// slots alike, because that verb re-attested on its own.
// * `/usr/bin/codesign`, which recomputes the slot hashes itself. It has no
@@ -103,7 +103,7 @@ enum WatchdogdFixture {
/// calls" is measured against an independent count.
static func sysctlCallSites(in data: Data) throws -> [UInt64] {
let text = try text(in: data)
- guard let symbols = CustomFirmwareWatchdogdSymbolTargets(data: data) else {
+ guard let symbols = CustomFirmwareWatchDogSymbolTargets(data: data) else {
throw PatcherError.invalidFormat("fixture has no symbol table")
}
let start = Int(text.fileOffset)
@@ -114,7 +114,7 @@ enum WatchdogdFixture {
where instruction.mnemonic == "bl"
{
guard let target = ARM64Encoder.decodeBranchTarget(
- insn: CustomFirmwareWatchdogd.word(of: instruction),
+ insn: CustomFirmwareWatchDog.word(of: instruction),
pc: instruction.address,
) else { continue }
if symbols.name(forBranchTarget: target) == "_sysctlbyname" {
@@ -160,12 +160,12 @@ enum WatchdogdGolden {
// MARK: - Anchoring
@Suite("watchdogd hv_vmm_present cache — anchoring")
-struct CustomFirmwareWatchdogdAnchorTests {
+struct CustomFirmwareWatchDogAnchorTests {
/// The shape the patch is written against, read off the real binary.
@Test(.enabled(if: WatchdogdFixture.hasWatchdogd))
func `locates both cache sites`() throws {
let data = try Data(contentsOf: WatchdogdFixture.watchdogd)
- let sites = try CustomFirmwareWatchdogd.locateSites(in: data)
+ let sites = try CustomFirmwareWatchDog.locateSites(in: data)
#expect(sites.count == 2, "24A435 watchdogd caches the answer in two functions")
for site in sites {
@@ -191,7 +191,7 @@ struct CustomFirmwareWatchdogdAnchorTests {
@Test(.enabled(if: WatchdogdFixture.hasWatchdogd))
func `cached byte lives in zero filled data`() throws {
let data = try Data(contentsOf: WatchdogdFixture.watchdogd)
- let sites = try CustomFirmwareWatchdogd.locateSites(in: data)
+ let sites = try CustomFirmwareWatchDog.locateSites(in: data)
let sections = MachOParser.parseSections(from: data)
let zeroFilled = ["__DATA,__bss", "__DATA,__common"].compactMap { sections[$0] }
#expect(!zeroFilled.isEmpty)
@@ -212,7 +212,7 @@ struct CustomFirmwareWatchdogdAnchorTests {
func `rejects the other sysctl call sites`() throws {
let data = try Data(contentsOf: WatchdogdFixture.watchdogd)
let calls = try WatchdogdFixture.sysctlCallSites(in: data)
- let sites = try CustomFirmwareWatchdogd.locateSites(in: data)
+ let sites = try CustomFirmwareWatchDog.locateSites(in: data)
#expect(calls.count == 5, "24A435 watchdogd calls sysctlbyname five times")
#expect(sites.count == 2)
@@ -227,8 +227,8 @@ struct CustomFirmwareWatchdogdAnchorTests {
@Test(.enabled(if: WatchdogdFixture.hasWatchdogd))
func `resolves the import through the indirect symbol table`() throws {
let data = try Data(contentsOf: WatchdogdFixture.watchdogd)
- let symbols = try #require(CustomFirmwareWatchdogdSymbolTargets(data: data))
- let sites = try CustomFirmwareWatchdogd.locateSites(in: data)
+ let symbols = try #require(CustomFirmwareWatchDogSymbolTargets(data: data))
+ let sites = try CustomFirmwareWatchDog.locateSites(in: data)
let call = try #require(sites.first)
let target = try #require(ARM64Encoder.decodeBranchTarget(
@@ -270,28 +270,28 @@ struct CustomFirmwareWatchdogdAnchorTests {
}
// add x9, … ; mov x0, x9 ; bl — the literal is the call's argument.
- #expect(try CustomFirmwareWatchdogd.passesLiteral(
+ #expect(try CustomFirmwareWatchDog.passesLiteral(
inRegister: "x9",
from: 1,
toCallAt: 3,
in: stream(movingInto: 0),
))
// The same shape moving into x1 is some other call's argument.
- #expect(try !CustomFirmwareWatchdogd.passesLiteral(
+ #expect(try !CustomFirmwareWatchDog.passesLiteral(
inRegister: "x9",
from: 1,
toCallAt: 3,
in: stream(movingInto: 1),
))
// No move at all, and the pointer never reaches x0.
- #expect(try !CustomFirmwareWatchdogd.passesLiteral(
+ #expect(try !CustomFirmwareWatchDog.passesLiteral(
inRegister: "x9",
from: 1,
toCallAt: 3,
in: stream(movingInto: nil),
))
// The direct form the shipped binary uses needs no move.
- #expect(try CustomFirmwareWatchdogd.passesLiteral(
+ #expect(try CustomFirmwareWatchDog.passesLiteral(
inRegister: "x0",
from: 1,
toCallAt: 3,
@@ -306,7 +306,7 @@ struct CustomFirmwareWatchdogdAnchorTests {
func `rejects A binary without the cache site`() throws {
let data = try Data(contentsOf: WatchdogdFixture.seputil)
#expect(throws: PatcherError.self) {
- try CustomFirmwareWatchdogd.locateSites(in: data)
+ try CustomFirmwareWatchDog.locateSites(in: data)
}
}
}
@@ -314,13 +314,13 @@ struct CustomFirmwareWatchdogdAnchorTests {
// MARK: - Patching
@Suite("watchdogd hv_vmm_present cache — patching")
-struct CustomFirmwareWatchdogdPatchTests {
+struct CustomFirmwareWatchDogPatchTests {
/// Both instructions, and nothing else in `__TEXT`.
@Test(.enabled(if: WatchdogdFixture.hasWatchdogd))
func `rewrites two instructions per site`() throws {
let original = try Data(contentsOf: WatchdogdFixture.watchdogd)
var data = original
- let report = try CustomFirmwareWatchdogd.patch(&data, log: nil)
+ let report = try CustomFirmwareWatchDog.patch(&data, log: nil)
#expect(report.outcome == .patched)
#expect(report.sitesWritten == 2)
@@ -351,7 +351,7 @@ struct CustomFirmwareWatchdogdPatchTests {
@Test(.enabled(if: WatchdogdFixture.hasWatchdogd))
func `reattests the page of every written instruction`() throws {
var data = try Data(contentsOf: WatchdogdFixture.watchdogd)
- let report = try CustomFirmwareWatchdogd.patch(&data, log: nil)
+ let report = try CustomFirmwareWatchDog.patch(&data, log: nil)
let directory = try #require(CustomFirmwareMachOCodeSignature.codeDirectories(in: data)?.first)
let writtenPages = Set(report.records.map { $0.fileOffset / directory.pageSize })
@@ -375,11 +375,11 @@ struct CustomFirmwareWatchdogdPatchTests {
@Test(.enabled(if: WatchdogdFixture.hasWatchdogd))
func `second run changes nothing`() throws {
var data = try Data(contentsOf: WatchdogdFixture.watchdogd)
- let first = try CustomFirmwareWatchdogd.patch(&data, log: nil)
+ let first = try CustomFirmwareWatchDog.patch(&data, log: nil)
#expect(first.outcome == .patched)
let afterFirst = data
- let second = try CustomFirmwareWatchdogd.patch(&data, log: nil)
+ let second = try CustomFirmwareWatchDog.patch(&data, log: nil)
#expect(second.outcome == .alreadyPatched)
#expect(second.sitesWritten == 0)
#expect(second.records.isEmpty)
@@ -398,7 +398,7 @@ struct CustomFirmwareWatchdogdPatchTests {
func `dry run writes nothing`() throws {
let original = try Data(contentsOf: WatchdogdFixture.watchdogd)
var data = original
- let report = try CustomFirmwareWatchdogd.patch(&data, dryRun: true, log: nil)
+ let report = try CustomFirmwareWatchDog.patch(&data, dryRun: true, log: nil)
#expect(report.outcome == .wouldPatch)
#expect(report.records.count == 4)
#expect(data == original)
@@ -413,11 +413,11 @@ struct CustomFirmwareWatchdogdPatchTests {
let attributes = FileManager.default.attributesOfItem(atPath:)
let modeBefore = try attributes(file.path)[.posixPermissions] as? NSNumber
- let report = try CustomFirmwareWatchdogd.patch(at: file, log: nil)
+ let report = try CustomFirmwareWatchDog.patch(at: file, log: nil)
#expect(report.outcome == .patched)
var expected = try Data(contentsOf: WatchdogdFixture.watchdogd)
- try CustomFirmwareWatchdogd.patch(&expected, log: nil)
+ try CustomFirmwareWatchDog.patch(&expected, log: nil)
#expect(try Data(contentsOf: file) == expected)
// watchdogd is installed executable and stays that way: the patch
@@ -433,12 +433,12 @@ struct CustomFirmwareWatchdogdPatchTests {
let file = try WatchdogdFixture.scratchCopy(of: WatchdogdFixture.watchdogd, named: "watchdogd")
defer { try? FileManager.default.removeItem(at: file.deletingLastPathComponent()) }
- try CustomFirmwareWatchdogd.patch(at: file, log: nil)
+ try CustomFirmwareWatchDog.patch(at: file, log: nil)
let afterFirst = try Data(contentsOf: file)
let stampAfterFirst = try FileManager.default
.attributesOfItem(atPath: file.path)[.modificationDate] as? Date
- let second = try CustomFirmwareWatchdogd.patch(at: file, log: nil)
+ let second = try CustomFirmwareWatchDog.patch(at: file, log: nil)
#expect(second.outcome == .alreadyPatched)
#expect(try Data(contentsOf: file) == afterFirst)
#expect(try FileManager.default
@@ -449,7 +449,7 @@ struct CustomFirmwareWatchdogdPatchTests {
// MARK: - Independent references
@Suite("watchdogd hv_vmm_present cache — independent references")
-struct CustomFirmwareWatchdogdReferenceTests {
+struct CustomFirmwareWatchDogReferenceTests {
/// The fixture the frozen digests were taken over. Without this a digest
/// mismatch below would read as a patcher bug when the real cause is a
/// different firmware's `watchdogd`.
@@ -471,7 +471,7 @@ struct CustomFirmwareWatchdogdReferenceTests {
@Test(.enabled(if: WatchdogdFixture.hasWatchdogd))
func `matches the frozen reference byte for byte`() throws {
var mine = try Data(contentsOf: WatchdogdFixture.watchdogd)
- let report = try CustomFirmwareWatchdogd.patch(&mine, log: nil)
+ let report = try CustomFirmwareWatchDog.patch(&mine, log: nil)
// Printed so the parity claim is checkable from outside this process:
// `shasum -a 256` over this patcher's output has to read the same.
@@ -499,14 +499,14 @@ struct CustomFirmwareWatchdogdReferenceTests {
)
defer { try? FileManager.default.removeItem(at: file.deletingLastPathComponent()) }
- try CustomFirmwareWatchdogd.patch(at: file, log: nil)
+ try CustomFirmwareWatchDog.patch(at: file, log: nil)
let afterFirst = try Data(contentsOf: file)
#expect(WatchdogdFixture.digest(afterFirst) == WatchdogdGolden.patched)
// The frozen half: the reference, handed this exact file, reported
// `all 2 matching site(s) already patched — nothing to do` and wrote
// nothing. This port lands on the same bytes when it re-runs.
- let second = try CustomFirmwareWatchdogd.patch(at: file, log: nil)
+ let second = try CustomFirmwareWatchDog.patch(at: file, log: nil)
#expect(second.outcome == .alreadyPatched)
#expect(try WatchdogdFixture.digest(Data(contentsOf: file)) == WatchdogdGolden.patchedTwice)
}
@@ -525,7 +525,7 @@ struct CustomFirmwareWatchdogdReferenceTests {
let before = try WatchdogdFixture.run(WatchdogdFixture.codesign, ["-v", "-v", file.path])
#expect(before.status == 0, "fixture must verify before patching: \(before.output)")
- try CustomFirmwareWatchdogd.patch(at: file, log: nil)
+ try CustomFirmwareWatchDog.patch(at: file, log: nil)
let after = try WatchdogdFixture.run(WatchdogdFixture.codesign, ["-v", "-v", file.path])
#expect(after.status == 0, "patched binary must still verify: \(after.output)")
diff --git a/tests/FirmwarePatcherTests/DyldSharedCacheHVVMMPatcherTests.swift b/tests/FirmwarePatcherTests/DyldSharedCacheHVVMMPatcherTests.swift
index 991ecc4e..1bf0ffb7 100644
--- a/tests/FirmwarePatcherTests/DyldSharedCacheHVVMMPatcherTests.swift
+++ b/tests/FirmwarePatcherTests/DyldSharedCacheHVVMMPatcherTests.swift
@@ -253,7 +253,7 @@ private enum FrozenReference {
// MARK: - Fixture discovery
-private enum HVVMMFixture {
+private enum HypervisorVirtualMachineFixture {
static let repoRoot = URL(fileURLWithPath: #filePath)
.deletingLastPathComponent()
.deletingLastPathComponent()
@@ -463,7 +463,7 @@ private enum Digest {
/// Assert that `directory` holds exactly the chunks the reference changed,
/// with exactly the reference's bytes.
static func expectMatches(_ directory: URL, _ frozen: [String: String]) throws {
- let pristine = try #require(HVVMMFixture.pristine, HVVMMFixture.missing)
+ let pristine = try #require(HypervisorVirtualMachineFixture.pristine, HypervisorVirtualMachineFixture.missing)
let changed = try TreeComparison.changedNames(in: directory, against: pristine)
#expect(changed == frozen.keys.sorted())
for name in changed {
@@ -479,35 +479,35 @@ private enum Digest {
/// No fixture needed: these are the reference modules' own constants, which the
/// port has to carry verbatim for anything else here to mean anything.
@Suite(.serialized)
-struct DyldSharedCacheHVVMMConstantsTests {
+struct DyldSharedCacheHypervisorVirtualMachineConstantsTests {
@Test
func `The cstring, its mangle and the blacklist match the reference modules`() {
- #expect(DyldSharedCacheHVVMMPatcher.needle.hex == FrozenReference.needleHex)
- #expect(DyldSharedCacheHVVMMPatcher.mangledNeedle.hex == FrozenReference.mangledNeedleHex)
- #expect(DyldSharedCacheHVVMMPatcher.mangleOffset == FrozenReference.mangleOffset)
- #expect(Data([DyldSharedCacheHVVMMPatcher.originalByte]).hex == FrozenReference.originalByteHex)
- #expect(Data([DyldSharedCacheHVVMMPatcher.mangledByte]).hex == FrozenReference.mangledByteHex)
- #expect(DyldSharedCacheHVVMMPatcher.dontPatchInstallNames == FrozenReference.blacklist)
+ #expect(DyldSharedCacheHypervisorVirtualMachinePatcher.needle.hex == FrozenReference.needleHex)
+ #expect(DyldSharedCacheHypervisorVirtualMachinePatcher.mangledNeedle.hex == FrozenReference.mangledNeedleHex)
+ #expect(DyldSharedCacheHypervisorVirtualMachinePatcher.mangleOffset == FrozenReference.mangleOffset)
+ #expect(Data([DyldSharedCacheHypervisorVirtualMachinePatcher.originalByte]).hex == FrozenReference.originalByteHex)
+ #expect(Data([DyldSharedCacheHypervisorVirtualMachinePatcher.mangledByte]).hex == FrozenReference.mangledByteHex)
+ #expect(DyldSharedCacheHypervisorVirtualMachinePatcher.dontPatchInstallNames == FrozenReference.blacklist)
// The mangle has to preserve the namespace prefix, or the name cannot
// resolve to any OID — see the patcher's file comment. This is the one
// property of the patch that is not a transcription of the reference.
- let prefix = Data(DyldSharedCacheHVVMMPatcher.sysctlNamespace.utf8)
- #expect(DyldSharedCacheHVVMMPatcher.needle.prefix(prefix.count) == prefix)
- #expect(DyldSharedCacheHVVMMPatcher.mangledNeedle.prefix(prefix.count) == prefix)
- #expect(DyldSharedCacheHVVMMPatcher.needle.count == DyldSharedCacheHVVMMPatcher.mangledNeedle.count)
- let differing = zip(DyldSharedCacheHVVMMPatcher.needle, DyldSharedCacheHVVMMPatcher.mangledNeedle)
+ let prefix = Data(DyldSharedCacheHypervisorVirtualMachinePatcher.sysctlNamespace.utf8)
+ #expect(DyldSharedCacheHypervisorVirtualMachinePatcher.needle.prefix(prefix.count) == prefix)
+ #expect(DyldSharedCacheHypervisorVirtualMachinePatcher.mangledNeedle.prefix(prefix.count) == prefix)
+ #expect(DyldSharedCacheHypervisorVirtualMachinePatcher.needle.count == DyldSharedCacheHypervisorVirtualMachinePatcher.mangledNeedle.count)
+ let differing = zip(DyldSharedCacheHypervisorVirtualMachinePatcher.needle, DyldSharedCacheHypervisorVirtualMachinePatcher.mangledNeedle)
.enumerated()
.filter { $0.element.0 != $0.element.1 }
.map(\.offset)
- #expect(differing == [DyldSharedCacheHVVMMPatcher.mangleOffset])
+ #expect(differing == [DyldSharedCacheHypervisorVirtualMachinePatcher.mangleOffset])
}
}
// MARK: - The real cache
-@Suite(.serialized, .enabled(if: HVVMMFixture.runs, HVVMMFixture.skipReason))
-struct DyldSharedCacheHVVMMCacheParityTests {
+@Suite(.serialized, .enabled(if: HypervisorVirtualMachineFixture.runs, HypervisorVirtualMachineFixture.skipReason))
+struct DyldSharedCacheHypervisorVirtualMachineCacheParityTests {
/// The parity gate.
///
/// One clone, one run, then require the tree to hold exactly the chunks the
@@ -521,12 +521,12 @@ struct DyldSharedCacheHVVMMCacheParityTests {
/// test has already produced.
@Test
func `The Swift patch reproduces the reference's cache`() throws {
- _ = try #require(HVVMMFixture.pristine, HVVMMFixture.missing)
+ _ = try #require(HypervisorVirtualMachineFixture.pristine, HypervisorVirtualMachineFixture.missing)
- let swiftClone = try HVVMMFixture.cloneCache(named: "swift")
- defer { HVVMMFixture.discard(swiftClone) }
+ let swiftClone = try HypervisorVirtualMachineFixture.cloneCache(named: "swift")
+ defer { HypervisorVirtualMachineFixture.discard(swiftClone) }
- let result = try DyldSharedCacheHVVMMPatcher.patch(chunksDirectory: swiftClone, log: nil)
+ let result = try DyldSharedCacheHypervisorVirtualMachinePatcher.patch(chunksDirectory: swiftClone, log: nil)
// Same verdict per dylib, including the zero-count entries that record
// "seen and deliberately left alone".
@@ -534,7 +534,7 @@ struct DyldSharedCacheHVVMMCacheParityTests {
#expect(result.mangled == FrozenReference.totalMangled)
#expect(result.mangled > 0, "the reference patched nothing — wrong fixture?")
- #expect(result.skippedInBlacklist == DyldSharedCacheHVVMMPatcher.dontPatchInstallNames.count)
+ #expect(result.skippedInBlacklist == DyldSharedCacheHypervisorVirtualMachinePatcher.dontPatchInstallNames.count)
#expect(result.skippedUnclassified == 0)
#expect(result.refused == 0)
#expect(result.isFullyAttested)
@@ -556,7 +556,7 @@ struct DyldSharedCacheHVVMMCacheParityTests {
// finds no pristine cstring left, queues the mangled ones so their slots
// stay in sync, and must not move a byte. The reference behaved the same
// way, so the frozen digests have to survive it.
- let second = try DyldSharedCacheHVVMMPatcher.patch(chunksDirectory: swiftClone, log: nil)
+ let second = try DyldSharedCacheHypervisorVirtualMachinePatcher.patch(chunksDirectory: swiftClone, log: nil)
#expect(second.mangled == 0)
#expect(second.pristineSiteCount == result.skippedInBlacklist)
#expect(second.alreadyMangledSiteCount == result.mangled)
@@ -570,23 +570,23 @@ struct DyldSharedCacheHVVMMCacheParityTests {
// blacklisted dylib in the cache must still hold the pristine cstring.
let chunks = try DyldSharedCacheChunkSet(directory: swiftClone)
var blacklistedSitesSeen = 0
- for vma in try chunks.findStringVMAs(DyldSharedCacheHVVMMPatcher.needle) {
+ for vma in try chunks.findStringVMAs(DyldSharedCacheHypervisorVirtualMachinePatcher.needle) {
let installName = try #require(
- DyldSharedCacheHVVMMPatcher.classify(vma, in: chunks),
+ DyldSharedCacheHypervisorVirtualMachinePatcher.classify(vma, in: chunks),
"a pristine cstring survived in a dylib that cannot be named",
)
#expect(
- DyldSharedCacheHVVMMPatcher.dontPatchSet.contains(installName),
+ DyldSharedCacheHypervisorVirtualMachinePatcher.dontPatchSet.contains(installName),
"\(installName) is not blacklisted but kept the original cstring",
)
blacklistedSitesSeen += 1
}
#expect(blacklistedSitesSeen == result.skippedInBlacklist)
- for vma in try chunks.findStringVMAs(DyldSharedCacheHVVMMPatcher.mangledNeedle) {
- let installName = try #require(DyldSharedCacheHVVMMPatcher.classify(vma, in: chunks))
+ for vma in try chunks.findStringVMAs(DyldSharedCacheHypervisorVirtualMachinePatcher.mangledNeedle) {
+ let installName = try #require(DyldSharedCacheHypervisorVirtualMachinePatcher.classify(vma, in: chunks))
#expect(
- !DyldSharedCacheHVVMMPatcher.dontPatchSet.contains(installName),
+ !DyldSharedCacheHypervisorVirtualMachinePatcher.dontPatchSet.contains(installName),
"\(installName) is blacklisted but was mangled",
)
}
@@ -594,12 +594,12 @@ struct DyldSharedCacheHVVMMCacheParityTests {
@Test
func `A dry run reports the same sites and leaves every byte alone`() throws {
- let pristine = try #require(HVVMMFixture.pristine, HVVMMFixture.missing)
+ let pristine = try #require(HypervisorVirtualMachineFixture.pristine, HypervisorVirtualMachineFixture.missing)
- let clone = try HVVMMFixture.cloneCache(named: "dryrun")
- defer { HVVMMFixture.discard(clone) }
+ let clone = try HypervisorVirtualMachineFixture.cloneCache(named: "dryrun")
+ defer { HypervisorVirtualMachineFixture.discard(clone) }
- let result = try DyldSharedCacheHVVMMPatcher.patch(
+ let result = try DyldSharedCacheHypervisorVirtualMachinePatcher.patch(
chunksDirectory: clone,
dryRun: true,
log: nil,
@@ -632,22 +632,22 @@ struct DyldSharedCacheHVVMMCacheParityTests {
/// test in this file.
@Test
func `A blacklisted dylib found mangled is reported as drift, not reverted`() throws {
- _ = try #require(HVVMMFixture.pristine, HVVMMFixture.missing)
+ _ = try #require(HypervisorVirtualMachineFixture.pristine, HypervisorVirtualMachineFixture.missing)
- let swiftClone = try HVVMMFixture.cloneCache(named: "drift-swift")
- defer { HVVMMFixture.discard(swiftClone) }
+ let swiftClone = try HypervisorVirtualMachineFixture.cloneCache(named: "drift-swift")
+ defer { HypervisorVirtualMachineFixture.discard(swiftClone) }
// The lowest-addressed site inside a blacklisted dylib, so the choice is
// the same on every run — and the same one the reference was given.
let probe = try DyldSharedCacheChunkSet(directory: swiftClone)
let driftVMA = try #require(
- try probe.findStringVMAs(DyldSharedCacheHVVMMPatcher.needle).sorted().first {
- guard let name = DyldSharedCacheHVVMMPatcher.classify($0, in: probe) else { return false }
- return DyldSharedCacheHVVMMPatcher.dontPatchSet.contains(name)
+ try probe.findStringVMAs(DyldSharedCacheHypervisorVirtualMachinePatcher.needle).sorted().first {
+ guard let name = DyldSharedCacheHypervisorVirtualMachinePatcher.classify($0, in: probe) else { return false }
+ return DyldSharedCacheHypervisorVirtualMachinePatcher.dontPatchSet.contains(name)
},
"no blacklisted dylib carries the cstring in this cache",
)
- let driftedDylib = try #require(DyldSharedCacheHVVMMPatcher.classify(driftVMA, in: probe))
+ let driftedDylib = try #require(DyldSharedCacheHypervisorVirtualMachinePatcher.classify(driftVMA, in: probe))
#expect(driftVMA == FrozenReference.driftVMA)
#expect(driftedDylib == FrozenReference.driftedInstallName)
@@ -655,18 +655,18 @@ struct DyldSharedCacheHVVMMCacheParityTests {
// out-of-band run would have left behind, and what the reference saw.
let chunks = try DyldSharedCacheChunkSet(directory: swiftClone)
try chunks.write(
- at: driftVMA &+ UInt64(DyldSharedCacheHVVMMPatcher.mangleOffset),
- Data([DyldSharedCacheHVVMMPatcher.mangledByte]),
+ at: driftVMA &+ UInt64(DyldSharedCacheHypervisorVirtualMachinePatcher.mangleOffset),
+ Data([DyldSharedCacheHypervisorVirtualMachinePatcher.mangledByte]),
)
- let result = try DyldSharedCacheHVVMMPatcher.patch(chunksDirectory: swiftClone, log: nil)
+ let result = try DyldSharedCacheHypervisorVirtualMachinePatcher.patch(chunksDirectory: swiftClone, log: nil)
#expect(result.blacklistDrift == 1)
#expect(result.alreadyMangledSiteCount == 1)
#expect(result.reattestOnly == 0)
#expect(result.refused == 0)
#expect(
- result.skippedInBlacklist == DyldSharedCacheHVVMMPatcher.dontPatchInstallNames.count - 1,
+ result.skippedInBlacklist == DyldSharedCacheHypervisorVirtualMachinePatcher.dontPatchInstallNames.count - 1,
"the drifted site is no longer pristine, so it is not counted as skipped",
)
#expect(result.mangledCountByInstallName[driftedDylib] == nil)
@@ -674,8 +674,8 @@ struct DyldSharedCacheHVVMMCacheParityTests {
// Not reverted: the byte is still mangled afterwards.
let after = try DyldSharedCacheChunkSet(directory: swiftClone)
- .bytesAtVMA(driftVMA, length: DyldSharedCacheHVVMMPatcher.needle.count)
- #expect(after == DyldSharedCacheHVVMMPatcher.mangledNeedle)
+ .bytesAtVMA(driftVMA, length: DyldSharedCacheHypervisorVirtualMachinePatcher.needle.count)
+ #expect(after == DyldSharedCacheHypervisorVirtualMachinePatcher.mangledNeedle)
// The same 17 chunks as the ordinary run, differing only in the one the
// drifted dylib lives in — which is what the reference left behind.
@@ -686,8 +686,8 @@ struct DyldSharedCacheHVVMMCacheParityTests {
// MARK: - Standalone Mach-O
-@Suite(.serialized, .enabled(if: HVVMMFixture.machORuns, HVVMMFixture.machOSkipReason))
-struct DyldSharedCacheHVVMMStandaloneTests {
+@Suite(.serialized, .enabled(if: HypervisorVirtualMachineFixture.machORuns, HypervisorVirtualMachineFixture.machOSkipReason))
+struct DyldSharedCacheHypervisorVirtualMachineStandaloneTests {
/// The other half of `cfw_patch_hv_vmm.py`, against the binaries the repo
/// keeps pristine copies of. Each carries one occurrence of the cstring on
/// this build.
@@ -696,7 +696,7 @@ struct DyldSharedCacheHVVMMStandaloneTests {
)
func `Standalone Mach-O mangling matches the reference`(name: String) throws {
let pristine = try #require(
- HVVMMFixture.machO(name),
+ HypervisorVirtualMachineFixture.machO(name),
"""
ipsws/ref_extract/macho_pristine/\(name) is required — it is the \
only standalone Mach-O fixture this half of the port has
@@ -710,11 +710,11 @@ struct DyldSharedCacheHVVMMStandaloneTests {
// below is a comparison.
#expect(try Digest.sha256(of: pristine) == reference.pristineSHA256)
- let swiftCopy = try HVVMMFixture.copyFile(pristine, named: "\(name).swift")
- defer { HVVMMFixture.discard(swiftCopy) }
+ let swiftCopy = try HypervisorVirtualMachineFixture.copyFile(pristine, named: "\(name).swift")
+ defer { HypervisorVirtualMachineFixture.discard(swiftCopy) }
// Same sites, in the same order, before anything is written.
- let sites = try DyldSharedCacheHVVMMPatcher.findStringSites(
+ let sites = try DyldSharedCacheHypervisorVirtualMachinePatcher.findStringSites(
inMachO: Data(contentsOf: pristine),
)
#expect(sites.count == reference.sites.count)
@@ -725,13 +725,13 @@ struct DyldSharedCacheHVVMMStandaloneTests {
#expect(mine.section == theirs.section)
}
- let count = try DyldSharedCacheHVVMMPatcher.patchStandaloneMachO(at: swiftCopy, log: nil)
+ let count = try DyldSharedCacheHypervisorVirtualMachinePatcher.patchStandaloneMachO(at: swiftCopy, log: nil)
#expect(count == sites.count)
#expect(try Digest.sha256(of: swiftCopy) == reference.patchedSHA256)
// Idempotent: the pristine literal is gone, so a second pass is a no-op.
// The reference's own second pass returned 0 and left its digest alone.
- let rerun = try DyldSharedCacheHVVMMPatcher.patchStandaloneMachO(at: swiftCopy, log: nil)
+ let rerun = try DyldSharedCacheHypervisorVirtualMachinePatcher.patchStandaloneMachO(at: swiftCopy, log: nil)
#expect(rerun == 0)
#expect(try Digest.sha256(of: swiftCopy) == reference.patchedSHA256)
print("[hv_vmm] \(name): \(count) standalone cstring site(s), bytes match")
diff --git a/tests/FirmwarePatcherTests/PatchComparisonTests.swift b/tests/FirmwarePatcherTests/PatchComparisonTests.swift
index e6442ee5..863f1fb8 100644
--- a/tests/FirmwarePatcherTests/PatchComparisonTests.swift
+++ b/tests/FirmwarePatcherTests/PatchComparisonTests.swift
@@ -13,7 +13,7 @@
// So the suites below run when someone still has the JSON and skip when they
// do not, rather than erroring on a missing file and reading as a regression.
// What still guards the patchers without them is the frozen-digest work
-// elsewhere in this directory — `FrozenReference` in DyldSharedCacheHVVMMPatcherTests and
+// elsewhere in this directory — `FrozenReference` in DyldSharedCacheHypervisorVirtualMachinePatcherTests and
// the `matchesTheFrozenReference*` tests — which carry the reference values in
// the source instead of in a file nobody has.