fix: dont interpret padding as instructions
a.out padds the text section with 0-bytes, which where interpreted as 0x00 0x00 instruction and occasionally as a single 0x00 byte. Add logic to ignore single 0x00 bytes and to remove dangling 0x00 0x00 instructions at the end of the instruction vec, so only the 'actual' instructions are presented in the end. Also adjust visibility of methods, so only the truncated instructions will ever be presented. Of course, this could remove an actual `0x00 0x00` instruction from the end, but they would not have any effect on execution anyway.
This commit is contained in:
11
src/main.rs
11
src/main.rs
@@ -1,4 +1,5 @@
|
||||
use clap::{Parser, Subcommand};
|
||||
use disasm::Disassembler;
|
||||
|
||||
mod aout;
|
||||
mod disasm;
|
||||
@@ -37,14 +38,12 @@ fn main() {
|
||||
|
||||
match args.command {
|
||||
Command::Disasm => {
|
||||
let instructions = disasm::disasm(&args);
|
||||
let mut disasm = Disassembler::new(&args);
|
||||
let instructions = disasm.disassemble();
|
||||
match instructions {
|
||||
Err(e) => {
|
||||
println!("(undefined)");
|
||||
println!("Encountered error during parsing: {e}")
|
||||
}
|
||||
Ok(instrs) => instrs.iter().for_each(|i| println!("{i}")),
|
||||
_ => {}
|
||||
};
|
||||
}
|
||||
}
|
||||
_ => panic!("Command not yet implemented"),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user