ソースを参照

Actually disable os_log for jailbroken devices

os_log cannot be disabled on-device without a trampoline-style function hook. Fishhook just rebinds lazy symbols, which isn't working on-device for some reason. This commit makes use of Substrate's MSHookFunction to do this, if it is available.
Tanner Bennett 6 年 前
コミット
d031dab174
共有1 個のファイルを変更した37 個の追加2 個の削除を含む
  1. 37 2
      Classes/GlobalStateExplorers/SystemLog/FLEXSystemLogViewController.m

+ 37 - 2
Classes/GlobalStateExplorers/SystemLog/FLEXSystemLogViewController.m

@@ -13,6 +13,7 @@
 #import "FLEXOSLogController.h"
 #import "FLEXSystemLogCell.h"
 #import "fishhook.h"
+#import <dlfcn.h>
 
 @interface FLEXSystemLogViewController ()
 
@@ -22,12 +23,17 @@
 
 @end
 
+static void (*MSHookFunction)(void *symbol, void *replace, void **result);
+
 static BOOL FLEXDidHookNSLog = NO;
-void (*orig_os_log_shim_enabled)() = nil;
+static BOOL FLEXNSLogHookWorks = NO;
+BOOL (*orig_os_log_shim_enabled)() = nil;
 BOOL my_os_log_shim_enabled() {
     return NO;
 }
 
+extern BOOL os_log_shim_enabled();
+
 @implementation FLEXSystemLogViewController
 
 + (void)load {
@@ -38,6 +44,35 @@ BOOL my_os_log_shim_enabled() {
         (void *)my_os_log_shim_enabled,
         (void **)&orig_os_log_shim_enabled
     }, 1) == 0;
+    
+    if (FLEXDidHookNSLog && orig_os_log_shim_enabled != nil) {
+        // Check if our rebinding worked
+        FLEXNSLogHookWorks = os_log_shim_enabled() == NO;
+    }
+    
+    // So, just because we rebind the lazily loaded symbol for
+    // this function doesn't mean it's even going to be used.
+    // While it seems to be sufficient for the simulator, for
+    // whatever reason it is not sufficient on-device. We need
+    // to actually hook the function with something like Substrate.
+    
+    // Check if we have substrate, and if so use that instead
+    void *handle = dlopen("/usr/lib/libsubstrate.dylib", RTLD_LAZY);
+    if (handle) {
+        MSHookFunction = dlsym(handle, "MSHookFunction");
+        
+        if (MSHookFunction) {
+            // Set the hook and check if it worked
+            //
+            // Very important that we use orig_os_log_shim_enabled
+            // here as opposed to os_log_shim_enabled.
+            MSHookFunction(orig_os_log_shim_enabled, my_os_log_shim_enabled, nil);
+            FLEXNSLogHookWorks = orig_os_log_shim_enabled() == NO;
+            if (FLEXNSLogHookWorks) {
+                return;
+            }
+        }
+    }
 }
 
 - (id)init {
@@ -56,7 +91,7 @@ BOOL my_os_log_shim_enabled() {
     };
 
     _logMessages = [NSMutableArray array];
-    if (FLEXOSLogAvailable() && !FLEXDidHookNSLog) {
+    if (FLEXOSLogAvailable() && !FLEXNSLogHookWorks) {
         _logController = [FLEXOSLogController withUpdateHandler:logHandler];
     } else {
         _logController = [FLEXASLLogController withUpdateHandler:logHandler];