I have a problem from 3 days :( I want to hook in CLLocationManagerDelegate protocol this method:
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations
I tried everything but without success. I know how to hook into class or framework but I can't find a solution to hook a Delegate. Please help me! Thanks
Hooking requires you to provide objective-C class you would like to hook. This is what
Class
type is for. One way to get obj-c class is by name viaobjc_getClass
function. But in your case as I understand it correctly you don't have the name. You want to hook every class that conforms toCLLocationManagerDelegate
protocol and implements specific method. Here is what you can do.You can obtain every registered obj-C class and search for those which conform to
CLLocationManagerDelegate
protocol like this:...
We need to know how many classes there is.
objc_getClassList(NULL, 0)
returns number of all registered classes.Allocating memory with
malloc(sizeof(Class) * numClasses)
and filling it with objects of typeClass
usingobjc_getClassList(list, numClasses)
.Searching through all these classes for those which conform to
CLLocationManagerDelegate
protocol and implementlocationManager:didUpdateLocations:
method. If we found one we are hooking it with our own implementation.In our own implementation we are printing some debug message and calling original implementation before returning. Of course, you can do whatever you what, this is just an example.
Freeing allocated memory using
free(list)
.