主要思路是替换掉在mono里image.c的mono_image_open_from_data_with_name函数,HOOK掉加载DLL的地方,实现读取自定义的DLL文件。
检查发现在Xcode工程里的libiPhone-lib.a里存在mono的库文件,在libiPhone-lib.a下有两个CPU架构的库
lipo -info libiPhone-lib.a
Architectures in the fat file: libiPhone-lib.a are: armv7 i386
使用
lipo libiPhone-lib.a -thin armv7 -output libiPhone-lib.arm
解压出armv7的库文件
ar -t libiPhone-lib.arm
filterscpuimplvectordata.o
filterscpuimplwarp.o
filterscpumipmaps.o
filterscpupassvectordata.o
filterscpupvrtc.o
filterscpufxmapsbuffer.o
filterscpufxmapsmain.o
filterscpufxmapsdrawjob.o
filterscpufxmapsdrawqueue.o
filterscpufxmapsjob.o
filterscpufxmapspool.o
filterscpufxmapsthread.o
parsebitmap.o
parseblend.o
parseblur.o
parsechannelsshuffle.o
parsecommon.o
parsecontext.o
parsedata.o
parsedirectionalmotionblur.o
parsedirectionalwarp.o
parseemboss.o
parsefxmaps.o
parsefxmapssetcell.o
parsegradientmap.o
parsegrayscaleconversion.o
parsehsl.o
parselevels.o
parsemotionblur.o
parsenormal.o
parsesharpen.o
parsetransformation2d.o
parseuniformcolor.o
parsevectorgraphicsdata.o
parsewarp.o
apicontext.o
apihandle.o
apiversion.o
libCrashReporter-iphoneos.a-armv7-master.o
ar -t libiPhone-lib.arm | grep image.o
image.o
可以看到armv7下确实有image.o的模块
解压出image.o模块
ar -x libiPhone-lib.arm image.o
用十六进制工具搜索
mono_image_open_from_data_with_name 替换成 mono_image_open_from_data_with_xxxx
自己编译一个imagehook.c的文件生成imagehook.o,内容如下
#include <stdio.h>
extern int *
mono_image_open_from_data_with_xxxx(
char *data, unsigned int data_len,
int need_copy,
int *status,
int only, const char *name);
int *
mono_image_open_from_data_with_name(
char *data, unsigned int data_len,
int need_copy,
int *status,
int only, const char *name)
{
printf("call mono_image_open_from_data_with_name 0x%x 0x%x 0x%x 0x%x 0x%x %s", (int)data, (int)data_len, need_copy, (int)status, only, name);
return mono_image_open_from_data_with_xxxx(data, data_len, need_copy, status, only, name);
}
将image.o 和 imagehook.o重新打包进libiPhone-lib.arm
ar -r libiPhone-lib.arm image.o
ar -q libiPhone-lib.arm imagehook.o
重新生成libiPhone-lib.a
lipo libiPhone-lib.a -replace armv7 libiPhone-lib.arm -output libiPhone-lib.a_01
这样用新生成的libiPhone-lib.a去链接应用程序会发现调用到了我们自己的函数。
但是你会发现都是没用的,因为mono在IOS下是FULL AOT模式编译的,每个脚本dll会生成对应的.s汇编代码直接连接到可执行文件里面.
关于JIT 和 AOT 相关内容:https://www.cnblogs.com/tekkaman/p/3973452.html?utm_source=tuicool&utm_medium=referral