diff --git a/Makefile b/Makefile index 7a9be2d..7dce04a 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ build:: clang -dynamiclib ./WeChatTweak.m -fobjc-link-runtime -current_version 1.0 -compatibility_version 1.0 -o ./${DYLIBFILE} debug:: + make clean make build DYLD_INSERT_LIBRARIES=./${DYLIBFILE} ${WECHATPATH}/WeChat & diff --git a/WeChatTweak.dylib b/WeChatTweak.dylib index 6aadb80..931ccd3 100755 Binary files a/WeChatTweak.dylib and b/WeChatTweak.dylib differ diff --git a/WeChatTweak.m b/WeChatTweak.m index af9b184..c63fe9f 100755 --- a/WeChatTweak.m +++ b/WeChatTweak.m @@ -3,12 +3,12 @@ #import #import -__attribute__((constructor)) -static void initializer(void) { - Class MessageServiceClass = NSClassFromString(@"MessageService"); - SEL onRevokeMsgSEL = NSSelectorFromString(@"onRevokeMsg:"); - IMP onRevokeMsgIMP = imp_implementationWithBlock(^(id self, id arg) { - NSString *message = (NSString *)arg; +// Tweak for no revoke message. +__attribute__((constructor(101))) static void noRevokeTweak(void) { + Class class = NSClassFromString(@"MessageService"); + SEL selector = NSSelectorFromString(@"onRevokeMsg:"); + Method method = class_getInstanceMethod(class, selector); + IMP imp = imp_implementationWithBlock(^(id self, NSString *message) { NSRange begin = [message rangeOfString:@""]; NSRange subRange = NSMakeRange(begin.location + begin.length,end.location - begin.location - begin.length); @@ -20,6 +20,16 @@ static void initializer(void) { [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:userNotification]; }); }); - Method onRevokeMsgMethod = class_getInstanceMethod(MessageServiceClass, onRevokeMsgSEL); - class_replaceMethod(MessageServiceClass, onRevokeMsgSEL, onRevokeMsgIMP, method_getTypeEncoding(onRevokeMsgMethod)); + class_replaceMethod(class, selector, imp, method_getTypeEncoding(method)); +} + +// Tweak for multiple instance. +__attribute__((constructor(102))) static void multipleInstanceTweak(void) { + Class class = object_getClass(NSClassFromString(@"CUtility")); + SEL selector = NSSelectorFromString(@"HasWechatInstance"); + Method method = class_getInstanceMethod(class, selector); + IMP imp = imp_implementationWithBlock(^(id self) { + return 0; + }); + class_replaceMethod(class, selector, imp, method_getTypeEncoding(method)); }