#import #import "DKHelper.h" #import "DKHelperSettingController.h" %hook MMServiceCenter %new + (id)defaultCenter{ return [[%c(MMContext) currentContext] serviceCenter]; } %end %hook MicroMessengerAppDelegate - (void)applicationDidEnterBackground:(UIApplication *)application{ %orig; [[DKHelperConfig shared] enterBackgroundHandler]; } -(void)applicationDidBecomeActive:(UIApplication *)application{ %orig; [DKHelperConfig.shared.bgTaskTimer invalidate]; } %end %hook NewSettingViewController - (void)reloadTableData{ %orig; WCTableViewManager *tableViewMgr = MSHookIvar(self, "m_tableViewMgr"); MMTableView *tableView = [tableViewMgr getTableView]; WCTableViewNormalCellManager *newCell = [%c(WCTableViewNormalCellManager) normalCellForSel:@selector(setting) target:self title:@"微信小助手"]; [((WCTableViewSectionManager*)tableViewMgr.sections[0]) addCell: newCell]; [tableView reloadData]; } %new - (void)setting { UIViewController *vc = [[DKHelperSettingController alloc] init]; [((UIViewController *)self).navigationController PushViewController:vc animated:true]; } %end %hook CMessageMgr - (void)AddEmoticonMsg:(NSString *)msg MsgWrap:(CMessageWrap *)msgWrap { if (DKHelperConfig.gamePlugEnable) { // 是否开启游戏作弊 if ([msgWrap m_uiMessageType] == 47 && ([msgWrap m_uiGameType] == 2|| [msgWrap m_uiGameType] == 1)) { NSString *title = [msgWrap m_uiGameType] == 1 ? @"请选择石头/剪刀/布" : @"请选择点数"; UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"请选择" message:title preferredStyle:UIAlertControllerStyleActionSheet]; NSArray *arr = @[@"剪刀",@"石头",@"布",@"1",@"2",@"3",@"4",@"5",@"6"]; for (int i = [msgWrap m_uiGameType] == 1 ? 0 : 3; i<([msgWrap m_uiGameType] == 1 ? 3 : 9); i++) { UIAlertAction* action1 = [UIAlertAction actionWithTitle:arr[i] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { [msgWrap setM_nsEmoticonMD5:[objc_getClass("GameController") getMD5ByGameContent:i+1]]; [msgWrap setM_uiGameContent:i+1]; %orig(msg, msgWrap); }]; [alert addAction:action1]; } UIAlertAction* action2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { }]; [alert addAction:action2]; [[[UIApplication sharedApplication] keyWindow].rootViewController presentViewController:alert animated:true completion:nil]; return; } } %orig(msg, msgWrap); } - (void)onRevokeMsg:(CMessageWrap *)arg1 { if (DKHelperConfig.preventRevoke) { NSString *msgContent = arg1.m_nsContent; NSString *(^parseParam)(NSString *, NSString *,NSString *) = ^NSString *(NSString *content, NSString *paramBegin,NSString *paramEnd) { NSUInteger startIndex = [content rangeOfString:paramBegin].location + paramBegin.length; NSUInteger endIndex = [content rangeOfString:paramEnd].location; NSRange range = NSMakeRange(startIndex, endIndex - startIndex); return [content substringWithRange:range]; }; NSString *session = parseParam(msgContent, @"", @""); NSString *newmsgid = parseParam(msgContent, @"", @""); NSString *fromUsrName = parseParam(msgContent, @"" options:NSLiteralSearch]; NSRange range3 = NSMakeRange(range1.location + range1.length, range2.location - range1.location - range1.length); content = [content substringWithRange:range3]; __block BOOL result = false; [[DKHelperConfig.redEnvelopTextFiter componentsSeparatedByString:@","] enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { if ([content containsString:obj]){ result = true; } }]; return result; }; /** 是否自动抢红包 */ BOOL (^shouldReceiveRedEnvelop)() = ^BOOL() { if (!DKHelperConfig.autoRedEnvelop) { return NO; } if (isGroupInBlackList()) { return NO; } if (isContaintKeyWords()) { return NO; } return isGroupReceiver() || (isGroupSender() && isReceiveSelfRedEnvelop()); }; NSDictionary *(^parseNativeUrl)(NSString *nativeUrl) = ^(NSString *nativeUrl) { nativeUrl = [nativeUrl substringFromIndex:[@"wxpay://c2cbizmessagehandler/hongbao/receivehongbao?" length]]; return [%c(WCBizUtil) dictionaryWithDecodedComponets:nativeUrl separator:@"&"]; }; /** 获取服务端验证参数 */ void (^queryRedEnvelopesReqeust)(NSDictionary *nativeUrlDict) = ^(NSDictionary *nativeUrlDict) { NSMutableDictionary *params = [@{} mutableCopy]; params[@"agreeDuty"] = @"0"; params[@"channelId"] = [nativeUrlDict stringForKey:@"channelid"]; params[@"inWay"] = @"0"; params[@"msgType"] = [nativeUrlDict stringForKey:@"msgtype"]; params[@"nativeUrl"] = [[wrap m_oWCPayInfoItem] m_c2cNativeUrl]; params[@"sendId"] = [nativeUrlDict stringForKey:@"sendid"]; WCRedEnvelopesLogicMgr *logicMgr = [[objc_getClass("MMServiceCenter") defaultCenter] getService:[objc_getClass("WCRedEnvelopesLogicMgr") class]]; [logicMgr ReceiverQueryRedEnvelopesRequest:params]; }; /** 储存参数 */ void (^enqueueParam)(NSDictionary *nativeUrlDict) = ^(NSDictionary *nativeUrlDict) { WeChatRedEnvelopParam *mgrParams = [[WeChatRedEnvelopParam alloc] init]; mgrParams.msgType = [nativeUrlDict stringForKey:@"msgtype"]; mgrParams.sendId = [nativeUrlDict stringForKey:@"sendid"]; mgrParams.channelId = [nativeUrlDict stringForKey:@"channelid"]; mgrParams.nickName = [selfContact getContactDisplayName]; mgrParams.headImg = [selfContact m_nsHeadImgUrl]; mgrParams.nativeUrl = [[wrap m_oWCPayInfoItem] m_c2cNativeUrl]; mgrParams.sessionUserName = isGroupSender() ? wrap.m_nsToUsr : wrap.m_nsFromUsr; mgrParams.sign = [nativeUrlDict stringForKey:@"sign"]; mgrParams.isGroupSender = isGroupSender(); [[WBRedEnvelopParamQueue sharedQueue] enqueue:mgrParams]; }; if (shouldReceiveRedEnvelop()) { NSString *nativeUrl = [[wrap m_oWCPayInfoItem] m_c2cNativeUrl]; NSDictionary *nativeUrlDict = parseNativeUrl(nativeUrl); queryRedEnvelopesReqeust(nativeUrlDict); enqueueParam(nativeUrlDict); } } break; } default: break; } } %end %hook WCDeviceStepObject -(NSInteger)m7StepCount { NSInteger stepCount = %orig; NSInteger newStepCount = DKHelperConfig.changedSteps; return DKHelperConfig.changeSteps ? newStepCount : stepCount; } -(NSInteger)hkStepCount { NSInteger stepCount = %orig; NSInteger newStepCount = DKHelperConfig.changedSteps; return DKHelperConfig.changeSteps ? newStepCount : stepCount; } %end %hook WCRedEnvelopesLogicMgr - (void)OnWCToHongbaoCommonResponse:(HongBaoRes *)arg1 Request:(HongBaoReq *)arg2 { %orig; // 非参数查询请求 if (arg1.cgiCmdid != 3) { return; } NSString *(^parseRequestSign)() = ^NSString *() { NSString *requestString = [[NSString alloc] initWithData:arg2.reqText.buffer encoding:NSUTF8StringEncoding]; NSDictionary *requestDictionary = [%c(WCBizUtil) dictionaryWithDecodedComponets:requestString separator:@"&"]; NSString *nativeUrl = [[requestDictionary stringForKey:@"nativeUrl"] stringByRemovingPercentEncoding]; NSDictionary *nativeUrlDict = [%c(WCBizUtil) dictionaryWithDecodedComponets:nativeUrl separator:@"&"]; return [nativeUrlDict stringForKey:@"sign"]; }; NSDictionary *responseDict = [[[NSString alloc] initWithData:arg1.retText.buffer encoding:NSUTF8StringEncoding] JSONDictionary]; WeChatRedEnvelopParam *mgrParams = [[WBRedEnvelopParamQueue sharedQueue] dequeue]; BOOL (^shouldReceiveRedEnvelop)() = ^BOOL() { // 手动抢红包 if (!mgrParams) { return NO; } // 自己已经抢过 if ([responseDict[@"receiveStatus"] integerValue] == 2) { return NO; } // 红包被抢完 if ([responseDict[@"hbStatus"] integerValue] == 4) { return NO; } // 没有这个字段会被判定为使用外挂 if (!responseDict[@"timingIdentifier"]) { return NO; } if (mgrParams.isGroupSender) { // 自己发红包的时候没有 sign 字段 return DKHelperConfig.autoRedEnvelop; } else { return [parseRequestSign() isEqualToString:mgrParams.sign] && DKHelperConfig.autoRedEnvelop; } }; if (shouldReceiveRedEnvelop()) { mgrParams.timingIdentifier = responseDict[@"timingIdentifier"]; unsigned int delaySeconds = [self calculateDelaySeconds]; WBReceiveRedEnvelopOperation *operation = [[WBReceiveRedEnvelopOperation alloc] initWithRedEnvelopParam:mgrParams delay:delaySeconds]; if (DKHelperConfig.redEnvelopMultipleCatch) { [[WBRedEnvelopTaskManager sharedManager] addSerialTask:operation]; } else { [[WBRedEnvelopTaskManager sharedManager] addNormalTask:operation]; } } } %new - (unsigned int)calculateDelaySeconds { NSInteger configDelaySeconds = DKHelperConfig.redEnvelopDelay ; if (DKHelperConfig.redEnvelopDelay) { unsigned int serialDelaySeconds; if ([WBRedEnvelopTaskManager sharedManager].serialQueueIsEmpty) { serialDelaySeconds = configDelaySeconds; } else { serialDelaySeconds = 15; } return serialDelaySeconds; } else { return (unsigned int)configDelaySeconds; } } %end // Enable CallKit %hook VoipCXMgr + (BOOL)isCallkitAvailable{ return DKHelperConfig.callKitEnable; } + (BOOL)isDeviceCallkitAvailable{ return DKHelperConfig.callKitEnable; } %end %hook UIViewController - (void)viewWillAppear:(BOOL)animated{ %orig; NSLog(@"\n***********************************************\n\t%@ appear\n***********************************************\n",NSStringFromClass([(NSObject*)self class])); } %end %hook MMTipsViewController %new - (NSString *)text{ return [self valueForKeyPath:@"_tipsTextView.text"]; } %end %hook WCTimelineMgr - (void)modifyDataItem:(WCDataItem *)arg1 notify:(BOOL)arg2{ if (!DKHelperConfig.likeCommentEnable){ %orig;return; } if (arg1.likeFlag){ arg1.commentUsers = [DKHelper commentWith:arg1]; arg1.commentCount = (int)arg1.commentUsers.count; arg1.likeUsers = DKHelper.commentUsers; arg1.likeCount = (int)DKHelper.commentUsers.count; } %orig(arg1,arg2); } %end