MemoryRegion

Struct MemoryRegion 

Source
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

Source

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).

Source

pub fn start_addr(&self) -> usize

Gets the start address of the memory region.

Source

pub fn len(&self) -> usize

Gets the length of the memory region.

Source

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.

Source

pub fn readable(&self) -> bool

Checks if the memory region is readable.

Source

pub fn shared(&self) -> bool

Checks if the memory region is shared.

Source

pub fn writable(&self) -> bool

Checks if the memory region is writable.

Examples found in repository?
examples/replacemem.rs (line 52)
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
Hide additional examples
examples/firefox_search.rs (line 18)
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}
Source

pub fn executable(&self) -> bool

Checks if the memory region is executable.

Source

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

Source§

fn clone(&self) -> MemoryRegion

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MemoryRegion

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.