Run a virtual iPhone on an Apple Silicon Mac.
Swift
Prevent device attitude simulation from respringing SpringBoard
Phineas Guo2be089b4417d
diff --git a/Research/0_binary_patch_comparison.md b/Research/0_binary_patch_comparison.mdindex b64a6548..b1a0b2ca 100644--- a/Research/0_binary_patch_comparison.md+++ b/Research/0_binary_patch_comparison.md@@ -281,6 +281,22 @@> guest cross-compilation passed; manual guest acceptance remains.> Contract and validation: `Research/Guest/virtual_attitude.md`.+> **Device attitude respring fix (2026-10-09; guest acceptance pending):**+> Two iOS 27.0.1 SpringBoard reports (19:41:21 and 19:42:51) show a+> Core Motion thread `SIGSEGV` at `0x10`, while the main thread calls native+> stop through `VPhoneAttitudeSession` during UIKit motion-effect subscription.+> The app-path loader had admitted SpringBoard; a fresh simulated session also+> stopped native updates without a preceding native start. SystemHook and the+> attitude dylib now exclude `/System/Library/` services and SpringBoard copies;+> native stop runs only for a previously forwarded native subscription.+> `system-apps-cfw-attitude` keeps its identifier, selection and iOS 18+ gate;+> no kernel, DSC or system executable patch is added. The new sensorless+> lifecycle regression fails before the stop guard and passes after it;+> sample, real host hook and injection-scope tests also pass. All 51 catalogue/+> model tests in six suites passed, and the full VPhone Debug bundle built,+> passed admission and strict deep signature verification. Updating the+> guest environment and rebooting is required for deployment verification.+> **Current launchd hook (2026-09-25; isolated VM verification):**> `cfw install` now places `launchdhook-vphone.dylib` and a diagnostic> `SystemHook-vphone.dylib` in `/usr/lib`, links `/vh` to the launchd hook,diff --git a/Research/Guest/virtual_attitude.md b/Research/Guest/virtual_attitude.mdindex f23998bc..81503f6e 100644--- a/Research/Guest/virtual_attitude.md+++ b/Research/Guest/virtual_attitude.md@@ -27,6 +27,11 @@ does not synthesize angular velocity or UIKit/display orientation changes.Guest System declares `system-apps-cfw-attitude`, selected by both presets oniOS 18+. It adds `/usr/lib/libvphoneattitude.dylib`. SystemHook loads it intoapps before the optional tweak loader; no bootstrap or new daemon is required.+The attitude loader excludes `/System/Library/` processes and SpringBoard+copies, even though their executable paths can contain `.app/`. The dylib+enforces the same exclusion before registering notifications or replacing+methods, so an older SystemHook cannot activate the hook in those services+after a live library update.Safe-mode/injection-disable flags still apply. No system executable, kernel orDSC bytes change. This intercepts the app's public Core Motion boundary;it does not claim that raw gyro HID events are fused attitude samples.@@ -45,12 +50,17 @@ copies, secure coding and relative quaternion multiplication. Weak timercaptures and cancellation prevent a timer retaining a released manager.Enabling/disabling an existing subscription switches between simulation andretained native implementations, including native availability when disabled.+Native stop is forwarded only for a subscription previously forwarded to+native start. A new or purely simulated subscription never initializes native+Core Motion by stopping it; repeated stops remain local after native shutdown.### Lock order-"Apps" are paths containing `.app/`, so SpringBoard-(`/System/Library/CoreServices/SpringBoard.app/SpringBoard`) loads the hook-too. Core Motion's `-[CMMotionManager setDeviceMotionUpdateInterval:]` (and+The original app gate matched every path containing `.app/`, so SpringBoard+(`/System/Library/CoreServices/SpringBoard.app/SpringBoard`) loaded the hook+too. The respring fix described below now excludes system UI services; the+lock-order rule still applies to regular app consumers. Core Motion's+`-[CMMotionManager setDeviceMotionUpdateInterval:]` (andother methods) hop synchronously to its `com.apple.CoreMotion.MotionThread`,and blocks on that thread call the public getters, such as`isDeviceMotionActive`, on the same manager. The first version held the@@ -117,6 +127,51 @@ gravity at zero and single-axis 90° poses. Check reset/disable while subscribedstopped-manager silence, and relaunch after blocking the patch. Host runtimechecks do not establish guest injection/sandbox acceptance or every app's API.+## SpringBoard respring investigation (2026-10-09)++The reported black screen followed by the Lock Screen is a SpringBoard crash,+not a VM reboot. Reports `SpringBoard-2026-10-09-194121.ips` and+`SpringBoard-2026-10-09-194251.ips` on iOS 27.0.1 (24A446), cloudOS 26.4,+both show `EXC_BAD_ACCESS` / `SIGSEGV` at address `0x10` on+`com.apple.CoreMotion.MotionThread`. The main thread waits in native Core+Motion from `-[VPhoneAttitudeSession stop]`, called by+`startWithFrame:queue:handler:` → `VPhoneStartCallback` → UIKit's+`-[_UIMotionEffectCoreMotionEventProvider startGeneratingEvents]`.+Both reports list `/usr/lib/libvphoneattitude.dylib` in SpringBoard.++The `.app/` injection gate admitted+`/System/Library/CoreServices/SpringBoard.app/SpringBoard`. Separately, every+new simulated subscription called native stop despite never having called+native start. The reports establish that this path reached guest Core Motion+and crashed its motion thread. The console's CloudKit preferences denial,+RunningBoard faults and “No accelerometer” message do not supply the crash+stack; the last message is consistent with the sensorless guest.++Fix: exclude system UI services in both loaders and guard native stop with+the session's native-start tracking. The sensorless lifecycle harness fails+the `stops == 0` assertion before that guard and passes after it. It covers+stop before start, simulated start/restart/stop, repeated stop, native forwarding+of unsupported reference frames, and native-to-simulated switching. Existing+real host hook tests still cover callbacks, polling and live enable/disable.+The upstream MotionThread lock-order regression test passes alongside the+sensorless lifecycle and process-exclusion tests.+Injection tests cover SpringBoard, AccessibilityUIServer, relocated SpringBoard,+Settings and a container-installed consumer.+The lifecycle executable is also run from a `/System/Library/`-shaped+SpringBoard path to verify that the dylib constructor leaves native methods+intact. All host attitude/injection checks and 51 catalogue/model tests in six+suites passed; the attitude and SystemHook dylibs cross-compiled for iPhoneOS.+The full VPhone Debug bundle built successfully, passed bundle admission and+strict deep signature verification.++Deployment acceptance remains pending: build and install the new bundle,+update the stopped guest's environment and boot it. Confirm the new+SpringBoard PID has no `attitude-hook=... result=loaded` entry, enable/edit/+disable attitude while opening/closing apps and locking/unlocking, and check+that no new SpringBoard crash reports appear. Confirm a regular consumer still+receives the expected polling and callback poses. Reboot is needed to apply+SystemHook; replacing a dylib cannot unhook a process that already loaded it.+ABI sources: Xcode iPhoneOS SDK CMMotionManager.h, CMAttitude.h, CMDeviceMotion.h,system notify.h, Apple [CMAttitude](https://developer.apple.com/documentation/coremotion/cmattitude)and [CMDeviceMotion](https://developer.apple.com/documentation/coremotion/cmdevicemotion).diff --git a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swiftindex 5b5ac3d4..b638f583 100644--- a/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift+++ b/VPhoneExecutable/VPhoneCommand/FirmwarePatcher/PatchSets/FirmwareGuestSystemPatchSet.swift@@ -244,7 +244,7 @@ public enum FirmwareGuestSystemPatchSet {VPhonePatchDeclaration(identifier: attitude,title: "Device attitude simulation",- summary: "Installs libvphoneattitude.dylib, loaded by SystemHook into apps. Supplies a stationary Core Motion pose configured through vphoned, with polling and callback updates in the arbitrary vertical reference frame. Disabling simulation restores native motion; removing the library reverts the hook on app relaunch.",+ summary: "Installs libvphoneattitude.dylib, loaded by SystemHook into apps outside system UI services such as SpringBoard. Supplies a stationary Core Motion pose configured through vphoned, with polling and callback updates in the arbitrary vertical reference frame. Disabling simulation restores native motion; removing the library reverts the hook on app relaunch.",target: .guestFile(path: "/usr/lib/libvphoneattitude.dylib"),applicability: VPhonePatchApplicability(iOSBase: .atLeast(major: 18, minor: 0)),),diff --git a/VPhoneGuestComponents/Attitude/libvphoneattitude.m b/VPhoneGuestComponents/Attitude/libvphoneattitude.mindex 427f394d..79982852 100644--- a/VPhoneGuestComponents/Attitude/libvphoneattitude.m+++ b/VPhoneGuestComponents/Attitude/libvphoneattitude.m@@ -1,9 +1,16 @@#import "VPhoneAttitudeSample.h"#import "VPhoneAttitudeMotionManager.h"+#include "../Shared/AttitudeProcess.h"#import <objc/runtime.h>+#include <limits.h>+#include <mach-o/dyld.h>#include <notify.h>#include <os/lock.h>+#ifndef VP_ATTITUDE_MANAGER_CLASS+#define VP_ATTITUDE_MANAGER_CLASS "CMMotionManager"+#endif+// MARK: - Shared configurationstatic NSRecursiveLock *configurationLock;@@ -149,9 +156,14 @@ static CMAttitudeReferenceFrame (*availableFrames)(id, SEL);self.latest = nil;self.handler = nil;self.deliveryQueue = nil;- self.invokingNative = YES;- stopUpdates(self.manager, @selector(stopDeviceMotionUpdates));- self.invokingNative = NO;+ // Starting a simulated subscription also comes through stop. Calling+ // native stop before a native start can initialize sensorless guest+ // Core Motion and crash its motion thread (SpringBoard respring).+ if (self.nativeActive) {+ self.invokingNative = YES;+ stopUpdates(self.manager, @selector(stopDeviceMotionUpdates));+ self.invokingNative = NO;+ }self.nativeActive = NO;}}@@ -270,13 +282,18 @@ static void VPhoneReadAttitude(void) {__attribute__((constructor)) static void VPhoneAttitudeInstall(void) {@autoreleasepool {+ // Also enforce scope here: a live dylib update can reach a guest+ // still running the older SystemHook until its next reboot.+ char path[PATH_MAX];+ uint32_t length = sizeof(path);+ if (_NSGetExecutablePath(path, &length) != 0 || !vpAttitudeAllowsProcess(path)) return;configurationLock = [NSRecursiveLock new];sessions = [NSHashTable weakObjectsHashTable];dispatch_queue_t queue = dispatch_queue_create("com.vphone.motion.attitude", DISPATCH_QUEUE_SERIAL);if (notify_register_dispatch(VP_ATTITUDE_NOTIFICATION, ¬ificationToken, queue,^(int token) { VPhoneReadAttitude(); }) != NOTIFY_STATUS_OK) return;VPhoneReadAttitude();- Class cls = NSClassFromString(@"CMMotionManager");+ Class cls = NSClassFromString(@VP_ATTITUDE_MANAGER_CLASS);// Validate the entire ABI before installing any part of the hook.SEL selectors[] = {@selector(startDeviceMotionUpdates), @selector(startDeviceMotionUpdatesUsingReferenceFrame:),@selector(startDeviceMotionUpdatesToQueue:withHandler:), @selector(startDeviceMotionUpdatesUsingReferenceFrame:toQueue:withHandler:),diff --git a/VPhoneGuestComponents/Makefile b/VPhoneGuestComponents/Makefileindex 8bf859f5..80a14b58 100644--- a/VPhoneGuestComponents/Makefile+++ b/VPhoneGuestComponents/Makefile@@ -88,7 +88,7 @@ GYROSCOPE_SOURCES := $(call find_sources,Gyroscope)GYROSCOPE_INPUTS := $(call find_headers,Gyroscope) $(call find_folders,Gyroscope)ATTITUDE := $(STAGE)/attitude/libvphoneattitude.dylibATTITUDE_SOURCES := $(call find_sources,Attitude)-ATTITUDE_INPUTS := $(call find_headers,Attitude) $(call find_folders,Attitude)+ATTITUDE_INPUTS := $(call find_headers,Attitude) $(call find_folders,Attitude) Shared/AttitudeProcess.hGPU_PLUGIN := $(STAGE)/gpu/libAppleParavirtCompilerPluginIOGPUFamily.dylibGPU_PLUGIN_SOURCES := $(wildcard GraphicLoader/*.mm)GPU_PLUGIN_INCLUDES := $(wildcard GraphicLoader/*.h GraphicLoader/*.hpp GraphicLoader/*.inc)@@ -316,6 +316,15 @@ test-attitude:-o $(OUT)/AttitudeLockOrderTests Tests/AttitudeLockOrderTests.m $(ATTITUDE_SOURCES) \-framework Foundation -framework CoreMotion@$(OUT)/AttitudeLockOrderTests+ xcrun --sdk macosx clang -fobjc-arc -Wall -Wextra -Werror -Wno-unused-parameter -IAttitude \+ -DVP_ATTITUDE_NOTIFICATION='"com.vphone.motion.attitude.lifecycle-test"' \+ -DVP_ATTITUDE_MANAGER_CLASS='"VPhoneTestMotionManager"' \+ -o $(OUT)/AttitudeLifecycleTests Tests/AttitudeLifecycleTests.m $(ATTITUDE_SOURCES) \+ -framework Foundation -framework CoreMotion+ @$(OUT)/AttitudeLifecycleTests+ @mkdir -p $(OUT)/attitude-scope/System/Library/CoreServices/SpringBoard.app+ @cp $(OUT)/AttitudeLifecycleTests $(OUT)/attitude-scope/System/Library/CoreServices/SpringBoard.app/SpringBoard+ @$(OUT)/attitude-scope/System/Library/CoreServices/SpringBoard.app/SpringBoardtest-gyroscope:@mkdir -p $(OUT)diff --git a/VPhoneGuestComponents/README.md b/VPhoneGuestComponents/README.mdindex 789a32a0..10629790 100644--- a/VPhoneGuestComponents/README.md+++ b/VPhoneGuestComponents/README.md@@ -70,6 +70,9 @@ CoreMotion acceptance is still pending; see `Research/Guest/virtual_gyroscope.md`system-apps-cfw-attitude` installs `libvphoneattitude.dylib`, loaded bySystemHook into apps. It supplies a stationary Core Motion pose through`motion.attitude.set/get/clear`, independently of gyro angular velocity.+System UI services under `/System/Library/` and SpringBoard copies are excluded+by both SystemHook and the attitude dylib itself. Purely simulated subscriptions+never call native Core Motion stop before native start.Removing the selected library and relaunching apps reverts the hook.`make test-attitude` checks samples and the actual host Core Motion subscriptionruntime. Guest validation is manual; see `Research/Guest/virtual_attitude.md`.diff --git a/VPhoneGuestComponents/Shared/AttitudeProcess.h b/VPhoneGuestComponents/Shared/AttitudeProcess.hnew file mode 100644index 00000000..e366be94--- /dev/null+++ b/VPhoneGuestComponents/Shared/AttitudeProcess.h@@ -0,0 +1,18 @@+#ifndef VPHONE_ATTITUDE_PROCESS_H+#define VPHONE_ATTITUDE_PROCESS_H++#include <string.h>++// .app paths also include SpringBoard and other system UI services. A+// simulated app pose must not drive their motion effects or native sensors.+static inline int vpAttitudeAllowsProcess(const char *path) {+ if (!path || path[0] != '/')+ return 0;+ if (strstr(path, "/System/Library/") != NULL)+ return 0;+ const char *springboard = "/SpringBoard.app/SpringBoard";+ size_t length = strlen(path), suffixLength = strlen(springboard);+ return length < suffixLength || strcmp(path + length - suffixLength, springboard) != 0;+}++#endifdiff --git a/VPhoneGuestComponents/SystemHook/SystemHook-vphone.c b/VPhoneGuestComponents/SystemHook/SystemHook-vphone.cindex b3971ca6..c371ff3b 100644--- a/VPhoneGuestComponents/SystemHook/SystemHook-vphone.c+++ b/VPhoneGuestComponents/SystemHook/SystemHook-vphone.c@@ -1,4 +1,5 @@#include "../Shared/InjectionEnvironment.h"+#include "../Shared/AttitudeProcess.h"#include "../Shared/JetsamLimits.h"#include "../Shared/RootHideLoaderLinks.h"#include <crt_externs.h>@@ -242,9 +243,8 @@ __attribute__((constructor)) static void vpLogProcess(void) {vpLoadLibrary("gyroscope-hook", VP_GYROSCOPE_HOOK);return;}- // Loaded before the app gate: SpringBoard is neither an app path nor a- // bootstrap executable, and the swizzle has to be in place before UIKit- // first asks CoreHaptics for an engine.+ // SpringBoard needs the haptics swizzle before UIKit first asks for an+ // engine, even though attitude simulation excludes this system UI app.if (vpIsSpringBoard(path))vpLoadLibrary("haptics-fix", VP_HAPTICS_FIX);// Loaded before the app gate too: the swizzle must be in place before@@ -258,7 +258,7 @@ __attribute__((constructor)) static void vpLogProcess(void) {// above, so background AuthKit auth is untouched).if (vpIsAppPath(path))vpLoadLibrary("signin-fix", VP_SIGNIN_FIX);- if (vpIsAppPath(path))+ if (vpIsAppPath(path) && vpAttitudeAllowsProcess(path))vpLoadLibrary("attitude-hook", VP_ATTITUDE_HOOK);if (vpIsAppPath(path) && dlopen(VP_AVFOUNDATION, RTLD_LAZY | RTLD_NOLOAD))vpLoadLibrary("camera-hook", VP_CAMERA_APP_HOOK);diff --git a/VPhoneGuestComponents/Tests/AttitudeLifecycleTests.m b/VPhoneGuestComponents/Tests/AttitudeLifecycleTests.mnew file mode 100644index 00000000..28e1a030--- /dev/null+++ b/VPhoneGuestComponents/Tests/AttitudeLifecycleTests.m@@ -0,0 +1,88 @@+#import "VPhoneAttitudeMotionManager.h"+#import "VPhoneAttitudeState.h"+#include "../Shared/AttitudeProcess.h"+#include <assert.h>+#include <limits.h>+#include <mach-o/dyld.h>+#include <notify.h>+#include <stdatomic.h>+#include <unistd.h>++// A sensorless manager records native entry points. The real macOS runtime+// tolerates stop-before-start; the guest Core Motion runtime can crash there.+static atomic_uint starts, stops;+@interface VPhoneTestMotionManager : NSObject <VPhoneAttitudeMotionManager>+@property (nonatomic) NSTimeInterval deviceMotionUpdateInterval;+@end+@implementation VPhoneTestMotionManager++ (CMAttitudeReferenceFrame)availableAttitudeReferenceFrames { return 0; }+- (BOOL)isDeviceMotionAvailable { return NO; }+- (BOOL)isDeviceMotionActive { return NO; }+- (CMDeviceMotion *)deviceMotion { return nil; }+- (CMAttitudeReferenceFrame)attitudeReferenceFrame { return CMAttitudeReferenceFrameXArbitraryZVertical; }+- (void)startDeviceMotionUpdates { starts++; }+- (void)startDeviceMotionUpdatesUsingReferenceFrame:(CMAttitudeReferenceFrame)frame { [self startDeviceMotionUpdates]; }+- (void)startDeviceMotionUpdatesToQueue:(NSOperationQueue *)queue withHandler:(CMDeviceMotionHandler)handler { [self startDeviceMotionUpdates]; }+- (void)startDeviceMotionUpdatesUsingReferenceFrame:(CMAttitudeReferenceFrame)frame toQueue:(NSOperationQueue *)queue withHandler:(CMDeviceMotionHandler)handler { [self startDeviceMotionUpdates]; }+- (void)stopDeviceMotionUpdates { stops++; }+@end++static void publish(int token, BOOL enabled, VPhoneTestMotionManager *manager) {+ assert(notify_set_state(token, VPhoneAttitudePack((VPhoneAttitudeState){enabled, 0, 0, 0})) == NOTIFY_STATUS_OK);+ assert(notify_post(VP_ATTITUDE_NOTIFICATION) == NOTIFY_STATUS_OK);+ for (int i = 0; i < 200; i++) {+ if (manager.deviceMotionAvailable == enabled) return;+ usleep(5000);+ }+ assert(!"Timed out waiting for attitude configuration");+}++int main(void) {+ @autoreleasepool {+ VPhoneTestMotionManager *manager = [VPhoneTestMotionManager new];+ char path[PATH_MAX];+ uint32_t length = sizeof(path);+ assert(_NSGetExecutablePath(path, &length) == 0);+ if (!vpAttitudeAllowsProcess(path)) {+ // Run this executable from a system-UI-shaped path as well: the+ // dylib must leave native entry points intact before main runs.+ [manager stopDeviceMotionUpdates];+ assert(stops == 1);+ assert(!manager.deviceMotionAvailable);+ assert([VPhoneTestMotionManager availableAttitudeReferenceFrames] == 0);+ puts("System UI process leaves attitude hooks uninstalled");+ return 0;+ }+ int token;+ assert(notify_register_check(VP_ATTITUDE_NOTIFICATION, &token) == NOTIFY_STATUS_OK);+ publish(token, YES, manager);+ [manager stopDeviceMotionUpdates];+ assert(stops == 0); // No native subscription exists yet.+ [manager startDeviceMotionUpdates];+ [manager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXArbitraryZVertical];+ [manager stopDeviceMotionUpdates];+ [manager stopDeviceMotionUpdates];+ assert(starts == 0 && stops == 0); // Simulation never touches native stop.++ // Unsupported frames retain native forwarding, including reentrant starts.+ [manager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXMagneticNorthZVertical];+ assert(starts == 1 && stops == 0);+ [manager stopDeviceMotionUpdates];+ [manager stopDeviceMotionUpdates];+ assert(stops == 1);++ // Switching a retained subscription stops native once, then stays simulated.+ publish(token, NO, manager);+ [manager startDeviceMotionUpdates];+ assert(starts == 2 && stops == 1);+ publish(token, YES, manager);+ for (int i = 0; i < 200 && !manager.deviceMotion; i++) usleep(5000);+ assert(manager.deviceMotion && stops == 2);+ [manager stopDeviceMotionUpdates];+ assert(stops == 2);+ publish(token, NO, manager);+ notify_cancel(token);+ puts("Sensorless native start/stop lifecycle tests passed");+ }+ return 0;+}diff --git a/VPhoneGuestComponents/Tests/InjectionEnvironmentTests.c b/VPhoneGuestComponents/Tests/InjectionEnvironmentTests.cindex 7f5dd404..c385ca28 100644--- a/VPhoneGuestComponents/Tests/InjectionEnvironmentTests.c+++ b/VPhoneGuestComponents/Tests/InjectionEnvironmentTests.c@@ -9,6 +9,7 @@#define VP_DEVICE_NAME VP_TEST_LIBRARY_DIR "/libdevicename.dylib"#include "../Shared/InjectionEnvironment.h"+#include "../Shared/AttitudeProcess.h"#include <assert.h>#include <errno.h>#include <fcntl.h>@@ -201,6 +202,13 @@ static void skipsRepeatedLibraries(void) {}int main(void) {+ assert(!vpAttitudeAllowsProcess(NULL));+ assert(!vpAttitudeAllowsProcess("SpringBoard.app/SpringBoard"));+ assert(!vpAttitudeAllowsProcess("/System/Library/CoreServices/SpringBoard.app/SpringBoard"));+ assert(!vpAttitudeAllowsProcess("/private/System/Library/CoreServices/AccessibilityUIServer.app/AccessibilityUIServer"));+ assert(!vpAttitudeAllowsProcess("/var/jb/Applications/SpringBoard.app/SpringBoard"));+ assert(vpAttitudeAllowsProcess("/Applications/Preferences.app/Preferences"));+ assert(vpAttitudeAllowsProcess("/private/var/containers/Bundle/Application/UUID/Motion.app/Motion"));insertsBoth();addsExtraBesideAnExistingHook();leavesACompleteEnvironmentAlone();