ft: add first basic test
This commit is contained in:
@@ -829,3 +829,36 @@ impl Disassembler {
|
|||||||
Ok(instructions)
|
Ok(instructions)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_basic() {
|
||||||
|
let text = Vec::from([0x0, 0x0]);
|
||||||
|
let mut disassembler = Disassembler {
|
||||||
|
offset: 0,
|
||||||
|
text,
|
||||||
|
instruction: Instruction::new(),
|
||||||
|
};
|
||||||
|
let instructions = disassembler.decode_instructions().ok();
|
||||||
|
if let Some(instrs) = instructions {
|
||||||
|
assert_eq!(
|
||||||
|
instrs[0],
|
||||||
|
Instruction {
|
||||||
|
start: 0,
|
||||||
|
raw: Vec::from([0, 0]),
|
||||||
|
opcode: Mnemonic::ADD_FromReg(
|
||||||
|
ModRmTarget::Memory(MemoryIndex {
|
||||||
|
base: Some(Register::BX),
|
||||||
|
index: Some(Register::SI),
|
||||||
|
displacement: None
|
||||||
|
}),
|
||||||
|
Register::AL
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
/// A single 'line' of executable ASM is called an Instruction, which
|
/// A single 'line' of executable ASM is called an Instruction, which
|
||||||
/// contains the `Mnemonic` that will be executed, alongside its starting offset
|
/// contains the `Mnemonic` that will be executed, alongside its starting offset
|
||||||
@@ -46,7 +46,7 @@ impl fmt::Display for Instruction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
#[allow(dead_code, non_camel_case_types)]
|
#[allow(dead_code, non_camel_case_types)]
|
||||||
/// All possible mnemonic variantions.
|
/// All possible mnemonic variantions.
|
||||||
/// These are sorted by type and are not in hex-encoding order.
|
/// These are sorted by type and are not in hex-encoding order.
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ impl fmt::LowerHex for Operand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
/// ModRM byte can either target a memory location or some register.
|
/// ModRM byte can either target a memory location or some register.
|
||||||
pub enum ModRmTarget {
|
pub enum ModRmTarget {
|
||||||
Memory(MemoryIndex),
|
Memory(MemoryIndex),
|
||||||
@@ -55,7 +55,7 @@ impl std::fmt::Display for ModRmTarget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
/// Memory displacements are signed versions of Byte and Word operands.
|
/// Memory displacements are signed versions of Byte and Word operands.
|
||||||
/// Encodes either Byte- or Word-sized operands.
|
/// Encodes either Byte- or Word-sized operands.
|
||||||
pub enum Displacement {
|
pub enum Displacement {
|
||||||
@@ -95,7 +95,7 @@ impl std::fmt::Display for Displacement {
|
|||||||
|
|
||||||
/// A memory index operand is usually created by ModRM bytes or words.
|
/// A memory index operand is usually created by ModRM bytes or words.
|
||||||
/// e.g. [bx+si]
|
/// e.g. [bx+si]
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct MemoryIndex {
|
pub struct MemoryIndex {
|
||||||
pub base: Option<Register>,
|
pub base: Option<Register>,
|
||||||
pub index: Option<Register>,
|
pub index: Option<Register>,
|
||||||
@@ -131,7 +131,7 @@ impl fmt::Display for MemoryIndex {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
/// 32-bit segment:offset pointer (e.g. for CALL instruction)
|
/// 32-bit segment:offset pointer (e.g. for CALL instruction)
|
||||||
pub struct Pointer {
|
pub struct Pointer {
|
||||||
pub raw: DWord,
|
pub raw: DWord,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
use crate::{disasm::DisasmError, operands::Operand};
|
use crate::{disasm::DisasmError, operands::Operand};
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
/// Registers of a 8086 processor
|
/// Registers of a 8086 processor
|
||||||
pub enum Register {
|
pub enum Register {
|
||||||
@@ -88,7 +88,7 @@ impl fmt::Display for Register {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Segment Registers of a 8086 processor
|
/// Segment Registers of a 8086 processor
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub enum SegmentRegister {
|
pub enum SegmentRegister {
|
||||||
DS,
|
DS,
|
||||||
|
|||||||
Reference in New Issue
Block a user