Struct process_memory::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
sourceimpl<T: Sized + Copy> DataMember<T>
impl<T: Sized + Copy> DataMember<T>
sourcepub fn new(handle: ProcessHandle) -> Self
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.
sourcepub fn new_offset(handle: ProcessHandle, offsets: Vec<usize>) -> Self
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
sourceimpl<T: Clone> Clone for DataMember<T>
impl<T: Clone> Clone for DataMember<T>
sourcefn clone(&self) -> DataMember<T>
fn clone(&self) -> DataMember<T>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresourceimpl<T: Debug> Debug for DataMember<T>
impl<T: Debug> Debug for DataMember<T>
sourceimpl<T: Sized + Copy> Memory<T> for DataMember<T>
impl<T: Sized + Copy> Memory<T> for DataMember<T>
sourcefn set_offset(&mut self, new_offsets: Vec<usize>)
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 moresourcefn get_offset(&self) -> Result<usize>
fn get_offset(&self) -> Result<usize>
Gets the actual total offset from the offsets given by
Memory::set_offset
. Read moresourceunsafe fn read(&self) -> Result<T>
unsafe fn read(&self) -> Result<T>
Reads the value of the pointer from the offsets given by
Memory::set_offset
. Read moreAuto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more