Some useful LLDB scripts for my macOS debugging
git clone [email protected]:kohnakagawa/LLDB.git $HOME/lldb
echo "command script import $HOME/lldb/commands/lldbinit.py" >> $HOME/.lldbinit
mkdir -p $HOME/Documents/Resources/
git clone https://github.com/DerekSelander/LLDB.git $HOME/Documents/Resources/LLDB
echo "command script import $HOME/Documents/Resources/LLDB/lldb_commands/dslldb.py" >> $HOME/.lldbinit
rm $HOME/Documents/Resources/LLDB/lldb_commands/generate_new_script.py
Summary
Sets breakpoints at all indirect branch instructions (call/jmp) in the main module of the target program. This command is specifically designed for x86_64 processes and currently only supports the main module.
Usage
(lldb) brt_set_bps
Details
- Identifies all indirect branch instructions in the
__TEXT.__textsection - Creates breakpoints at each identified instruction
- When a breakpoint is hit, it records:
- Current module name
- Function name
- Values of all 64-bit general purpose registers
- Destination address of the branch
- Collected data can be saved to a JSON file using the
brt_savecommand
Requirements
This tool uses the radare2 tool to identify indirect branch instructions, so you need to install it first.
brew install radare2
Summary
Saves the collected branch trace data to a JSON file in the /tmp directory. The saved JSON file can be loaded through my Binja Missing Link Plugin.
Usage
(lldb) brt_save
Summary
Sets breakpoints on swift_allocObject and swift_initStackObject to obtain type metadata. Collected type metadata can be saved to a JSON file using the swtt_save command.
Usage
(lldb) swtt_set_bps
Summary
Saves the collected type metadata to a JSON file in the /tmp directory. The saved JSON file can be loaded through our Binja Swift Analyzer Plugin.
Usage
(lldb) swtt_save
Summary
Prints the contents of a Swift object.
Usage
(lldb) sdump <object address>
Summary
Prints the contents of an existential container.
Usage
(lldb) p_boxed_array <object address>
(lldb) po_boxed_array <object address>
(lldb) dump_boxed_array <object address>
Summary
Dumps what YaraMatcher object is initialized with what YARA rule string. This command works only for XProtectRemediator binaries (version 145).
Usage
(lldb) xpr_yara_dump
Koh M. Nakagawa (@tsunek0h)