implement find_str and find_str_backwards

This commit is contained in:
mykola2312 2023-08-26 17:34:54 +03:00
parent e698b825f6
commit 22fee005cd
2 changed files with 10 additions and 3 deletions

View file

@ -25,10 +25,15 @@ impl Raw {
search.search_in(&self.mem[offset..])
}
pub fn find_all_str(&self, str: &str) -> Vec<usize> {
let mut offsets: Vec<usize> = Vec::new();
pub fn find_str_backwards(&self, str: &str) -> Option<usize> {
for i in (0..self.mem.len()-str.len()).step_by(1024).rev() {
match self.find_str(str, i) {
Some(offset) => return Some(i+offset),
None => continue
};
}
offsets
None
}
pub fn assemble_file(&self, path: &Path, blocks: Vec<Raw>) -> Result<()> {

View file

@ -80,6 +80,8 @@ impl Save {
pub fn save(&self, path: &Path) -> Result<()> {
let raw = Raw { offset: 0, size: self.raw.len(), mem: self.raw.clone() };
println!("found world at {:x}", raw.find_str_backwards("<world>").unwrap());
const START: usize = 0x99A84;
const END: usize = 0xD1B1E; //0xD1B1E;