一.debugserver重新簽名,填加權(quán)限
1.把手機(jī)的debugserver復(fù)制到桌面,所在手機(jī)路徑如圖

查看ldid有哪些功能
ldid
輸出
usage: ldid -S[entitlements.xml] <binary>
ldid -e MobileSafari
ldid -S cat
ldid -Stfp.xml gdb
cd到桌面
cd ~/Desktop/
2.導(dǎo)出原來(lái)手機(jī)安裝的debugserver權(quán)限
ldid -e debugserver > debugserver.entitlements
雙擊打開(kāi),可以用Xcode查看其權(quán)限,后綴名為entitlements,實(shí)際上是plist文件,如圖

這個(gè)時(shí)候,這個(gè)debugserver只能調(diào)試通過(guò)Xcode安裝的App,無(wú)法調(diào)試其他App,如果想要調(diào)試其他App,需要對(duì)debugserver重新簽名,簽上兩個(gè)相關(guān)的權(quán)限
3.添加調(diào)試其他App的權(quán)限
get-task-allow
task_for_pid-allow
如圖

4.添加好后,給debugserver重新簽名
ldid -Sdebugserver.entitlements debugserver
5.驗(yàn)證重新簽名后的debugserver是否有剛剛添加的權(quán)限
重新導(dǎo)出debugserver權(quán)限,給個(gè)新的名字new.entitlements
ldid -e debugserver > new.entitlements

查看如圖,已經(jīng)添加上
由于手機(jī)的Device->Develop->usr->bin目錄是只讀,所以無(wú)法用新簽名的debugserver替換原來(lái)的debugserver
但是可以把debugserver放在Device->usr->bin目錄,因?yàn)閡sr-bin目錄已經(jīng)在環(huán)境變量path里面,之前已經(jīng)操作過(guò)
連接登錄越獄手機(jī)
嘗試指令
debugserver
輸出
-sh: /usr/bin/debugserver: Permission denied
6.給debugserver添加權(quán)限
chmod +x /usr/bin/debugserver
再次輸入
debugserver
輸出
debugserver-@(#)PROGRAM:debugserver PROJECT:debugserver-340.3.124 for arm64.
Usage:
debugserver host:port [program-name program-arg1 program-arg2 ...]
debugserver /path/file [program-name program-arg1 program-arg2 ...]
debugserver host:port --attach=<pid>
debugserver /path/file --attach=<pid>
debugserver host:port --attach=<process_name>
debugserver /path/file --attach=<process_name>
至此debugserver環(huán)境已經(jīng)搭建好
二.如何讓debugserver附加到某個(gè)App上???
debugserver *:端口號(hào) -a 進(jìn)程
*表示主機(jī)地址為任意,相當(dāng)于通配符
-a 相當(dāng)于attach pid就是進(jìn)程名稱,比如微信的WeChat
三.如何讓mac上的lldb連接到手機(jī)的debugserver進(jìn)行調(diào)試App?
首先,mac電腦usb與手機(jī)的端口映射關(guān)系使用vim打開(kāi)usb.sh
python ~/Documents/iOS/usbmuxd/tcprelay.py -t 22:10010 10011:10011
這樣訪問(wèn)電腦上的10011相當(dāng)于訪問(wèn)手機(jī)上的10011
重新連接登錄手機(jī)
執(zhí)行轉(zhuǎn)發(fā)命令,可以看到有兩個(gè)端口轉(zhuǎn)發(fā)
Forwarding local port 10010 to remote port 22
Forwarding local port 10011 to remote port 10011
使用debugserver執(zhí)行監(jiān)聽(tīng)調(diào)試微信命令
debugserver *:10011 -a WeChat
輸出
debugserver-@(#)PROGRAM:debugserver PROJECT:debugserver-340.3.124
for arm64.
Attaching to process WeChat...
Listening to port 10011 for a connection from *...
現(xiàn)在點(diǎn)擊微信上任意按鈕,發(fā)現(xiàn)微信無(wú)法響應(yīng)
接下來(lái)在終端上啟動(dòng)lldb
終端輸入
lldb
接著輸入
process connect connect://localhost:10011
過(guò)了一會(huì)約10秒
- Hook 1 (expr -- @import UIKit)
- Hook 2 (target stop-hook disable)
Process 22566 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
frame #0: 0x0000000182ae8fd8 libsystem_kernel.dylib`mach_msg_trap + 8
libsystem_kernel.dylib`mach_msg_trap:
-> 0x182ae8fd8 <+8>: ret
libsystem_kernel.dylib`mach_msg_overwrite_trap:
0x182ae8fdc <+0>: mov x16, #-0x20
0x182ae8fe0 <+4>: svc #0x80
0x182ae8fe4 <+8>: ret
Target 0: (WeChat) stopped.
一旦打印出thread #1, queue = 'com.apple.main-thread,證明監(jiān)聽(tīng)了WeChat成功了
WeChat程序現(xiàn)在屬于斷點(diǎn)模式
lldb終端輸入指令c,去除斷點(diǎn)
c
輸出
Process 22566 resuming