Decompiler Overview
The Ghidra decompiler translates assembly code into high-level C-like pseudocode for easier analysis.Implemented by the
DecompilePlugin, the decompiler provides a high-level interpretation of assembly functions with interactive editing capabilities.Opening the Decompiler
1
Enable Decompiler Window
Access the decompiler view:
Window>Decompiler- Default: docked on right side
- Can float or dock to any location
2
Navigate to Function
The decompiler automatically displays:
- Current function at cursor location
- Updates when you navigate in listing
- Synchronized with Code Browser
3
Wait for Decompilation
Decompilation is performed on-demand:
- Brief delay for complex functions
- Progress indicator shown
- Results cached for performance
Decompiler Interface
Main Components
- Decompiler View
- Function Signature
- Local Variables
Primary decompiled code display:
- C-like pseudocode representation
- Syntax highlighting
- Line numbers
- Collapsible code blocks
- Token-based navigation
Synchronization with Listing
1
Bidirectional Sync
Decompiler and listing stay synchronized:
- Click in decompiler → highlights assembly
- Click in assembly → highlights decompiled code
- Both views track same location
2
Token Highlighting
Clicking tokens highlights:
- All uses of the variable/function
- Related assembly instructions
- Data flow dependencies
3
Cross-Reference Navigation
Follow references from decompiler:
Enteron function callsEnteron global variables- Navigation history maintained
Editing in the Decompiler
Renaming Variables
1
Select Variable
Click on variable name in decompiled code
2
Rename Action
- Press
Lfor rename - Right-click >
Rename Variable - Enter new meaningful name
3
Apply Changes
New name appears:
- Throughout decompiled function
- In assembly as comments
- In function signature if parameter
Retyping Variables
1
Select Variable
Click on variable to retype
2
Change Type
- Press
Ctrl + Lfor retype - Right-click >
Retype Variable - Choose from Data Type Manager
3
Propagation
Type changes affect:
- Variable declaration
- Cast expressions
- Decompiler output clarity
- Structure member access
Function Signature Editing
1
Edit Signature
Modify function signature:
- Right-click function name >
Edit Function Signature - Or press
Ctrl + Shift + Gin listing
2
Modify Components
Change signature elements:
- Return type
- Parameter types and names
- Calling convention
- Varargs specification
3
Commit Changes
Changes trigger:
- Automatic re-decompilation
- Updated call sites
- Improved type propagation
Decompiler Features
Hover Tooltips
Multiple hover services provide information:- Data Type Hover
- Function Signature Hover
- Reference Hover
- Scalar Value Hover
Implemented by
DataTypeDecompilerHoverPlugin:- Shows full type definition
- Structure layouts
- Typedef resolution
Control Flow Visualization
The decompiler shows control structures:- If/Else: Conditional logic
- Loops: While, for, do-while patterns
- Switch: Case statement detection
- Goto: Remaining unconditional jumps
The decompiler attempts to structure all assembly into high-level constructs, but complex or obfuscated code may still contain goto statements.
Decompiler Options
Configuration Settings
1
Access Options
Open decompiler options:
Edit>Tool Options>Decompiler- Configure analysis and display
2
Analysis Options
Control decompilation behavior:
- Maximum instruction count
- Maximum payload bytes
- Simplification style
- Eliminate unreachable code
3
Display Options
Customize appearance:
- Color scheme
- Font settings
- Line spacing
- Brace style (Allman, K&R, etc.)
Language-Specific Settings
Decompiler uses processor specifications:- Calling conventions
- Register usage
- Stack frame layout
- Special instructions
Working with Complex Code
Structures and Arrays
1
Structure Access
Decompiler shows structure members:
struct->membernotation- Offset calculations converted to members
- Nested structure access
2
Array Indexing
Arrays displayed with brackets:
array[index]notation- Multi-dimensional arrays
- Pointer arithmetic simplified
3
Type Propagation
Defining types improves output:
- Set parameter types
- Define global data types
- Create custom structures
- Decompiler propagates through code
Pointer Analysis
Decompiler handles pointers:- Dereference operators (
*ptr) - Address-of operators (
&var) - Pointer arithmetic
- Multi-level indirection
Function Pointers
Indirect calls are shown as:- Function pointer variables
- Casts to function types
- Indirect call notation
- Virtual function tables
Advanced Usage
Creating Disconnected Decompilers
1
Open Secondary Decompiler
Create additional decompiler views:
Window>Decompiler(creates new instance)- Independent navigation
- Compare different functions
2
Compare Views
Use multiple decompilers to:
- Compare similar functions
- Track related code paths
- Analyze caller and callee together
Debugging Decompiler Output
If decompilation quality is poor:1
Check Function Boundaries
Ensure function is properly defined:
- Correct entry point
- All code included
- Return statements identified
2
Fix Data Flow
Improve analysis:
- Define parameter types
- Set return type
- Mark no-return functions
- Fix incorrect references
3
Adjust Settings
Try different options:
- Increase instruction limit
- Disable certain optimizations
- Change simplification level
Exporting Decompiled Code
1
Copy to Clipboard
Copy decompiled code:
- Select code in decompiler
Ctrl + Cto copy- Paste into external editor
2
Export Function
Export single function:
- Right-click >
Export to C - Choose file location
- Includes function signature and body
3
Bulk Export
Export multiple functions:
- Use
ExporterfromFilemenu - Select C/C++ format
- Exports all or selected functions
