MonkeyDev中hook系统NSLog函数

讲道理,利用fishhook进行hook其实就可以了

比如说我们的ViewDidLoad方法当中的方法里面有输出123,456 我们想要对其进行hook

- (void)viewDidLoad {
    [super viewDidLoad];

    NSLog(@"123");

    NSLog(@"456");
}

创建一个monkeyDev的项目,然后在里面写入hook代码

#import <UIKit/UIKit.h>
#import "fishhook.h"

static void (*old_log)(NSString *format, ...);

void newLog(NSString *format, ...)
{
     format = [format stringByAppendingString:@"上钩"];

    old_log(format);
}

%hook ViewController

- (void)viewDidLoad {


    NSLog(@"哈哈");


    struct rebinding nslogBind;
    //函数的名称
    nslogBind.name="NSLog";
    //新的函数地址
    nslogBind.replacement = (void *)newLog;
    //保存原始函数的地址的变量的指针,只需要告诉它是指针就可以了,因为指针就占据8个字节
    nslogBind.replaced = (void **)&old_log;

    //定义数组
    struct rebinding rebs[] = {nslogBind};

    /*
     arg1:存放rebinding结构体的数组
     arg2:数组的长度
     */
    //可以通过这个函数交换很多组的函数
    rebind_symbols(rebs, 1);

      %orig;


}

%end

成功hook

这里写图片描述

猜你喜欢

转载自blog.csdn.net/ZCMUCZX/article/details/80349193