-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecompiler.rs
33 lines (27 loc) · 1000 Bytes
/
decompiler.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//! Tool to decompile the binary, to help with reverse-engineering it.
// Format:
// 2022 eq reg[4] reg[2] 10000
use crate::vm::instructions::BUILDERS;
use super::instructions::is_opcode;
use super::storage::Memory;
#[allow(dead_code)]
pub fn decompile() {
let mem = Memory::new();
let mut address = 0;
while address < mem.len() {
let opcode = mem.read(address);
// All the code seems to be before 6090
if address < 6090 && is_opcode(opcode) {
let ins = BUILDERS[opcode as usize](address, mem.ins_slice(address));
println!("{}", ins.decompile());
address += ins.offset();
} else {
// TODO add instruction validation to the instruction instance methods.
// if is_opcode(opcode) {
// println!("Possible opcode: {}\t{}", address, mem.read(address));
// }
println!("{}\t{}", address, mem.read(address));
address += 1;
}
}
}