今天又是接近逆向的一天~
-
今天准备来个案例:在
某信
的设置界面,注入UI
(为了以后的自动抢红包
来个前奏~) -
首先我们看下效果图
1. 准备工作
无论是
正向
还是逆向
开发,我们写代码之前,都要缕一波思路:我们的目的就是在设置界面增加UI
1.1. 定位设置界面
上一篇博客已经说了
Monkey
和Logos
,我们正好来用一波。
-
我们使用的是
8.0.2的微信包
。(当然你可以使用最新的8.0.5
的,我们应该是一样的) -
- 我们重签
WeChat
,运行Monkey
- 我们重签
-
- 我们可以用
viewDebug
定位控制器的名称为:NewSettingViewController
- 我们可以用
-
- 而且我们也可以观察到界面是一个
WCTableView
,我们要找到他的数据源(dataSource)
,所以我们先看下
- 而且我们也可以观察到界面是一个
可以知道:
datasource=<WCTableViewManager: 0x282ba8db0>
-
class-dump
获取微信
的H文件
,sublime
打开之后寻找WCTableViewManager
-
- 发现
WCTableViewManager
里面有section组
和tableView
的代理方法
- 发现
-
- 我们查看有多少使用WCTableViewManager管理的
-
- 我们可以确定,其中一个是设置界面:我们可以通过
响应链条
,找到设置界面
- 我们可以确定,其中一个是设置界面:我们可以通过
2. UI注入
我们已经找到了设置界面,可以通过
class-dump
.通过头文件查看他的方法
- 我直接写代码了~ (里面写了注释,这个比较简单,兄弟们看看有机会可以试一下,不过有被封的风险~ ? ,所以我是在冒着被封的风险来探索~)
#import <UIKit/UIKit.h>
#define XGDefaults [NSUserDefaults standardUserDefaults]
#define XGSWITCHKEY @"XGSWITCHKEY"
#define XGTEXTKEY @"XGTEXTKEY"
@interface WCTableViewManager : NSObject
//在class-dump中的方法。我要调用,所以copy过来~
@property(retain, nonatomic) NSMutableArray *sections;
- (long long)numberOfSectionsInTableView:(UITableView *)tableView;
@end
//由于用到self,需要知道self的定位
@interface MMUIViewController : UIViewController
@end
@interface NewSettingViewController : MMUIViewController
@end
%hook WCTableViewManager
//要hook的方法~ 滑动时,键盘回收
- (void)scrollViewWillBeginDragging:(id)arg1{
%orig;
//确定是在设置界面
if([MSHookIvar <UITableView *>(self,"_tableView").nextResponder.nextResponder isKindOfClass:%c(NewSettingViewController)]){
[MSHookIvar <UITableView *>(self,"_tableView") endEditing:YES];
}
}
//自定义textfield方法
%new
-(void)xg_textFieldDidChangeValue:(NSNotification *)notification{
UITextField *textField = (UITextField *)[notification object];
[XGDefaults setValue:textField.text forKey:XGTEXTKEY];
[XGDefaults synchronize];
[MSHookIvar <UITableView *>(self,"_tableView") reloadData];
}
//自定义switch开关方法
%new
-(void)xg_switchChang:(UISwitch *)switchView{
[XGDefaults setBool:switchView.isOn forKey:XGSWITCHKEY];
[XGDefaults synchronize];
[MSHookIvar <UITableView *>(self,"_tableView") reloadData];
}
//cell设置
- (id)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
// NSLog(@"indexPath:%ld,section:%ld",indexPath,[indexPath section]);
//如果在设置界面并且是最后一组。设置cell
if([tableView.nextResponder .nextResponder isKindOfClass:%c(NewSettingViewController)] && ([indexPath section] == [self numberOfSectionsInTableView:tableView]-1)){
UITableViewCell * cell = nil;
//笑脸UI SWICH开关
if([indexPath row] == 0){
static NSString * swCell = @"SWCELL";
cell = [tableView dequeueReusableCellWithIdentifier:swCell];
if(!cell){
cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:nil];
}
cell.textLabel.text = @"逆向开始!!";
UISwitch * switchView = [[UISwitch alloc] init];
switchView.on = [XGDefaults boolForKey:XGSWITCHKEY];
[switchView addTarget:self action:@selector(xg_switchChang:) forControlEvents:(UIControlEventValueChanged)];
cell.accessoryView = switchView;
cell.imageView.image = [UIImage imageNamed:([XGDefaults boolForKey:XGSWITCHKEY] == 1) ? @"unlocked" : @"locked"];
}else if([indexPath row] == 1){
static NSString * waitCell = @"UICELL";
cell = [tableView dequeueReusableCellWithIdentifier:waitCell];
if(!cell){
cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:nil];
}
cell.textLabel.text = @"增加个小UI!";
//首先设置一个输入框的大小
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 80, 30)];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(xg_textFieldDidChangeValue:) name:UITextFieldTextDidChangeNotification object:textField];
textField.text = [XGDefaults valueForKey:XGTEXTKEY];
//我们通过class-dump中header可以知道,cell有一个- (void)setAccessoryView:(id)arg1;方法
[cell setAccessoryView:textField];
cell.imageView.image = [UIImage imageNamed:@"1003_filled"];
}
cell.backgroundColor = [UIColor whiteColor];
return cell;
}else{
return %orig;
}
}
//每组有多少行
- (long long)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
//如果在设置界面并且是最后一组。增加2行
if([tableView.nextResponder .nextResponder isKindOfClass:%c(NewSettingViewController)] && (section == [self numberOfSectionsInTableView:tableView]-1)){
return 2;
}else{
return %orig;
}
}
// 多少组 .nextResponder .nextResponder
- (long long)numberOfSectionsInTableView:(UITableView *)tableView {
//可以判断是在设置界面
if([tableView.nextResponder .nextResponder isKindOfClass:%c(NewSettingViewController)]){
return %orig + 1;
}else{
return %orig;
}
}
//行高
- (double)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
//如果在设置界面并且是最后一组。设置行高~
if([tableView.nextResponder .nextResponder isKindOfClass:%c(NewSettingViewController)] && ([indexPath section] == [self numberOfSectionsInTableView:tableView]-1)){
return 44;
}else{
return %orig;
}
}
%end
//由于我们增加了一个textfield控件,想象一下,键盘谈起的话,会遮挡视图所以我们可以处理下(当然,可以可以不处理,只是个界面遮挡的问题,不过对于有点小小强迫症的我来说,还是要处理下)
//要做的2件事,,1、键盘谈起,tableview,上移!2、滑动tableview,键盘回收
%hook NewSettingViewController
//弹出
%new
- (void)xg_keyboardWillShow:(NSNotification *)notification{
UIView * view = self.view;
CGRect keyBoardRect=[notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
view.frame = CGRectMake(0, -keyBoardRect.size.height, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height );
}
//消失
%new
- (void)xg_keyboardWillHide:(NSNotification *)notification{
UIView * view = self.view;
view.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
}
// hook 方法,增加通知~
- (void)viewDidLoad{
%orig;
//监听键盘的弹出和消失
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(xg_keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(xg_keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
%end
复制代码
- 实物图走上一波
3. 总结
-
某信
有风险,慎触~ ? -
这篇博客主要是为
自动抢红包
做个准备,要不一下代码太多兄弟研究的时候就不好预览了~ -
兄弟们要是试的话,用大号测试。到时候可以解封(由于有被封的风险)
-
我们就是研究下他的技术,学习一下,所以没有什么问题的
-
这次注入UI没有写什么功能,所以比较简单些。最后,兄得们,我去加班了~ (公司老是下班之前来工作!!?)
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END