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.
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.
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.
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.
Useful add-ons
Analysis
Replica – Ghisra auto-analysis enhancer
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.
-
Processor and target support
Scripting
-
-
-
Ghidra manual:
-
-
Refer to the Ghidra Snippets and Scripting Cheat-sheet, then look things up in the
API docs :)
Scripts
Themes
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
-
Radare2
r2ghidra – Integrate the Ghidra decompiler and disassembler into Radare2
Cutter GUI (uses the Rizin fork of Radare2)