fix: only push raw instruction once
This commit is contained in:
@@ -25,7 +25,7 @@ pub enum DisasmError {
|
||||
IllegalModRMByteMode(u8),
|
||||
IllegalModRMByteIndex(u8),
|
||||
IllegalOperand(String),
|
||||
ReadBeyondTextSection(Disassembler),
|
||||
ReadBeyondTextSection(),
|
||||
UnknownRegister(usize),
|
||||
}
|
||||
|
||||
@@ -61,10 +61,9 @@ impl fmt::Display for DisasmError {
|
||||
modrm
|
||||
),
|
||||
DisasmError::IllegalOperand(msg) => write!(f, "Error (Illegal operand). {}", msg),
|
||||
DisasmError::ReadBeyondTextSection(disasm) => write!(
|
||||
DisasmError::ReadBeyondTextSection() => write!(
|
||||
f,
|
||||
"Error (Out of bounds access). Disassembler state: {:?}",
|
||||
disasm
|
||||
"Error (Out of bounds access). Wanted to paese an additional byte, but there is no more text section.",
|
||||
),
|
||||
DisasmError::UnknownRegister(id) => write!(
|
||||
f,
|
||||
@@ -124,7 +123,7 @@ impl Disassembler {
|
||||
let byte = self
|
||||
.text
|
||||
.get(self.offset)
|
||||
.ok_or(DisasmError::ReadBeyondTextSection(self.clone()))?;
|
||||
.ok_or(DisasmError::ReadBeyondTextSection())?;
|
||||
log::debug!("Parsed byte {byte:#04x}");
|
||||
self.instruction.raw.push(*byte);
|
||||
Ok(*byte)
|
||||
@@ -137,8 +136,6 @@ impl Disassembler {
|
||||
log::debug!("Attempting to parse word at {:#04x} ...", self.offset);
|
||||
let byte1 = self.parse_byte()?;
|
||||
let byte2 = self.parse_byte()?;
|
||||
self.instruction.raw.push(byte1);
|
||||
self.instruction.raw.push(byte2);
|
||||
Ok(u16::from_le_bytes([byte1, byte2]))
|
||||
}
|
||||
|
||||
@@ -203,7 +200,6 @@ impl Disassembler {
|
||||
register_width: Operand,
|
||||
) -> Result<(ModRmTarget, RegisterId), DisasmError> {
|
||||
let modrm = self.parse_byte()?;
|
||||
self.instruction.raw.push(modrm);
|
||||
|
||||
let (mode, reg, rm) = Self::deconstruct_modrm_byte(modrm);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user