之前分享过如何搭建theos开发环境,
这次分享下用theos开发一个微信自动抢红包的插件
微信相关类参考来自http://bbs.iosre.com/ ,大家也可以自己结合静态动态分析来找到微信关于红包的几个类
---------------------------------------又是凌乱分割线----------------------------------------
大概思路:在微信聊天界面中BaseMsgContentViewController,发现有红包出现WCPayC2CMessageNodeView,自动模拟点击事件onClick,弹出红包详情页WCRedEnvelopesReceiveHomeView,自动获取红包OnOpenRedEnvelopes
问题来了:
问题1:怎么知道红包什么时候出现呢?
答:通过勾取(- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath) 方法,当红包出现的时候会通过reloadData刷出红包,ios开发都懂的,这是必走的过程。通过获取cell中contentView的subViews找到WCPayC2CMessageNodeView就是说明有红包的出现
问题2:如何过滤掉已经抢过的红包
答:其实最好的办法就是能记录下打开过的红包id,但是从上面几个类的分析中没有分析出红包id的位置,大家可以看看这个红包详情页WCRedEnvelopesReceiveHomeView的data类型,红包id肯定在data里面,只是什么结构需要继续分析下
-(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