hook地址 ms不生效 dobby可以

代码如下, 效果: MS hook不到 dobby可以hook到, 是什么情况

static uintptr_t sub_102345678 = 0x102345678;
int64_t (*old_sub_102345678)(int64_t);
static int64_t hook_sub_102345678(int64_t a1) {
    NSLog(@"mshookfunction hook_sub_102345678");
    int64_t (*imp)(int64_t) = (void *)sub_102345678;
    return imp(a1);
}

static __attribute__((constructor)) void hook_sub_xx() {
    uintptr_t aslr = _dyld_get_image_vmaddr_slide(0);
    sub_102345678 = sub_102345678 + aslr;
    MSHookFunction((void *)sub_102345678, &hook_sub_102345678, (void *)&sub_102345678);
}




// 注释MS 用Do 可以hook到
static uintptr_t sub_102345678 = 0x102345678;
static int64_t hook_sub_102345678(int64_t a1) {
    NSLog(@"dobby hook_sub_102345678");
    int64_t (*imp)(int64_t) = (void *)sub_102345678;
    return imp(a1);
}

static __attribute__((constructor)) void hook_sub_xx() {
    uintptr_t aslr = _dyld_get_image_vmaddr_slide(0);
    sub_102345678 = sub_102345678 + aslr;
    DobbyHook((void *)sub_102345678, hook_sub_102345678, (void *)&sub_102345678);
}


1 个赞

substiute 2.0以上版本的hook address有问题,查查是不是这个原因