From: Jay Freeman (saurik) Date: Sat, 18 Jan 2014 14:18:24 +0000 (-0800) Subject: Cache __NSMallocBlock__ and verify it even exists. X-Git-Tag: v0.9.500~41 X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/6ea25be22c0c0ea430ec1a15863bed9f4a45eee7 Cache __NSMallocBlock__ and verify it even exists. --- diff --git a/ObjectiveC/Library.mm b/ObjectiveC/Library.mm index b6410c7..0e863fa 100644 --- a/ObjectiveC/Library.mm +++ b/ObjectiveC/Library.mm @@ -294,6 +294,7 @@ static JSClassRef ObjectiveC_Images_; #endif #ifdef __APPLE__ +static Class __NSMallocBlock__; static Class NSCFBoolean_; static Class NSCFType_; static Class NSGenericDeallocHandler_; @@ -662,6 +663,7 @@ static void BlockClosure_(ffi_cif *cif, void *result, void **arguments, void *ar } NSObject *CYMakeBlock(JSContextRef context, JSObjectRef function, sig::Signature &signature) { + _assert(__NSMallocBlock__ != Nil); BlockLiteral *literal(reinterpret_cast(malloc(sizeof(BlockLiteral)))); CYBlockDescriptor *descriptor(new CYBlockDescriptor); @@ -670,7 +672,7 @@ NSObject *CYMakeBlock(JSContextRef context, JSObjectRef function, sig::Signature descriptor->internal_ = CYMakeFunctor_(context, function, signature, &BlockClosure_); literal->invoke = reinterpret_cast(descriptor->internal_->GetValue()); - literal->isa = objc_getClass("__NSMallocBlock__"); + literal->isa = __NSMallocBlock__; literal->flags = BLOCK_HAS_SIGNATURE | BLOCK_HAS_COPY_DISPOSE | BLOCK_IS_GLOBAL; literal->reserved = 0; literal->descriptor = descriptor; @@ -2754,6 +2756,8 @@ void CYObjectiveC_Initialize() { /*XXX*/ JSContextRef context(NULL); CYPoolTry { Object_ = objc_getClass("Object"); #ifdef __APPLE__ + __NSMallocBlock__ = objc_getClass("__NSMallocBlock__"); + // XXX: apparently, iOS now has both of these NSCFBoolean_ = objc_getClass("__NSCFBoolean"); if (NSCFBoolean_ == nil)