This commit is contained in:
2025-07-03 13:13:44 +03:00
commit 1b84da8f9d
6 changed files with 83 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/target

7
Cargo.lock generated Normal file
View File

@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "hexdump"
version = "0.1.0"

6
Cargo.toml Normal file
View File

@@ -0,0 +1,6 @@
[package]
name = "hexdump"
version = "0.1.0"
edition = "2024"
[dependencies]

3
example.txt Normal file
View File

@@ -0,0 +1,3 @@
forsen is bald
forsen is bald
forsen is bald

36
src/hd_ai.rs Normal file
View File

@@ -0,0 +1,36 @@
use std::env;
use std::fs::File;
use std::io::{self, Read};
fn main() -> io::Result<()> {
// Get the file name from command line arguments
let args: Vec<String> = env::args().collect();
if args.len() < 2 {
eprintln!("Usage: {} <filename>", args[0]);
return Ok(());
}
let filename = &args[1];
// Open the file
let mut file = File::open(filename)?;
let mut buffer = Vec::new();
// Read the file into the buffer
file.read_to_end(&mut buffer)?;
// Print the hex dump
for (i, byte) in buffer.iter().enumerate() {
// Print the address
if i % 16 == 0 {
if i != 0 {
println!(); // New line after every 16 bytes
}
print!("{:08x} ", i);
}
// Print the byte in hex format
print!("{:02x} ", byte);
}
println!(); // Final new line
Ok(())
}

30
src/main.rs Normal file
View File

@@ -0,0 +1,30 @@
use std::env;
use std::fs;
fn main() {
let args: Vec<String> = env::args().collect();
if args.len() < 2 {
eprintln!("Usage: {} <file>", args[0]);
return;
}
let file_path = &args[1];
let contents = fs::read(file_path).expect("Failed to read file");
println!("File name: {file_path}\n");
println!("Contents of the file but in hex:");
hex(&contents);
}
fn hex(bytes: &[u8]) {
for (i, &byte) in bytes.iter().enumerate() {
if i % 8 == 0 {
print!("\n{:08x}: ", i);
}
print!("{:04x} ", byte);
}
println!();
}