facebook fishhook

来源:互联网 发布:淘宝丝袜买家晒图 编辑:程序博客网 时间:2024/04/28 05:35
  1. #import <dlfcn.h>  
  2.   
  3. #import <UIKit/UIKit.h>  
  4.   
  5. #import "AppDelegate.h"  
  6. #import "fishhook.h"  
  7.   
  8. static int (*orig_close)(int);  
  9. static int (*orig_open)(const charchar *, int, ...);  
  10.   
  11. void save_original_symbols() {  
  12.   orig_close = dlsym(RTLD_DEFAULT, "close");  
  13.   orig_open = dlsym(RTLD_DEFAULT, "open");  
  14. }  
  15.   
  16. int my_close(int fd) {  
  17.   printf("Calling real close(%d)\n", fd);  
  18.   return orig_close(fd);  
  19. }  
  20.   
  21. int my_open(const charchar *path, int oflag, ...) {  
  22.   va_list ap = {0};  
  23.   mode_t mode = 0;  
  24.   
  25.   if ((oflag & O_CREAT) != 0) {  
  26.     // mode only applies to O_CREAT  
  27.     va_start(ap, oflag);  
  28.     mode = va_arg(ap, int);  
  29.     va_end(ap);  
  30.     printf("Calling real open('%s', %d, %d)\n", path, oflag, mode);  
  31.     return orig_open(path, oflag, mode);  
  32.   } else {  
  33.     printf("Calling real open('%s', %d)\n", path, oflag);  
  34.     return orig_open(path, oflag, mode);  
  35.   }  
  36. }  
  37.   
  38. int main(int argc, charchar * argv[])  
  39. {  
  40.   @autoreleasepool {  
  41.     save_original_symbols();  
  42.     //fishhook用法  
  43.     rebind_symbols((struct rebinding[2]){{"close", my_close}, {"open", my_open}}, 2);  
  44.   
  45.     // Open our own binary and print out first 4 bytes (which is the same  
  46.     // for all Mach-O binaries on a given architecture)  
  47.     int fd = open(argv[0], O_RDONLY);  
  48.     uint32_t magic_number = 0;  
  49.     read(fd, &magic_number, 4);  
  50.     printf("Mach-O Magic Number: %x \n", magic_number);  
  51.     close(fd);  
  52.   
  53.     return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));  
  54.   }  
  55. }
0 0
原创粉丝点击