]> git.saurik.com Git - cycript.git/commitdiff
Solve a corner case of dealloc hooking on JS derived class objects using MobileSubstrate.
authorJay Freeman (saurik) <saurik@saurik.com>
Wed, 14 Oct 2009 21:58:51 +0000 (21:58 +0000)
committerJay Freeman (saurik) <saurik@saurik.com>
Wed, 14 Oct 2009 21:58:51 +0000 (21:58 +0000)
Library.mm

index 5d292ae621245999e73c9f14245082f4d2fc4445..9cb0060e14d0b3db5dd55c37fcf7694c375f16bf 100644 (file)
@@ -1996,24 +1996,19 @@ static JSValueRef $objc_msgSend(JSContextRef context, JSObjectRef object, JSObje
     return CYSendMessage(pool, context, self, _cmd, count - 2, arguments + 2, uninitialized, exception);
 }
 
-void dealloc_(id self, SEL sel) {
+MSHook(void, CYDealloc, id self, SEL sel) {
     CYInternal *internal;
     object_getInstanceVariable(self, "cy$internal_", reinterpret_cast<void **>(&internal));
     if (internal != NULL)
         delete internal;
-    if (Method dealloc = class_getInstanceMethod(object_getClass(self), @selector(cy$dealloc)))
-        reinterpret_cast<void (*)(id, SEL)>(method_getImplementation(dealloc))(self, sel);
+    _CYDealloc(self, sel);
 }
 
 MSHook(void, objc_registerClassPair, Class _class) {
     Class super(class_getSuperclass(_class));
     if (super == NULL || class_getInstanceVariable(super, "cy$internal_") == NULL) {
         class_addIvar(_class, "cy$internal_", sizeof(CYInternal *), log2(sizeof(CYInternal *)), "^{CYInternal}");
-        if (!class_addMethod(_class, @selector(dealloc), reinterpret_cast<IMP>(&dealloc_), "v8@0:4")) {
-            Method dealloc(class_getInstanceMethod(_class, @selector(dealloc)));
-            class_addMethod(_class, @selector(cy$dealloc), method_getImplementation(dealloc), method_getTypeEncoding(dealloc));
-            method_setImplementation(dealloc, reinterpret_cast<IMP>(&dealloc_));
-        }
+        MSHookMessage(_class, @selector(dealloc), MSHake(CYDealloc));
     }
 
     _objc_registerClassPair(_class);