Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Create Irisin's data folder in the jbroot's home on RootHide

Lakrc4a008136dc0
diff --git a/Research/vphoned_http_api.md b/Research/vphoned_http_api.md
index da8dcecf..b55006f6 100644
--- a/Research/vphoned_http_api.md
+++ b/Research/vphoned_http_api.md
@@ -117,10 +117,15 @@ It selects the matching architecture, verifies the release
asset's GitHub SHA-256 digest and Debian control fields, then uses IcliKit to
extract the `.deb` into a temporary directory. It copies the full payload
into the bootstrap, creates Irisin's mobile-owned data directory, registers
-the app with IcliKit, and loads the daemon through IcliKit. mobile owns
-`/var/mobile/Documents`, so vphoned opens it and `wiki.qaq.irisin` without
-following a symlink. It refuses an entry that is not a real directory and sets
-the owner and mode through the directory descriptor. It also attempts
+the app with IcliKit, and loads the daemon through IcliKit. The data directory
+is `Documents/wiki.qaq.irisin` in the app's home: the system's `/var/mobile`
+on rootless, the jbroot's `var/mobile` on RootHide, where an uncontained
+bootstrap app gets that as HOME (`CFFIXED_USER_HOME`) and dpkg puts package
+data. mobile owns the home and `Documents`, so vphoned opens each level
+relative to its parent without following a symlink, creates a missing level
+owned by mobile (a missing jbroot `var` root-owned), refuses an entry that is
+not a real directory, and sets the owner and mode through the directory
+descriptor. 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
diff --git a/Skills/vphone-guest-control/references/guest-layout.md b/Skills/vphone-guest-control/references/guest-layout.md
index 73daf528..963ec89e 100644
--- a/Skills/vphone-guest-control/references/guest-layout.md
+++ b/Skills/vphone-guest-control/references/guest-layout.md
@@ -118,7 +118,9 @@ vphone-launchpad-cli guest rpc myphone bootstrap.uninstall '{"roots":["<path fro
Uninstall removes **every listed root**, unloads their daemons, unregisters
their apps, marks the record uninstalled and **reboots the guest** (add
`"reboot":false` to skip). The paths must match the current inspection
-exactly. Irisin's data under `/var/mobile/Documents` is kept. It destroys the
+exactly. Rootless Irisin keeps its data in the system's
+`/var/mobile/Documents`, which is kept; RootHide Irisin keeps it in the
+jbroot's `var/mobile`, which goes with the root. It destroys the
user's installed packages, so run it only when asked or as the stated recovery
for a failed first install.
diff --git a/VPhoneDaemon/Daemon/Bootstrap/GuestIrisinInstaller+Payload.swift b/VPhoneDaemon/Daemon/Bootstrap/GuestIrisinInstaller+Payload.swift
index 3d82a34b..070d3f63 100644
--- a/VPhoneDaemon/Daemon/Bootstrap/GuestIrisinInstaller+Payload.swift
+++ b/VPhoneDaemon/Daemon/Bootstrap/GuestIrisinInstaller+Payload.swift
@@ -22,35 +22,54 @@ extension GuestIrisinInstaller {
else { throw GuestAPIError.operationFailed("Irisin release payload is incomplete or has the wrong layout") }
}
- /// mobile owns /var/mobile/Documents, so either path component may be a
- /// symlink it planted to have root hand another directory to mobile. Both
- /// are opened without following a link, and ownership is set through the
- /// descriptor rather than the path.
- static func prepareAppData() throws {
- let documents = "/var/mobile/Documents"
- let name = "wiki.qaq.irisin"
- if mkdir(documents, 0o755) != 0, errno != EEXIST {
- throw GuestAPIError.operationFailed("Could not create \(documents): \(String(cString: strerror(errno)))")
- }
- let parent = open(documents, O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC)
- guard parent >= 0 else {
- throw GuestAPIError.operationFailed("\(documents) is not a real directory")
- }
- defer { close(parent) }
- if mkdirat(parent, name, 0o755) != 0, errno != EEXIST {
- throw GuestAPIError.operationFailed("Could not create Irisin app data: \(String(cString: strerror(errno)))")
+ /// The bootstrap app's home: RootHide gives an uncontained app the
+ /// jbroot's `/var/mobile` as HOME, and its dpkg puts package data there;
+ /// rootless uses the system's.
+ static func appHome(layout: String, root: String) -> String {
+ layout == "roothide" ? root + "/var/mobile" : "/var/mobile"
+ }
+
+ /// mobile owns its home and Documents, so any of the three mobile-owned
+ /// levels may be a symlink it planted to have root hand another directory
+ /// to mobile. Each is opened relative to its parent without following a
+ /// link, a level vphoned creates is given to mobile, and ownership is set
+ /// through the descriptor rather than the path. A fresh jbroot may have
+ /// no `var` yet; it is created root-owned like the rest of the base.
+ static func prepareAppData(home: String) throws {
+ let parentPath = (home as NSString).deletingLastPathComponent
+ if mkdir(parentPath, 0o755) == 0 {
+ guard chown(parentPath, 0, 0) == 0, chmod(parentPath, 0o755) == 0 else {
+ throw GuestAPIError.operationFailed("Could not set the owner and mode of \(parentPath)")
+ }
+ } else if errno != EEXIST {
+ throw GuestAPIError.operationFailed("Could not create \(parentPath): \(String(cString: strerror(errno)))")
}
- var info = stat()
- guard fstatat(parent, name, &info, AT_SYMLINK_NOFOLLOW) == 0,
- info.st_mode & mode_t(S_IFMT) == mode_t(S_IFDIR)
- else { throw GuestAPIError.operationFailed("Irisin app data path is not a real directory") }
- let directory = openat(parent, name, O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC)
- guard directory >= 0 else {
- throw GuestAPIError.operationFailed("Irisin app data path is not a real directory")
+ var current = open(parentPath, O_RDONLY | O_DIRECTORY | O_CLOEXEC)
+ guard current >= 0 else {
+ throw GuestAPIError.operationFailed("\(parentPath) is not a directory")
}
- defer { close(directory) }
- guard fchown(directory, 501, 501) == 0, fchmod(directory, 0o755) == 0 else {
- throw GuestAPIError.operationFailed("Could not assign Irisin app data to mobile")
+ defer { close(current) }
+ let levels = [(home as NSString).lastPathComponent, "Documents", "wiki.qaq.irisin"]
+ for (index, name) in levels.enumerated() {
+ let created = mkdirat(current, name, 0o755) == 0
+ if !created, errno != EEXIST {
+ throw GuestAPIError.operationFailed("Could not create Irisin app data: \(String(cString: strerror(errno)))")
+ }
+ var info = stat()
+ guard fstatat(current, name, &info, AT_SYMLINK_NOFOLLOW) == 0,
+ info.st_mode & mode_t(S_IFMT) == mode_t(S_IFDIR)
+ else { throw GuestAPIError.operationFailed("Irisin app data path is not a real directory: \(name)") }
+ let next = openat(current, name, O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC)
+ guard next >= 0 else {
+ throw GuestAPIError.operationFailed("Irisin app data path is not a real directory: \(name)")
+ }
+ close(current)
+ current = next
+ if created || index == levels.count - 1 {
+ guard fchown(current, 501, 501) == 0, fchmod(current, 0o755) == 0 else {
+ throw GuestAPIError.operationFailed("Could not assign Irisin app data to mobile")
+ }
+ }
}
}
diff --git a/VPhoneDaemon/Daemon/Bootstrap/GuestIrisinInstaller.swift b/VPhoneDaemon/Daemon/Bootstrap/GuestIrisinInstaller.swift
index f0b04689..d21a582c 100644
--- a/VPhoneDaemon/Daemon/Bootstrap/GuestIrisinInstaller.swift
+++ b/VPhoneDaemon/Daemon/Bootstrap/GuestIrisinInstaller.swift
@@ -316,7 +316,7 @@ enum GuestIrisinInstaller {
if layout == "roothide" {
_ = try patchRootHideDaemon(at: plist.path, root: root)
}
- try prepareAppData()
+ try prepareAppData(home: appHome(layout: layout, root: root))
let rootURL = URL(fileURLWithPath: root, isDirectory: true)
let installedApp = rootURL.appendingPathComponent("Applications/irisin.app", isDirectory: true)