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.
51 lines
1.1 KiB
Rust
51 lines
1.1 KiB
Rust
use clap::{Parser, Subcommand};
|
|
use disasm::Disassembler;
|
|
|
|
mod aout;
|
|
mod disasm;
|
|
mod disasm_macros;
|
|
mod instructions;
|
|
mod operands;
|
|
mod register;
|
|
|
|
#[derive(Subcommand, Debug)]
|
|
enum Command {
|
|
/// Disassemble the binary into 8086 instructions
|
|
Disasm,
|
|
|
|
/// Interpret the 8086 instructions
|
|
Interpret,
|
|
}
|
|
|
|
/// Simple program to disassemble and interpret 8086 a.out compilates, e.g.
|
|
/// such for MINIX.
|
|
#[derive(Parser, Debug)]
|
|
#[command(version, about, long_about = None)]
|
|
struct Args {
|
|
#[command(subcommand)]
|
|
command: Command,
|
|
|
|
/// Path of the binary
|
|
#[arg(short, long, global = true)]
|
|
path: Option<String>,
|
|
}
|
|
|
|
fn main() {
|
|
env_logger::init();
|
|
|
|
let args = Args::parse();
|
|
log::debug!("{:?}", args);
|
|
|
|
match args.command {
|
|
Command::Disasm => {
|
|
let mut disasm = Disassembler::new(&args);
|
|
let instructions = disasm.disassemble();
|
|
match instructions {
|
|
Ok(instrs) => instrs.iter().for_each(|i| println!("{i}")),
|
|
_ => {}
|
|
}
|
|
}
|
|
_ => panic!("Command not yet implemented"),
|
|
}
|
|
}
|