The decompiler
Basilisk’s decompiler is a port of Ghidra’s C++ decompiler, written as a set of Rust crates. It runs in the same process as the rest of Basilisk (Ghidra runs its decompiler as a separate process), and it decompiles functions in parallel.
What exists today
Section titled “What exists today”| Part | Crate | State |
|---|---|---|
| The type system and the C declaration parser | bk-decomp-types |
Done |
| Value ranges (strided intervals) | bk-decomp-range |
Done |
| Compiler specifications and calling-convention models | bk-cspec |
Done |
| The block graph, its analyses and control-flow structuring | bk-decomp-cfg |
Done; structures all of the reference’s test functions as Ghidra does |
| The reference: Ghidra’s decompiler with state dumps at every stage | test tooling | Done |
| Varnodes, operations and the function’s data flow | bk-decomp-ir |
In progress |
| Symbols and scopes | bk-decomp-symbols |
In progress |
| Flow, SSA construction, the simplification rules, type recovery, variable merging, output | — | Planned, in that order |
The pipeline
Section titled “The pipeline”The decompiler works on p-code, the processor-independent operations SLEIGH produces for each instruction.
The stages
Section titled “The stages”- Lift. SLEIGH turns each instruction into p-code.
- Control flow. The p-code is followed from the function’s entry into basic blocks and a graph; indirect jumps are resolved into switch tables.
- SSA form. Every value gets one definition, so that the flow of data is explicit. Ghidra calls this heritage.
- Simplify. Well over a hundred rewrite rules run until nothing changes: constants fold, flag computations collapse into comparisons, stack arithmetic becomes variables.
- Types and variables. Types flow from known signatures and from how values are used; values that are the same variable in the source are merged.
- Structure. The graph of blocks becomes
if,while,switchand, where nothing else fits,goto. - Print. The result is emitted as C, with every token tied back to the operation and address it came from, which is what makes the Decompiler view clickable.
How it is checked
Section titled “How it is checked”The decompiler is the part of Ghidra where “the same answer” is hardest to show, so it is checked stage by stage. Ghidra’s decompiler is built with extra commands that dump its internal state at chosen points; each Basilisk pass is loaded with Ghidra’s state before that pass and must produce Ghidra’s state after it. The final acceptance is Ghidra’s 93 decompiler data tests (bytes, a language and a script, with no program database) and a larger corpus, with output equal to Ghidra’s. See How results are checked.
Improvements
Section titled “Improvements”Parity comes first: the default output is Ghidra’s. Improvements to the output are designed as separate, named profiles that you choose, so that a difference from Ghidra is always one you asked for.