implement find_str and find_str_backwards
This commit is contained in:
parent
e698b825f6
commit
22fee005cd
2 changed files with 10 additions and 3 deletions
|
|
@ -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<()> {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue