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

hook malloc_zone_malloc EXC_BAD_ACCESS (code=2, address=0x10ecb50cd) #63

Open
wMellon opened this issue Jun 13, 2019 · 1 comment
Open

Comments

@wMellon
Copy link

wMellon commented Jun 13, 2019

I try to hook malloc_zone_malloc, but I get crash.Why?

void *my_malloc_zone_malloc(malloc_zone_t *zone, size_t size){
printf("Calling real malloc( %zu)\n", size);
return 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 malloc_zone_free(zone, ptr);

}

rebind_symbols((struct rebinding[2]){{"malloc_zone_malloc", my_malloc_zone_malloc,(void*)&malloc_zone_malloc}, {"malloc_zone_free", my_malloc_zone_free,(void*)&malloc_zone_free}}, 2);

@PotatoMapper
Copy link

I try to avoid contributing responses to poorly defined or not an issue with the project itself.

But it does not appear you ever declared a "Holder" pointer function where the original implementation of malloc_zone_malloc OR malloc_zone_free could be invoked from.

If you reference the homepage of the repo it clearly outlines a very simple and clear example of the proper way to swap the implementations.

I very quickly typed up what a single hook for malloc_zone_malloc should look like. Beware copy and pasting this as I typed it up on the fly and am EXTREMELY prone to overlooking typos.

#import "fishhook.h"
#import <Wherever_Malloc_structs_are_defined>

static void * (*orig_malloc_zone_malloc)(malloc_zone_t, size_t);

void * my_malloc_zone_malloc(malloc_zone_t *zone, size_t size) {
	// Do Stuff here
	// Log whatever you wanna play with or what have you
	orig_malloc_zone_malloc(zone,size);
}

rebind_symbols((struct rebinding[1])
	{{"malloc_zone_malloc", my_malloc_zone_malloc, (void *)&orig_malloc_zone_malloc}},1);

Note the static definition of the ptr func for the original implementation you do not have.

Try this and see if you still run into issues. Either way this is not an issue with fishhook itself at first glance, and should really be closed until you get to an error that is indicative of a failure on the project itself.

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

2 participants