MSHookFunction可以挂起C函数,比如open,fopen还是write?

时间:2013-04-02 13:40:14

标签: iphone objective-c jailbreak theos cydia-substrate

由于各种原因,我需要挂钩这些函数,尤其是open。所以我在 theos 中编写了这段代码来测试:

#import <CoreFoundation/CoreFoundation.h> 
#include <substrate.h>

static int (*orig_open)(const char * pathname,int oflag,...);

int new_open(const char * pathname,int oflag,...)
{                   
  printf("-------------------I have success hook the C function open");
  //static int crashed = 0;
  va_list va;
  mode_t mode = 0;
  va_start(va, oflag);
  if (oflag & O_CREAT) mode = va_arg(va, int);
  va_end(va);
  int ret = orig_open(pathname, oflag, mode);
  if (strcmp(pathname, "/dev/dlci.spi-baseband.sms") == 0) 
  {
     printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!@@@@@@@@@@@@@@@@@@@@~~~~~~~~~~~~~~~~~~~~~");
  }
  else
  {
     printf("~~%%");
  }
  return ret;
}
%ctor
{
   NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];    
   MSHookFunction((void *)open, (void *)new_open, (void **)&orig_open);   
   [pool drain];
}

然而,似乎什么也没发生。那么,我的代码有什么问题吗?

0 个答案:

没有答案