【iOS逆向】微信发现添加cell 关联 数据存储 加载图片资源
2018-04-25 本文已影响0人
丿沧海一粟丿
总结:1、%orig和%new两个方法;2、宏定义#path方法;3、资源加载打包方法
需求:微信“发现”界面增加2行cell

找到数据源控制器

找到手机中的Mach-O文件,查看是否脱壳,如果已脱壳,直接复制出进行dump头文件。



返回cell

退出微信功能实现

数据存储


崩溃了 因为找不到autoChange这个方法
查看手机的崩溃信息


在hook里面写的方法都认为是替换以前的方法。
新方法(最好都加一个前缀)需要添加一个%new

加载图片资源
写全路径
在tweak工程文件夹中新建一个layout(相当于手机中的Devices)文件夹

和以下层级文件夹放入图片在Preferences然后再新建一个App单独的文件夹(防止冲突)


则路径

宏定义优化


[图片上传中...(image-ea1e30-1524636864290-0)]
未越狱手机也可以写插件,后面可能会讲到。
shift+command+.显示隐藏文件
所有代码
define MJDefaults [NSUserDefaults standardUserDefaults]
define MJAutoKey @"mj_auto_key"
define MJFile(path) @"/Library/PreferenceLoader/Preferences/MJWeChat/" #path
%hook FindFriendEntryViewController
// 一共有多少组
- (long long)numberOfSectionsInTableView:(id)tableView
{
return %orig + 1;
}
// 每一组有多少行
- (long long)tableView:(id)tableView numberOfRowsInSection:(long long)section
{
if (section == [self numberOfSectionsInTableView:tableView] - 1) {
return 2;
} else {
return %orig;
}
}
// 监听自动抢红包的开关(新方法需要添加%new)
%new
- (void)mj_autoChange:(UISwitch *)switchView
{
[MJDefaults setBool:switchView.isOn forKey:MJAutoKey];
[MJDefaults synchronize];
}
// 返回每一行的cell
- (id)tableView:(id)tableView cellForRowAtIndexPath:(id)indexPath
{
if ([indexPath section] !=
[self numberOfSectionsInTableView:tableView] - 1) {
return %orig;
}
// 最后一组cell的公共代码
NSString *cellId = ([indexPath row] == 1) ? @"exitCellId" : @"autoCellId";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:cellId];
if (cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:cellId];
cell.backgroundColor = [UIColor whiteColor];
// 图片
cell.imageView.image = [UIImage imageWithContentsOfFile:MJFile(skull.png)];
}
// 最后一组cell的具体代码
if ([indexPath row] == 0) {
cell.textLabel.text = @"自动抢红包";
// 开关
UISwitch *switchView = [[UISwitch alloc] init];
switchView.on = [MJDefaults boolForKey:MJAutoKey];
[switchView addTarget:self
action:@selector(mj_autoChange:)
forControlEvents:UIControlEventValueChanged];
cell.accessoryView = switchView;
} else if ([indexPath row] == 1) {
cell.textLabel.text = @"退出微信";
}
return cell;
}
// 每一行的高度
- (double)tableView:(id)tableView heightForRowAtIndexPath:(id)indexPath
{
if ([indexPath section] !=
[self numberOfSectionsInTableView:tableView] - 1) {
return %orig;
}
return 44;
}
// 点击的监听
- (void)tableView:(id)tableView didSelectRowAtIndexPath:(id)indexPath
{
if ([indexPath section] !=
[self numberOfSectionsInTableView:tableView] - 1) {
%orig;
return;
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if ([indexPath row] == 1) {
// exit(0);
// 终止进程
abort();
}
}
%end