Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void APEHookMessageEx(Class class, SEL selector, IMP replacement, IMP *result) {
- if(class == nil) {
- printf("APEInject:Warning: nil class argument\n");
- return;
- } else if (selector == nil) {
- printf("APEInject:Warning: nil sel argument\n");
- return;
- } else if (replacement == nil) {
- printf("APEInject:Warning: nil imp argument\n");
- return;
- }
- const char *name = sel_getName(selector);
- Method method = class_getInstanceMethod(class, selector);
- if(method == nil) {
- printf("APEInject:Warning: message not found [%s %s]\n", class_getName(class), name);
- return;
- }
- const char *type = method_getTypeEncoding(method);
- IMP old = method_getImplementation(method);
- if (result != NULL)
- *result = old;
- if(!class_addMethod(class, selector, replacement, type))
- method_setImplementation(method, replacement);
- }
Add Comment
Please, Sign In to add comment