Mini Decompiler
A decompiler for a defined x86-64 subset that turns functions in an ELF relocatable object you compiled into structured C. It recompiles its own output, runs a differential test over an input grid, compares relocation-masked bytes and writes an evidence report that lists every unknown.
A decompiler that turns the functions of an x86-64 relocatable object you compiled into one C file, and an evidence report that says what was proved and what stays unknown.
- Run python3 -m minidec verify on your own object and its source. The command writes decompiled.c, recompiled.o and report.json; a CI job can fail on status fail or unknown.
- Disassembly and Control Flow: From Bytes to a Graph You Can Check
- Lifting to Pseudocode: IR, SSA, and Structuring From Scratch
- Rebuild and Prove Equal: Differential Tests, Byte Comparison, and the Evidence Loop
- Calling Conventions and Stack Frames: System V, Windows x64, and AArch64
- Compiler Idioms: What Optimization Does to Your Code and How to Read It Back
- Program Anatomy: An ELF Reader From Scratch
- Recovering Data and Types: Structs, Arrays, C++ Objects, and DWARF
- Evidence, Confidence, and Unknowns in Binary Analysis
- Python 3.10+ with the standard library only. clang is optional and enables the recompile and differential legs of stage 8.
- Lessons on ELF anatomy, disassembly and control flow, lifting to pseudocode, calling conventions, compiler idioms and rebuild-and-prove.
Mini Decompiler in 8 stages
A decompiler for a defined x86-64 subset that turns functions in an object you compiled into structured C, then proves the output.
Read an ELF relocatable object
Validate the ELF64 header, read section headers, the symbol table and every RELA record, and cut each function out of .text with its relocations and its alignment padding. A PC-relative record points at S + A + (end of instruction - P), so a target is resolved only with the end of the instruction that holds the field.
starter · ~2 hours · Python
ElfObjectElfObject.functionrelocation_targetDecode the x86-64 subset
Decode legacy prefixes, REX, one and two byte opcodes, ModRM, SIB, displacements and immediates for the instructions the fixtures use. Record where the displacement and immediate fields sit so relocations can be matched to operands. Every instruction must agree with the captured disassembler listing by address, bytes and AT&T text.
core · ~3 hours · Python
decodelinear_sweepcompare_with_objdumpRecover control flow
Follow control flow by recursive descent, resolve the position-independent jump table from its relocations and bounds check, split basic blocks, then compute dominators, dominance frontiers, post-dominators, back edges and natural loops. An indirect jump with no matching idiom stays unresolved and is reported.
core · ~2 hours · Python
recursive_descentjump_table_resolverControlFlowGraphdominance_frontiersLift to IR and build SSA
Lift each instruction to a small IR in which flags are an ordinary variable, frame bookkeeping disappears and frame-pointer slots become locals. Place phi statements on iterated dominance frontiers and rename over the dominator tree so every value has one definition, with explicit casts where a narrow definition meets a wide use.
core · ~3 hours · Python
lift_instructionlift_functioninsert_phisrenameSimplify and fold idioms
Turn flag conditions into comparisons, propagate copies and constants, delete dead definitions, merge congruent phis and substitute single-use values without moving a load across a store. Recognize the multiply-and-shift form of signed division by a constant and fold it only when the multiplier, shift and error bound prove the divisor.
core · ~2 hours · Python
magic_divisoroptimizepropagate_copiesremove_dead_codeRecover the signature and types
A System V argument register read before any write is a parameter, and the highest one fixes the count. Coalesce phi webs into C variables, make a scaled element access a pointer to its element and constant offsets a struct, and choose signedness from the instructions that touch each value. Every choice carries its instruction evidence.
core · ~2 hours · Python
collect_paramscoalesce_websinfer_typesrecover_signatureStructure the graph and emit C
Match loops, two-way and n-way conditionals with the immediate post-dominator as the join, emit if, if-else, while, do-while and switch, and print C with recovered struct and table definitions. A region that matches no shape produces a counted goto, and every heuristic goes into the unknowns list.
stretch · ~2 hours · Python
Structurerdecompiledecompile_alltranslation_unitProve the output
Recompile the emitted C with the fixture flags, compare each function with relocation fields masked, compare the constants each relocation points at, and run original and candidate side by side over an input grid that crosses limits, zero, negatives and compare constants. The report is fail-closed and lists every unknown. Without clang the recompile and differential legs skip and say why.
stretch · ~2 hours · Python
mask_relocationscompare_function_bytesinput_gridverify
Lessons this project uses
- Disassembly and Control Flow: From Bytes to a Graph You Can Check
- Lifting to Pseudocode: IR, SSA, and Structuring From Scratch
- Rebuild and Prove Equal: Differential Tests, Byte Comparison, and the Evidence Loop
- Calling Conventions and Stack Frames: System V, Windows x64, and AArch64
- Compiler Idioms: What Optimization Does to Your Code and How to Read It Back
- Program Anatomy: An ELF Reader From Scratch
- Recovering Data and Types: Structs, Arrays, C++ Objects, and DWARF
- Evidence, Confidence, and Unknowns in Binary Analysis