一、概述
我们Xcode中的lldb可以调试手机中的应用,是因为手机中的debugserver开启的相关服务。所以在越狱环境中,我们只需要开启debugserver服务就可以利用LLDB远程调试三方应用了。
当手机第一次调试的时候,mac会将与手机对应版本的debugserver安装在手机上。
越狱环境下,需要打开手机中的debugserver, 让debueserver附加到app并提供端口,lldb去连接debugserver,就可以调试对应的应用了。
二、debugserver位置
Mac中的debugserver:
在/APPlication/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/ 中可以看到对应不同iOS系统版本的镜像文件
打开dmg文件,进入usr/bin目录可以看到debugserver。这就是xcode安装到真机中的文件。
手机中的debugserver:
三、Debugserver开启调试权限
1、Xcode中上述位置取出手机对应版本的debugserver,
2、ldid工具导出debugerver中的.entitlemenets
3、在.entitlements添加2个项,get-task-allow,task_for_pid-allow,都设置为YES。
4、ldid工具将修改后的.entitlemenets对debugserver签名。
5、将重签名后的debugserver拷贝至手机的/usr/bin目录下
四、debugserver的使用
1.启动debugserver
iPhone中开启debugserver服务。
$debugserver 主机地址:端口号 –a 应用进程
由于主机地址是当前手机,可以使用*代替
端口号:启动server服务,开放端口,让远程的LLDB通过sever调试进程
2.Mac上启动LLDB连接iPhone
启动LLDB$lldb
连接debugserver
(lldb)process connect connect://手机IP:服务端口号
进入断点状态: procerss interrupt
五、lldb手动砸壳WeChat
1.开启debugserver依附到微信APP进程,并开放端口12346
2.Mac映射本地端口12346到远程手机端口12346
3.Mac进入LLDB下,并连接手机的debugserver, process connect connect://127.0.0.1:12346
4.找到MatchO的首地址
5.otool -l查看MatchO文件
可以看到MatchO是从Crypoff处开始加密,加密大小为cryptsize
6.使用Memory read指令从内存中读出加密的那一段
Memory read —force —outfile ./decrypted.bin —binary —count xxx 内存地址
—force 按字节读取
—outfile 拷贝出来的路径
—binary 二进制
—count (读多少字节) cryptsize的大小
内存地址:marcho的起始地址 + Crypoff
7.将内存中dump出来的文件写入原先加密的那个MatchO(从加密处开始写)
8.修改cryptid为0
9.使用Classdump验证,是否砸壳成功。
dump出了微信头文件,lldb砸壳成功。