这个系列,是很早听 MJ 课程时的整理,如今分享出来。 其中一些参考资料有些有引用,有些可能忘记添加了,若是有引用部分资料,能够联系我。html
iOS 逆向(一)环境搭建
iOS 逆向(二)Cycript
iOS 逆向(三)逆向工具
iOS 逆向(四)脱壳
审核中 iOS 逆向(五)Theos工具 iOS 逆向(六)动态调试
iOS 逆向(七)重签名git
对Mach-O文件的静态分析,有如下工具:github
对运行中的APP进行代码调试,工具包括:缓存
注入代码到APP中,必要时还可能须要从新签名、打包ipa。sass
具体实现,参考逆向(五)Theos工具、逆向(六)动态调试。bash
Cycript在上篇文章中已经介绍。因此此处着重介绍Reveal。markdown
Mac版本架构
官网:revealapp.com 经过邮箱可得到14天试用期.app
手机版编辑器
Reveal Loader
必定要安装该源的loader。
安装完Reveal Loader后,打开【设置】,找到Reveal
,选择须要调试的APP
找到Mac的Reveal中的RevealServer
文件,覆盖iPhone的/Library/RHRevealLoader/RevealServer
文件
以后,最好重启桌面,能够在iPhone上输入终端命令
打开Mac版本Reveal,在手机上开启容许Reveal调试的APP,Reveal mac就会出现调试APP。
如图按照上述步骤没有连上app,问题解决 1)安装 Reveal2Loader 2) 打开Reveal选择顶部菜单Help->Show Reveal Library in Finder->iOS Library,把RevealServer.frameworkr拷贝到手机Device->Library->Frameworks文件夹下,拷贝方式能够经过iFunBox手动操做 3)从新启动手机以后能够看到app显示出来
顾名思义,它的做用就是把Mach-O文件的class信息给dump出来(把类信息给导出来),生成对应的.h头文件
下载地址见文末,下载完成后,将class-dump文件复制到Mac的/usr/local/bin
目录,这样在终端就能识别class-dump
命令了
经常使用格式
//直接在控制台输出
$ class-dump ~/Desktop/jike
//-H 表示要生成头文件
//-o 用于制定头文件的存放目录
$ class-dump -H Mach-O文件路径 -o 头文件存放目录
复制代码
Hopper Disassmbler可以将Mach-O文件的机器语言代码反编译成汇编代码、OC伪代码或者Swift伪代码
另外,IDA一样是反汇编工具,做用同Hopper相似。
不一样的OC代码,编译出来的汇编代码多是同样的
可是在同一种架构平台下,每一条汇编指令都有与之对应的惟一的机器指令
经常使用快捷键
Shift + Option + X 找出哪里引用了这个方法
MachOView是查看Mach-O文件的工具,Mach-O是苹果平台的可执行文件格式,其具体能够参考Mach-O(一)结构、Mach-O(二)内存分布。
该工具是开源工具,可从Github下载。
MachOExploer和MachOView功能同样,也是开源工具。Github地址
在iOS中,系统库,如UIKit、Foundation等,苹果为了提升效率,将这些库都打包成一个动态库,并在系统启动的时候加载,这个集合库,就叫作共享库缓存。
咱们在逆向时,为了分析代码,须要将该共享库提取出来。
在macOS/iOS中,是使用了/usr/lib/dyld
程序来加载动态库。
dyld,dynamic link editor(动态连接编辑器),也叫dynamic loader(动态加载器)。
因此第一种方式,直接以dyld的方式提取。dyld源码地址参考文末。
下载最新代码,本文更新时,最新版本是dyld-635.2
可使用dyld源码中的launch-cache/dsc_extractor.cpp
将#if 0前面的代码删除(包括#if 0),把最后面的#endif也删掉
最后只剩下:
#include <stdio.h>
#include <stddef.h>
#include <dlfcn.h>
typedef int (*extractor_proc)(const char* shared_cache_file_path, const char* extraction_root_path,
void (^progress)(unsigned current, unsigned total));
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;
}
复制代码
编译dsc_extractor.cpp,得到dsc_extractor
$ clang++ -o dsc_extractor dsc_extractor.cpp
复制代码
或者
$ clang++ -o dsc_extractor ./dsc_extractor.cpp dsc_iterator.cpp
复制代码
动态库共享缓存在iPhone的目录为:/System/Library/Caches/com.apple.dyld
,将其拷贝到电脑上:
而后解析出动态库:
// dsc_extractor 缓存 输出文件夹
$ dsc_extractor dyld_shared_cache_armv7s armv7s
复制代码
工具地址:JTool
用法
//提取UIKit动态库
$ jtool -extract UIKit path/to/dyld_shared_cache
//提取所有动态库,注意,该提取动做会产生超大的文件,10G+
$ jtool -lv cache_armv7 | cut -c 24- | tail +5 | while read line ; do jtool -extract $line cache_armv7 ; done
复制代码
dyld_cache_extract 是一个GUI工具,蛮方便的工具。
【越狱-逆向】处理iOS APP信息的命令行工具。MJAppTools有详细说明。
其它经常使用命令,好比lldb、otool、nm、codesign。
连接