pub struct MemoryRegion { /* private fields */ }Expand description
A description of a memory region spanning any given address range with information about its start address, its access permissions (i.e. whether it’s readable, writable, and/or executable), and whether or not it’s shared or private.
You can obtain an iterator over all of a processes’ memory
regions using the RamInspector::regions method.
Implementations§
Source§impl MemoryRegion
impl MemoryRegion
Sourcepub fn get_contents(
&self,
inspector: &mut RamInspector,
) -> Result<Vec<u8>, RamInspectError>
pub fn get_contents( &self, inspector: &mut RamInspector, ) -> Result<Vec<u8>, RamInspectError>
Attempts to read the contents of the memory region. This fails if the memory region is not readable, and may spuriously fail if the memory region is shared (in which case you should always handle errors).
Sourcepub fn start_addr(&self) -> usize
pub fn start_addr(&self) -> usize
Gets the start address of the memory region.
Sourcepub fn end_addr(&self) -> usize
pub fn end_addr(&self) -> usize
Gets the end address of the memory region. This is equivalent to adding the length to the start address.
Checks if the memory region is shared.
Sourcepub fn writable(&self) -> bool
pub fn writable(&self) -> bool
Checks if the memory region is writable.
Examples found in repository?
48 fn inspect_process(pid: i32, search_term: &str, replacement_term: &str) -> Result<(), RamInspectError> {
49 unsafe {
50 let mut inspector = RamInspector::new(pid)?;
51 for (result_addr, memory_region) in inspector.search_for_term(search_term.as_bytes())? {
52 if !memory_region.writable() {
53 continue;
54 }
55
56 inspector.queue_write(result_addr, replacement_term.as_bytes());
57 }
58
59 inspector.flush().unwrap();
60 }
61
62 Ok(())
63 }More examples
8fn main() {
9 use raminspect::RamInspector;
10 // Iterate over all running Firefox instances
11 for pid in raminspect::find_processes("/usr/lib/firefox/firefox") {
12 let mut inspector = match RamInspector::new(pid) {
13 Ok(inspector) => inspector,
14 Err(_) => continue,
15 };
16
17 for (proc_addr, memory_region) in inspector.search_for_term(b"Old search text").unwrap() {
18 if !memory_region.writable() {
19 continue;
20 }
21
22 unsafe {
23 // This is safe because modifying the text in the Firefox search bar will not crash
24 // the browser or negatively impact system stability in any way.
25
26 println!("Writing to process virtual address: 0x{:X}", proc_addr);
27 inspector.queue_write(proc_addr, b"New search text");
28 }
29 }
30
31 unsafe {
32 // This is safe since the process is not currently resumed, which would possibly cause a data race.
33 inspector.flush().unwrap();
34 }
35 }
36}Sourcepub fn executable(&self) -> bool
pub fn executable(&self) -> bool
Checks if the memory region is executable.
Sourcepub fn is_readwrite(&self) -> bool
pub fn is_readwrite(&self) -> bool
Checks whether or not the memory region is both readable and writable.
Trait Implementations§
Source§impl Clone for MemoryRegion
impl Clone for MemoryRegion
Source§fn clone(&self) -> MemoryRegion
fn clone(&self) -> MemoryRegion
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more