The VB Decompiler is a comprehensive tool for reverse engineering Visual Basic 6 executables. It consists of two main components:
- Core Library (Zig): High-performance decompiler engine
- GUI Frontend (Qt 6/C++ 23): User-friendly interface similar to Ghidra/IDA
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Qt 6/C++ 23 GUI Frontend β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Main Window β β
β β ββββββββββββ¬ββββββββββββββββββββββββββββββββββββ β β
β β β Function β Disassembly / Decompiler View β β β
β β β Browser βββββββββββββββββββββββββββββββββββββ€ β β
β β β β Hex View β β β
β β ββββββββββββ΄ββββββββββββββββββββββββββββββββββββ β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββ
β C FFI
βββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββ
β libvbdecomp.so/.dll/.dylib (Zig) β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β C API Layer β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ€ β
β β PE Parser β VB6 Detector β Disassembler β β
β β β β β β β
β β Lifter β IR Optimizer β Decompiler β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββ
β vbdecomp CLI (Zig) β
β analyze | disasm | decompile | sections β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Parses Windows Portable Executable files:
- DOS header and stub
- PE signature and headers
- COFF header
- Optional header (32-bit)
- Section headers (.text, .data, .rsrc, etc.)
- Data directories (imports, exports, resources)
Identifies Visual Basic binaries:
- Checks for MSVBVM60.DLL/MSVBVM50.DLL imports
- Detects compilation type (Native vs P-Code)
- Identifies binary type (EXE, DLL, OCX)
- Locates VB object table
- Detects forms and resources
Phase 1 (Current): Native x86 disassembly
- Custom x86 instruction decoder
- Linear sweep and recursive descent
- Basic block identification
Phase 2: P-Code disassembly
- P-Code opcode interpreter
- Stack simulation
- Conversion to readable format
Intermediate representation for analysis:
- Ghidra P-Code: Primary IR (well-documented, proven)
- SSA form
- Generic operations
- Architecture-independent
- LLVM IR: Secondary target for advanced optimizations
High-level code generation:
- Type recovery (VB6 types: Integer, Long, String, Variant, Object, etc.)
- Control flow structuring (If/Then, Select Case, For/Next, Do/Loop)
- Variable naming
- Comment generation
- VB6 pseudo-code output
Static analysis passes:
- Cross-references: Track code and data references
- Strings: Extract and catalog string literals
- Functions: Detect function boundaries and signatures
- Data flow: Track variable usage and propagation
Central hub with dockable panels:
- Menu bar and toolbar
- Status bar
- Plugin architecture for extensibility
-
Disassembly View (
gui/src/widgets/disassembly_view.cpp)- Address column
- Bytes column (hex)
- Instruction mnemonics
- Operands with hyperlinks
- Comments
- Jump arrows for control flow
-
Decompiler View (
gui/src/widgets/decompiler_view.cpp)- VB6 pseudo-code
- Syntax highlighting
- Collapsible code blocks
- Side-by-side with disassembly
-
Hex View (
gui/src/widgets/hex_view.cpp)- Address, hex, ASCII columns
- Data type interpretation
- Synchronized with other views
-
Function Browser (
gui/src/widgets/function_browser.cpp)- Tree view of program structure
- Modules, forms, classes
- Functions and procedures
- Search and filtering
-
Graph View (
gui/src/widgets/graph_view.cpp)- Control flow graphs
- Call graphs
- Interactive navigation
- Layout algorithms
-
Cross-Reference View (
gui/src/widgets/xref_view.cpp)- "Where is this used?"
- Code and data xrefs
- Bidirectional navigation
-
String/Resource Viewers
- String table
- Icons, bitmaps, dialogs
- Form data extraction
Manages communication with Zig library:
- Dynamic library loading
- C API wrapping
- Error handling
- Thread safety
VB6 Binary (EXE/DLL/OCX)
β
PE Parser
β
VB6 Detector β Is VB? β Native or P-Code?
β
Disassembler (x86 or P-Code)
β
IR Lifter β Ghidra P-Code
β
IR Optimizer β DCE, const prop, CSE
β
Type Recovery β VB6 types
β
Control Flow Structuring
β
Code Generator β VB6 pseudo-code
β
Display in GUI
User opens file in GUI
β
GUI calls vbdecomp_open() via C API
β
Core parses PE and detects VB6
β
GUI displays file info
β
User clicks on function in browser
β
GUI calls vbdecomp_disassemble()
β
Disassembly displayed in view
β
User clicks "Decompile"
β
GUI calls vbdecomp_decompile()
β
VB6 pseudo-code displayed
VB Decompiler is designed to work on Windows, Linux, and macOS.
File I/O:
- Uses C standard library (fopen, fread, fseek) for maximum portability
- No platform-specific file APIs (no POSIX open/read, no Windows CreateFile)
Path Handling:
- Accepts forward slashes on all platforms
- Internally converts paths to platform-native format when needed
Memory Management:
- Pure Zig allocators work identically across platforms
- No platform-specific memory APIs
GUI (Qt 6):
- Qt provides full cross-platform abstraction
- Same codebase builds on all platforms
- Native look and feel on each OS
Build System:
- CMake orchestrates multi-platform builds
- Zig's cross-compilation capabilities enable building for any target
- Separate build scripts for platform-specific packaging
| Platform | Compiler | Status |
|---|---|---|
| Linux x64 | Zig 0.16.0 + GCC 13 | β Tested |
| Windows x64 | Zig 0.16.0 + MSVC 2022 | π Planned |
| macOS ARM64 | Zig 0.16.0 + Clang 16 | π Planned |
- Performance: Near C-level performance
- Safety: Compile-time memory safety checks
- C interop: Seamless C API generation
- Modern: Better ergonomics than C
- No runtime: Minimal dependencies
- Cross-compilation: Build for any platform from any platform
- Cross-platform: Linux, Windows, macOS
- Mature: Stable, well-documented
- Widgets: Rich set of UI components
- C++ 23: Modern C++ features
- Community: Large ecosystem
- Proven: Used in production decompiler
- Documented: Extensive documentation
- Generic: Architecture-independent
- Simple: Easier to implement than LLVM IR
- Extensible: Can add custom operations
- Control: Full control over output format
- Learning: Educational value
- VB6-specific: Can add VB6-specific annotations
- No dependencies: Reduces complexity
- Lightweight: Smaller binary size
Analysis results stored in SQLite database:
- Efficient: Fast queries for large binaries
- Standard: Well-supported, portable
- Structured: Relational model fits our needs
- Extensible: Easy to add new tables
- Tooling: Can inspect with standard SQL tools
-- Binary metadata
CREATE TABLE binary_info (
path TEXT PRIMARY KEY,
vb_version INTEGER,
binary_type INTEGER,
compilation_type INTEGER,
entry_point INTEGER,
image_base INTEGER
);
-- Functions
CREATE TABLE functions (
address INTEGER PRIMARY KEY,
name TEXT,
size INTEGER,
is_export BOOLEAN,
is_thunk BOOLEAN
);
-- Disassembly
CREATE TABLE disassembly (
address INTEGER PRIMARY KEY,
mnemonic TEXT,
operands TEXT,
bytes BLOB,
comment TEXT
);
-- User annotations
CREATE TABLE comments (
address INTEGER PRIMARY KEY,
text TEXT,
author TEXT,
timestamp INTEGER
);
-- Cross-references
CREATE TABLE xrefs (
from_addr INTEGER,
to_addr INTEGER,
type INTEGER,
PRIMARY KEY (from_addr, to_addr)
);- CMake invokes
zig buildfor core library - CMake builds Qt GUI
- CMake links GUI against libvbdecomp
- CMake creates installer package
vbdecomp_core: Zig shared libraryvbdecomp-gui: Qt applicationvbdecomp: CLI tool (built by Zig)install: Install all componentstest: Run unit tests
cd core
zig build testTests each module independently.
End-to-end tests with sample VB6 binaries:
- Simple Hello World (Native + P-Code)
- GUI app with forms
- DLL with exports
- OCX control
cd gui/tests
./test_runnerTests UI components and interactions.
- Custom IR passes: Add optimization passes
- Analysis plugins: New analysis algorithms
- GUI plugins: Custom views and tools
- Export formats: HTML, Markdown, JSON
- Scripting: Python/Lua bindings (future)
- Lazy loading: Parse sections on-demand
- Caching: Cache disassembly and decompilation results
- Threading: Background analysis in worker threads
- Streaming: Process large files incrementally
- Memory mapping: Use mmap for file access
- Sandboxing: Parse untrusted binaries safely
- Input validation: Validate all PE structures
- Bounds checking: Prevent buffer overflows
- No code execution: Never execute target binary
- Fuzzing: Test with malformed inputs
- P-Code decompilation: Complete P-Code support
- Form reconstruction: Visual form editor
- Scripting: Python API for automation
- Collaborative: Multi-user annotations
- Cloud: Save projects to cloud storage
- Diff: Compare different versions
- Signature matching: Library function identification
- Type libraries: Import .tlb files for better typing