`
wanzhanzhuce
  • 浏览: 25754 次
社区版块
存档分类
最新评论

[转]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汇编代码直接连接到可执行文件里面.
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics