fixed stupid bug

This commit is contained in:
Aviv "RustyStriker" Romem 2022-06-11 13:31:28 +03:00
parent 889812f505
commit 345f95b1ff

View file

@ -141,6 +141,7 @@ fn write_injection(s: &str, out: &mut File, inp: &mut File, cfolder: &str, cfile
else if s.contains(tag) { else if s.contains(tag) {
// We have the first tag but not the second, so we want to go back in the input file.. // We have the first tag but not the second, so we want to go back in the input file..
let (copy, keep) = s.split_once(tag).unwrap(); let (copy, keep) = s.split_once(tag).unwrap();
println!("Contains only tag\npre {}\n post {}", copy, keep);
out.write(copy.as_bytes()).unwrap(); out.write(copy.as_bytes()).unwrap();
// Return the length of whatever we just read and the tag length // Return the length of whatever we just read and the tag length
@ -148,14 +149,13 @@ fn write_injection(s: &str, out: &mut File, inp: &mut File, cfolder: &str, cfile
} }
else { else {
// Make sure we are not just cutting it in the middle // Make sure we are not just cutting it in the middle
let chars = tag.chars().collect::<Vec<_>>();
let mut wrote = false; let mut wrote = false;
for i in 1..chars.len() { for i in 1..tag.chars().count() {
if s.ends_with(&chars[..i]) { let slice = tag.get(..i).unwrap();
let back: usize = chars[..i].iter().map(|x| x.len_utf8()).sum(); if s.ends_with(slice) {
let to_write = s.replace(&chars[..i], ""); let back: usize = slice.len();
let to_write = s.replace(slice, "");
out.write(to_write.as_bytes()).unwrap(); out.write(to_write.as_bytes()).unwrap();
inp.seek(SeekFrom::Current(-1 * back as i64)).unwrap(); inp.seek(SeekFrom::Current(-1 * back as i64)).unwrap();
wrote = true; wrote = true;
break; break;