一、新建 Xcode 工程评雌,運(yùn)行在真機(jī)上
需要記住bundleID : com.swhl.HOOK-APP
新建Xcode工程
<- (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];
}>
在真機(jī)上效果
未hook.gif
二酸员、新建 Tweak 工程
tweak.xm 文件本質(zhì)為 dylib 動(dòng)態(tài)庫文件
1.打開終端蛾绎,找到theos安裝目錄
屏幕快照 2016-08-26 17.36.27.png
2.創(chuàng)建tweak工程之后
當(dāng)前目錄下會(huì)產(chǎn)生你創(chuàng)建的tweak文件夾
屏幕快照 2016-08-26 17.48.29.png
3 Makefile
Makefile中加入3行代碼
屏幕快照 2016-08-26 18.00.59.png
4.Tweak.xm
hook的相關(guān)代碼將寫在這個(gè)文件中悔详。攔截了ViewController 中的 buttonClick 消息晰韵,并且可以重寫再發(fā)出。
%hook - %end 是固定寫法拆魏,可以去了解下盯桦。
%hook ViewController
- (void)buttonClick
{
UIAlertController *alerView = [UIAlertController alertControllerWithTitle:@"恭? 喜" message:@"新消息被攔截" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction =[UIAlertAction actionWithTitle:@"Theos:iOS越獄插件開發(fā)工具" style:UIAlertActionStyleCancel handler:nil];
[alerView addAction:cancelAction];
[self presentViewController:alerView animated:YES completion:nil];
}
%end
三、 通過 make package install 安裝在Cydia上
終端切到hookDemo目錄下渤刃,此時(shí)保持電腦手機(jī)在同一wifi下拥峦。
make package install
屏幕快照 2016-08-26 18.15.21.png
root@IP 's password : alpine
屏幕快照 2016-08-26 18.15.03.png
成功