我想实现动态库注入。以下是我的工作,但没有成功:
1。通过compile injection.c创建injection.dylib:
#include <stdio.h>
#include <objc/objc.h>
id evil_say(id self, SEL op) {
printf("Bawhawhawhaw! I'm Evil!\n");
FILE *f= fopen("/tmp/sample.txt","w");
fprintf(f, "OKOK");
fclose(f);
return self;
}
static void __attribute__((constructor)) initialize(void) {
FILE *f= fopen("/tmp/sample.txt2","w");
fprintf(f, "OKOK");
fclose(f);
class_replaceMethod( objc_getClass("SaySomething"), sel_registerName("say:"), evil_say, "@:" );
}
2。 sign lib
ldid -S injection.dylib
第3。编写示例HelloWorld iOS:
#import "ViewController.h"
@interface SaySomething : NSObject - (void) say: (NSString *) phrase; @end
@implementation SaySomething
- (void) say: (NSString *) phrase {
printf("%s\n", [ phrase UTF8String ]); }
@end
@interface ViewController ()
@end
@implementation ViewController
(void)viewDidLoad {
[super viewDidLoad];
SaySomething *saySomething = [ [ SaySomething alloc ] init ];
[ saySomething say: @"Hello, world!" ];
...
4。通过xcode7构建并运行应用程序 - &gt; HelloWorld应用程序已安装并运行
5。使用iFunBox将injection.dylib复制到HelloWorld.app文件夹
6。通过添加环境变量(字典)和1项来修改HelloWorld.app文件夹中的Info.plist:
key=DYLD_INSERT_LIBRARIES
value=/var/lib/mobile/<xxx-xxx....>/HelloWorld.app/injection.dylib
7。在iPhone上打开HelloWorld应用程序
但我在iPhone的/ tmp文件夹中找不到任何sample.txt / sample.txt2。这意味着库没有被加载。
有人能告诉我我的错吗?