diff options
author | 53hornet <atc@53hor.net> | 2021-08-05 11:09:04 -0400 |
---|---|---|
committer | 53hornet <atc@53hor.net> | 2021-08-05 11:09:04 -0400 |
commit | a2c00337bc9bac1942ad835181ae09f8a66d524b (patch) | |
tree | 7e06629303e9118aa83200f8f566a762438fdaf7 | |
download | rexdump-a2c00337bc9bac1942ad835181ae09f8a66d524b.tar.xz rexdump-a2c00337bc9bac1942ad835181ae09f8a66d524b.zip |
init
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Cargo.lock | 7 | ||||
-rw-r--r-- | Cargo.toml | 8 | ||||
-rw-r--r-- | src/main.rs | 37 |
4 files changed, 53 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..2c91df1 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "rexdump" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..2928ae6 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "rexdump" +version = "0.1.0" +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..da0e599 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,37 @@ +use std::{env, fs::File, io::Read}; + +fn main() -> Result<(), Box<dyn std::error::Error>> { + const CHUNK_SIZE: usize = 8; + + let filename = env::args().nth(1).unwrap_or_default(); + if filename.is_empty() { + eprintln!("error missing filename"); + return Ok(()); + } + + let mut file = File::open(&filename)?; + let mut chunk = Vec::with_capacity(CHUNK_SIZE); + let mut idx = 0; + + while { + chunk.clear(); + file.by_ref() + .take(CHUNK_SIZE as u64) + .read_to_end(&mut chunk)? + > 0 + } { + // write index + print!("{:010}: ", idx); + + // write hex + for byte in &chunk { + print!("{:02X} ", byte); + } + + // write ascii + println!("{}", String::from_utf8_lossy(&chunk).replace('\n', "⏎")); + idx += CHUNK_SIZE; + } + + Ok(()) +} |