44 lines
937 B
Rust
44 lines
937 B
Rust
use std::fs::File;
|
|
use std::io;
|
|
|
|
mod colormap;
|
|
|
|
mod tohex;
|
|
use tohex::hexdump;
|
|
mod tobin;
|
|
use tobin::bindump;
|
|
|
|
use clap::Parser;
|
|
|
|
#[derive(Parser)]
|
|
#[command(version, about = "A simple hexdump tool")]
|
|
struct Arguments {
|
|
/// Revert a hexdump to binary
|
|
#[arg(short, long)]
|
|
revert: bool,
|
|
/// Stop after <len> octets
|
|
#[arg(short, long)]
|
|
length: Option<usize>,
|
|
|
|
/// Filename to read, if left out read from stdin
|
|
filename: Option<String>,
|
|
}
|
|
|
|
fn main() {
|
|
let args = Arguments::parse();
|
|
|
|
let reader: Box<dyn io::Read> = if args.filename.is_none() {
|
|
Box::new(io::stdin())
|
|
} else {
|
|
let filename = args.filename.unwrap();
|
|
Box::new(File::open(filename).expect("Could not open file."))
|
|
};
|
|
|
|
if !args.revert {
|
|
hexdump(reader, args.length.unwrap());
|
|
} else {
|
|
let writer: Box<dyn io::Write> = Box::new(io::stdout());
|
|
bindump(reader, writer);
|
|
}
|
|
}
|