iOS 使用 lldb 断点加载调试工具如 Reveal-Lookin-Woodpecker
整体的 lldb 加载命令如下, 放在 ~/.lldbinit 文件内
### Reveal LLDB commands support - DO NOT MODIFY
command script import /Users/manajay/Library/Application\ Support/Reveal/RevealServerCommands.py
###
# Woodpecker commands begin
# path to your own woodpecker.py path
command script import ~/Documents/WoodPecker/woodpecker.py
command script add -f woodpecker.doload woodpecker
# Woodpecker commands end
# Lookin to your own lookin.py path
command script import ~/Documents/Lookin/lookin.py
command script add -f lookin.doload lookin
# Lookin commands end
主要是学习 Reveal 的加载脚本 RevealServerCommands.py , 这个是 Reveal App 包内部的文件, 参考后复刻简易版来 加载自己常用的其他工具, 比如 Lookin , Woodpecker 等, 将需要注入到 App 的 framework 使用 lldb 加载进去
注意这里主要是针对模拟器
先展示最终结果
Woodpecker load succeed
2022-05-21 22:52:43.990163+0800 LLDB[78677:7229760] LookinServer - Will launch. Framework version: 1.0.0
LookinServer load succeed
2022-05-21 22:52:44.897321+0800 LLDB[78677:7229760] INFO: Reveal Server started (Protocol Version 55).
Loading Reveal Server from /Users/LLDB/Library/Application Support/Reveal/RevealServer/RevealServer.xcframework/ios-arm64_i386_x86_64-simulator/RevealServer.framework/RevealServer...
Reveal Server was loaded successfully.
2022-05-21 22:52:44.929975+0800 LLDB[78677:7229760] LookinServer - Trying to connect ...
2022-05-21 22:52:44.930194+0800 LLDB[78677:7229760] LookinServer - Connected successfully on 127.0.0.1:47164
2022-05-21 22:52:44.930425+0800 LLDB[78677:7229760] INFO: Reveal Server started (Protocol Version 55).
Lookin
资源
需要脚本和 framework 如下, 放在 比如 ~/Documents/Lookin
文件夹下
LookinServer.framework
lookin.py
脚本
对应Lookin的lldb 脚本
#!/usr/bin/python
import lldb
import sys
import os
LookinSupportDirectory = os.path.expanduser("~/Documents/Lookin")
# Entry point
def __lldb_init_module(debugger, internal_dict):
# Install command
debugger.HandleCommand("command script add -f woodpecker.doload woodpecker")
def localLookinServerServerBinaryPath():
return os.path.join(LookinSupportDirectory, "LookinServer.framework/LookinServer")
def doload(debugger, command, exe_ctx, result, dict):
# path to the framework binary file
path = localLookinServerServerBinaryPath()
exists = os.path.exists(path)
if not exists:
print ("LookinServer framework not exists: {0}".format(path))
return
imagePath = lldb.SBFileSpec(path)
error = lldb.SBError()
process = exe_ctx.process
process.LoadImage(imagePath, error)
if error.Success():
print ("LookinServer load succeed")
else:
print(error)
lldb
然后在 ~/.lldbinit
中添加
# Lookin to your own lookin.py path
command script import ~/Documents/Lookin/lookin.py
command script add -f lookin.doload lookin
# Lookin commands end
断点
最后 iOS 项目中 添加符号断点
其中 Name 随意填写, 比如 加载 WoodPecker
Symbol 填写: UIApplicationMain
Action 选择 Debugger Command 内容填写: woodpecker
最后将最下面的 Options 勾选中, 断点后继续运行
注意: 断点最好 move 到 User 下, 这样多个项目可以共享
WoodPecker
资源
需要脚本和 framework 如下, 放在 比如 ~/Documents/WoodPecker
文件夹下
WoodPeckeriOS.framework
woodpecker.py
脚本
对应WoodPecker的lldb 脚本
#!/usr/bin/python
import lldb
import sys
import os
WoodPeckerSupportDirectory = os.path.expanduser("~/Documents/WoodPecker")
# Entry point
def __lldb_init_module(debugger, internal_dict):
# Install command
debugger.HandleCommand("command script add -f woodpecker.doload woodpecker")
def localWoodPeckerServerBinaryPath():
return os.path.join(WoodPeckerSupportDirectory, "WoodPeckeriOS.framework/WoodPeckeriOS")
def doload(debugger, command, exe_ctx, result, dict):
# path to the framework binary file
path = localWoodPeckerServerBinaryPath()
exists = os.path.exists(path)
if not exists:
print ("Woodpecker framework not exists: {0}".format(path))
return
imagePath = lldb.SBFileSpec(path)
error = lldb.SBError()
process = exe_ctx.process
process.LoadImage(imagePath, error)
if error.Success():
print ("Woodpecker load succeed")
else:
print(error)
lldb
然后在 ~/.lldbinit
中添加
# Woodpecker commands begin
# path to your own woodpecker.py path
command script import ~/Documents/WoodPecker/woodpecker.py
command script add -f woodpecker.doload woodpecker
# Woodpecker commands end
其中 Name 随意填写, 比如 加载 Lookin
Symbol 填写: UIApplicationMain
Action 选择 Debugger Command 内容填写: lookin
最后将最下面的 Options 勾选中, 断点后继续运行
注意: 断点最好 move 到 User 下, 这样多个项目可以共享
Member discussion