Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Free the merge's decrypted images as soon as it is done with them

Maximilian Paß92af8b9dfba1
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcher.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcher.swift
index 687a6be9..d06ad0eb 100644
--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcher.swift
+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcher.swift
@@ -173,6 +173,10 @@ public final class CryptexFilesystemPatcher: BufferedPatcher {
let targetImagePath = tmpDir.appending(path: "disk.dmg")
do {
try convertToRawImage(input: osDmgPath, output: targetImagePath)
+ // The decrypted OS image is only the conversion's input. Gone now,
+ // its ~7 GB are free for the merge, which on a nearly full disk
+ // otherwise runs out of room (iOS 18.6 22G86 with 24 GB free).
+ try? FileManager.default.removeItem(at: osDmgPath)
let (targetDevice, targetMount) = try attachImage(path: targetImagePath, forceRW: true)
defer { try? detachImage(deviceNode: targetDevice) }
@@ -230,6 +234,7 @@ public final class CryptexFilesystemPatcher: BufferedPatcher {
print("- Finalizing merged image…")
try shrinkImage(dmg: targetImagePath)
try convertToUDRWImage(input: targetImagePath, output: newDmgPath)
+ try? FileManager.default.removeItem(at: targetImagePath)
let metadata = try getAeaMetadata(restoreDir.appending(path: osPath))
let key = try getAeaKey(restoreDir.appending(path: osPath), metadata: metadata)
let finalFile = newDmgPath.appendingPathExtension("aea")
@@ -252,6 +257,8 @@ public final class CryptexFilesystemPatcher: BufferedPatcher {
} else {
try decryptAeaFile(restoreDir.appending(path: componentPath("Cryptex1,SystemOS")))
}
+ // The System OS image is a decrypted copy; drop it once detached.
+ defer { if systemOS { try? FileManager.default.removeItem(at: osPath) } }
let (osDevice, osMount) = try attachImage(path: osPath, readonly: true)
defer { try? detachImage(deviceNode: osDevice) }