ProcessMemory

Struct ProcessMemory 

Source
pub struct ProcessMemory { /* private fields */ }

Implementations§

Source§

impl ProcessMemory

Source

pub fn attach_process(pid: u32) -> Option<ProcessMemory>

Source

pub fn new_process( file_name: &str, arguments: &Vec<String>, ) -> Option<ProcessMemory>

This spawns a process suspended and has to be manually resumed via public self.resume()

On Linux, this creates a new process via fork() which maps to clone(2) depending on libc ptrace the fork and replace the current image with a new one in create_reference_process

On Windows, this calls CreateProcess with the flag CREATE_SUSPENDED

On macOS, this calls posix_spawn(2) with the flag POSIX_SPAWN_START_SUSPENDED

Accepts a file path, as well as arguments to the new process

Source

pub fn write_memory(&self, _address: usize, data: &Vec<u8>, offset: bool)

Write the buffer (vector, identifier: data) at the address in the process

If the offset bool is set to true, then only an offset is given to this function, relative to the first mapping/module in the process.

Example, the first module is loaded at 0x00400000

offset is set to true, and _address = 5

Memory would be written at 0x00400005

If offset is false, it takes an immediate - direct address.

Source

pub fn read_memory(&self, _address: usize, size: usize, offset: bool) -> Vec<u8>

Read memory from the process and return a vector. If the offset bool is set to true, then only an offset is given to this function, relative to the first mapping/module in the process.

Example, the first module is loaded at 0x00400000

offset is set to true,

and _address = 5

Memory would be read from 0x00400005

If offset is false, it takes an immediate - direct address.

For example, _address = 0x00400005

Source

pub fn resume(&self)

Resume the process by resuming the first thread (Windows) or sending a continue signal (Unix)

Source

pub fn base(&self) -> usize

Retrieve the first mapping/module loaded into memory for the process

Source

pub fn kill(&self)

Kill the process by sending a forceful SIGKILL or via TerminateProcess

Source

pub fn pid(&self) -> u32

Get the process ID

Source

pub fn raw_descriptor(&self) -> usize

Retrieve a raw handle/task port, or the PID for Linux as ptrace(2) does not use file descriptors

Source

pub fn early_close(&mut self)

This will close the handles/task ports or detach from a ptrace(2) session, making the ProcessMemory object effectively useless with the exception of retaining data.

Trait Implementations§

Source§

impl Drop for ProcessMemory

Source§

fn drop(&mut self)

Executes the destructor for this type. 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> 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, 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.