Ghidra cheat sheet
These are a few notes to remind myself about some features of the Ghidra SRE framework, which I keep forgetting!
Left-click label highlighting
The default assignment for label highlighting in IDA is a left-click on the name of the label. Ghidra also has this feature, but the default binding is the middle mouse button. To change this:
- In the CodeBrowser, select: Edit → Tool Options
- In the option tree, select: Options → Listing Fields → Cursor Text Highlight
- Enable Cursor Text Highlight, and set the “Mouse button to activate” field to “Left”.
Fixing broken switch-cases/jump tables
References:
If a computed jump instruction (e.g. JMP (jumptableAddr, X)
) doesn't include a range check guard above it, Ghidra may assume that the valid range is the full range of the index register. This completely screws up disassembly and decompiling.
Jump table not recovered at all ("Unrecovered Jumptable")
- Navigate to the jump table (find the computed
JMP
instruction and follow the reference). - Set the first element to be a pointer (keyboard: P).
- Press
[
to define the number of elements in the jump table.- This will trigger a disassembly of the jump table targets, but these functions are not yet part of the function.
- Navigate to the
JMP
instruction which performs the jump, e.g.JMP (jumpTable, X)
. - Press
R
to bring up the References Editor and click on the mnemonic. Either:- Use the green plus to add
COMPUTED_JUMP
references to each address stored, one at a time, or - Use the CodeBrowser's forward-references feature:
- Select the
JMP
instruction in the CodeBrowser. - Select → Forward Refs (may have to do this twice)
- Drag the selection into the References Editor.
- Right-click on the function which contains the jump table, and select Function → Recreate Function
- Finally, navigate back to the
JMP
instruction, and use the Script Manager to run SwitchOverride.java.- This fixes the JumpTable references used by the decompiler
Jumptable recovered with wrong range
Follow the instructions above, but don't try to add the references. Instead, remove the extraneous ones.
- Navigate to the
JMP
instruction which performs the jump, e.g.JMP (jumpTable, X)
. - Press
R
to bring up the References Editor and click on the mnemonic.- Edit the reference list to remove any incorrect table references.
- Right-click on the function which contains the jump table, and select Function → Recreate Function
- Finally, navigate back to the
JMP
instruction, and use the Script Manager to run SwitchOverride.java.- This fixes the JumpTable references used by the decompiler
Useful add-ons
Analysis
- Replica – Ghisra auto-analysis enhancer
- Detect crypto algorithm constants
- Fix undefined ASCII strings and data
- SVD Loader – Loads ARM CMSIS SVD (System View Description) files into Ghidra to describe and annotate ARM processor SFRs. See also the project homepage
Emulation
- GhidraEmu – Native Pcode emulation. Uses SLEIGH descriptions to emulate a processor.
- AngryGhidra – Use angr for binary analysis and symbolic execution.
Processor and target support
- GhidraBoy – Sharp SM83 and Game Boy support
Scripting
- Ghidra Snippets – examples showing how to work with the Ghidra Python APIs
- Ghidrathon – Python 3 inside Ghidra
- Ghidra manual:
- GhidraScript – summary of the scripting environment
- Flat Program API – the functions in the root of the Python environment
- Refer to the Ghidra Snippets and Scripting Cheat-sheet, then look things up in the API docs :)
Scripts
-
- Call chain between two functions
- Highlight function calls
- ROP gadget finders for MIPS and ARM
Themes
Useful non-Ghidra tools
These tools don't integrate into Ghidra, but may be useful to supplement it.
- ImHex – ludicrously powerful hex editor
- File hashing, disassembler, data analyser (file magic based identification, entropy graph, …)
- C++-like pattern description language (like Synalyze It!) for parsing binary data
- Built-in disassembler
- Kaitai Struct – file format description language
- Radare2