Skip to content

Commit

Permalink
Add tweak for multiple instance
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnyyoung committed Mar 17, 2017
1 parent 9e45c60 commit 0ec8de7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 &

Expand Down
Binary file modified WeChatTweak.dylib
Binary file not shown.
26 changes: 18 additions & 8 deletions WeChatTweak.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
#import <objc/message.h>
#import <Cocoa/Cocoa.h>

__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:@"<replacemsg><![CDATA["];
NSRange end = [message rangeOfString:@"]]></replacemsg>"];
NSRange subRange = NSMakeRange(begin.location + begin.length,end.location - begin.location - begin.length);
Expand All @@ -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));
}

0 comments on commit 0ec8de7

Please sign in to comment.