// 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]));
}
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);
}
void my_malloc_zone_free(malloc_zone_t zone, void ptr){ printf("Calling real free( %zu)\n",malloc_size(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);
}