Skip to content

Commit fb459a5

Browse files
committed
feat: inject strings to eof
1 parent b916d3e commit fb459a5

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

README.rst

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
Hex_Manipulation
22
=========================================================
33

4-
Introduction
4+
Introduction::
55
------------
66

77
Hex Manipulation like the one used in the `cicadia 3301` puzzle on 4chan.
88

9-
What is Hex Manipulation?
9+
What is Hex Manipulation?::
1010
--------------------------
1111

1212
Hex manipulation is the process of converting data from one format to another using hexadecimal 'notation'.
1313
hexadecimal representation is not obsfucation, but data can be hidden in a file (typically at the end of the file) and then extracted using hex manipulation.
1414

1515
--------------------------
1616

17-
To build this project on windows, you will need to install the following:
17+
To build this project on windows, you will need to install the following::
1818

1919
* [Rust](https://www.rust-lang.org/tools/install)
2020
* And it's dependencies.
@@ -23,4 +23,13 @@ run the following command in the root directory of the project:
2323

2424
1) `cargo build --release`
2525

26-
The resulting binary will be located in `target/release/`
26+
The resulting binary will be located in `target/release/`
27+
28+
--------------------------
29+
Usage::
30+
31+
1) `hex_manipulation.exe` to run the binary.
32+
2) Drag and drop a file onto your terminal to open said file.
33+
3) Once the file is done loading, you will be prompted to enter an input.
34+
4) Press enter to exit the program, feel free to check the output file yourself to see if it worked.
35+
--------------------------

src/main.rs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
// rust cli tool to read files and print their hex values
22
use colored::Colorize;
33
use std::env;
4-
use hex::FromHex;
4+
use std::io::Write;
5+
use hex;
56
use std::fs::File;
67
use std::io::{BufReader, Read};
78

89
extern crate colored;
910

1011
fn main() {
12+
env::set_var("RUST_BACKTRACE", "1");
1113
println!("{}","\t\tHex Editor".bold().bright_green());
1214
println!("{}","\t\tby editor99".bold().bright_green());
1315
println!("{}","\t\t\nDrag & Drop a file to open it.".blue());
@@ -16,11 +18,11 @@ fn main() {
1618
let mut file_path = String::new();
1719
std::io::stdin().read_line(&mut file_path).expect("Error reading file path");
1820
file_path = file_path.trim().to_string();
19-
let file = File::open(file_path).expect("File not found");
21+
let file = File::open(file_path.clone()).expect("File not found");
2022
let mut reader = BufReader::new(file);
2123
let mut buffer = Vec::new();
2224
reader.read_to_end(&mut buffer).expect("Error reading file");
23-
let hex_string = hex::encode(buffer);
25+
let hex_string = hex::encode(buffer.clone());
2426
let bytes = hex::decode(&hex_string).unwrap();
2527

2628
// print hex values in a grid
@@ -49,8 +51,28 @@ fn main() {
4951
println!("File size: {} bytes", bytes.len().to_string().bright_yellow());
5052

5153
// write to file
52-
54+
// get user input for hex string to inject
55+
println!("{}","\n\nEnter hex string to inject (without spaces):".blue());
56+
let mut hex_string = String::new();
57+
std::io::stdin().read_line(&mut hex_string).expect("Error reading hex string");
58+
// hex_string to hex bytes
59+
let hex_string = hex::encode(hex_string.trim().as_bytes());
60+
61+
// decode hex string to bytes and append to buffer
62+
let injected_bytes = hex::decode(&hex_string).expect("Error decoding hex string");
63+
buffer.extend(injected_bytes);
64+
65+
// write buffer to file
66+
let mut file = File::create(&file_path).expect("Error creating file");
67+
file.write_all(&buffer).expect("Error writing to file");
5368

69+
// print file size and exit message
70+
println!("File size: {} bytes", buffer.len().to_string().bright_yellow());
5471
println!("{}","Press Enter to exit.".bold().bright_green());
5572
let mut exit = String::new();
73+
std::io::stdin().read_line(&mut exit).expect("Error reading exit input");
74+
75+
76+
println!("{}","Press Enter to exit.".bold().bright_green());
77+
let exit = String::new();
5678
}

0 commit comments

Comments
 (0)