Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

 
 

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenDecompiler (odc)

OpenDecompiler is a high-performance C++20 decompilation framework. It supports decompiling 32-bit (x86) and 64-bit (x64) PE binaries (Executables and Dynamic Link Libraries) as well as Direct Text Assembly to C++ decompilation.


Features

  • Binary Decompilation: Auto-detects 32-bit (PE32) and 64-bit (PE32+) binaries.
  • DLL Export Parsing: Automatically parses PE Export Address Tables (EAT) to decompile all exported functions.
  • Direct Text Assembly Mode: Decompiles inline assembly strings or .asm text files directly into C++.
  • 7-Stage Pipeline:
    1. Binary/Assembly Parsing: PE Header parsing or Assembly string parsing.
    2. Instruction Decoding: ModR/M, REX prefix, displacement, and immediate decoding.
    3. IR Lifting: Translates machine semantics into platform-agnostic IR nodes.
    4. SSA Construction: Cooper-Harvey-Kennedy Dominator Trees, Dominance Frontiers, and $\phi$-node variable placement.
    5. Optimization Passes: Constant Folding, Dead Code Elimination, Copy Propagation, and CFG Simplification.
    6. Control-Flow Structuring: Recovery of if/else, while, do-while, and region nesting.
    7. AST & C++ Generation: Type inference and formatted C++ code emission.

Directory Structure

open_decompiler/
├── CMakeLists.txt
├── README.md
├── .gitignore
└── src/
    ├── main.cpp                              # CLI Frontend (Binary & ASM modes)
    ├── pe_loader.h / pe_loader.cpp           # PE32/PE32+ File & DLL Export Parser
    ├── asm_decompiler.h / .cpp               # Text Assembly to C++ Parser & Decompiler
    │
    ├── ir/                                   # Core IR & Def-Use Graph
    │   ├── value.h / value.cpp               # Base Value class with Use tracking
    │   ├── use.h / use.cpp                   # Def-Use Graph edge representation
    │   ├── user.h / user.cpp                 # Value consumer containing operands
    │   ├── instruction.h / instruction.cpp   # IR Instruction Node
    │   ├── opcode.h / opcode.cpp             # Architecture-neutral opcodes
    │   ├── integer_constant.h / .cpp         # Integer Constant Node
    │   ├── float_constant.h / .cpp           # Floating-point Constant Node
    │   ├── basic_block.h / basic_block.cpp   # CFG Basic Block container
    │   ├── basic_block_factory.h / .cpp      # Block Factory allocator
    │   └── ir_builder.h / ir_builder.cpp     # IR Construction API
    │
    ├── arch/
    │   └── x86/                              # x86/x64 Architecture Subsystem
    │       ├── x86_instruction.h / .cpp      # Decoded x86 instruction representation
    │       ├── x86_operand.h / .cpp          # Registers, Immediates, and Memory operands
    │       ├── x86_decoder.h / .cpp          # 32/64-bit x86 Stream Decoder
    │       ├── x86_instruction_semantics.h   # Semantic translation to IR
    │       └── x86_lifter.h / x86_lifter.cpp # Function lifting manager
    │
    ├── analysis/                             # SSA & Control Flow Structuring
    │   ├── dominator_tree.h / .cpp           # Cooper-Harvey-Kennedy Dominator Tree
    │   ├── dominance_frontier.h / .cpp       # Dominance Frontier computation
    │   ├── ssa/
    │   │   ├── phi_node.h / phi_node.cpp     # SSA Phi-Node (Φ) instruction
    │   │   ├── ssa_renamer.h / .cpp          # Variable Renaming Engine
    │   │   └── ssa_builder.h / .cpp          # Full SSA Construction Orchestrator
    │   ├── passes/
    │   │   ├── constant_folding.h / .cpp     # Constant Folding & Expression Simplification
    │   │   ├── dead_code_elimination.h       # Iterative Dead Code Removal
    │   │   ├── copy_propagation.h / .cpp     # Copy Chain Elimination
    │   │   └── cfg_simplifier.h / .cpp       # Unreachable Block Removal & Edge Merging
    │   ├── loop_info.h / loop_info.cpp       # Natural Loop data structure
    │   ├── loop_recovery.h / .cpp            # Back-edge analysis & Loop classifier
    │   ├── condition_info.h / .cpp           # Conditional Branching data structure
    │   ├── condition_recovery.h / .cpp       # Merge-point detection for if/else
    │   ├── region.h / region.cpp             # Block, Sequence, If, and Loop Regions
    │   └── structurer.h / structurer.cpp     # CFG-to-Region Structuring Engine
    │
    ├── ast/                                  # High-Level AST Representation
    │   ├── ast_node.h / ast_node.cpp         # AST Node (Statements & Expressions)
    │   └── ast_builder.h / ast_builder.cpp   # Region & IR to AST Converter
    │
    └── codegen/                              # C++ Emitter
        ├── type_inference.h / .cpp           # Type Inference Engine
        ├── source_writer.h / .cpp            # Code Formatter & Indentation Stream
        └── cpp_generator.h / .cpp            # C++ Source Code Generator

Building

# Clone the repository
git clone https://github.com/your-org/open_decompiler.git
cd open_decompiler

# Build with CMake
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build

Command Line Usage

1. Decompile a Binary File (32-bit/64-bit EXE or DLL)

odc <path_to_binary> [options]

Examples:

# Decompile a 64-bit EXE to C++ file
odc sample_app.exe -o output.cpp

# Decompile a 32-bit DLL with diagnostic logs
odc core_library.dll --verbose -o dll_output.cpp

2. Decompile Assembly Text directly (ASM to C++)

odc -a <inline_asm_or_asm_file> [options]

Examples:

# Decompile inline Assembly string
odc -a "mov eax, ecx; add eax, edx; ret" -o output.cpp

# Decompile an assembly source file (.asm)
odc -a code.asm -o output.cpp

Options Matrix

Option Description
<input_binary> Path to target PE binary file (.exe or .dll).
-a <input>, --asm <input> Decompile textual Assembly directly (inline string or .asm file).
-o <file>, --output <file> Specify output filename for C++ source code (Default: stdout).
--emit-ssa Dump SSA Intermediate Representation to stdout for debugging.
--no-opt Disable optimization passes.
-v, --verbose Enable diagnostic stage logging.
-h, --help Display command-line usage menu.

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages