I am wondering how do I hook to a function that is in the dylib, i.e. a C function. My target is to hook to a function CTRegistrationSetCellularDataIsEnabled that is in CoreTelephony.
Thanks!
You will need access to MobileSubtrate if you want any hope of hooking a dylib function, which is done like so (hooking a function called CFShow(), from here):
static void (*original_CFShow)(CFTypeRef obj); // a function pointer to store the original CFShow().
void replaced_CFShow(CFTypeRef obj) {
// our replacement of CFShow().
printf("Calling original CFShow(%p)...", obj);
original_CFShow(obj); // calls the original CFShow.
printf(" done.\n");
}
// hook CFShow to our own implementation.
MSHookFunction(CFShow, replaced_CFShow, &original_CFShow);
// From now on any call to CFShow will pass through replaced_CFShow first.
CFShow(CFSTR("test"));