Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Store bootstrap completion on writable data volume

Lakr158d704bc4a9
diff --git a/Research/vphoned_http_api.md b/Research/vphoned_http_api.md
index c909e6c4..cf8a712a 100644
--- a/Research/vphoned_http_api.md
+++ b/Research/vphoned_http_api.md
@@ -42,6 +42,9 @@ into the bootstrap, creates Irisin's mobile-owned data directory, registers
the app with IcliKit, and loads the daemon through IcliKit. It also attempts
to start the daemon; a launchd start error is returned as
`service_start_warning` while the installed bootstrap remains available.
+On the iOS 26.6.2 RootHide test VM, launchd returned service-configure status
+144 during installation, then started `irisind` on demand when Irisin opened
+after a reboot.
RootHide's plist gets a physical daemon path and `__Patched`
marker before launchd reads it. This is a manual payload install: no maintainer
script runs. For this minimal vphone bootstrap, vphoned writes a real installed
@@ -63,8 +66,11 @@ jobs whose launch path does not pass through either observed spawn bridge.
repairs the record for a bootstrap already identified by the completion marker
without running another install. The reply includes the tag,
bootstrap path, registration record, and launchd status. A successful bootstrap
-writes `.vphoned-boostrap-completed` beside the running vphoned binary; later
-requests refuse to bootstrap again when that marker exists.
+writes `/private/var/db/vphoned/bootstrap.json` on the writable data volume;
+later requests refuse to bootstrap again while that record describes an installed
+bootstrap. Older records beside the vphoned binary are read when no data-volume
+record exists. Uninstall writes a tombstone so a legacy record on a read-only
+system volume cannot reappear.
The VM window exposes the same operation at Guest > Install Bootstrap…;
choose Rootless or RootHide in the confirmation sheet. The item is enabled
when vphoned advertises `bootstrap_install`. Its sheet polls
@@ -82,10 +88,11 @@ recorded by vphoned. A rootless `/var/jb` symlink is accepted only when its
target is a physical directory under `/private/preboot`; the target and link
are both removed. The daemon rejects a changed path and symlinked child
directories. It unloads the bootstrap's launch daemons, unregisters apps in
-its `Applications` directory, deletes the bootstrap root and completion marker,
-then schedules a full guest reboot. If cleanup fails, the marker remains so
-the operation can be retried. Irisin's mobile Documents data outside the
-bootstrap is retained. Guest > Uninstall Bootstrap… shows the recorded path
+its `Applications` directory, deletes the bootstrap root, marks the completion
+record uninstalled, then schedules a full guest reboot. If cleanup fails, the
+installed record remains so the operation can be retried. Irisin's mobile
+Documents data outside the bootstrap is retained. Guest > Uninstall Bootstrap…
+shows the recorded path
in a destructive confirmation alert before sending the request.
## HTTP and WebSocket contract
diff --git a/VPhoneDaemon/Daemon/GuestIrisinInstaller.swift b/VPhoneDaemon/Daemon/GuestIrisinInstaller.swift
index 932bc195..1fcadcd6 100644
--- a/VPhoneDaemon/Daemon/GuestIrisinInstaller.swift
+++ b/VPhoneDaemon/Daemon/GuestIrisinInstaller.swift
@@ -11,15 +11,16 @@ enum GuestIrisinInstaller {
private static let installLock = NSLock()
private static let progressLock = NSLock()
nonisolated(unsafe) private static var progress: [String: Any] = ["phase": "idle"]
- private static let completionMarker = Bundle.main.executableURL!
+ private static let completionMarker = URL(fileURLWithPath: "/private/var/db/vphoned/bootstrap.json")
+ private static let legacyCompletionMarker = Bundle.main.executableURL!
.deletingLastPathComponent()
.appendingPathComponent(".vphoned-boostrap-completed")
static func install(jailbreak: [String: Any], layout: String) throws -> [String: Any] {
installLock.lock()
defer { installLock.unlock() }
- guard !itemExists(completionMarker) else {
- throw GuestAPIError.operationFailed("Irisin bootstrap already completed: \(completionMarker.path)")
+ guard try completedBootstrap() == nil else {
+ throw GuestAPIError.operationFailed("Irisin bootstrap already completed")
}
setProgress(["phase": "preparing", "layout": layout])
do {
@@ -82,7 +83,9 @@ enum GuestIrisinInstaller {
try files.removeItem(atPath: removal.physicalPath)
}
if removal.isSymlink { try files.removeItem(at: rootURL) }
- try files.removeItem(at: completionMarker)
+ // A legacy marker may live beside vphoned on the read-only system
+ // volume. Shadow it with a writable tombstone after removal.
+ try writeMarker(["installed": false])
DispatchQueue.global().asyncAfter(deadline: .now() + 1) {
do {
_ = try requestReboot(userspace: false, force: true)
@@ -94,10 +97,14 @@ enum GuestIrisinInstaller {
}
private static func completedBootstrap() throws -> (layout: String, root: String)? {
- guard itemExists(completionMarker) else { return nil }
- let data = try Data(contentsOf: completionMarker)
- guard let marker = try JSONSerialization.jsonObject(with: data) as? [String: String],
- let layout = marker["layout"], let root = marker["jbroot"],
+ guard let markerURL = markerForRead() else { return nil }
+ let data = try Data(contentsOf: markerURL)
+ guard let marker = try JSONSerialization.jsonObject(with: data) as? [String: Any] else {
+ throw GuestAPIError.operationFailed("Completed bootstrap marker is invalid")
+ }
+ if marker["installed"] as? Bool == false { return nil }
+ guard let layout = marker["layout"] as? String,
+ let root = marker["jbroot"] as? String,
(layout == "rootless" && root == "/var/jb") ||
(layout == "roothide" && root.hasPrefix("/private/var/containers/Bundle/Application/")
&& roothideName(String(root.dropFirst("/private/var/containers/Bundle/Application/".count))))
@@ -105,6 +112,21 @@ enum GuestIrisinInstaller {
return (layout, root)
}
+ private static func markerForRead() -> URL? {
+ if itemExists(completionMarker) { return completionMarker }
+ if itemExists(legacyCompletionMarker) { return legacyCompletionMarker }
+ return nil
+ }
+
+ private static func writeMarker(_ marker: [String: Any]) throws {
+ try FileManager.default.createDirectory(
+ at: completionMarker.deletingLastPathComponent(),
+ withIntermediateDirectories: true,
+ attributes: [.posixPermissions: 0o755],
+ )
+ try JSONSerialization.data(withJSONObject: marker).write(to: completionMarker, options: .atomic)
+ }
+
private static func directoryExistsWithoutSymlink(_ path: String) throws -> Bool {
var info = stat()
if lstat(path, &info) != 0 {
@@ -258,7 +280,7 @@ enum GuestIrisinInstaller {
setProgress(["phase": "firmware", "layout": layout, "tag": release.tag])
let firmware = try ensureFirmwareRecord(root: root)
let marker = ["tag": release.tag, "layout": layout, "jbroot": root]
- try JSONSerialization.data(withJSONObject: marker).write(to: completionMarker, options: .atomic)
+ try writeMarker(marker)
for entry in replaced {
if let backup = entry.backup { try? FileManager.default.removeItem(at: backup) }
}
@@ -301,22 +323,19 @@ enum GuestIrisinInstaller {
static func repairFirmwareRecord() throws -> [String: Any] {
installLock.lock()
defer { installLock.unlock() }
- let data = try Data(contentsOf: completionMarker)
- guard let marker = try JSONSerialization.jsonObject(with: data) as? [String: String],
- let layout = marker["layout"], let root = marker["jbroot"],
- layout == "rootless" || layout == "roothide",
- root == (try bootstrapRoot(layout: layout, detected: nil)),
- isDirectory(root)
+ guard let marker = try completedBootstrap(),
+ marker.root == (try bootstrapRoot(layout: marker.layout, detected: nil)),
+ isDirectory(marker.root)
else { throw GuestAPIError.operationFailed("No valid completed vphoned bootstrap was found") }
- let firmware = try ensureFirmwareRecord(root: root)
- return ["layout": layout, "jbroot": root,
+ let firmware = try ensureFirmwareRecord(root: marker.root)
+ return ["layout": marker.layout, "jbroot": marker.root,
"firmware_version": firmware.version, "dpkg_database_updated": firmware.updated]
}
static func refreshBootstrapOnStartup() {
- guard itemExists(completionMarker) else { return }
do {
- if let installation = try completedBootstrap(), installation.layout == "roothide" {
+ guard let installation = try completedBootstrap() else { return }
+ if installation.layout == "roothide" {
try ensureRootHideLinks(root: installation.root)
}
} catch {