This is an old revision of the document!
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