您的位置:首页 > 移动开发 > IOS开发

正版ipa加载dylib且正常运行思路

2016-06-30 11:25 495 查看
转:http://bbs.pediy.com/showthread.php?t=204372

这边咋也不讲什么技术,就只说说大致的思路: (这是两年前的东西啦,有朋友在问,索性就把这老东西翻出来)

这边的说的正版ipa hook只是针对自身,这是由于IOS沙盒的限制;

那如何去hook自身正版的ipa呢?

首先, 要让ipa能加载我们的dylib;

其次, 要让这个ipa能正常的在设备上运行;

只要满足这2个条件,那么恭喜你,可以自己去YY了;

要满足以上2点的话,我这边就用下面的例子还说:

====================================================
让ipa能加载我们的dylib

====================================================
一、十六进制编辑器打开ModernCombat5




头结构如下: 

struct mach_header {

  uint32_t      magic;      /* mach magic number identifier */

  cpu_type_t    cputype;      /* cpu specifier */

  cpu_subtype_t  cpusubtype;    /* machine specifier */

  uint32_t      filetype;      /* type of file */
  uint32_t      ncmds;      /* number of load commands */

  uint32_t      sizeofcmds;    /* the size of all the load commands */

  uint32_t      flags;      /* flags */

};

以上颜色,标注地方为所需要修改的地方,由于添加load commands的dylib类型的@executable_path:

ncmds     = 0x2E   = 0x2C + 1;

Sizeofcmds   = 0x12E8 = 0x12C0 + 0x28;

其中0x28的大小为所需要添加的@executable_path的load commands的dylib项

二、 添加@executable_path





union lc_str {

  uint32_t offset;          /* offset to the string */

#ifndef __LP64__

  char *ptr;             /* pointer to the string */

#endif 

}; 

struct dylib {

    union lc_str  name;         /* library's path name */

    uint32_t timestamp;         /* library's build time stamp */

    uint32_t current_version;       /* library's current version number */

    uint32_t compatibility_version;     /* library's compatibility vers number*/

}; 

struct dylib_command {

  uint32_t cmd;           /* LC_ID_DYLIB, LC_LOAD_{,WEAK_}DYLIB,LC_REEXPORT_DYLIB */

  uint32_t cmdsize;           /* includes pathname string */

  struct dylib dylib;         /* the library identification */

};

二进制: 0C00000028000000180000000200000000000000000000004065786563757461626C655F706174682F4D43506C7567696E2E64796C6962

三、获取可用的receipt,并替换MCPlugin.dylib中的receipt,重新编译成一个可用的receipt;

用正版的MC启动,遇到以下界面时候,输入正确的购买账号,在MC目录下回生成StoreKit/receipt目录文件,拷贝出来,对StoreKit/receipt的内容进行Base64得到MCPlugin.dylib可用的receipt,替换MCPlugin.dylib目录下的receipt,重新编译;





====================================================
dylib 中的hook

====================================================

这边的hook可以参考:

fishhook:http://blog.csdn.net/yiyaaixuexi/art...tails/19094765
分析substrate的HookMessageEx实现细节:http://bbs.pediy.com/showthread.php?t=191507
substrate;

这边就不重点说明了

====================================================
 让这个ipa能正常的在设备上运行

====================================================

到这边大家关心的应该就是怎么在机器上跑了,没也没什么特别的方法,就是企业签名重签;

首先, 使用企业签名重签dylib

其次, 使用企业签名对整个ipa包(包含已签名的dylib)重签

这样就可以在设备上跑了,而且也能正常的使用我们给这个ipa的插件dylib

以上是个人的总结, 如果有不对的地方请指出;

[PDF]:  现代战争修改文档.pdf

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  iOS