以前分享過如何搭建theos開發環境,ios
此次分享下用theos開發一個微信自動搶紅包的插件git
微信相關類參考來自http://bbs.iosre.com/ ,你們也能夠本身結合靜態動態分析來找到微信關於紅包的幾個類github
---------------------------------------又是凌亂分割線----------------------------------------微信
大概思路:在微信聊天界面中BaseMsgContentViewController,發現有紅包出現WCPayC2CMessageNodeView,自動模擬點擊事件onClick,彈出紅包詳情頁WCRedEnvelopesReceiveHomeView,自動獲取紅包OnOpenRedEnvelopesspa
問題來了:.net
問題1:怎麼知道紅包何時出現呢?插件
答:經過勾取(- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath) 方法,當紅包出現的時候會經過reloadData刷出紅包,ios開發都懂的,這是必走的過程。經過獲取cell中contentView的subViews找到WCPayC2CMessageNodeView就是說明有紅包的出現code
問題2:如何過濾掉已經搶過的紅包orm
答:其實最好的辦法就是能記錄下打開過的紅包id,可是從上面幾個類的分析中沒有分析出紅包id的位置,你們能夠看看這個紅包詳情頁WCRedEnvelopesReceiveHomeView的data類型,紅包id確定在data裏面,只是什麼結構須要繼續分析下blog
-(id)initWithFrame:(CGRect)frame andData:(id)data delegate:(id)delegate; -(void)refreshViewWithData:(id)data;
我目前的作法是比較low,就是隻查看最後一個cell的類型,若是是紅包就打開,打開後會有打開提示語放到tableView的最後,因此不會重複打個一個cell
問題3:爲何要一直打開聊天界面才能自動搶紅包,在首頁不行嗎?可能多個羣在一塊兒搶紅包呢?
答:固然能夠在首頁作到直接搶紅包了,只是須要分析底層消息體獲取解析的代碼,難度可能比界面分析要難不少。
固然,大神年年有,今年特別多,看這個 https://github.com/buginux/WeChatRedEnvelop
------------------------------------------凌亂的分割線---------------------------------------------
我自問自答也是夠了,上代碼讓你們看看吧
%hook BaseMsgContentViewController %new - (id)someValue { return objc_getAssociatedObject(self, @selector(someValue)); } %new - (void)setSomeValue:(id)value { objc_setAssociatedObject(self, @selector(someValue), value, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } %end %hook BaseMsgContentViewController - (id)tableView:(id)arg1 cellForRowAtIndexPath:(id)arg2 { UITableViewCell *cell = %orig(arg1,arg2); NSIndexPath *indexpath = arg2; NSString *value = [self performSelector:@selector(someValue)]; if(indexpath.row + 1 == [value integerValue]) { for (id subView in cell.contentView.subviews) { if([NSStringFromClass([subView class]) isEqualToString:@"WCPayC2CMessageNodeView"]) { [subView performSelector:@selector(onClick)]; } } } return cell; } - (long long)tableView:(id)arg1 numberOfRowsInSection:(long long)arg2 { long long result = %orig(arg1,arg2); [self performSelector:@selector(setSomeValue:) withObject:[NSString stringWithFormat:@"%zd",result]]; return result; } %end %hook WCRedEnvelopesReceiveHomeView - (void)refreshViewWithData:(id)arg1 { %orig; [self performSelector:@selector(OnOpenRedEnvelopes)]; [self performSelector:@selector(OnCancelButtonDone)]; } %end