准备工作:
tweak教程正式开始
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
-(void)viewDidAppear:(BOOL)animated{
[self bigun_test];
}
-(void)bigun_test{
NSLog(@"12");
}
@end
运行起来,直接输出"12"
终端执行命令
$THOES_HOME/bin/nic.pl
注意,不得在$THOES_HOME中运行,否则报错
选择"iphone/tweak",那个选项,也就是输入”17"
#import
@interface ViewController:UIViewController //为了使用self,否则编译不过
@end
%hook ViewController
-(void)bigun_test{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"标题" message:@"恭喜hook成功" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *conform = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"点击了确认按钮");
}];
[alert addAction:conform];
[self presentViewController:alert animated:YES completion:nil];
}
%end
Tweak.x:39:5: error: use of undeclared identifier 'UIAlertView'
编译、打包、运行
make clean && make package && make install
如无意外,则有以下日志
期间可能要输入两次ssh的密码
OK~,hook插件已编写及安装完毕,再次运行你的demo工程,你就会发现弹出一个窗口啦!
以下是常见错误及解决方法:
执行编译安装时提示以下报错
ssh: connect to host 192.168.1.102 port 22: Operation timed out
解决:
检查cydia中是否已安装open_ssh