2

由于各种原因,我需要挂钩这些功能,尤其是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];
}

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

4

0 回答 0