|
|
|
@ -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 = "<INJECT>";
|
|
|
|
|
let ctag : &str = "</INJECT>";
|
|
|
|
|
|
|
|
|
@ -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..
|
|
|
|
|