Struct DataMember

Source
pub struct DataMember<T> { /* private fields */ }
Expand description

§Tools for working with memory of other programs

This module provides functions for modifying the memory of a program from outside of the address space of that program.

Examples:

// We have a variable with some value
let x = 4u32;
println!("Original x-value: {}", x);

// We need to make sure that we get a handle to a process, in this case, ourselves
let handle = (std::process::id() as Pid).try_into_process_handle().unwrap();
// We make a `DataMember` that has an offset referring to its location in memory
let member = DataMember::new_offset(handle, vec![&x as *const _ as usize]);
// The memory refered to is now the same
println!("Memory location: &x: {}, member: {}", &x as *const _ as usize,
    member.get_offset().unwrap());
assert_eq!(&x as *const _ as usize, member.get_offset().unwrap());
// The value of the member is the same as the variable
println!("Member value: {}", unsafe { member.read().unwrap() });
assert_eq!(x, unsafe { member.read().unwrap() });
// We can write to and modify the value of the variable using the member
member.write(&6u32).unwrap();
println!("New x-value: {}", x);
assert_eq!(x, 6u32);

Implementations§

Source§

impl<T: Sized + Copy> DataMember<T>

Source

pub fn new(handle: ProcessHandle) -> Self

Create a new DataMember from a ProcessHandle. You must remember to call try_into_process_handle on a Pid, because the types may have the same backing type, resulting in errors when called with the wrong value.

By default, there will be no offsets, leading to an error when attempting to call Memory::read, so you will likely need to call Memory::set_offset before attempting any reads.

Source

pub fn new_offset(handle: ProcessHandle, offsets: Vec<usize>) -> Self

Create a new DataMember from a ProcessHandle and some number of offsets. You must remember to call try_into_process_handle on a Pid as sometimes the Pid can have the same backing type as a ProcessHandle, resulting in an error.

Trait Implementations§

Source§

impl<T: Clone> Clone for DataMember<T>

Source§

fn clone(&self) -> DataMember<T>

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<T: Debug> Debug for DataMember<T>

Source§

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

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

impl<T: Sized + Copy> Memory<T> for DataMember<T>

Source§

fn set_offset(&mut self, new_offsets: Vec<usize>)

Set the offsets to the location in memory. This is used for things such as multi-level pointers, such as a Vec<Vec<T>> or a Vec<String>. Read more
Source§

fn get_offset(&self) -> Result<usize>

Gets the actual total offset from the offsets given by Memory::set_offset. Read more
Source§

unsafe fn read(&self) -> Result<T>

Reads the value of the pointer from the offsets given by Memory::set_offset. Read more
Source§

fn write(&self, value: &T) -> Result<()>

Writes value to the pointer from the offsets given by Memory::set_offset. Read more

Auto Trait Implementations§

§

impl<T> Freeze for DataMember<T>

§

impl<T> RefUnwindSafe for DataMember<T>
where T: RefUnwindSafe,

§

impl<T> !Send for DataMember<T>

§

impl<T> !Sync for DataMember<T>

§

impl<T> Unpin for DataMember<T>

§

impl<T> UnwindSafe for DataMember<T>
where T: RefUnwindSafe,

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.