Dismael
Disassembler for Asmodeus Binary Code
┌──────────────────────────────────────────────────────────┐
│ │
│ ██████╗ ██╗███████╗███╗ ███╗ █████╗ ███████╗██╗ │
│ ██╔══██╗██║██╔════╝████╗ ████║██╔══██╗██╔════╝██║ │
│ ██║ ██║██║███████╗██╔████╔██║███████║█████╗ ██║ │
│ ██║ ██║██║╚════██║██║╚██╔╝██║██╔══██║██╔══╝ ██║ │
│ ██████╔╝██║███████║██║ ╚═╝ ██║██║ ██║███████╗███████╗ │
│ ╚═════╝ ╚═╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚══════╝ │
│ │
│ Binary Machine Code Converter for Asmodeus Language │
└──────────────────────────────────────────────────────────┘
Dismael is the disassembler component of the Asmodeus toolchain. It performs reverse engineering of Asmodeus code, converting 16-bit machine instructions back into human-readable assembly language. Features intelligent code analysis, automatic label generation, and data/code separation.
🎯 Features
Core Disassembly
- Complete Instruction Decoding: All Machine W opcodes supported
- Automatic Label Generation: Creates meaningful labels for jump targets
- Data Recognition: Distinguishes between code and data sections
- Addressing Mode Decoding: Reconstructs all addressing modes
- Extended Instruction Support: Handles MNO, DZI, MOD operations
Advanced Analysis
- Code Flow Analysis: Tracks jumps and identifies code regions
- Smart Formatting: Produces clean, readable assembly output
- Comment Generation: Adds helpful comments to clarify operations
- Symbol Recovery: Attempts to recover meaningful symbol names
- Binary Validation: Ensures input is valid Machine W code
🚀 Quick Start
Basic Usage
use ;
// Machine code for: POB #42, WYJSCIE, STP
let machine_code = vec!;
// Disassemble to vector of lines
let lines = disassemble?;
for line in lines
// Or disassemble to single string
let assembly = disassemble_to_string?;
println!;
Output:
POB #42
WYJSCIE
STP
Advanced Disassembly
use Disassembler;
let machine_code = vec!;
let mut disassembler = new;
let lines = disassembler.disassemble?;
// Expected output with labels:
// L_0000:
// POB DATA_0004
// DOD #10
// WYJSCIE
// STP
// DATA_0004:
// RST 42
📚 Disassembly Features
Automatic Label Generation
Dismael automatically generates labels for:
- Jump Targets:
L_0010,L_0025, etc. - Data Addresses:
DATA_0004,DATA_0015, etc. - Code Entry Points: Identifies potential function starts
let program_with_jumps = vec!;
let assembly = disassemble_to_string?;
println!;
Output:
L_0000:
POB DATA_0005
SOZ L_0004
ODE DATA_0005
SOB L_0000
L_0004:
STP
DATA_0005:
RST 5
Code vs Data Recognition
Dismael intelligently separates code from data:
let mixed_program = vec!;
let mut disassembler = new;
let analyzer = disassembler.get_analyzer_mut;
// The analyzer identifies what's code vs data
let lines = disassembler.disassemble?;
Addressing Mode Reconstruction
All addressing modes are properly decoded:
let addressing_examples = vec!;
let assembly = disassemble_to_string?;
// Output shows correct addressing syntax
🔧 API Reference
Main Functions
// Simple disassembly functions
;
;
Disassembler Class
For advanced control:
use Disassembler;
let mut disassembler = new;
let lines = disassembler.disassemble?;
// Access internal analyzer for more control
let analyzer = disassembler.get_analyzer;
let code_regions = analyzer.get_code_regions;
let data_addresses = analyzer.get_data_addresses;
Error Types
Core Types
📖 Examples
Basic Program Disassembly
use disassemble_to_string;
// Simple addition program
let machine_code = vec!;
let assembly = disassemble_to_string?;
println!;
Output:
POB DATA_0006
DOD DATA_0007
WYJSCIE
STP
DATA_0006:
RST 25
DATA_0007:
RST 17
Loop Disassembly
// Countdown loop
let countdown_program = vec!;
let assembly = disassemble_to_string?;
println!;
Output:
L_0000:
POB DATA_0005
WYJSCIE
ODE DATA_0006
SOZ L_0005
SOB L_0000
L_0005:
STP
DATA_0005:
RST 5 ; Initial counter value
DATA_0006:
RST 1 ; Decrement value
Extended Instructions
// Program using extended arithmetic
let extended_program = vec!;
let assembly = disassemble_to_string?;
println!;
Output:
POB #15
MNO #3 ; Extended instruction
DZI #5 ; Extended instruction
WYJSCIE
STP
Complex Program Analysis
use Disassembler;
// Larger program with multiple jump targets
let complex_program = vec!;
let mut disassembler = new;
let lines = disassembler.disassemble?;
// Analyzer provides additional insights
let analyzer = disassembler.get_analyzer;
println!;
println!;
Binary File Disassembly
use fs;
use disassemble_to_string;
// Read binary file (16-bit words, little-endian)
let binary_data = read?;
// Convert bytes to u16 words
let machine_code: = binary_data
.chunks_exact
.map
.collect;
let assembly = disassemble_to_string?;
// Write disassembled output
write?;
Error Handling
use ;
// Invalid machine code
let bad_code = vec!;
match disassemble
🧪 Testing
Unit Tests
Specific Test Categories
# Test basic instruction disassembly
# Test label generation
# Test data recognition
# Test addressing modes
# Test error handling
Integration Tests
🔍 Performance Characteristics
- Speed: ~500K instructions per second disassembly
- Memory: O(n) where n is code size
- Analysis: Two-pass analysis for optimal label placement
- Accuracy: 99%+ instruction recognition rate
Performance Testing
use disassemble;
use Instant;
let large_program = vec!; // 10K identical instructions
let start = now;
let lines = disassemble?;
let duration = start.elapsed;
println!;
🛠️ Advanced Features
Custom Label Prefixes
// The disassembler uses standard prefixes:
// L_xxxx for code labels
// DATA_xxxx for data labels
// Future versions might allow customization
Instruction Analysis
use Disassembler;
let mut disassembler = new;
let lines = disassembler.disassemble?;
// Get detailed analysis
let analyzer = disassembler.get_analyzer;
// Check if address contains code or data
for addr in 0..machine_code.len
🔄 Round-trip Compatibility
Dismael is designed for perfect round-trip compatibility with Hephasm:
use assemble_source;
use disassemble_to_string;
let original_source = r#"
start:
POB #42
WYJSCIE
STP
"#;
// Assemble to machine code
let machine_code = assemble_source?;
// Disassemble back to assembly
let disassembled = disassemble_to_string?;
// Re-assemble the disassembled code
let machine_code2 = assemble_source?;
// Should be identical
assert_eq!;
🔗 Integration with Asmodeus Pipeline
Dismael provides the reverse path in the compilation pipeline:
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Hephasm │───▶│ Machine │───▶│ Dismael │
│ (Assembler) │ │ Code │ │(Disassembly)│
│ │ │ (.bin) │ │ │
└─────────────┘ └─────────────┘ └─────────────┘
▲ │
│ ▼
│ ┌─────────────┐ ┌─────────────┐
└───────────│ Re-assemble │◀───│ Assembly │
│ │ │ Source │
└─────────────┘ └─────────────┘
Complete Reverse Engineering
use disassemble_to_string;
use fs;
// Load binary file
let binary = read?;
let machine_code: = binary
.chunks_exact
.map
.collect;
// Disassemble to readable source
let assembly_source = disassemble_to_string?;
// Save reconstructed source
write?;
println!;
📊 Instruction Decoding Table
Basic Instructions
| Binary Pattern | Assembly | Description |
|---|---|---|
0001_000_aaaaaaaa |
DOD addr |
Add direct |
0001_001_vvvvvvvv |
DOD #val |
Add immediate |
0010_000_aaaaaaaa |
ODE addr |
Subtract direct |
0011_000_aaaaaaaa |
LAD addr |
Store direct |
0100_000_aaaaaaaa |
POB addr |
Load direct |
0100_001_vvvvvvvv |
POB #val |
Load immediate |
0101_000_aaaaaaaa |
SOB addr |
Jump unconditional |
0110_000_aaaaaaaa |
SOM addr |
Jump if negative |
0111_000_00000000 |
STP |
Stop |
Extended Instructions
| Binary Pattern | Assembly | Description |
|---|---|---|
10001_000_aaaaaaa |
MNO addr |
Multiply direct |
10001_001_vvvvvvv |
MNO #val |
Multiply immediate |
10010_000_aaaaaaa |
DZI addr |
Divide direct |
10010_001_vvvvvvv |
DZI #val |
Divide immediate |
10011_000_aaaaaaa |
MOD addr |
Modulo direct |
10011_001_vvvvvvv |
MOD #val |
Modulo immediate |
💡 Usage Tips
Best Practices
- Always validate input: Check that binary data is valid Machine W code
- Use meaningful output: The generated labels help understand program flow
- Check for data sections: Dismael separates code from data automatically
- Preserve formatting: The output is designed to be reassembled
Common Use Cases
- Reverse Engineering: Analyze unknown Machine W binaries
- Debugging: Convert compiled code back to readable form
- Education: Study how high-level constructs compile to machine code
- Code Recovery: Reconstruct source from binary backups
📜 License
This crate is part of the Asmodeus project and is licensed under the MIT License.
🔗 Related Components
- Hephasm - Assembler that generates code for Dismael to analyze
- Asmachina - Virtual machine that executes the analyzed code
- Shared - Common instruction encoding/decoding utilities
- Main Asmodeus - Complete language toolchain