mirror of
https://github.com/Sunnyyoung/WeChatTweak-macOS.git
synced 2025-05-23 06:46:10 +08:00
Add tweak for multiple instance
This commit is contained in:
parent
9e45c60a81
commit
0ec8de7b53
1
Makefile
1
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 &
|
||||
|
||||
|
|
Binary file not shown.
|
@ -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);
|
||||
|
@ -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));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user