iOS越狱开发:hook(拦截)一个自己写的方法
2016-08-26 本文已影响0人
什么东东额
开发越狱插件需要先配置开发环境 Theos: iOS越狱插件开发工具
本文主要搬运至:iOS逆向工程(手动HOOK自己编写的APP)- 学习整理
------------ 开始 ------------
一、新建 Xcode 工程,运行在真机上
- 需要记住bundleID : com.swhl.HOOK-APP

- (void)setUpButton {
self.view.backgroundColor = [UIColor lightGrayColor];
UIButton *btn = [UIButton new];
btn.frame = CGRectMake(0, 0, 100, 40);
btn.center = self.view.center;
btn.backgroundColor = [UIColor orangeColor];
[self.view addSubview:btn];
[btn setTitle:@"接收新消息" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventTouchUpInside];
}
- (void)buttonClick {
UIAlertController *alerView = [UIAlertController alertControllerWithTitle:@"提示" message:@"啥都没有" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction =[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
[alerView addAction:cancelAction];
[self presentViewController:alerView animated:YES completion:nil];
}
- 在真机上效果

二、新建 Tweak 工程
tweak.xm 文件本质为 dylib 动态库文件
- 1.打开终端,找到theos安装目录

- 2.创建tweak工程之后
当前目录下会产生你创建的tweak文件夹

- 3 Makefile
Makefile中加入3行代码

- 4.Tweak.xm
hook的相关代码将写在这个文件中。拦截了ViewController 中的 buttonClick 消息,并且可以重写再发出。
%hook - %end 是固定写法,可以去了解下。
%hook ViewController
- (void)buttonClick
{
UIAlertController *alerView = [UIAlertController alertControllerWithTitle:@"恭 喜" message:@"新消息被拦截" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction =[UIAlertAction actionWithTitle:@"Theos:iOS越狱插件开发工具" style:UIAlertActionStyleCancel handler:nil];
[alerView addAction:cancelAction];
[self presentViewController:alerView animated:YES completion:nil];
}
%end
三、 通过 make package install 安装在Cydia上
终端切到hookDemo目录下,此时保持电脑手机在同一wifi下。
make package install

root@IP 's password : alpine

- 成功
