ft: add dump flag

This commit is contained in:
2025-05-28 15:59:37 +09:00
parent 7e8fdeba54
commit 4c63b7a21a
3 changed files with 24 additions and 10 deletions

View File

@@ -43,7 +43,7 @@ impl fmt::Display for DisasmError {
DisasmError::IoError(msg) => write!(f, "{}", msg),
DisasmError::OpcodeUndefined(opcode) => write!(
f,
"Error (Undefined Opcode). '{:#04x} is considered undefined by the Spec",
"Error (Undefined Opcode). '{:#04x} is considered undefined by the Spec for 8086.\nMaybe you are trying to interpret a x86 binary?\nAborting to stop misinterpretation of following instructions.",
opcode
),
DisasmError::IllegalGroupMnemonic(group, mnemonic) => write!(
@@ -106,7 +106,7 @@ impl Disassembler {
/// Start the disassmble and allow for some error handling wrapped around
/// the actual decoding function.
pub fn disassemble(&mut self) -> Result<Vec<Instruction>, DisasmError> {
pub fn disassemble(&mut self, dump: bool) -> Result<Vec<Instruction>, DisasmError> {
let is_ok = self.decode_instructions();
// a.out pads the text section to byte align, so the fasely interpreted
@@ -126,7 +126,16 @@ impl Disassembler {
Ok(instructions)
}
_ => {
println!("Encountered error during disassembly: {e}");
if dump {
self.instructions.iter().for_each(|i| println!("{i}"));
println!(
"Encountered error during disassembly, but this is the process so far...\n{e}\nRun with RUST_LOG=debug for furhter information."
);
} else {
println!(
"Encountered error during disassembly.\nRun with --dump to get sucessfully parsed instructions.\n{e}"
);
}
Err(e)
}
},
@@ -485,7 +494,7 @@ impl Disassembler {
// additional raw bytes will be pushed by parse functions
self.instruction.raw.push(opcode);
log::debug!("Parsing next opcode with opcode: {opcode:#04}");
log::debug!("Parsing next opcode with opcode: {opcode:#04x}");
self.instruction.opcode = match opcode {
0x00 => modrm_8b_register!(self, ADD_FromReg),
0x01 => modrm_16b_register!(self, ADD_FromReg),