Run a virtual iPhone on an Apple Silicon Mac.
Swift
Give libmisfix a positive control, not just a query log
Lakrc9057eebe437
diff --git a/VPhoneGuestComponents/MISFix/MISFixConfig.c b/VPhoneGuestComponents/MISFix/MISFixConfig.cindex 2961a794..12af3492 100644--- a/VPhoneGuestComponents/MISFix/MISFixConfig.c+++ b/VPhoneGuestComponents/MISFix/MISFixConfig.c@@ -1,6 +1,10 @@#include "MISFixConfig.h"+#include <os/log.h>+#include <stdarg.h>+#include <stdio.h>#include <sys/stat.h>+#include <unistd.h>// Two locations, first match wins.//@@ -164,3 +168,18 @@ int MISFixConfiguredFlag(CFStringRef key) {return 0;return CFBooleanGetValue((CFBooleanRef)value) ? 1 : 0;}++void MISFixLog(const char *format, ...) {+ if (!MISFixConfiguredFlag(kMISFixLogQueriesKey))+ return;+ char message[512];+ va_list arguments;+ va_start(arguments, format);+ int written = vsnprintf(message, sizeof(message), format, arguments);+ va_end(arguments);+ if (written <= 0)+ return;+ // One prefix for every line this dylib writes, so a single predicate finds+ // them whichever process is carrying the hook.+ os_log(OS_LOG_DEFAULT, "libmisfix[%d]: %{public}s", getpid(), message);+}diff --git a/VPhoneGuestComponents/MISFix/MISFixConfig.h b/VPhoneGuestComponents/MISFix/MISFixConfig.hindex bd15f7cf..f0c8c1a8 100644--- a/VPhoneGuestComponents/MISFix/MISFixConfig.h+++ b/VPhoneGuestComponents/MISFix/MISFixConfig.h@@ -37,4 +37,13 @@ CFStringRef MISFixCopyConfiguredDeviceIdentifier(void);/// a boolean, or no configuration can be read.int MISFixConfiguredFlag(CFStringRef key);+/// Log `format` under `LogQueries`, prefixed so one predicate finds every line+/// this dylib writes, from whichever process is carrying it.+///+/// A no-op unless the flag is set.+void MISFixLog(const char *format, ...) __attribute__((format(printf, 1, 2)));++/// The flag every diagnostic in this dylib is behind.+#define kMISFixLogQueriesKey CFSTR("LogQueries")+#endifdiff --git a/VPhoneGuestComponents/MISFix/MISFixDeviceIdentity.c b/VPhoneGuestComponents/MISFix/MISFixDeviceIdentity.cindex 7856644b..d17e0093 100644--- a/VPhoneGuestComponents/MISFix/MISFixDeviceIdentity.c+++ b/VPhoneGuestComponents/MISFix/MISFixDeviceIdentity.c@@ -60,7 +60,7 @@#include "MISFixConfig.h"#include "MISFixInterpose.h"-#include <os/log.h>+#include <mach-o/dyld.h>extern CFTypeRef MGCopyAnswer(CFStringRef property);extern CFTypeRef MGCopyAnswerWithError(CFStringRef property, uint32_t *error);@@ -80,16 +80,26 @@ extern CFTypeRef MGCopyAnswerWithError(CFStringRef property, uint32_t *error);/// installd, the call is not coming through `MGCopyAnswer` and the hook needs a/// different point to stand on.static void vpLogQuery(CFStringRef property, int answered) {- if (!MISFixConfiguredFlag(CFSTR("LogQueries")))- return;char name[128];if (property == NULL|| !CFStringGetCString(property, name, sizeof(name), kCFStringEncodingUTF8)){return;}- os_log(OS_LOG_DEFAULT, "libmisfix: MGCopyAnswer(%{public}s) %{public}s",- name, answered ? "-> override" : "passed through");+ MISFixLog("MGCopyAnswer(%s) %s", name, answered ? "-> override" : "passed through");+}++/// Say, once, that this dylib is in this process.+///+/// The positive control the diagnosis needs. Without it, "installd logged no+/// MGCopyAnswer" has two readings that look the same — the call never came+/// through the interposed symbol, or the hook was not in the process at all —+/// and they call for opposite fixes. With it, the pair of lines is decisive:+/// this one and no query line means the call is bypassing the interpose.+__attribute__((constructor)) static void vpAnnounce(void) {+ char path[4096];+ uint32_t size = sizeof(path);+ MISFixLog("loaded into %s", _NSGetExecutablePath(path, &size) == 0 ? path : "<unknown>");}/// MobileGestalt's key for the UDID. A plain string, not the SDK constant:diff --git a/VPhoneGuestComponents/MISFix/MISFixSignature.c b/VPhoneGuestComponents/MISFix/MISFixSignature.cindex 9bf10f96..44a3a4c9 100644--- a/VPhoneGuestComponents/MISFix/MISFixSignature.c+++ b/VPhoneGuestComponents/MISFix/MISFixSignature.c@@ -61,6 +61,7 @@// hook is attached — weak, deliberately, so an installd whose libmisfix has// been removed still boots.+#include "MISFixConfig.h"#include "MISFixInterpose.h"#include <CoreFoundation/CoreFoundation.h>@@ -132,6 +133,22 @@ static CFDictionaryRef vpWidenedOptions(CFDictionaryRef options) {return widened;}+/// Log one validation, under `LogQueries`.+///+/// This is the other half of the control. `MISValidateSignatureAndCopyInfo` is+/// reached the same way the UDID query is — from MobileInstallation, in the+/// shared cache, into libmis, also in the shared cache, with the main+/// executable's own image not involved. So if this line appears in installd+/// and the `MGCopyAnswer` line does not, the two calls are being treated+/// differently and the difference is in MobileGestalt, not in whether an+/// interpose can cross the cache at all.+static void vpLogValidation(MISPath path, int result) {+ char buffer[1024];+ if (path == NULL || !CFStringGetCString(path, buffer, sizeof(buffer), kCFStringEncodingUTF8))+ return;+ MISFixLog("MISValidateSignatureAndCopyInfo(%s) -> 0x%x", buffer, (unsigned)result);+}+static int vpMISValidateSignatureAndCopyInfo(MISPath path,CFDictionaryRef options,@@ -143,6 +160,7 @@ static int vpMISValidateSignatureAndCopyInfo(return MISValidateSignatureAndCopyInfo(path, options, info);int result = MISValidateSignatureAndCopyInfo(path, widened, info);CFRelease(widened);+ vpLogValidation(path, result);return result;}@@ -157,6 +175,7 @@ static int vpMISValidateSignatureAndCopyInfoWithProgress(return MISValidateSignatureAndCopyInfoWithProgress(path, options, info, progress);int result = MISValidateSignatureAndCopyInfoWithProgress(path, widened, info, progress);CFRelease(widened);+ vpLogValidation(path, result);return result;}