Вопрос

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"));

Другие советы

You will need to use class dump to get the headers from the classes you need to use, and then call this function

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top