Ghidra & IDA Pro Internals
How Decompilers Work · Reverse Engineering track
5 min read
In this module
The Tools of the Trade
Two tools dominate reverse engineering: Ghidra (free, open-source, NSA-built) and IDA Pro (commercial, Hex-Rays). Both are full-featured interactive disassemblers and decompilers. Understanding their internals makes you more effective with both and gives you a genuine appreciation for the engineering that goes into binary analysis.
Ghidra Architecture
Ghidra is written mostly in Java and uses a modular architecture. The big exception is the decompiler itself, a native C++ program that the Java front end runs as a separate process and talks to over a pipe:
SLEIGH: Ghidra's processor specification language. Each supported architecture (x86, ARM, MIPS, etc.) is defined in a SLEIGH file that describes instruction encoding, disassembly, and P-Code semantics. Adding support for a new architecture means writing a new SLEIGH specification.
P-Code Engine: All analysis operates on P-Code, Ghidra's intermediate representation. This abstraction means the decompiler only needs one implementation regardless of the input architecture.
Decompiler: Ghidra's decompiler takes P-Code as input and produces C-like output. It performs SSA construction, dead code elimination, type inference, control flow structuring, and expression simplification.
Program Database: Ghidra stores all analysis results (disassembly, cross-references, type information, user annotations) in a structured database that supports undo/redo and collaborative analysis.
Ghidra and IDA both transform machine code through multiple stages: disassembly, IR lifting, optimisation, type recovery, and control flow structuring. The key difference is that Ghidra is free and open-source (enabling custom extensions and research), while IDA Pro is commercial with a more mature decompiler (Hex-Rays).
IDA Pro Architecture
IDA (Interactive DisAssembler) has been the industry standard since the 1990s. Its key components:
IDA Kernel: The core disassembly engine that handles file loading, cross-referencing, and the interactive database (IDB file).
Processor Modules: Plugins that define disassembly for specific architectures. IDA supports dozens of processor families; the exact list depends on the version and licence you have.
Hex-Rays Decompiler: A separate (paid) plugin that converts IDA's internal representation into C pseudocode. It uses its own microcode IR with multiple optimisation levels and is generally considered to produce higher-quality output than Ghidra for complex code.
IDAPython: A Python scripting interface that allows automation, custom analysis, and plugin development. The community has built thousands of scripts and plugins.
Put the two side by side and the shapes line up more than the names suggest. Each has an architecture-specific front end, an IR that the decompiler works on, and a database that keeps everything you've learned about the binary:
One difference shows up clearly: in Ghidra the same SLEIGH file drives both the disassembly listing and the IR, while IDA's processor modules only decode, and Hex-Rays does its own lifting to microcode afterwards.
Using Decompilers Effectively
Raw decompiler output is often messy. Effective reverse engineers refine the output iteratively:
Renaming: The decompiler produces names like var_8 and sub_401000. Renaming them to meaningful names (like buffer_size and parse_header) dramatically improves readability. Both Ghidra and IDA propagate renames throughout the analysis.
Retyping: Changing a variable's type from int to char* or applying a struct definition causes the decompiler to reinterpret all operations on that variable, often revealing the code's true purpose.
Adding signatures: Providing function signatures (parameter types and return types) lets the decompiler correctly identify arguments and produce cleaner output.
Marking up data: Identifying arrays, strings, and data structures in the binary's data sections helps the decompiler understand how they are used in code.
Binary Ninja and Other Tools
Binary Ninja: A newer alternative to IDA/Ghidra with a focus on a clean API and modern architecture. Its IL (intermediate language) has multiple levels of abstraction, from low-level to high-level, and its Python API is designed for scripting and automation.
Radare2/rizin: Free, open-source, command-line-focused reverse engineering framework. Less polished UI than Ghidra or IDA, but highly scriptable and runs on almost any platform.
angr: A Python-based binary analysis framework focused on symbolic execution and automated vulnerability discovery rather than interactive analysis.
The AI Revolution in Decompilation
Recent advances in machine learning are being applied to decompilation. Neural networks trained on pairs of (source code, compiled binary) can suggest variable names, recover function names, and even improve the readability of decompiled output. Plugins that hand decompiler output to a large language model for naming and commenting (Gepetto for IDA, for example) and various research prototypes are pushing the boundary of what automated analysis can achieve. What ships in each tool changes from release to release.
AI-assisted decompilation has real limits though — it shines on common patterns and produces confidently wrong output on unusual or obfuscated code. Supplement to human analysis, not a replacement.
Why This Matters
Understanding how decompilers work helps you:
- Recognise when decompiler output is wrong and manually correct it
- Navigate efficiently using cross-references and the function call graph
- Write better scripts that work directly against the tool's internal representations
- Understand the limitations - what information is truly lost during compilation
In the next modules, you will see how this knowledge applies to function hooking, anti-reversing techniques, and malware analysis.
Choosing Between the Tools
For most people, Ghidra is the right starting point — free, actively maintained, extensible, and the decompiler output is solid. IDA Pro is widely seen as the professional standard; many analysts find its analysis more refined on hard cases, and its plugin ecosystem is older and broader. Many practitioners use both: Ghidra for initial triage, IDA for deep dives. They complement each other well.
The most transferable skill isn't mastering one tool specifically. It's understanding the decompilation pipeline well enough to interpret and sanity-check the output, whoever generated it.