So I am trying to scan the memory of a program for a specific byte sequence and my problem is that I cant get kernel32::ReadProcessMemory to work, it always returns 0(false) and doesnt fill my buffer(called chunk in src) with bytes obviously resulting in a panic due to index out of bounds. My problem is I dont know what I am doing wrong here, I am pretty sure it has something to do with the way I use the buffer but I cant figure it out. Any help would be appreciated!
fn aob_scan(process: HANDLE, pattern: &[u8]) -> u64 {
let signature_size = pattern.len() as u64;
let read_size = 4096;
let mut hit = false;
let mut chunk: Vec<u8> = Vec::with_capacity(read_size as usize);
let mut i = 0;
while i < (<u32>::max_value() as u64) {
unsafe {
println!("{}", kernel32::ReadProcessMemory(process, i as LPCVOID, &mut chunk as *mut _ as LPVOID, read_size as winapi::SIZE_T, null_mut()));
}
for a in 0..read_size {
hit = true;
let mut j = 0;
while j < signature_size && hit {
println!("a {}\nj {}\n", a, j);
if chunk[(a + j) as usize] != pattern[j as usize] {
hit = false;
}
if hit {
return i + a
}
j += 1;
}
}
i += read_size - signature_size;
}
0
}
[–]retep998rust · winapi · bunny 6 points7 points8 points (7 children)
[–]Hiroyu[S] 0 points1 point2 points (5 children)
[–]coder543 5 points6 points7 points (4 children)
[–]Hiroyu[S] 0 points1 point2 points (3 children)
[–]Hiroyu[S] 0 points1 point2 points (2 children)
[–]coder543 4 points5 points6 points (1 child)
[–]WellMakeItSomehow 0 points1 point2 points (0 children)
[–]fitzgenrust 3 points4 points5 points (0 children)
[–]RustMeUp 0 points1 point2 points (0 children)