fix: only push raw instruction once
This commit is contained in:
@@ -36,8 +36,11 @@ impl Aout {
|
||||
let data_start = text_end + 1;
|
||||
let data_end = data_start + hdr.data as usize;
|
||||
|
||||
dbg!(&hdr);
|
||||
|
||||
let text_section = &buf[text_start..text_end];
|
||||
let data_section = &buf[data_start..data_end];
|
||||
// let data_section = &buf[data_start..data_end];
|
||||
let data_section = [];
|
||||
|
||||
Aout {
|
||||
header: hdr,
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
10
src/main.rs
10
src/main.rs
@@ -37,8 +37,14 @@ fn main() {
|
||||
|
||||
match args.command {
|
||||
Command::Disasm => {
|
||||
let instructions = disasm::disasm(&args).unwrap();
|
||||
log::debug!("{:?}", &instructions);
|
||||
let instructions = disasm::disasm(&args);
|
||||
match instructions {
|
||||
Err(e) => {
|
||||
println!("(undefined)");
|
||||
println!("Encountered error during parsing: {e}")
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
}
|
||||
_ => panic!("Command not yet implemented"),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user