iOS 攻防实践: 提取系统动态库文件

dyld_shared_cache文件
我们假如想通过反编译来分析系统的动态库,首先就得找到动态库的Mach-O文件。系统绝大部分的动态库都是存放在设施的/System/Library/Frameworks路径下。然而在连接设施后进入上述目录并没有找到库对应的Mach-O文件。
实际上苹果已经将大部分的系统动态库与插件都合并到了dyld_shared_cache文件当中来提升性能。该文件存放在设施的/System/Library/Caches/com.apple.dyld/dyld_shared_cache_armX路径下,X所代表的是当前设施CPU所支持的指令集架构。
提取动态库
接下来就是要从dyld_shared_cache_armX文件中提取动态库的Mach-O文件了。网上有jtool、dyld_decache等工具可以提取动态库。这里我们借助苹果提供的dsc_extractor程序来完成提取的工作。
首先要将设施里的dyld_shared_cache_armX文件拷贝到本机。
从苹果的开源网站里面下载dyld源码,这里下载的是最新的dyld-519.2.2.tar.gz版本。
dyld程序是使用来加载链接动态库的,该程序在设施的
/usr/lib/dyld路径下
- 打开
/dyld-519.2.2/launch-cache/dsc_extractor.cpp源文件。该文件里面有一段main函数的代码。下面是dsc_extractor.cpp中的main函数代码:
int main(int argc, const char* argv[]){ if ( argc != 3 ) { fprintf(stderr, "usage: dsc_extractor <path-to-cache-file> <path-to-device-dir>\n"); return 1; } //void* handle = dlopen("/Volumes/my/src/dyld/build/Debug/dsc_extractor.bundle", RTLD_LAZY); void* handle = dlopen("/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/usr/lib/dsc_extractor.bundle", RTLD_LAZY); if ( handle == NULL ) { fprintf(stderr, "dsc_extractor.bundle could not be loaded\n"); return 1; } extractor_proc proc = (extractor_proc)dlsym(handle, "dyld_shared_cache_extract_dylibs_progress"); if ( proc == NULL ) { fprintf(stderr, "dsc_extractor.bundle did not have dyld_shared_cache_extract_dylibs_progress symbol\n"); return 1; } int result = (*proc)(argv[1], argv[2], ^(unsigned c, unsigned total) { printf("%d/%d\n", c, total); } ); fprintf(stderr, "dyld_shared_cache_extract_dylibs_progress() => %d\n", result); return 0;}这段代码判断了参数和资源载入的有效性,同时通过usage: dsc_extractor <path-to-cache-file> <path-to-device-dir>错误参数打印的语句可以知道dsc_extractor的用方式。
修改dsc_extractor.cpp文件:删除main()函数以外其他的代码(#if#endif预解决指令也需要删除)

编译dsc_extractor.cpp文件:
$ clang++ -o dsc_extractor dsc_extractor.cpp运行dsc_extractor开始提取动态库:
$ ./dsc_extractor dyld_shared_cache文件路径 输出动态库的路径
查看提取的结果:

1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是摆设,本站源码仅提供给会员学习使用!
7. 如遇到加密压缩包,请使用360解压,如遇到无法解压的请联系管理员
开心源码网 » iOS 攻防实践: 提取系统动态库文件