Struct MapRange

Source
pub struct MapRange {
    pub offset: usize,
    pub dev: String,
    pub flags: String,
    pub inode: usize,
    /* private fields */
}
Expand description

A struct representing a single virtual memory region.

While this structure is only for Linux, the macOS, Windows, and FreeBSD variants have identical exposed methods

Fields§

§offset: usize§dev: String§flags: String§inode: usize

Implementations§

Source§

impl MapRange

Source

pub fn size(&self) -> usize

Returns the size of this MapRange in bytes

Examples found in repository?
examples/print_maps.rs (line 26)
3fn main() {
4    let args: Vec<String> = std::env::args().collect();
5
6    let pid = if args.len() > 1 {
7        args[1].parse().expect("invalid pid")
8    } else {
9        panic!("Usage: print_maps <PID>");
10    };
11
12    println!(
13        "{:^30} {:^16} {:^7} {}",
14        "ADDRESSES", "SIZE", "MODES", "PATH"
15    );
16
17    let empty_path = std::path::Path::new("");
18    let maps = proc_maps::get_process_maps(pid).expect("failed to get proc maps");
19    for map in maps {
20        let r_flag = if map.is_read() { "R" } else { "-" };
21        let w_flag = if map.is_write() { "W" } else { "-" };
22        let x_flag = if map.is_exec() { "X" } else { "-" };
23        let filename = map.filename().unwrap_or(empty_path).to_str().unwrap_or("-");
24        println!(
25            "{:>30} {:>16} [{} {} {}] {}",
26            format!("{:#x}-{:#x}", map.start(), map.start() + map.size()),
27            map.size(),
28            r_flag,
29            w_flag,
30            x_flag,
31            filename,
32        );
33    }
34}
Source

pub fn start(&self) -> usize

Returns the address this MapRange starts at

Examples found in repository?
examples/print_maps.rs (line 26)
3fn main() {
4    let args: Vec<String> = std::env::args().collect();
5
6    let pid = if args.len() > 1 {
7        args[1].parse().expect("invalid pid")
8    } else {
9        panic!("Usage: print_maps <PID>");
10    };
11
12    println!(
13        "{:^30} {:^16} {:^7} {}",
14        "ADDRESSES", "SIZE", "MODES", "PATH"
15    );
16
17    let empty_path = std::path::Path::new("");
18    let maps = proc_maps::get_process_maps(pid).expect("failed to get proc maps");
19    for map in maps {
20        let r_flag = if map.is_read() { "R" } else { "-" };
21        let w_flag = if map.is_write() { "W" } else { "-" };
22        let x_flag = if map.is_exec() { "X" } else { "-" };
23        let filename = map.filename().unwrap_or(empty_path).to_str().unwrap_or("-");
24        println!(
25            "{:>30} {:>16} [{} {} {}] {}",
26            format!("{:#x}-{:#x}", map.start(), map.start() + map.size()),
27            map.size(),
28            r_flag,
29            w_flag,
30            x_flag,
31            filename,
32        );
33    }
34}
Source

pub fn filename(&self) -> Option<&Path>

Returns the filename of the loaded module

Examples found in repository?
examples/print_maps.rs (line 23)
3fn main() {
4    let args: Vec<String> = std::env::args().collect();
5
6    let pid = if args.len() > 1 {
7        args[1].parse().expect("invalid pid")
8    } else {
9        panic!("Usage: print_maps <PID>");
10    };
11
12    println!(
13        "{:^30} {:^16} {:^7} {}",
14        "ADDRESSES", "SIZE", "MODES", "PATH"
15    );
16
17    let empty_path = std::path::Path::new("");
18    let maps = proc_maps::get_process_maps(pid).expect("failed to get proc maps");
19    for map in maps {
20        let r_flag = if map.is_read() { "R" } else { "-" };
21        let w_flag = if map.is_write() { "W" } else { "-" };
22        let x_flag = if map.is_exec() { "X" } else { "-" };
23        let filename = map.filename().unwrap_or(empty_path).to_str().unwrap_or("-");
24        println!(
25            "{:>30} {:>16} [{} {} {}] {}",
26            format!("{:#x}-{:#x}", map.start(), map.start() + map.size()),
27            map.size(),
28            r_flag,
29            w_flag,
30            x_flag,
31            filename,
32        );
33    }
34}
Source

pub fn is_exec(&self) -> bool

Returns whether this range contains executable code

Examples found in repository?
examples/print_maps.rs (line 22)
3fn main() {
4    let args: Vec<String> = std::env::args().collect();
5
6    let pid = if args.len() > 1 {
7        args[1].parse().expect("invalid pid")
8    } else {
9        panic!("Usage: print_maps <PID>");
10    };
11
12    println!(
13        "{:^30} {:^16} {:^7} {}",
14        "ADDRESSES", "SIZE", "MODES", "PATH"
15    );
16
17    let empty_path = std::path::Path::new("");
18    let maps = proc_maps::get_process_maps(pid).expect("failed to get proc maps");
19    for map in maps {
20        let r_flag = if map.is_read() { "R" } else { "-" };
21        let w_flag = if map.is_write() { "W" } else { "-" };
22        let x_flag = if map.is_exec() { "X" } else { "-" };
23        let filename = map.filename().unwrap_or(empty_path).to_str().unwrap_or("-");
24        println!(
25            "{:>30} {:>16} [{} {} {}] {}",
26            format!("{:#x}-{:#x}", map.start(), map.start() + map.size()),
27            map.size(),
28            r_flag,
29            w_flag,
30            x_flag,
31            filename,
32        );
33    }
34}
Source

pub fn is_write(&self) -> bool

Returns whether this range contains writeable memory

Examples found in repository?
examples/print_maps.rs (line 21)
3fn main() {
4    let args: Vec<String> = std::env::args().collect();
5
6    let pid = if args.len() > 1 {
7        args[1].parse().expect("invalid pid")
8    } else {
9        panic!("Usage: print_maps <PID>");
10    };
11
12    println!(
13        "{:^30} {:^16} {:^7} {}",
14        "ADDRESSES", "SIZE", "MODES", "PATH"
15    );
16
17    let empty_path = std::path::Path::new("");
18    let maps = proc_maps::get_process_maps(pid).expect("failed to get proc maps");
19    for map in maps {
20        let r_flag = if map.is_read() { "R" } else { "-" };
21        let w_flag = if map.is_write() { "W" } else { "-" };
22        let x_flag = if map.is_exec() { "X" } else { "-" };
23        let filename = map.filename().unwrap_or(empty_path).to_str().unwrap_or("-");
24        println!(
25            "{:>30} {:>16} [{} {} {}] {}",
26            format!("{:#x}-{:#x}", map.start(), map.start() + map.size()),
27            map.size(),
28            r_flag,
29            w_flag,
30            x_flag,
31            filename,
32        );
33    }
34}
Source

pub fn is_read(&self) -> bool

Returns whether this range contains readable memory

Examples found in repository?
examples/print_maps.rs (line 20)
3fn main() {
4    let args: Vec<String> = std::env::args().collect();
5
6    let pid = if args.len() > 1 {
7        args[1].parse().expect("invalid pid")
8    } else {
9        panic!("Usage: print_maps <PID>");
10    };
11
12    println!(
13        "{:^30} {:^16} {:^7} {}",
14        "ADDRESSES", "SIZE", "MODES", "PATH"
15    );
16
17    let empty_path = std::path::Path::new("");
18    let maps = proc_maps::get_process_maps(pid).expect("failed to get proc maps");
19    for map in maps {
20        let r_flag = if map.is_read() { "R" } else { "-" };
21        let w_flag = if map.is_write() { "W" } else { "-" };
22        let x_flag = if map.is_exec() { "X" } else { "-" };
23        let filename = map.filename().unwrap_or(empty_path).to_str().unwrap_or("-");
24        println!(
25            "{:>30} {:>16} [{} {} {}] {}",
26            format!("{:#x}-{:#x}", map.start(), map.start() + map.size()),
27            map.size(),
28            r_flag,
29            w_flag,
30            x_flag,
31            filename,
32        );
33    }
34}

Trait Implementations§

Source§

impl Clone for MapRange

Source§

fn clone(&self) -> MapRange

Returns a copy 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 MapRange

Source§

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

Formats the value using the given formatter. Read more
Source§

impl PartialEq for MapRange

Source§

fn eq(&self, other: &MapRange) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for MapRange

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.