Run a virtual iPhone on an Apple Silicon Mac.
Swift
Turn off CoreAnimation's surface compression in iOS 18 restore images
Maximilian Paß61928e2bbece
diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcher.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcher.swiftindex 06dff920..6a4e99a1 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcher.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcher.swift@@ -72,7 +72,7 @@ public final class CryptexFilesystemPatcher: BufferedPatcher {/// One record per step the gate lets through. The merge itself is the/// patcher: the pipeline builds it only when the merge is on.public func findAll() throws -> [PatchRecord] {- Self.steps.filter { gate.isEnabled($0.identifier) }.map { step in+ Self.steps.filter { gate.isEnabled($0.identifier) && ($0.identifier != FirmwareRestoreImagePatchSet.surfaceCompression || isIOS18) }.map { step inPatchRecord(patchID: step.identifier,component: "",@@ -87,6 +87,7 @@ public final class CryptexFilesystemPatcher: BufferedPatcher {static let steps: [(identifier: String, description: String)] = [(FirmwareRestoreImagePatchSet.cryptexMerge, "Merge the cryptex filesystems inside the OS filesystem"),(FirmwareRestoreImagePatchSet.gpuDriver, "Install the paravirtual GPU driver"),+ (FirmwareRestoreImagePatchSet.surfaceCompression, "Turn off CoreAnimation's surface compression (iOS 18)"),(FirmwareRestoreImagePatchSet.mobileActivation, "Patch mobileactivationd"),(FirmwareRestoreImagePatchSet.vphoned, "Install vphoned and its launch daemon"),(FirmwareRestoreImagePatchSet.launchdCacheLoader, "Patch launchd_cache_loader"),@@ -174,6 +175,10 @@ public final class CryptexFilesystemPatcher: BufferedPatcher {print("- Fixing GPU driver…")try addGpuDriver(targetMount: targetMount)}+ if gate.isEnabled(FirmwareRestoreImagePatchSet.surfaceCompression), isIOS18 {+ print("- Turning off CoreAnimation's surface compression (iOS 18)…")+ try addCoreAnimationDefaults(targetMount: targetMount)+ }if gate.isEnabled(FirmwareRestoreImagePatchSet.mobileActivation) {print("- Patching mobile activation…")diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcherGuestPayload.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcherGuestPayload.swiftindex 6026747b..32ac98c4 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcherGuestPayload.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcherGuestPayload.swift@@ -141,6 +141,40 @@ extension CryptexFilesystemPatcher {}}+ /// Whether the merged system is iOS 18, whose paravirtual IOSurface driver+ /// takes no compressed surfaces.+ var isIOS18: Bool {+ (try? getProductVersion())?.hasPrefix("18.") ?? false+ }++ /// iOS 18's AppleParavirtIOSurface maps only address format 0 and rejects+ /// the compressed surfaces CoreAnimation asks for ("invalid address format+ /// (3)"): backboardd's framebuffer allocation fails at boot, it retries+ /// forever, and the screen stays black. Turning off IOSurface and+ /// framebuffer compression and the deep (10-bit) framebuffer in the+ /// any-user global domain fixes it, checked across a reboot (a backboardd+ /// restart also comes up without these keys, so it proves nothing).+ /// backboardd consults neither com.apple.coreanimation nor the managed+ /// any-user file. The restore copies the image's /private/var into the+ /// data volume, so the preferences are written there.+ func addCoreAnimationDefaults(targetMount: String) throws {+ let directory = URL(filePath: targetMount).appending(path: "private/var/preferences")+ try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true)+ let plist = directory.appending(path: ".GlobalPreferences.plist")+ var preferences: [String: Any] = [:]+ if let data = try? Data(contentsOf: plist),+ let existing = try? PropertyListSerialization.propertyList(from: data, format: nil) as? [String: Any]+ {+ preferences = existing+ }+ for key in ["CAEnableIOSurfaceCompression", "CAEnableFramebufferCompression", "CAEnableDeepFramebuffer"] {+ preferences[key] = false+ }+ try PropertyListSerialization.data(fromPropertyList: preferences, format: .binary, options: 0).write(to: plist)+ try chownRecursively(uid: 0, gid: 0, at: plist)+ try setMode(0o644, at: plist)+ }+/// The driver and its compiler plugin are built for iOS, and dyld refuses a/// library of another platform than the process's: on a watch they say/// watchOS, are signed again and the bundle sealed again.diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareRestoreImagePatchSet.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareRestoreImagePatchSet.swiftindex aec9532d..2c1781c3 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareRestoreImagePatchSet.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareRestoreImagePatchSet.swift@@ -23,6 +23,8 @@ public enum FirmwareRestoreImagePatchSet {/// into the merged image, so they run only with it.public static let cryptexMerge = "filesystem-boot-cryptex_merge"public static let gpuDriver = "filesystem-boot-gpu_driver"+ /// Applies to an iOS 18 guest only; the patcher skips it on any other.+ public static let surfaceCompression = "filesystem-boot-ios18_surface_compression"public static let mobileActivation = "filesystem-boot-mobileactivationd_should_hactivate"public static let vphoned = "filesystem-boot-vphoned"public static let launchdCacheLoader = "filesystem-boot-launchd_cache_loader_unsecure_cache_gate"@@ -54,6 +56,11 @@ public enum FirmwareRestoreImagePatchSet {"GPU driver","Installs the paravirtual GPU driver from the cloudOS into the merged image.",),+ filesystem(+ surfaceCompression,+ "iOS 18 surface compression",+ "On iOS 18, turns off CoreAnimation's IOSurface and framebuffer compression and its deep framebuffer, which that release's paravirtual IOSurface driver rejects, leaving the screen black.",+ ),filesystem(mobileActivation,"Activation",diff --git a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/minimal.plist b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/minimal.plistindex 3963fba2..cba086dc 100644--- a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/minimal.plist+++ b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/minimal.plist@@ -47,6 +47,7 @@<string>devicetree-cfw-watch_companion</string><string>filesystem-boot-cryptex_merge</string><string>filesystem-boot-gpu_driver</string>+ <string>filesystem-boot-ios18_surface_compression</string><string>filesystem-boot-launchd_cache_loader_unsecure_cache_gate</string><string>filesystem-boot-mobileactivationd_should_hactivate</string><string>filesystem-boot-vphoned</string>diff --git a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/watchos.plist b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/watchos.plistindex 2d3196c2..9765cd42 100644--- a/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/watchos.plist+++ b/VPhoneExecutable/VPhoneVirtualization/Resources/patches_presets/watchos.plist@@ -50,6 +50,7 @@<string>devicetree-cfw-watch_presentation</string><string>filesystem-boot-cryptex_merge</string><string>filesystem-boot-gpu_driver</string>+ <string>filesystem-boot-ios18_surface_compression</string><string>filesystem-boot-launchd_cache_loader_unsecure_cache_gate</string><string>filesystem-boot-mobileactivationd_should_hactivate</string><string>filesystem-boot-vphoned</string>