[转]IOS热更新研究

http://blog.csdn.net/yy405145590/article/details/41282669

主要思路是替换掉在mono里image.c的mono_image_open_from_data_with_name函数,HOOK掉加载DLL的地方,实现读取自定义的DLL文件。


检查发现在Xcode工程里的libiPhone-lib.a里存在mono的库文件,在libiPhone-lib.a下有两个CPU架构的库

[html] view plaincopy在CODE上查看代码片派生到我的代码片
lipo -info libiPhone-lib.a

Architectures in the fat file: libiPhone-lib.a are: armv7 i386

使用
[html] view plaincopy在CODE上查看代码片派生到我的代码片
lipo libiPhone-lib.a -thin armv7 -output libiPhone-lib.arm

解压出armv7的库文件
[html] view plaincopy在CODE上查看代码片派生到我的代码片
ar -t libiPhone-lib.arm
[html] view plaincopy在CODE上查看代码片派生到我的代码片
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

[html] view plaincopy在CODE上查看代码片派生到我的代码片
ar -t libiPhone-lib.arm | grep image.o
[html] view plaincopy在CODE上查看代码片派生到我的代码片
image.o
可以看到armv7下确实有image.o的模块


解压出image.o模块

[html] view plaincopy在CODE上查看代码片派生到我的代码片
ar -x libiPhone-lib.arm image.o
用十六进制工具搜索

[cpp] view plaincopy在CODE上查看代码片派生到我的代码片
mono_image_open_from_data_with_name 替换成 mono_image_open_from_data_with_xxxx

自己编译一个imagehook.c的文件生成imagehook.o,内容如下

[cpp] view plaincopy在CODE上查看代码片派生到我的代码片
#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
[html] view plaincopy在CODE上查看代码片派生到我的代码片
ar -r libiPhone-lib.arm image.o
ar -q libiPhone-lib.arm imagehook.o

重新生成libiPhone-lib.a
[html] view plaincopy在CODE上查看代码片派生到我的代码片
lipo libiPhone-lib.a -replace armv7 libiPhone-lib.arm -output libiPhone-lib.a_01

这样用新生成的libiPhone-lib.a去链接应用程序会发现调用到了我们自己的函数。

但是你会发现都是没用的,因为mono在IOS下是FULL AOT模式编译的,每个脚本dll会生成对应的.s汇编代码直接连接到可执行文件里面.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值