1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use super::OwnedProcess;
use windows::Win32::System::Memory::PAGE_PROTECTION_FLAGS;
#[derive(Debug)]
pub struct MemoryRegion {
pub start: usize,
pub end: usize,
pub size: usize,
pub protection: PAGE_PROTECTION_FLAGS,
pub initial: PAGE_PROTECTION_FLAGS,
}
pub struct MemoryRegionIter<'a> {
proc: &'a OwnedProcess,
current: usize,
}
impl<'a> MemoryRegionIter<'a> {
pub fn new(proc: &'a OwnedProcess) -> Self {
Self { current: 0, proc }
}
}
impl<'a> Iterator for MemoryRegionIter<'a> {
type Item = MemoryRegion;
fn next(&mut self) -> Option<Self::Item> {
let mut chunk = self.proc.query_memory(self.current).ok()?;
while chunk.state.0 == 0x10000 {
self.current = chunk.base_address + chunk.region_size;
chunk = self.proc.query_memory(self.current).ok()?;
}
let region = MemoryRegion {
start: chunk.base_address,
end: chunk.base_address + chunk.region_size,
size: chunk.region_size,
protection: chunk.protection,
initial: chunk.alloc_protection,
};
self.current = chunk.base_address + chunk.region_size;
Some(region)
}
}