Explorar el Código

Fix #324, crash when viewing NSNumber

Tanner Bennett hace 6 años
padre
commit
07f0b07a91

+ 2 - 1
Classes/GlobalStateExplorers/FLEXInstancesTableViewController.m

@@ -61,7 +61,8 @@
     NSMutableArray *instances = [NSMutableArray array];
     [FLEXHeapEnumerator enumerateLiveObjectsUsingBlock:^(__unsafe_unretained id object, __unsafe_unretained Class actualClass) {
         if (strcmp(classNameCString, class_getName(actualClass)) == 0) {
-            // Note: objects of certain classes crash when retain is called. It is up to the user to avoid tapping into instance lists for these classes.
+            // Note: objects of certain classes crash when retain is called.
+            // It is up to the user to avoid tapping into instance lists for these classes.
             // Ex. OS_dispatch_queue_specific_queue
             // In the future, we could provide some kind of warning for classes that are known to be problematic.
             if (malloc_size((__bridge const void *)(object)) > 0) {

+ 15 - 4
Classes/Utility/FLEXRuntimeUtility.m

@@ -398,8 +398,21 @@ const unsigned int kFLEXNumberOfImplicitArgs = 2;
         return nil;
     }
 
-    // Build the invocation
+    // Probably an unsupported type encoding, like bitfields
+    // or inline arrays. In the future, we could calculate
+    // the return length on our own. For now, we abort.
+    //
+    // For future reference, the code here will get the true type encoding.
+    // NSMethodSignature will convert {?=b8b4b1b1b18[8S]} to {?}
+    // A solution might involve hooking NSGetSizeAndAlignment.
+    //
+    // returnType = method_getTypeEncoding(class_getInstanceMethod([object class], selector));
     NSMethodSignature *methodSignature = [object methodSignatureForSelector:selector];
+    if (!methodSignature.methodReturnLength) {
+        return nil;
+    }
+
+    // Build the invocation
     NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature];
     [invocation setSelector:selector];
     [invocation setTarget:object];
@@ -454,9 +467,6 @@ const unsigned int kFLEXNumberOfImplicitArgs = 2;
     // Try to invoke the invocation but guard against an exception being thrown.
     id returnObject = nil;
     @try {
-        // Some methods are not fit to be called...
-        // Looking at you -[UIResponder(UITextInputAdditions) _caretRect]
-        [invocation invoke];
 
         // Retrieve the return value and box if necessary.
         const char *returnType = methodSignature.methodReturnType;
@@ -467,6 +477,7 @@ const unsigned int kFLEXNumberOfImplicitArgs = 2;
             [invocation getReturnValue:&objectReturnedFromMethod];
             returnObject = objectReturnedFromMethod;
         } else if (returnType[0] != FLEXTypeEncodingVoid) {
+            NSAssert(methodSignature.methodReturnLength, @"Memory corruption lies ahead");
             // Will use arbitrary buffer for return value and box it.
             void *returnValue = malloc(methodSignature.methodReturnLength);