Run a virtual iPhone on an Apple Silicon Mac.
Swift
Ship only pre-signed vphoned in VPhone bundle
Lakrcabb80a13e9f
diff --git a/Documents/Guides/bundle-integration.md b/Documents/Guides/bundle-integration.mdindex 1a899750..697508c9 100644--- a/Documents/Guides/bundle-integration.md+++ b/Documents/Guides/bundle-integration.md@@ -11,9 +11,10 @@ executables and resources, not a macOS app or a dynamically loaded plug-in.| `Contents/MacOS/vphone-cli` | Unentitled command entry point || `Contents/MacOS/vphone-vm` | VM and window process; private virtualization entitlements || `Contents/MacOS/VPhoneEscalator` | AMFI allowlist tool for the current VM cdhash |-| `Contents/MacOS/vphoned.signed` | Guest daemon payload with its own entitlements |+| `Contents/MacOS/vphoned.signed` | Pre-signed guest daemon payload with its own entitlements; the bundle contains no unsigned copy || Guest dylibs in `Contents/MacOS` | Guest installation payloads |-| `Contents/Resources` | Guest configuration and nonexecutable resources |+| `Contents/Resources/guest/vphoned.plist` | Guest launch daemon configuration |+| `Contents/Resources` | Guest configuration and nonexecutable resources; no signing script or entitlement file is shipped |All executable payloads use ad hoc code signatures. Only the required childprocesses carry private entitlements. The bundle has no `CFBundleExecutable`,diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcherGuestPayload.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcherGuestPayload.swiftindex 568caeec..e9bd48e5 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcherGuestPayload.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/CryptexFilesystem/CryptexFilesystemPatcherGuestPayload.swift@@ -44,15 +44,12 @@ extension CryptexFilesystemPatcher {func injectLaunchDaemons(targetMount: String) throws {let target = URL(filePath: targetMount)- let scriptDir = resources.scriptsDir-let tmpDir = try createTmpDir()let launchdPath = tmpDir.appending(path: "launchd.plist")let launchdOgPath = target.appending(path: "/System/Library/xpc/launchd.plist")try FileManager.default.moveItem(at: launchdOgPath, to: launchdPath)- let vphonedSrc = scriptDir.appendingPathComponent("vphoned")- let vphonedLaunchdPlist = vphonedSrc.appending(path: "vphoned.plist")+ let vphonedLaunchdPlist = resources.base.appendingPathComponent("guest/vphoned.plist")try FileManager.default.copyItem(at: vphonedLaunchdPlist,to: target.appending(path: "System/Library/LaunchDaemons/vphoned.plist"),@@ -65,25 +62,16 @@ extension CryptexFilesystemPatcher {func addVphoned(targetMount: String) throws {let target = URL(filePath: targetMount)- let scriptDir = resources.scriptsDir- let vphonedSrc = scriptDir.appendingPathComponent("vphoned")- // vphonedSrc (bundled source) is read-only inside a packaged .app, so the- // compiled binary must land in a writable temp dir, not next to the source.+ // The signed payload in the bundle is read-only, so stage it in a+ // writable temp directory before copying it into the mounted guest.let buildDir = try createTmpDir()let vphonedBin = buildDir.appendingPathComponent("vphoned")try stageVphoned(to: vphonedBin)defer { try? FileManager.default.removeItem(at: vphonedBin) }- // Signlet targetBin = target.appending(path: "/usr/bin/vphoned")try FileManager.default.copyItem(at: vphonedBin, to: targetBin)- try VPhoneSigner.sign(- fileAt: targetBin,- options: guestSigningOptions(- entitlements: vphonedSrc.appendingPathComponent("VPhoneDaemon.entitlements"),- ),- )try setMode(0o755, at: targetBin)}@@ -95,7 +83,7 @@ extension CryptexFilesystemPatcher {/// that VM. vphoned is cross-compiled at build time now/// by the Xcode guest target and staged into the bundle.func stageVphoned(to vphonedBin: URL) throws {- let prebuilt = try VPhoneGuestBinaries.resolve("vphoned")+ let prebuilt = try VPhoneGuestBinaries.resolve("vphoned.signed")try FileManager.default.copyItem(at: prebuilt, to: vphonedBin)}diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swiftindex ba233bae..07e4b362 100644--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Firmware/VPhoneCustomFirmwareInstaller.swift@@ -355,7 +355,7 @@ struct VPhoneCustomFirmwareInstaller {// Install the same signed bytes that vm launch uses for auto-update.// Re-signing here changes the binary hash and forces an upload and// daemon restart on the VM's first boot.- let vphoned = try VPhoneGuestBinaries.resolve("vphoned")+ let vphoned = try VPhoneGuestBinaries.resolve("vphoned.signed")let staged = work.appendingPathComponent("vphoned")try fm.copyItem(at: vphoned, to: staged)try replace(staged, at: system.appendingPathComponent("usr/bin/vphoned"), mode: 0o755)@@ -364,7 +364,7 @@ struct VPhoneCustomFirmwareInstaller {try fm.removeItem(at: signed)}try fm.copyItem(at: staged, to: signed)- let daemon = resources.scriptsDir.appendingPathComponent("vphoned/vphoned.plist")+ let daemon = resources.base.appendingPathComponent("guest/vphoned.plist")try replace(daemon,at: system.appendingPathComponent(diff --git a/VPhoneExecutable/VPhoneVirtualization/Build/StageBundle.sh b/VPhoneExecutable/VPhoneVirtualization/Build/StageBundle.shindex 7c2ad469..55763a5a 100755--- a/VPhoneExecutable/VPhoneVirtualization/Build/StageBundle.sh+++ b/VPhoneExecutable/VPhoneVirtualization/Build/StageBundle.sh@@ -50,18 +50,17 @@ if /usr/bin/nm -u "$daemon_products/vphoned" | /usr/bin/grep -q '_swift_initBorrfi/bin/rm -rf "$macos" "$resources"-/bin/mkdir -p "$macos" "$resources/scripts/vphoned" "$resources/guest"+/bin/mkdir -p "$macos" "$resources/guest"/bin/cp "$TARGET_BUILD_DIR/vphone-vm" "$macos/vphone-vm"/bin/cp "$command_products/vphone-cli" "$macos/vphone-cli"-/bin/cp "$daemon_products/vphoned" "$macos/vphoned"+/bin/cp "$daemon_products/vphoned" "$macos/vphoned.signed"/bin/cp "$amfi_products/VPhoneEscalator" "$macos/VPhoneEscalator"/bin/cp "$guest_products/camfix/libcamfix.dylib" "$macos/libcamfix.dylib"/bin/cp "$guest_products/vcamcaptured/libvcamcaptured.dylib" "$macos/libvcamcaptured.dylib"/bin/cp "$guest_products/launchhook/launchdhook-vphone.dylib" "$macos/launchdhook-vphone.dylib"/bin/cp "$guest_products/systemhook/SystemHook-vphone.dylib" "$macos/SystemHook-vphone.dylib"/bin/cp "$guest_products/gpu/libAppleParavirtCompilerPluginIOGPUFamily.dylib" "$macos/libAppleParavirtCompilerPluginIOGPUFamily.dylib"-/bin/cp "$root/VPhoneDaemon/Configuration/vphoned.plist" "$resources/scripts/vphoned/vphoned.plist"-/bin/cp "$root/VPhoneDaemon/Configuration/VPhoneDaemon.entitlements" "$resources/scripts/vphoned/VPhoneDaemon.entitlements"+/bin/cp "$root/VPhoneDaemon/Configuration/vphoned.plist" "$resources/guest/vphoned.plist"/bin/cp "$guest_products/camfix/libcamfix.plist" "$resources/guest/libcamfix.plist"/bin/cp "$guest_products/vcamcaptured/libvcamcaptured.plist" "$resources/guest/libvcamcaptured.plist"@@ -83,8 +82,7 @@ compatibility_library="$(/usr/bin/xcrun swift-stdlib-tool --print \/bin/rm -f "$bundle/Contents/Frameworks/libswiftCompatibilitySpan.dylib"/usr/bin/codesign --force --sign - "$macos/vphone-cli"-/usr/bin/codesign --force --sign - --entitlements "$root/VPhoneDaemon/Configuration/VPhoneDaemon.entitlements" "$macos/vphoned"-/bin/cp "$macos/vphoned" "$macos/vphoned.signed"+/usr/bin/codesign --force --sign - --entitlements "$root/VPhoneDaemon/Configuration/VPhoneDaemon.entitlements" "$macos/vphoned.signed"/usr/bin/codesign --force --sign - "$macos/VPhoneEscalator"/usr/bin/codesign --force --sign - "$macos/libswiftCompatibilitySpan.vphone.dylib"/usr/bin/codesign --force --sign - --entitlements "$root/VPhoneExecutable/VPhoneVirtualization/Resources/VPhoneVirtualization.entitlements" "$macos/vphone-vm"diff --git a/VPhoneExecutable/VPhoneVirtualization/Build/ValidateBundle.sh b/VPhoneExecutable/VPhoneVirtualization/Build/ValidateBundle.shindex dcfaf1d2..d7fc9d1d 100755--- a/VPhoneExecutable/VPhoneVirtualization/Build/ValidateBundle.sh+++ b/VPhoneExecutable/VPhoneVirtualization/Build/ValidateBundle.sh@@ -19,7 +19,7 @@ file_copy_spawns="$(/usr/bin/find "$root/VPhoneExecutable" "$root/VPhoneKit" \[[ -d "$bundle" ]] || { print -u2 "Missing Xcode bundle: $bundle"; exit 1; }-for name in vphone-vm vphone-cli VPhoneEscalator vphoned vphoned.signed \+for name in vphone-vm vphone-cli VPhoneEscalator vphoned.signed \libswiftCompatibilitySpan.vphone.dylib libcamfix.dylib libvcamcaptured.dylib \launchdhook-vphone.dylib SystemHook-vphone.dylib \libAppleParavirtCompilerPluginIOGPUFamily.dylib; do@@ -34,16 +34,18 @@ for name in vphone-vm vphone-cli VPhoneEscalator vphoned vphoned.signed \}done-for name in vphone-app VPhoneAMFIAllow vphone-archive icli vpregister vphone-ask-for-permission; do+for name in vphoned vphone-app VPhoneAMFIAllow vphone-archive icli vpregister vphone-ask-for-permission; do[[ ! -e "$macos/$name" ]] || { print -u2 "Obsolete binary: $name"; exit 1; }done-for name in vphoned.plist VPhoneDaemon.entitlements; do- [[ -f "$resources/scripts/vphoned/$name" ]] || {- print -u2 "Missing guest configuration: $name"- exit 1- }-done+[[ -f "$resources/guest/vphoned.plist" ]] || {+ print -u2 "Missing guest configuration: vphoned.plist"+ exit 1+}+[[ ! -e "$resources/scripts" ]] || {+ print -u2 "Obsolete scripts directory in bundle"+ exit 1+}/usr/bin/codesign --verify --strict "$bundle"/usr/bin/codesign --verify "$macos/vphone-vm"