Unity IOS下的热更新研究(转)

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


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

[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. lipo -info libiPhone-lib.a  
  2.   
  3. Architectures in the fat file: libiPhone-lib.a are: armv7 i386  

使用

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

解压出armv7的库文件

[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. ar -t libiPhone-lib.arm  

[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. filterscpuimplvectordata.o  
  2. filterscpuimplwarp.o  
  3. filterscpumipmaps.o  
  4. filterscpupassvectordata.o  
  5. filterscpupvrtc.o  
  6. filterscpufxmapsbuffer.o  
  7. filterscpufxmapsmain.o  
  8. filterscpufxmapsdrawjob.o  
  9. filterscpufxmapsdrawqueue.o  
  10. filterscpufxmapsjob.o  
  11. filterscpufxmapspool.o  
  12. filterscpufxmapsthread.o  
  13. parsebitmap.o  
  14. parseblend.o  
  15. parseblur.o  
  16. parsechannelsshuffle.o  
  17. parsecommon.o  
  18. parsecontext.o  
  19. parsedata.o  
  20. parsedirectionalmotionblur.o  
  21. parsedirectionalwarp.o  
  22. parseemboss.o  
  23. parsefxmaps.o  
  24. parsefxmapssetcell.o  
  25. parsegradientmap.o  
  26. parsegrayscaleconversion.o  
  27. parsehsl.o  
  28. parselevels.o  
  29. parsemotionblur.o  
  30. parsenormal.o  
  31. parsesharpen.o  
  32. parsetransformation2d.o  
  33. parseuniformcolor.o  
  34. parsevectorgraphicsdata.o  
  35. parsewarp.o  
  36. apicontext.o  
  37. apihandle.o  
  38. apiversion.o  
  39. libCrashReporter-iphoneos.a-armv7-master.o  


[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. ar -t libiPhone-lib.arm | grep image.o  
[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. image.o  

可以看到armv7下确实有image.o的模块


解压出image.o模块

[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. ar -x libiPhone-lib.arm image.o  

用十六进制工具搜索

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


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

[cpp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. #include <stdio.h>  
  2.   
  3. extern int *  
  4. mono_image_open_from_data_with_xxxx(  
  5.                                     char *data, unsigned int data_len,  
  6.                                     int  need_copy,  
  7.                                     int *status,  
  8.                                     int only, const char *name);  
  9.   
  10.   
  11. int *  
  12. mono_image_open_from_data_with_name(  
  13.                                     char *data, unsigned int data_len,  
  14.                                     int  need_copy,  
  15.                                     int *status,  
  16.                                     int only, const char *name)  
  17. {  
  18.     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);  
  19.     return mono_image_open_from_data_with_xxxx(data, data_len, need_copy, status, only, name);  
  20. }  

将image.o 和 imagehook.o重新打包进libiPhone-lib.arm

[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. ar -r libiPhone-lib.arm image.o  
  2. ar -q libiPhone-lib.arm imagehook.o  

重新生成libiPhone-lib.a

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

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


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


转自http://blog.youkuaiyun.com/yy405145590/article/details/41282669

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值