Run a virtual iPhone on an Apple Silicon Mac.
Swift
Remove obsolete shared restore and staging directory compatibility
Lakrcb518e6aef5f
diff --git a/Documents/Guides/create-and-run.md b/Documents/Guides/create-and-run.mdindex 69359b15..98f70771 100644--- a/Documents/Guides/create-and-run.md+++ b/Documents/Guides/create-and-run.md@@ -58,7 +58,7 @@ The online restore obtains its ticket in process. For an offline restore, see `v| `~/.vphone/machines/<name>/` | One VM, including its disk, `config.plist`, and patch work files || `~/.vphone/machines/<name>/.ipsw-cache/` | Remote source IPSWs downloaded for that VM; local IPSWs are read in place |-`VPHONE_ROOT` relocates the VM library. `VPHONE_LIBRARY_ROOT` takes precedence for the library alone. Downloaded IPSWs remain cached inside their VM; the prepared restore tree is removed after a successful `vm create` unless `--keep-artifacts` is set. JB patching does not create `~/.vphone/tools`.+`VPHONE_ROOT` relocates the VM library. `VPHONE_LIBRARY_ROOT` takes precedence for the library alone. Downloaded IPSWs remain cached inside their VM; the prepared restore tree is removed after a successful `vm create` unless `--keep-artifacts` is set.```shvphone-cli vm listdiff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Host/VPhonePCCGPURecovery.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Host/VPhonePCCGPURecovery.swiftindex dff9f0b5..453872ce 100644--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Host/VPhonePCCGPURecovery.swift+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/Host/VPhonePCCGPURecovery.swift@@ -40,6 +40,7 @@ enum VPhonePCCGPURecovery {romSource: VPhoneBundleOperations.defaultROMSource(),sepromSource: VPhoneBundleOperations.defaultSEPROMSource(),), in: library)+ let temporaryRestore = vm.url.appending(path: "iPhonePCC_Restore")defer {let diskImage = vm.url.appendingPathComponent("Disk.img")if let info = try? run("/usr/bin/hdiutil", ["info"]),@@ -51,12 +52,9 @@ enum VPhonePCCGPURecovery {}}- // The restore backend accepts a linked directory. Reuse the already- // extracted cloudOS tree instead of writing a second copy of its OS image.- try fm.createSymbolicLink(- at: vm.url.appending(path: "iPhonePCC_Restore"),- withDestinationURL: cloudOSDirectory,- )+ // The manifest already consumed this tree. Move it into the temporary+ // machine so restore reads only from that machine's directory.+ try fm.moveItem(at: cloudOSDirectory, to: temporaryRestore)let launcher = try VPhoneGuestLaunchPlanner()let (executable, arguments) = launcher.plan(["--config", vm.configURL.path, "--dfu"])let dfu = VPhoneManagedProcess(executable, arguments, cwd: vm.url, echo: false)diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneRestore/VPhoneRestore/Restore/VPhoneRestoreLayout.swift b/VPhoneExecutable/VPhoneCommand/VPhoneRestore/VPhoneRestore/Restore/VPhoneRestoreLayout.swiftindex c3a3ce29..b469e0a9 100644--- a/VPhoneExecutable/VPhoneCommand/VPhoneRestore/VPhoneRestore/Restore/VPhoneRestoreLayout.swift+++ b/VPhoneExecutable/VPhoneCommand/VPhoneRestore/VPhoneRestore/Restore/VPhoneRestoreLayout.swift@@ -4,14 +4,12 @@ import Foundation/// Where a restore's files sit inside a VM bundle.///-/// Both rules here come from `scripts/pymobiledevice3_bridge.py` and both are-/// load-bearing: `vphone-cli restore --offline` and the-/// `vm create` orchestrator all find the `.shsh` by the name this produces.+/// `vphone-cli restore --offline` and the `vm create` orchestrator find the+/// `.shsh` by the name this produces.public enum VPhoneRestoreLayout {// MARK: Restore directory- /// Python's `find_restore_dir`: the ONE `iPhone*_Restore` directory in the- /// bundle.+ /// The one `iPhone*_Restore` directory in the bundle.////// Neither failure is defensive. None means `fw_prepare` has not run (or/// ran into a different bundle), and more than one means two firmware trees@@ -28,7 +26,7 @@ public enum VPhoneRestoreLayout {return vmDir.appendingPathComponent(first, isDirectory: true)}- /// The sorted names matching Python's `vm_dir.glob("iPhone*_Restore")`.+ /// The sorted names matching `iPhone*_Restore` inside the bundle.////// `hasPrefix` + `hasSuffix` is the whole of that glob here, because no/// suffix of "iPhone" is a prefix of "_Restore" — the two literals cannot@@ -41,25 +39,16 @@ public enum VPhoneRestoreLayout {return entries.filter { name inguard name.hasPrefix("iPhone"), name.hasSuffix("_Restore") else { return false }- // `fileExists(atPath:isDirectory:)` stats through a symlink,- // which is what Python's `p.is_dir()` did — a bundle that- // points its restore tree at a shared firmware directory has- // to keep working. `URLResourceValues.isDirectory` would NOT:- // it answers for the link itself.- var isDirectory: ObjCBool = false- let exists = fm.fileExists(- atPath: vmDir.appendingPathComponent(name).path,- isDirectory: &isDirectory,- )- return exists && isDirectory.boolValue+ return (try? vmDir.appendingPathComponent(name)+ .resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory == true}.sorted()}// MARK: SHSH output- /// Python's `derive_shsh_output`: `<ECID as %016X>.shsh` beside the bundle,- /// or `auto.shsh` when the device never reported an ECID.+ /// `<ECID as %016X>.shsh` beside the bundle, or `auto.shsh` when the device+ /// never reported an ECID.////// The name is a contract, not a convenience — `VPhoneRestoreCommand`'s/// `--offline` path picks the first `*.shsh` in the bundle, and thediff --git a/VPhoneExecutable/VPhoneCommand/VPhoneRestore/VPhoneRestoreTests/RestoreLayoutTests.swift b/VPhoneExecutable/VPhoneCommand/VPhoneRestore/VPhoneRestoreTests/RestoreLayoutTests.swiftindex 0480e982..f8a60929 100644--- a/VPhoneExecutable/VPhoneCommand/VPhoneRestore/VPhoneRestoreTests/RestoreLayoutTests.swift+++ b/VPhoneExecutable/VPhoneCommand/VPhoneRestore/VPhoneRestoreTests/RestoreLayoutTests.swift@@ -2,7 +2,7 @@ import Foundationimport Testing@testable import VPhoneRestore-/// `find_restore_dir` and `derive_shsh_output`. Both rules are contracts:+/// Restore directory and ticket naming rules. Both are contracts:/// `--offline` picks the first `*.shsh` in a bundle, and restoring from/// whichever of two firmware trees happened to sort first would flash a build/// nobody chose.@@ -82,8 +82,7 @@ struct RestoreLayoutTests {@Test func `a file with the right name is not A restore tree`() throws {try withTemporaryDirectory { root in- // Python's `if p.is_dir()`. A stray file would otherwise be handed- // to idevicerestore as a restore directory.+ // A stray file must not be handed to idevicerestore as a restore directory.try Data("not a tree".utf8).write(to: root.appendingPathComponent("iPhone17,3_Restore"))#expect(throws: VPhoneRestoreBackendError.noRestoreDirectory(root)) {@@ -111,17 +110,16 @@ struct RestoreLayoutTests {}}- @Test func `a symlink to A directory counts`() throws {+ @Test func `a symlink to a shared directory is not a restore tree`() throws {try withTemporaryDirectory { root in- // Python's glob + `p.is_dir()` follows symlinks, and a bundle that- // points at a shared firmware tree is a reasonable thing to build.try makeDirectory("real_tree", in: root)try FileManager.default.createSymbolicLink(at: root.appendingPathComponent("iPhone17,3_Restore"),withDestinationURL: root.appendingPathComponent("real_tree"),)- let found = try VPhoneRestoreLayout.findRestoreDirectory(in: root)- #expect(found.lastPathComponent == "iPhone17,3_Restore")+ #expect(throws: VPhoneRestoreBackendError.noRestoreDirectory(root)) {+ try VPhoneRestoreLayout.findRestoreDirectory(in: root)+ }}}diff --git a/VPhoneExecutable/VPhoneVirtualization/Build/StageBundle.sh b/VPhoneExecutable/VPhoneVirtualization/Build/StageBundle.shindex e77b87a5..1adedf52 100755--- a/VPhoneExecutable/VPhoneVirtualization/Build/StageBundle.sh+++ b/VPhoneExecutable/VPhoneVirtualization/Build/StageBundle.sh@@ -79,8 +79,6 @@ compatibility_library="$(/usr/bin/xcrun swift-stdlib-tool --print \/bin/cp "$compatibility_library" "$macos/libswiftCompatibilitySpan.vphone.dylib"/usr/bin/install_name_tool -change @rpath/libswiftCompatibilitySpan.dylib \@loader_path/libswiftCompatibilitySpan.vphone.dylib "$macos/vphone-vm"-/bin/rm -f "$macos/libswiftCompatibilitySpan.dylib" \- "$macos/libswiftCompatibilitySpan.dylib.original"/bin/rm -f "$bundle/Contents/Frameworks/libswiftCompatibilitySpan.dylib"/usr/bin/codesign --force --sign - "$macos/vphone-cli"diff --git a/VPhoneKit/VPhoneArchiveKit/Archive/VPhoneArchiveWriter.swift b/VPhoneKit/VPhoneArchiveKit/Archive/VPhoneArchiveWriter.swiftindex 3459b788..08b2bccf 100644--- a/VPhoneKit/VPhoneArchiveKit/Archive/VPhoneArchiveWriter.swift+++ b/VPhoneKit/VPhoneArchiveKit/Archive/VPhoneArchiveWriter.swift@@ -19,9 +19,8 @@ public enum VPhoneArchiveWriter {/// `vm export` needs it: an export holds exactly one top-level bundle/// directory, and import checks for exactly that.///- /// `excluding` takes `fnmatch` patterns, matched against the path relative- /// to `root` — not against `topLevel/...`, so a VM whose name happens to- /// contain `cfw_input` does not exclude its own contents.+ /// `excluding` takes `fnmatch` patterns matched against paths relative to+ /// `root`, not against `topLevel/...`.////// `bytesPacked` reports the running total of file bytes copied, as they/// are copied. `progress` fires once per entry, which is enough for adiff --git a/VPhoneKit/VPhoneArchiveKitTests/BundleTransferTests.swift b/VPhoneKit/VPhoneArchiveKitTests/BundleTransferTests.swiftindex 9128b6f2..c81e1ac0 100644--- a/VPhoneKit/VPhoneArchiveKitTests/BundleTransferTests.swift+++ b/VPhoneKit/VPhoneArchiveKitTests/BundleTransferTests.swift@@ -150,22 +150,12 @@ struct BundleTransferTests {defer { try? FileManager.default.removeItem(at: root) }let lib = VPhoneLibrary(root: root)let b = try makeBundle("orig", in: lib)- let fm = FileManager.defaulttry Data([0]).write(to: b.url.appendingPathComponent(".vphoned.signed"))- try fm.createDirectory(at: b.url.appendingPathComponent("cfw_input/jb"), withIntermediateDirectories: true)- try Data([0]).write(to: b.url.appendingPathComponent("cfw_input/jb/f"))- try fm.createDirectory(at: b.url.appendingPathComponent("cfw_jb_input"), withIntermediateDirectories: true)- try Data([0]).write(to: b.url.appendingPathComponent("cfw_jb_input/f"))- try fm.createDirectory(at: b.url.appendingPathComponent(".cfw_temp"), withIntermediateDirectories: true)- try Data([0]).write(to: b.url.appendingPathComponent(".cfw_temp/f"))let archive = root.appendingPathComponent("orig.tgz")try VPhoneBundleTransfer.export(bundleNamed: "orig", to: archive, includeIPSW: false, in: lib)let members = try VPhoneArchiveReader.entries(of: archive).map(\.path)#expect(!members.contains { $0.contains(".vphoned.signed") })- #expect(!members.contains { $0.contains("cfw_input") })- #expect(!members.contains { $0.contains("cfw_jb_input") })- #expect(!members.contains { $0.contains(".cfw_temp") })// The real payload still travels.#expect(members.contains("orig/Disk.img"))#expect(members.contains("orig/config.plist"))diff --git a/VPhoneKit/VPhoneCoreKit/Bundle/VPhoneBundleOperations.swift b/VPhoneKit/VPhoneCoreKit/Bundle/VPhoneBundleOperations.swiftindex ff643055..873b128f 100644--- a/VPhoneKit/VPhoneCoreKit/Bundle/VPhoneBundleOperations.swift+++ b/VPhoneKit/VPhoneCoreKit/Bundle/VPhoneBundleOperations.swift@@ -191,14 +191,10 @@ public enum VPhoneBundleOperations {// MARK: - Export- /// Regenerable staging artifacts that never need to travel in an export:- /// `.vphoned.signed` is re-staged on the next launch, and the CFW install- /// inputs/temp are consumed at install time (the result already lives in- /// `Disk.img`). Always excluded.+ /// `.vphoned.signed` is re-staged on the next launch and need not be exported.////// Export itself is `VPhoneBundleTransfer` in `VPhoneArchiveKit` — it needs/// libarchive, and this does not. The list stays here because it describes/// what a bundle is, and `VPhoneRestoreInfo` is checked against it.- public static let exportExcludePatterns =- ["*.vphoned.signed", "*cfw_input*", "*cfw_jb_input*", "*.cfw_temp*"]+ public static let exportExcludePatterns = ["*.vphoned.signed"]}