Mach-O文件结构 https://www.jianshu.com/p/1f22d1e667e3
MachOView
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//这里必须要先加载一次NSLog,如果不写NSLog,符号表里面根本就不会出现NSLog的地址
NSLog(@"123");
//定义rebinding结构体
struct rebinding nslogBind;
//函数的名称
nslogBind.name = "NSLog";
//新的函数地址
nslogBind.replacement = myMethod;
//保存原始函数地址变量的指针
nslogBind.replaced = (void *)&old_nslog;
//定义数组
struct rebinding rebs[] = {nslogBind};
/**
arg1: 存放rebinding结构体的数组
arg2: 数组的长度
*/
rebind_symbols(rebs, 1);
}
//函数指针,用来保存原始的函数地址
static void (*old_nslog)(NSString *format, ...);
//新的NSLog
void myMethod(NSString *format, ...) {
//再调用原来的
old_nslog(@"勾上了!");
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
NSLog(@"点击屏幕");
}
lldb
- iOS之LLDB常用命令 https://www.jianshu.com/p/7fb43e0b956a