fixed stupid bug

This commit is contained in:
Aviv "RustyStriker" Romem 2022-06-11 13:31:28 +03:00
parent 889812f505
commit 345f95b1ff
1 changed files with 6 additions and 6 deletions

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) {
// 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();
println!("Contains only tag\npre {}\n post {}", copy, keep);
out.write(copy.as_bytes()).unwrap();
// 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 {
// Make sure we are not just cutting it in the middle
let chars = tag.chars().collect::<Vec<_>>();
let mut wrote = false;
for i in 1..chars.len() {
if s.ends_with(&chars[..i]) {
let back: usize = chars[..i].iter().map(|x| x.len_utf8()).sum();
let to_write = s.replace(&chars[..i], "");
for i in 1..tag.chars().count() {
let slice = tag.get(..i).unwrap();
if s.ends_with(slice) {
let back: usize = slice.len();
let to_write = s.replace(slice, "");
out.write(to_write.as_bytes()).unwrap();
inp.seek(SeekFrom::Current(-1 * back as i64)).unwrap();
wrote = true;
break;