Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

device malloc_zone_malloc hook #42

Open
one2zero opened this issue May 4, 2017 · 0 comments
Open

device malloc_zone_malloc hook #42

one2zero opened this issue May 4, 2017 · 0 comments

Comments

@one2zero
Copy link

one2zero commented May 4, 2017

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]));  
}  

}

@jobsyu jobsyu mentioned this issue Jun 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant