chore: move pointer parsing function to disasm module

This commit is contained in:
2025-05-25 20:31:55 +09:00
parent 74e936ab76
commit f9ae0dc6ee
2 changed files with 22 additions and 41 deletions

View File

@@ -1,10 +1,7 @@
//! All types which a Mnemonic can have as some kind of operand.
//! This includes things such as immediates, ModRM byte targets, etc. etc.
use crate::{
disasm::{DisasmError, Disassembler},
register::Register,
};
use crate::register::Register;
use core::fmt;
pub type Byte = u8; // b
@@ -139,37 +136,6 @@ pub struct Pointer {
pub offset: Word,
}
impl Pointer {
pub fn new(disasm: &mut Disassembler) -> Result<Self, DisasmError> {
log::debug!(
"Seeking 4 bytes ahead of current text offset... ({} + 4)",
disasm.offset
);
let byte0 = disasm
.text
.get(disasm.offset)
.ok_or(DisasmError::ReadBeyondTextSection(disasm.clone()))?;
let byte1 = disasm
.text
.get(disasm.offset + 1)
.ok_or(DisasmError::ReadBeyondTextSection(disasm.clone()))?;
let byte2 = disasm
.text
.get(disasm.offset + 2)
.ok_or(DisasmError::ReadBeyondTextSection(disasm.clone()))?;
let byte3 = disasm
.text
.get(disasm.offset + 3)
.ok_or(DisasmError::ReadBeyondTextSection(disasm.clone()))?;
Ok(Pointer {
raw: DWord::from_le_bytes([*byte0, *byte1, *byte2, *byte3]),
segment: disasm.parse_word()?,
offset: disasm.parse_word()?,
})
}
}
impl std::fmt::Display for Pointer {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "[{:#04x}] ({}:{})", self.raw, self.segment, self.offset)