#disassembler #disassembly #vax

vax-disassembler

DEC VAX 单行反汇编器

2个版本

新版本 0.1.1 2024年8月25日
0.1.0 2024年8月25日

#187 in 调试

MIT 许可证

99KB
1K SLoC

vax-disassembler - DEC VAX 单行反汇编器

此crate提供Digital Equipment Corporation VAX架构的单指令反汇编器。

The [ReadMacro32] trait向任何支持Read trait的对象添加了disassemble()函数。disassemble函数返回一个[Instruction]枚举。

[Instruction]枚举存储了反汇编指令的信息。

当前版本支持反汇编和显示指令,以及多种检查指令细节的方法。其预期目的是解码模拟VAX的内存转储,然而,随着时间允许,我计划增加其功能。

  • 添加从指令输出机器代码的能力。
  • 为[Instruction]枚举实现FromStr trait(即向crate添加单行汇编功能)。
  • 将程序计数器(PC)的意识添加到反汇编指令中。

示例

use vax_disassembler::{
    IndexedOperand,
    Instruction,
    Operand,
    ReadMacro32,
    Register::*,
};
use std::io::Cursor;

static SAMPLE_BUFFER: &'static [u8] = &[
    // PUSHR   #0x3F                        ; Push R0 through R5 on the stack
    0xBB, 0x3F,
    // EDIV    -4(R2)[R3], R0, 16(SP), 20(SP); Divide R0:R1 by longword at (R3 * 4) + R2 - 4.
    //                                      ; Put dividend in SP + 8 and remainder in SP + 12
    0x7B, 0x43, 0xA2, 0xFC, 0x50, 0xAE,   16, 0xAE,   20,
    // ADDL2   S^#16, SP                    ; Release stack space
    0xC0,   16, 0x5E,
    // MOVQ    (SP)+, R0                    ; Put dividend in R0 and remainder in R1 from the stack
    0x7D, 0x8E, 0x50,
    // RSB
    0x05,
];

let mut code_buf = Cursor::new(SAMPLE_BUFFER);

let mut instruction = Vec::new();
for _ in 0..5 {
    instruction.push(code_buf.disassemble().unwrap());
}

// The machine code is transformed into Instructions
assert_eq!(instruction[0], Instruction::PUSHR([Operand::Literal(0x3F)]));
assert_eq!(instruction[1], Instruction::EDIV([
    Operand::Indexed(IndexedOperand::ByteDisplacement(-4, R2), R3),
    Operand::Register(R0),
    Operand::ByteDisplacement(16, SP),
    Operand::ByteDisplacement(20, SP),
]));
assert_eq!(instruction[2], Instruction::ADDL2([Operand::Literal(16), Operand::Register(SP)]));
assert_eq!(instruction[3], Instruction::MOVQ([Operand::AutoIncrement(SP), Operand::Register(R0)]));
assert_eq!(instruction[4], Instruction::RSB([]));

// Instructions have a display implementation. . .
assert_eq!(&format!("{}", instruction[0]), "PUSHR   S^#63");
assert_eq!(&format!("{}", instruction[1]), "EDIV    B^-4(R2)[R3], R0, B^16(SP), B^20(SP)");
assert_eq!(&format!("{}", instruction[2]), "ADDL2   S^#16, SP");
assert_eq!(&format!("{}", instruction[3]), "MOVQ    (SP)+, R0");
assert_eq!(&format!("{}", instruction[4]), "RSB");

依赖项

~0.6–1MB
~23K SLoC