From 889812f505ca216f8b644a4ac1bb1eefa9cafaac Mon Sep 17 00:00:00 2001 From: "Aviv \"RustyStriker\" Romem" Date: Sat, 11 Jun 2022 13:05:25 +0300 Subject: [PATCH] readme usage --- README.md | 11 ++++++++++- src/main.rs | 21 +++++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 18a35a6..bfc172d 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,12 @@ # command_injector -Simple command injector for html files(also copies them to a different folder, maintaining the original files!) \ No newline at end of file +Simple command injector for html files(also copies them to a different folder, maintaining the original files!) + +## Usage + +Simply put a `%COMMAND%` in your html files, +and it will copy all other files(except hidden ones). + +then compile using `cargo run -- from_dir to_dir [-r]` + +or directly calling the compiled bin `injector from_dir to_dor [-r]` \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 5f034d8..a15a60e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -64,7 +64,13 @@ fn inject_file(file: &Path, output: &Path) { } match from_utf8(&buf[..len]) { Ok(s) => { - write_injection(s, &mut out, &mut inp, file.parent().unwrap().as_os_str().to_str().unwrap()); + write_injection( + s, + &mut out, + &mut inp, + file.parent().unwrap().as_os_str().to_str().unwrap(), + file.file_name().unwrap().to_str().unwrap(), + ); }, Err(e) => { if e.valid_up_to() == 0 { @@ -74,7 +80,13 @@ fn inject_file(file: &Path, output: &Path) { let s = unsafe { from_utf8_unchecked(&buf[..e.valid_up_to()]) }; inp.seek(SeekFrom::Current(-1 * (len - e.valid_up_to()) as i64)).unwrap(); - write_injection(s, &mut out, &mut inp, file.parent().unwrap().as_os_str().to_str().unwrap()); + write_injection( + s, + &mut out, + &mut inp, + file.parent().unwrap().as_os_str().to_str().unwrap(), + file.file_name().unwrap().to_str().unwrap(), + ); }, } @@ -99,7 +111,7 @@ fn inject_file(file: &Path, output: &Path) { out.flush().expect(&format!("Cannot flush file {:?}", output.as_os_str())); } -fn write_injection(s: &str, out: &mut File, inp: &mut File, cfolder: &str) { +fn write_injection(s: &str, out: &mut File, inp: &mut File, cfolder: &str, cfile: &str) { let tag : &str = ""; let ctag : &str = ""; @@ -115,6 +127,7 @@ fn write_injection(s: &str, out: &mut File, inp: &mut File, cfolder: &str) { .arg(com) .env("HOME", unsafe { &HOME_DIR }) .env("CURRENT", cfolder) + .env("FILE", cfile) .output(); let com = match com { @@ -123,7 +136,7 @@ fn write_injection(s: &str, out: &mut File, inp: &mut File, cfolder: &str) { }; out.write(com.as_bytes()).unwrap(); - write_injection(post, out, inp, cfolder); + write_injection(post, out, inp, cfolder, cfile); } else if s.contains(tag) { // We have the first tag but not the second, so we want to go back in the input file..