iOS Hacker LLDB 和 debugserver 实例调试
LLDB 和 debugserver 實(shí)例調(diào)試
GDB 也可以調(diào)試 iOS 程序,但是效果不如蘋(píng)果的 LLDB, LLDB 可以在程序運(yùn)行的時(shí)候輸入命令下斷點(diǎn),而 GDB 卻不行。
一、LLDB 和 debugserver 的配置
插上手機(jī),運(yùn)行 Xcode,會(huì)將 debugserver 自動(dòng)復(fù)制到手機(jī)上
到手機(jī)上下載 /Developer/usr/bin/debugserver 到 osx 上
lipo -thin arm64 ~/debugserver -output ~/debugserver //給debugserver 減肥
/opt/theos/bin/ldid -Sent.xml debugserver //給 debugserver 添加 task_for_pid 權(quán)限
codesign -s - –entitlements ent.plist -f debugserver //如果上一條指令出錯(cuò)就試試這個(gè)
將處理完后的 debugserver 上傳到手機(jī) /usr/bin/debugserver 上
chmod +x /usr/bin/debugserver //給 debugserver 設(shè)置權(quán)限
二、LLDB 和 debugserver 的連接方法
debugserver *:1234 -a “MobileSMS” //附加進(jìn)程MobileSMS進(jìn)程, 開(kāi)啟1234端口,等待所有l(wèi)ldb來(lái)連接
debugserver 192.168.4.75:1234 -a “MobileSMS” //附加進(jìn)程,開(kāi)啟 1234端口, 等待 192.168.4.75 來(lái)連接
debugserver -x backboard *:1234 /Applications/Calculator.app/Calculator //執(zhí)行進(jìn)程
三、實(shí)際調(diào)試
下面是一個(gè)調(diào)試實(shí)例
ios 上運(yùn)行
debugserver *:1234 -a “SpringBoard”
osx 上運(yùn)行 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
連接成功之后會(huì)斷下來(lái),輸入 c 跑起來(lái),相當(dāng)于 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 相關(guān)的命令
ni //單步
si //步入
po x0po[x0 class] //打印數(shù)據(jù)的 class
p (char*)$x1
b NSLog //給函數(shù)下斷點(diǎn)
b [Network sendData:withFile:] //給類(lèi)函數(shù)下斷點(diǎn)
br -s -a address //給地址下斷點(diǎn)
br -s -n main //給函數(shù)下斷點(diǎn)
br l //查看斷點(diǎn)
br del //刪除所有斷點(diǎn)
br del 1 //刪除1號(hào)斷點(diǎn)
register write 寄存器 值 //與寄存器
register read //查看所有寄存器的信息
register read $x0 //查看寄存器的值
dis //查看匯編代碼
dis -a address //查看某個(gè)地址的匯編代碼
x $x0 //查看內(nèi)存
memory read address //讀內(nèi)存
memory write address xxx //寫(xiě)內(nèi)存
br comand add 1 //斷點(diǎn)添加
po $x0
c
DONE
//添加表達(dá)式,將 str 變量置空
expression
str = nil
四、通過(guò) usb 連接 ssh 進(jìn)行調(diào)試
由于某些情況下沒(méi)有 wifi ,或者是網(wǎng)絡(luò)環(huán)境比較差,網(wǎng)速很慢。這時(shí)候可以選擇使用 usb 數(shù)據(jù)線(xiàn)連接 ssh 進(jìn)行調(diào)試。使用 usb 的方式,連接速度很快。方法如下:
1. 把數(shù)據(jù)線(xiàn)接上,下載 usbmuxd 工具,下載地址。
2. 下載完成解壓,切換到 python-client 目錄,運(yùn)行命令 python tcprelay.py -t 22:2222,相當(dāng)于把 iOS 的 22 端口轉(zhuǎn)發(fā)到電腦本機(jī)的 2222 端口。
3. ssh root@localhost -p 2222 //連接本機(jī) 2222 端口,相當(dāng)于連接 iOS 的 ssh
4. debugserver *:1234 -a “SpringBoard” // 在 iOS 上開(kāi)啟 debugserver
5. python tcprelay.py -t 1234:12345 // 在 OSX 上運(yùn)行,將 iOS 的 1234 端口轉(zhuǎn)發(fā)到電腦本機(jī)的 12345 端口
6. lldb //運(yùn)行 lldb
7. process connectconnect://localhost:12345 //連接本機(jī)的 12345 端口,開(kāi)始你的調(diào)試吧
總結(jié)
以上是生活随笔為你收集整理的iOS Hacker LLDB 和 debugserver 实例调试的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 关于iOS沙盒的目录结构和获取
- 下一篇: 使用fastcoll进行md5碰撞,两个