iOS Hacker LLDB 和 debugserver 实例调试

来源:互联网 发布:日本球员 中超 知乎 编辑:程序博客网 时间:2024/05/19 02:24

LLDB 和 debugserver 实例调试

GDB 也可以调试 iOS 程序,但是效果不如苹果的 LLDB, LLDB 可以在程序运行的时候输入命令下断点,而 GDB 却不行。

一、LLDB 和 debugserver 的配置

  1. 插上手机,运行 Xcode,会将 debugserver 自动复制到手机上

  2. 到手机上下载 /Developer/usr/bin/debugserver 到 osx 上

  3. lipo -thin arm64 ~/debugserver -output ~/debugserver //给debugserver 减肥

  4. /opt/theos/bin/ldid -Sent.xml debugserver //给 debugserver 添加 task_for_pid 权限

  5. codesign -s - –entitlements ent.plist -f debugserver //如果上一条指令出错就试试这个

  6. 将处理完后的 debugserver 上传到手机 /usr/bin/debugserver 上

  7. chmod +x /usr/bin/debugserver //给 debugserver 设置权限

二、LLDB 和 debugserver 的连接方法

  1. debugserver *:1234 -a “MobileSMS” //附加进程MobileSMS进程, 开启1234端口,等待所有lldb来连接

  2. debugserver 192.168.4.75:1234 -a “MobileSMS” //附加进程,开启 1234端口, 等待 192.168.4.75 来连接

  3. debugserver -x backboard *:1234 /Applications/Calculator.app/Calculator //执行进程

三、实际调试

下面是一个调试实例

ios 上运行

debugserver *:1234 -a “SpringBoard”

osx 上运行 lldb

(lldb) process connectconnect://192.168.4.132:1234

Process 837 stopped

* thread #1: tid = 0x771a, 0x0000000199038e7clibsystem_kernel.dylib`mach_msg_trap + 8, queue = ‘com.apple.main-thread’, stopreason = signal SIGSTOP

frame #0: 0x0000000199038e7c libsystem_kernel.dylib`mach_msg_trap + 8

libsystem_kernel.dylib`mach_msg_trap:

-> 0x199038e7c <+8>: ret

libsystem_kernel.dylib`mach_msg_overwrite_trap:

0x199038e80 <+0>: movn x16, #0x1f

0x199038e84 <+4>: svc #0x80

0x199038e88 <+8>: ret

(lldb) c

Process 837 resuming

连接成功之后会断下来,输入 c 跑起来,相当于 windbg 里的 g

image list -o -f //显示加载的模块

[ 0]0x00000000000ec000/System/Library/CoreServices/SpringBoard.app/SpringBoard(0x00000001000ec000)

[ 1]0x000000010075c000/Library/MobileSubstrate/MobileSubstrate.dylib(0x000000010075c000)

[ 2]0x0000000006528000 /Users/boot/Library/Developer/Xcode/iOS DeviceSupport/8.1(12B411)/Symbols/System/Library/PrivateFrameworks/StoreServices.framework/StoreServices

[ 3]0x0000000006528000 /Users/boot/Library/Developer/Xcode/iOS DeviceSupport/8.1(12B411)/Symbols/System/Library/PrivateFrameworks/AirTraffic.framework/AirTraffic

[ 4]0x0000000006528000 /Users/boot/Library/Developer/Xcode/iOS DeviceSupport/8.1(12B411)/Symbols/System/Library/PrivateFrameworks/IOSurface.framework/IOSurface

[ 5]0x0000000006528000 /Users/boot/Library/Developer/Xcode/iOS DeviceSupport/8.1(12B411)/Symbols/System/Library/PrivateFrameworks/MultitouchSupport.framework/MultitouchSupport

[ 6]0x0000000006528000 /Users/boot/Library/Developer/Xcode/iOS DeviceSupport/8.1(12B411)/Symbols/System/Library/PrivateFrameworks/MobileWiFi.framework/MobileWiFi

[ 7]0x0000000006528000 /Users/boot/Library/Developer/Xcode/iOS DeviceSupport/8.1(12B411)/Symbols/usr/lib/libIOAccessoryManager.dylib

[ 8]0x0000000006528000 /Users/boot/Library/Developer/Xcode/iOS DeviceSupport/8.1(12B411)/Symbols/System/Library/PrivateFrameworks/IOMobileFramebuffer.framework/IOMobileFramebuffer

[ 9]0x0000000006528000 /Users/boot/Library/Developer/Xcode/iOS DeviceSupport/8.1(12B411)/Symbols/System/Library/PrivateFrameworks/BluetoothManager.framework/BluetoothManager

………………………………………………………

其他 lldb 相关的命令

ni //单步
si //步入

po x0po[x0 class] //打印数据的 class
p (char*)$x1

b NSLog //给函数下断点
b [Network sendData:withFile:] //给类函数下断点
br -s -a address //给地址下断点
br -s -n main //给函数下断点
br l //查看断点
br del //删除所有断点
br del 1 //删除1号断点

register write 寄存器 值 //与寄存器
register read //查看所有寄存器的信息
register read $x0 //查看寄存器的值

dis //查看汇编代码
dis -a address //查看某个地址的汇编代码

x $x0 //查看内存
memory read address //读内存
memory write address xxx //写内存

br comand add 1 //断点添加
po $x0
c
DONE

//添加表达式,将 str 变量置空
expression
str = nil

四、通过 usb 连接 ssh 进行调试

由于某些情况下没有 wifi ,或者是网络环境比较差,网速很慢。这时候可以选择使用 usb 数据线连接 ssh 进行调试。使用 usb 的方式,连接速度很快。方法如下:
1. 把数据线接上,下载 usbmuxd 工具,下载地址。
2. 下载完成解压,切换到 python-client 目录,运行命令 python tcprelay.py -t 22:2222,相当于把 iOS 的 22 端口转发到电脑本机的 2222 端口。
3. ssh root@localhost -p 2222 //连接本机 2222 端口,相当于连接 iOS 的 ssh
4. debugserver *:1234 -a “SpringBoard” // 在 iOS 上开启 debugserver
5. python tcprelay.py -t 1234:12345 // 在 OSX 上运行,将 iOS 的 1234 端口转发到电脑本机的 12345 端口
6. lldb //运行 lldb
7. process connectconnect://localhost:12345 //连接本机的 12345 端口,开始你的调试吧

原创粉丝点击