chore: fix panic

ModRM parsing still used old parsing style.
This commit is contained in:
2025-05-27 09:21:40 +09:00
parent 8ea91d80b8
commit 3463b5b4ae

View File

@@ -1,5 +1,7 @@
//! The main dissembling logic. //! The main dissembling logic.
use env_logger::Target;
use crate::aout::Aout; use crate::aout::Aout;
use crate::operands::{ use crate::operands::{
Byte, DWord, Displacement, IByte, IWord, MemoryIndex, ModRmTarget, Operand, Pointer, Word, Byte, DWord, Displacement, IByte, IWord, MemoryIndex, ModRmTarget, Operand, Pointer, Word,
@@ -200,9 +202,7 @@ impl Disassembler {
&mut self, &mut self,
register_width: Operand, register_width: Operand,
) -> Result<(ModRmTarget, RegisterId), DisasmError> { ) -> Result<(ModRmTarget, RegisterId), DisasmError> {
// advance to operand let modrm = self.parse_byte()?;
self.offset += 1;
let modrm = self.text[self.offset];
self.instruction.raw.push(modrm); self.instruction.raw.push(modrm);
let (mode, reg, rm) = Self::deconstruct_modrm_byte(modrm); let (mode, reg, rm) = Self::deconstruct_modrm_byte(modrm);
@@ -219,8 +219,9 @@ impl Disassembler {
match mode { match mode {
0b00 => { 0b00 => {
if rm == 0b110 { if rm == 0b110 {
displacement = Some(Displacement::IWord(self.parse_word()? as IWord)); let word = Displacement::IWord(self.parse_word()? as IWord);
log::debug!("ModRM direct memory read at {displacement:?}"); log::debug!("ModRM direct memory read at {word:?}");
displacement = Some(word);
return Ok(( return Ok((
ModRmTarget::Memory(MemoryIndex { ModRmTarget::Memory(MemoryIndex {
base: None, base: None,
@@ -421,6 +422,7 @@ impl Disassembler {
let mut instructions = Vec::new(); let mut instructions = Vec::new();
log::debug!("Starting to decode text of length {}", self.text.len());
while self.offset < self.text.len() { while self.offset < self.text.len() {
self.instruction.start = self.offset; self.instruction.start = self.offset;