Run a virtual iPhone on an Apple Silicon Mac.
Swift
Fix the remaining Swift, Objective-C and linker warnings
Lakr2337813b8799895
diff --git a/VPhoneDaemon/Daemon/main.swift b/VPhoneDaemon/Daemon/main.swiftindex 79a310c3..ad446b8c 100644--- a/VPhoneDaemon/Daemon/main.swift+++ b/VPhoneDaemon/Daemon/main.swift@@ -34,9 +34,15 @@ do {return channel.eventLoop.makeSucceededFuture(allowed ? HTTPHeaders() : nil)},upgradePipelineHandler: { channel, request in- channel.pipeline.removeHandler(http).flatMap {+ // Add the post-upgrade handlers synchronously on the channel's+ // event loop (removeHandler's future completes there). Building+ // them through syncOperations keeps them off any concurrency+ // boundary, so NIOWebSocketFrameAggregator's unavailable Sendable+ // conformance is never required. The pipeline is unchanged.+ channel.pipeline.removeHandler(http).flatMapThrowing {+ let sync = channel.pipeline.syncOperationsif let port = GuestPortForwardHandler.port(from: request.uri) {- return channel.pipeline.addHandlers([+ try sync.addHandlers([NIOWebSocketFrameAggregator(minNonFinalFragmentSize: 1,maxAccumulatedFrameCount: 32,@@ -44,15 +50,16 @@ do {),GuestPortForwardHandler(port: port),])+ } else {+ try sync.addHandlers([+ NIOWebSocketFrameAggregator(+ minNonFinalFragmentSize: 1,+ maxAccumulatedFrameCount: 32,+ maxAccumulatedFrameSize: 1 << 20,+ ),+ GuestWebSocketHandler(hub: hub),+ ])}- return channel.pipeline.addHandlers([- NIOWebSocketFrameAggregator(- minNonFinalFragmentSize: 1,- maxAccumulatedFrameCount: 32,- maxAccumulatedFrameSize: 1 << 20,- ),- GuestWebSocketHandler(hub: hub),- ])}},)diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/Kernel/JailbreakPatches/CodeSigning/KernelJailbreakPatchCredLabel.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/Kernel/JailbreakPatches/CodeSigning/KernelJailbreakPatchCredLabel.swiftindex 9435e458..9fae7dd7 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/Kernel/JailbreakPatches/CodeSigning/KernelJailbreakPatchCredLabel.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/Kernel/JailbreakPatches/CodeSigning/KernelJailbreakPatchCredLabel.swift@@ -72,6 +72,7 @@ extension KernelJailbreakPatcher {log(" [-] csflags stack reload (ldr x26, [x29, #imm]) not found")return}+ log(" [+] csflags reload: ldr \(csflagsDesc)")// 6. Allocate code caves.var denyCaveOff: Int? = nildiff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/Kernel/KernelExperimentalPatcher.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/Kernel/KernelExperimentalPatcher.swiftindex 829ad874..ec8f0ae0 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/Kernel/KernelExperimentalPatcher.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/Kernel/KernelExperimentalPatcher.swift@@ -20,7 +20,7 @@ public final class KernelExperimentalPatcher: KernelJailbreakPatcherBase, Patchepublic let component = "kernelcache_exp"public func findAll() throws -> [PatchRecord] {- try parseMachO()+ parseMachO()buildADRPIndex()buildBLIndex()buildSymbolTable()diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/Kernel/KernelJailbreakPatcher.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/Kernel/KernelJailbreakPatcher.swiftindex 974fa4fe..71d442b7 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/Kernel/KernelJailbreakPatcher.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/Kernel/KernelJailbreakPatcher.swift@@ -28,7 +28,7 @@ public final class KernelJailbreakPatcher: KernelJailbreakPatcherBase, Patcher {public var applyFrida = falsepublic func findAll() throws -> [PatchRecord] {- try parseMachO()+ parseMachO()buildADRPIndex()buildBLIndex()buildSymbolTable()diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swiftindex 4c0f57bb..f1a44df4 100644--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift@@ -438,7 +438,7 @@ struct VPhoneCustomFirmwareInstaller {let mount = work.appendingPathComponent("preboot")try fm.createDirectory(at: mount, withIntermediateDirectories: false)try tool("/sbin/mount_apfs", ["-o", "rw", "/dev/\(device)", mount.path])- defer { try? tool("/sbin/umount", [mount.path], quiet: true) }+ defer { _ = try? tool("/sbin/umount", [mount.path], quiet: true) }let roots = try fm.contentsOfDirectory(at: mount, includingPropertiesForKeys: [.isDirectoryKey])let candidates = roots.map {$0.appendingPathComponent("usr/standalone/firmware/devicetree.img4")diff --git a/VPhoneExecutable/VPhoneVirtualization/UI/HostDevices/VPhoneFrameProducer.swift b/VPhoneExecutable/VPhoneVirtualization/UI/HostDevices/VPhoneFrameProducer.swiftindex f947dfbf..a544fbb3 100644--- a/VPhoneExecutable/VPhoneVirtualization/UI/HostDevices/VPhoneFrameProducer.swift+++ b/VPhoneExecutable/VPhoneVirtualization/UI/HostDevices/VPhoneFrameProducer.swift@@ -140,6 +140,8 @@ final class VPhoneVideoFileProducer: VPhoneFrameProducer, @unchecked Sendable {private let height: Intprivate let bytesPerRow: Intprivate var asset: AVURLAsset+ private let videoTrack: AVAssetTrack+ private let composition: AVMutableVideoCompositionprivate var reader: AVAssetReader?private var readerOutput: AVAssetReaderVideoCompositionOutput?@@ -149,24 +151,82 @@ final class VPhoneVideoFileProducer: VPhoneFrameProducer, @unchecked Sendable {self.height = heightbytesPerRow = ((width * 4) + 15) & ~15asset = AVURLAsset(url: url)+ // The track and its geometry are invariant for the asset, so they+ // are loaded once and the composition is reused on every loop.+ let loaded = try Self.loadVideoTrack(from: asset, url: url)+ videoTrack = loaded.track+ composition = Self.letterboxComposition(loaded, width: width, height: height)try restartReader()}+ private struct LoadedTrack {+ let track: AVAssetTrack+ let naturalSize: CGSize+ let preferredTransform: CGAffineTransform+ let duration: CMTime+ }++ /// Bridges the async AVFoundation loaders into this synchronous,+ /// throwing initializer. AVFoundation runs the load on its own queue, so+ /// the caller's thread just parks on the semaphore until it resolves.+ private static func loadVideoTrack(from asset: AVURLAsset, url: URL) throws -> LoadedTrack {+ let box = LoadedTrackBox()+ let semaphore = DispatchSemaphore(value: 0)+ Task {+ do {+ if let track = try await asset.loadTracks(withMediaType: .video).first {+ let (size, transform) = try await track.load(.naturalSize, .preferredTransform)+ let duration = try await asset.load(.duration)+ box.result = .success(LoadedTrack(+ track: track,+ naturalSize: size,+ preferredTransform: transform,+ duration: duration,+ ))+ } else {+ box.result = .success(nil)+ }+ } catch {+ box.result = .failure(error)+ }+ semaphore.signal()+ }+ semaphore.wait()+ switch box.result {+ case let .success(loaded?):+ return loaded+ case .success(nil), .none:+ throw NSError(+ domain: "VPhoneVideoFileProducer",+ code: 1,+ userInfo: [NSLocalizedDescriptionKey:+ "\(url.lastPathComponent): no video track"],+ )+ case let .failure(error):+ throw error+ }+ }++ /// Carries the async load result across the semaphore hand-off.+ private final class LoadedTrackBox: @unchecked Sendable {+ var result: Result<LoadedTrack?, Error>?+ }+/// Aspect-fit letterbox composition at the camera size.- private func letterboxComposition(for track: AVAssetTrack) -> AVMutableVideoComposition {+ private static func letterboxComposition(_ loaded: LoadedTrack, width: Int, height: Int) -> AVMutableVideoComposition {let composition = AVMutableVideoComposition()composition.renderSize = CGSize(width: width, height: height)composition.frameDuration = CMTime(value: 1, timescale: 30)- let bounds = CGRect(origin: .zero, size: track.naturalSize)- .applying(track.preferredTransform)+ let bounds = CGRect(origin: .zero, size: loaded.naturalSize)+ .applying(loaded.preferredTransform)let boundsWidth = abs(bounds.width)let boundsHeight = abs(bounds.height)let scale = min(CGFloat(width) / boundsWidth, CGFloat(height) / boundsHeight)let tx = (CGFloat(width) - boundsWidth * scale) / 2 - bounds.minX * scalelet ty = (CGFloat(height) - boundsHeight * scale) / 2 - bounds.minY * scale- let layer = AVMutableVideoCompositionLayerInstruction(assetTrack: track)+ let layer = AVMutableVideoCompositionLayerInstruction(assetTrack: loaded.track)layer.setTransform(- track.preferredTransform+ loaded.preferredTransform.concatenating(CGAffineTransform(scaleX: scale, y: scale)).concatenating(CGAffineTransform(translationX: tx, y: ty)),at: .zero,@@ -175,21 +235,14 @@ final class VPhoneVideoFileProducer: VPhoneFrameProducer, @unchecked Sendable {// Assigning it to `instructions` directly raises an unrecognized// selector (`timeRange`) when the reader validates the composition.let instruction = AVMutableVideoCompositionInstruction()- instruction.timeRange = CMTimeRange(start: .zero, duration: asset.duration)+ instruction.timeRange = CMTimeRange(start: .zero, duration: loaded.duration)instruction.layerInstructions = [layer]composition.instructions = [instruction]return composition}private func restartReader() throws {- guard let track = asset.tracks(withMediaType: .video).first else {- throw NSError(- domain: "VPhoneVideoFileProducer",- code: 1,- userInfo: [NSLocalizedDescriptionKey:- "\(url.lastPathComponent): no video track"],- )- }+ let track = videoTracklet r = try AVAssetReader(asset: asset)let output = AVAssetReaderVideoCompositionOutput(videoTracks: [track],@@ -198,7 +251,7 @@ final class VPhoneVideoFileProducer: VPhoneFrameProducer, @unchecked Sendable {Int(kCVPixelFormatType_32BGRA),],)- output.videoComposition = letterboxComposition(for: track)+ output.videoComposition = compositionoutput.alwaysCopiesSampleData = falser.add(output)guard r.startReading() else {diff --git a/VPhoneGuestComponents/Makefile b/VPhoneGuestComponents/Makefileindex 6d1f95c8..34639942 100644--- a/VPhoneGuestComponents/Makefile+++ b/VPhoneGuestComponents/Makefile@@ -23,6 +23,30 @@ SYSTEMHOOK_INCLUDES := $(wildcard SystemHook/*.h SystemHook/*.inc Shared/*.h)GPU_PLUGIN := $(STAGE)/gpu/libAppleParavirtCompilerPluginIOGPUFamily.dylibGPU_PLUGIN_SOURCES := $(wildcard GraphicLoader/*.mm)GPU_PLUGIN_INCLUDES := $(wildcard GraphicLoader/*.h GraphicLoader/*.hpp GraphicLoader/*.inc)+# The compiler plugin resolves the guest's libLLVM.dylib and libGPUCompiler.dylib+# entry points at runtime; neither is in the iPhoneOS SDK, so those symbols are+# left for flat dynamic lookup. Naming them individually (`-U`) keeps the link+# import table identical to `-undefined dynamic_lookup` — the C++/libSystem+# symbols still bind two-level — without that flag's iOS deprecation warning.+GPU_DYNAMIC_LOOKUP_SYMS := \+ -Wl,-U,_LLVMDisposeMemoryBuffer \+ -Wl,-U,_LLVMGetBufferStart \+ -Wl,-U,_LLVMGetBufferSize \+ -Wl,-U,_LLVMGetTarget \+ -Wl,-U,_LLVMExtraMakeSharedModule \+ -Wl,-U,_LLVMExtraDisposeSharedModule \+ -Wl,-U,_LLVMGetNamedMetadataNumOperands \+ -Wl,-U,_LLVMGetNamedMetadataOperands \+ -Wl,-U,_LLVMGetMDNodeNumOperands \+ -Wl,-U,_LLVMGetMDNodeOperands \+ -Wl,-U,_LLVMGetValueName2 \+ -Wl,-U,_MTLGPUCompilerCreate \+ -Wl,-U,_MTLGPUCompilerDestroy \+ -Wl,-U,_MTLDowngradeAIRModule \+ -Wl,-U,_MTLMetalLibCreateExecutableWithTriple \+ -Wl,-U,_MTLMetalFunctionCreate \+ -Wl,-U,_MTLMetalLibInsertFunction \+ -Wl,-U,_MTLWriteMetalLibToMemoryBufferARTIFACTS := $(CAMFIX) $(VCAMCAPTURED) $(LAUNCHHOOK) $(SYSTEMHOOK) $(GPU_PLUGIN)PLISTS := $(STAGE)/camfix/libcamfix.plist $(STAGE)/vcamcaptured/libvcamcaptured.plistGPU_PROVENANCE := $(STAGE)/gpu/README.md@@ -89,7 +113,7 @@ $(SYSTEMHOOK): $(SYSTEMHOOK_SOURCES) $(SYSTEMHOOK_INCLUDES) SystemHook Shared |$(GPU_PLUGIN): $(GPU_PLUGIN_SOURCES) $(GPU_PLUGIN_INCLUDES) GraphicLoader | $(STAGE)/gpuxcrun --sdk iphoneos clang++ -arch arm64e -miphoneos-version-min=26.1 \- -std=c++17 -O2 -dynamiclib -Wl,-undefined,dynamic_lookup \+ -std=c++17 -O2 -dynamiclib $(GPU_DYNAMIC_LOOKUP_SYMS) \-Wl,-not_for_dyld_shared_cache \-install_name /System/Library/Extensions/AppleParavirtGPUMetalIOGPUFamily.bundle/libAppleParavirtCompilerPluginIOGPUFamily.dylib \-o $@ $(GPU_PLUGIN_SOURCES)diff --git a/VPhoneGuestComponents/VCamCaptured/VCamImageResolution.inc b/VPhoneGuestComponents/VCamCaptured/VCamImageResolution.incindex f6ee442c..124a0142 100644--- a/VPhoneGuestComponents/VCamCaptured/VCamImageResolution.inc+++ b/VPhoneGuestComponents/VCamCaptured/VCamImageResolution.inc@@ -518,7 +518,13 @@ static BOOL vcc_slot_value_is_cfarray(uintptr_t slot_addr) {for (unsigned i = 0; array_classes[i]; i++) {Class c = objc_getClass(array_classes[i]);if (!c) continue;- uintptr_t c_class = ((uintptr_t)c) & VCC_ISA_CLASS_MASK;+ // Compare against the class object's raw address. Copy its bits into an+ // integer first so the mask runs on a plain uintptr_t: bit-twiddling an+ // Objective-C pointer directly is deprecated+ // (-Wdeprecated-objc-pointer-introspection).+ uintptr_t c_addr;+ memcpy(&c_addr, &c, sizeof(c_addr));+ uintptr_t c_class = c_addr & VCC_ISA_CLASS_MASK;if (isa_class == c_class) return YES;}return NO;