Guest User

Untitled

a guest
Oct 17th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. static void APEHookMessageEx(Class class, SEL selector, IMP replacement, IMP *result) {
  2. if(class == nil) {
  3. printf("APEInject:Warning: nil class argument\n");
  4. return;
  5. } else if (selector == nil) {
  6. printf("APEInject:Warning: nil sel argument\n");
  7. return;
  8. } else if (replacement == nil) {
  9. printf("APEInject:Warning: nil imp argument\n");
  10. return;
  11. }
  12. const char *name = sel_getName(selector);
  13. Method method = class_getInstanceMethod(class, selector);
  14. if(method == nil) {
  15. printf("APEInject:Warning: message not found [%s %s]\n", class_getName(class), name);
  16. return;
  17. }
  18. const char *type = method_getTypeEncoding(method);
  19. IMP old = method_getImplementation(method);
  20. if (result != NULL)
  21. *result = old;
  22. if(!class_addMethod(class, selector, replacement, type))
  23. method_setImplementation(method, replacement);
  24.  
  25. }
Add Comment
Please, Sign In to add comment