Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Let the probe run in installd and nowhere else

Lakr0ba2b55d3bdb
diff --git a/VPhoneGuestComponents/MISFix/MISFixCacheWriteProbe.c b/VPhoneGuestComponents/MISFix/MISFixCacheWriteProbe.c
index 884045f5..fa571eab 100644
--- a/VPhoneGuestComponents/MISFix/MISFixCacheWriteProbe.c
+++ b/VPhoneGuestComponents/MISFix/MISFixCacheWriteProbe.c
@@ -51,6 +51,7 @@
#include <dlfcn.h>
#include <errno.h>
#include <libkern/OSCacheControl.h>
+#include <mach-o/dyld.h>
#include <mach/mach.h>
#include <ptrauth.h>
#include <stdint.h>
@@ -242,9 +243,29 @@ static void vpProbeExecutableMemory(void) {
}
}
+/// Whether this process is the one the probe is allowed to run in.
+///
+/// installd, and only installd. SystemHook also inserts this dylib into
+/// misagent and SpringBoard, and the executable-memory step can end the
+/// process outright — in SpringBoard that is a respring, and a repeating one
+/// while the flag is on. installd is on-demand and launchd starts it again for
+/// the next client, so a kill there costs one failed install and nothing else.
+static int vpProbeIsPermittedProcess(void) {
+ char path[4096];
+ uint32_t size = sizeof(path);
+ if (_NSGetExecutablePath(path, &size) != 0)
+ return 0;
+ static const char suffix[] = "/installd";
+ size_t length = strlen(path);
+ return length >= sizeof(suffix) - 1
+ && strcmp(path + length - (sizeof(suffix) - 1), suffix) == 0;
+}
+
__attribute__((constructor)) static void vpProbeCacheWrite(void) {
if (!MISFixConfiguredFlag(kMISFixProbeCacheWriteKey))
return;
+ if (!vpProbeIsPermittedProcess())
+ return;
// This dylib's own text first. It is private, file-backed and already
// carries write in its maximum protection, so it is the easy case — and if