From 272c3da334ce4d6925eb6520a275cd6e503852e7 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Wed, 14 Oct 2009 21:58:51 +0000 Subject: [PATCH] Solve a corner case of dealloc hooking on JS derived class objects using MobileSubstrate. --- Library.mm | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Library.mm b/Library.mm index 5d292ae..9cb0060 100644 --- a/Library.mm +++ b/Library.mm @@ -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(&internal)); if (internal != NULL) delete internal; - if (Method dealloc = class_getInstanceMethod(object_getClass(self), @selector(cy$dealloc))) - reinterpret_cast(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(&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(&dealloc_)); - } + MSHookMessage(_class, @selector(dealloc), MSHake(CYDealloc)); } _objc_registerClassPair(_class); -- 2.45.2