diff --git a/WeChatTweak.xcodeproj/project.pbxproj b/WeChatTweak.xcodeproj/project.pbxproj index ac97b97..f9fed2c 100644 --- a/WeChatTweak.xcodeproj/project.pbxproj +++ b/WeChatTweak.xcodeproj/project.pbxproj @@ -9,6 +9,8 @@ /* Begin PBXBuildFile section */ 7D14E5A41F6447DB00D75132 /* AlfredManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 7D14E5A21F6447DB00D75132 /* AlfredManager.h */; }; 7D14E5A51F6447DB00D75132 /* AlfredManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D14E5A31F6447DB00D75132 /* AlfredManager.m */; }; + 7D2194C32646E62E0068F4CC /* AutoAuth.h in Headers */ = {isa = PBXBuildFile; fileRef = 7D2194C12646E62E0068F4CC /* AutoAuth.h */; }; + 7D2194C42646E62E0068F4CC /* AutoAuth.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D2194C22646E62E0068F4CC /* AutoAuth.m */; }; 7D54A05C20E74D9400CB5306 /* TweakPreferencesController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7D54A05E20E74D9400CB5306 /* TweakPreferencesController.xib */; }; 7D54A06A20E74FE500CB5306 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 7D54A06C20E74FE500CB5306 /* Localizable.strings */; }; 7D9049F51F82A41A004E6370 /* fishhook.c in Sources */ = {isa = PBXBuildFile; fileRef = 7D9049F31F82A415004E6370 /* fishhook.c */; }; @@ -34,6 +36,8 @@ 153504EC5C9196C0D85213CF /* libPods-WeChatTweak.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-WeChatTweak.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 7D14E5A21F6447DB00D75132 /* AlfredManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AlfredManager.h; sourceTree = ""; }; 7D14E5A31F6447DB00D75132 /* AlfredManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AlfredManager.m; sourceTree = ""; }; + 7D2194C12646E62E0068F4CC /* AutoAuth.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AutoAuth.h; sourceTree = ""; }; + 7D2194C22646E62E0068F4CC /* AutoAuth.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AutoAuth.m; sourceTree = ""; }; 7D54A05F20E74E4600CB5306 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/TweakPreferencesController.xib; sourceTree = ""; }; 7D54A07020E74FFD00CB5306 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = ""; }; 7D54A07120E7535F00CB5306 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = ""; }; @@ -159,6 +163,8 @@ children = ( 7DF8422A1F40583F00D42D79 /* WeChatTweak.h */, 7DF842331F4058AB00D42D79 /* WeChatTweak.m */, + 7D2194C12646E62E0068F4CC /* AutoAuth.h */, + 7D2194C22646E62E0068F4CC /* AutoAuth.m */, 7D5AAF3720DF4BB300860EEE /* Vendor */, 7D5AAF3620DF4BA400860EEE /* Category */, 7D5AAF3520DF4B9700860EEE /* Controller */, @@ -202,6 +208,7 @@ 7D14E5A41F6447DB00D75132 /* AlfredManager.h in Headers */, 7DF842601F40590500D42D79 /* WeChatTweakHeaders.h in Headers */, 7DF842521F4058C600D42D79 /* TweakPreferencesController.h in Headers */, + 7D2194C32646E62E0068F4CC /* AutoAuth.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -328,6 +335,7 @@ 7DB8AFBF206211D900E683AE /* WTConfigManager.m in Sources */, 7D9049F51F82A41A004E6370 /* fishhook.c in Sources */, 7DF8425C1F4058DD00D42D79 /* NSBundle+WeChatTweak.m in Sources */, + 7D2194C42646E62E0068F4CC /* AutoAuth.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/WeChatTweak/AutoAuth.h b/WeChatTweak/AutoAuth.h new file mode 100644 index 0000000..97ddef4 --- /dev/null +++ b/WeChatTweak/AutoAuth.h @@ -0,0 +1,20 @@ +// +// AutoAuth.h +// WeChatTweak +// +// Created by Sunny Young on 2021/5/8. +// Copyright © 2021 Sunnyyoung. All rights reserved. +// + +#import +#import +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface NSObject (AutoAuth) + +@end + +NS_ASSUME_NONNULL_END diff --git a/WeChatTweak/AutoAuth.m b/WeChatTweak/AutoAuth.m new file mode 100644 index 0000000..5ab1c52 --- /dev/null +++ b/WeChatTweak/AutoAuth.m @@ -0,0 +1,56 @@ +// +// AutoAuth.m +// WeChatTweak +// +// Created by Sunny Young on 2021/5/8. +// Copyright © 2021 Sunnyyoung. All rights reserved. +// + +#import "AutoAuth.h" +#import "WeChatTweakHeaders.h" +#import "WTConfigManager.h" + +@implementation NSObject(AutoAuth) + +static void __attribute__((constructor)) tweak(void) { + [objc_getClass("MMLoginOneClickViewController") jr_swizzleMethod:NSSelectorFromString(@"onLoginButtonClicked:") withMethod:@selector(tweak_onLoginButtonClicked:) error:nil]; + [objc_getClass("MMMainViewController") jr_swizzleMethod:NSSelectorFromString(@"viewDidLoad") withMethod:@selector(tweak_viewDidLoad) error:nil]; + [objc_getClass("LogoutCGI") jr_swizzleMethod:NSSelectorFromString(@"FFVCRecvDataAddDataToMsgChatMgrRecvZZ:") withMethod:@selector(tweak_FFVCRecvDataAddDataToMsgChatMgrRecvZZ:) error:nil]; + [objc_getClass("AccountService") jr_swizzleMethod:NSSelectorFromString(@"FFAddSvrMsgImgVCZZ") withMethod:@selector(tweak_FFAddSvrMsgImgVCZZ) error:nil]; +} + +- (void)tweak_onLoginButtonClicked:(id)sender { + AccountService *accountService = [[objc_getClass("MMServiceCenter") defaultCenter] getService:objc_getClass("AccountService")]; + BOOL enabledAutoAuth = [NSUserDefaults.standardUserDefaults boolForKey:WeChatTweakPreferenceAutoAuthKey]; + BOOL canAutoAuth = accountService.canAutoAuth; + if (enabledAutoAuth && canAutoAuth) { + [accountService AutoAuth]; + } else { + [self tweak_onLoginButtonClicked:sender]; + } +} + +- (void)tweak_viewDidLoad { + [self tweak_viewDidLoad]; + if ([NSUserDefaults.standardUserDefaults boolForKey:WeChatTweakPreferenceAutoAuthKey]) { + MMSessionMgr *mgr = [[objc_getClass("MMServiceCenter") defaultCenter] getService:objc_getClass("MMSessionMgr")]; + [mgr loadSessionData]; + [mgr loadBrandSessionData]; + } +} + +- (void)tweak_FFVCRecvDataAddDataToMsgChatMgrRecvZZ:(id)arg { + if (![NSUserDefaults.standardUserDefaults boolForKey:WeChatTweakPreferenceAutoAuthKey]) { + [self tweak_FFVCRecvDataAddDataToMsgChatMgrRecvZZ:arg]; + } +} + +- (void)tweak_FFAddSvrMsgImgVCZZ { + if ([NSUserDefaults.standardUserDefaults boolForKey:WeChatTweakPreferenceAutoAuthKey]) { + return; + } else { + [self tweak_FFAddSvrMsgImgVCZZ]; + } +} + +@end diff --git a/WeChatTweak/Controller/TweakPreferencesController.h b/WeChatTweak/Controller/TweakPreferencesController.h index a62b6b0..7f5f35a 100644 --- a/WeChatTweak/Controller/TweakPreferencesController.h +++ b/WeChatTweak/Controller/TweakPreferencesController.h @@ -8,15 +8,6 @@ #import "WeChatTweakHeaders.h" -typedef NS_ENUM(NSUInteger, RevokeNotificationType) { - RevokeNotificationTypeFollow = 0, - RevokeNotificationTypeReceiveAll, - RevokeNotificationTypeDisable, -}; - -static NSString * const WeChatTweakPreferenceAutoAuthKey = @"WeChatTweakPreferenceAutoAuthKey"; -static NSString * const WeChatTweakPreferenceRevokeNotificationTypeKey = @"WeChatTweakPreferenceRevokeNotificationTypeKey"; - @interface TweakPreferencesController : NSViewController @end diff --git a/WeChatTweak/Supporting Files/WeChatTweakHeaders.h b/WeChatTweak/Supporting Files/WeChatTweakHeaders.h index 9bece88..66f29ac 100644 --- a/WeChatTweak/Supporting Files/WeChatTweakHeaders.h +++ b/WeChatTweak/Supporting Files/WeChatTweakHeaders.h @@ -11,6 +11,12 @@ #import #import +typedef NS_ENUM(NSUInteger, RevokeNotificationType) { + RevokeNotificationTypeFollow = 0, + RevokeNotificationTypeReceiveAll, + RevokeNotificationTypeDisable, +}; + typedef NS_ENUM(unsigned int, MessageDataType) { MessageDataTypeText = 1, MessageDataTypeImage = 3, @@ -21,6 +27,9 @@ typedef NS_ENUM(unsigned int, MessageDataType) { MessageDataTypePrompt = 10000 }; +static NSString * const WeChatTweakPreferenceAutoAuthKey = @"WeChatTweakPreferenceAutoAuthKey"; +static NSString * const WeChatTweakPreferenceRevokeNotificationTypeKey = @"WeChatTweakPreferenceRevokeNotificationTypeKey"; + @interface NSString (MD5) - (NSString *)md5String; @@ -29,8 +38,6 @@ typedef NS_ENUM(unsigned int, MessageDataType) { @interface WeChat : NSObject -@property(nonatomic) BOOL isAppTerminating; - + (instancetype)sharedInstance; - (void)lock:(id)block; - (void)showMainWindow; @@ -112,13 +119,6 @@ typedef NS_ENUM(unsigned int, MessageDataType) { - (BOOL)canAutoAuth; - (void)AutoAuth; -- (void)onAuthOKOfUser:(id)arg1 withSessionKey:(id)arg2 withServerId:(id)arg3 autoAuthKey:(id)arg4 isAutoAuth:(BOOL)arg5; - -@end - -@interface LogoutCGI: NSObject - -- (void)sendLogoutCGIWithCompletion:(id)arg1; @end @@ -128,6 +128,13 @@ typedef NS_ENUM(unsigned int, MessageDataType) { @end +@interface MMSessionMgr: NSObject + +- (void)loadSessionData; +- (void)loadBrandSessionData; + +@end + @protocol MASPreferencesViewController @property(readonly, nonatomic) NSString *toolbarItemLabel; diff --git a/WeChatTweak/WeChatTweak.m b/WeChatTweak/WeChatTweak.m index 59390f6..c40520c 100755 --- a/WeChatTweak/WeChatTweak.m +++ b/WeChatTweak/WeChatTweak.m @@ -53,11 +53,6 @@ static void __attribute__((constructor)) tweak(void) { // Method Swizzling class_addMethod(objc_getClass("AppDelegate"), @selector(applicationDockMenu:), method_getImplementation(class_getInstanceMethod(objc_getClass("AppDelegate"), @selector(tweak_applicationDockMenu:))), "@:@"); [objc_getClass("AppDelegate") jr_swizzleMethod:NSSelectorFromString(@"applicationDidFinishLaunching:") withMethod:@selector(tweak_applicationDidFinishLaunching:) error:nil]; - [objc_getClass("LogoutCGI") jr_swizzleMethod:NSSelectorFromString(@"sendLogoutCGIWithCompletion:") withMethod:@selector(tweak_sendLogoutCGIWithCompletion:) error:nil]; - [objc_getClass("LogoutCGI") jr_swizzleMethod:NSSelectorFromString(@"FFVCRecvDataAddDataToMsgChatMgrRecvZZ:") withMethod:@selector(tweak_sendLogoutCGIWithCompletion:) error:nil]; - [objc_getClass("AccountService") jr_swizzleMethod:NSSelectorFromString(@"onAuthOKOfUser:withSessionKey:withServerId:autoAuthKey:isAutoAuth:") withMethod:@selector(tweak_onAuthOKOfUser:withSessionKey:withServerId:autoAuthKey:isAutoAuth:) error:nil]; - [objc_getClass("AccountService") jr_swizzleMethod:NSSelectorFromString(@"ManualLogout") withMethod:@selector(tweak_ManualLogout) error:nil]; - [objc_getClass("AccountService") jr_swizzleMethod:NSSelectorFromString(@"FFAddSvrMsgImgVCZZ") withMethod:@selector(tweak_ManualLogout) error:nil]; [objc_getClass("MessageService") jr_swizzleMethod:NSSelectorFromString(@"onRevokeMsg:") withMethod:@selector(tweak_onRevokeMsg:) error:nil]; [objc_getClass("MessageService") jr_swizzleMethod:NSSelectorFromString(@"FFToNameFavChatZZ:") withMethod:@selector(tweak_onRevokeMsg:) error:nil]; [objc_getClass("MessageService") jr_swizzleMethod:NSSelectorFromString(@"FFToNameFavChatZZ:sessionMsgList:") withMethod:@selector(tweak_onRevokeMsg:sessionMessageList:) error:nil]; @@ -435,42 +430,11 @@ static void __attribute__((constructor)) tweak(void) { [task waitUntilExit]; } -#pragma mark - Auto Auth +#pragma mark - Alfred - (void)tweak_applicationDidFinishLaunching:(NSNotification *)notification { + [AlfredManager.sharedInstance startListener]; [self tweak_applicationDidFinishLaunching:notification]; - NSString *bundleIdentifier = NSBundle.mainBundle.bundleIdentifier; - NSArray *instances = [NSRunningApplication tweak_runningApplicationsWithBundleIdentifier:bundleIdentifier]; - // Detect multiple instance conflict - BOOL hasInstance = instances.count == 1; - BOOL enabledAutoAuth = [[NSUserDefaults standardUserDefaults] boolForKey:WeChatTweakPreferenceAutoAuthKey]; - if (hasInstance && enabledAutoAuth) { - AccountService *accountService = [[objc_getClass("MMServiceCenter") defaultCenter] getService:objc_getClass("AccountService")]; - if ([accountService canAutoAuth]) { - [accountService AutoAuth]; - } - } -} - -- (void)tweak_onAuthOKOfUser:(id)arg1 withSessionKey:(id)arg2 withServerId:(id)arg3 autoAuthKey:(id)arg4 isAutoAuth:(BOOL)arg5 { - [[AlfredManager sharedInstance] startListener]; - [self tweak_onAuthOKOfUser:arg1 withSessionKey:arg2 withServerId:arg3 autoAuthKey:arg4 isAutoAuth:arg5]; -} - -- (void)tweak_sendLogoutCGIWithCompletion:(id)completion { - BOOL enabledAutoAuth = [[NSUserDefaults standardUserDefaults] boolForKey:WeChatTweakPreferenceAutoAuthKey]; - WeChat *wechat = [objc_getClass("WeChat") sharedInstance]; - if (enabledAutoAuth && wechat.isAppTerminating) { - return; - } - [self tweak_sendLogoutCGIWithCompletion:completion]; -} - -- (void)tweak_ManualLogout { - BOOL enabledAutoAuth = [[NSUserDefaults standardUserDefaults] boolForKey:WeChatTweakPreferenceAutoAuthKey]; - if (!enabledAutoAuth) { - [self tweak_ManualLogout]; - } } #pragma mark - Preferences Window