facebook / fishhook

A library that enables dynamically rebinding symbols in Mach-O binaries running on iOS.
BSD 3-Clause "New" or "Revised" License
5.18k stars 966 forks source link

device malloc_zone_malloc hook #42

Open one2zero opened 7 years ago

one2zero commented 7 years ago

I am trying to hook “malloc_zone_malloc”,it works well with iOS Simulator ,but useless on an iOS device。what else should i do?

void my_malloc_zone_malloc(malloc_zone_t *zone, size_t size){ printf("Calling real malloc( %zu)\n", size);

 return orig_malloc_zone_malloc(zone, size);

}

void my_malloc_zone_free(malloc_zone_t zone, void ptr){ printf("Calling real free( %zu)\n",malloc_size(ptr));

return orig_malloc_zone_free(zone, ptr);

}

int main(int argc, char argv[]) { @autoreleasepool { rebind_symbols((struct rebinding[2]){{"malloc_zone_malloc", my_malloc_zone_malloc,(void)&orig_malloc_zone_malloc}, {"malloc_zone_free", my_malloc_zone_free,(void*)&orig_malloc_zone_free}}, 2);

    // Open our own binary and print out first 4 bytes (which is the same
    // for all Mach-O binaries on a given architecture)
    int fd = open(argv[0], O_RDONLY);
    uint32_t magic_number = 0;
    read(fd, &magic_number, 4);
    printf("Mach-O Magic Number: %x \n", magic_number);
    close(fd);

    return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));  
}  

}