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>
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§
Source§impl<T: Clone> Clone for DataMember<T>
impl<T: Clone> Clone for DataMember<T>
Source§fn clone(&self) -> DataMember<T>
fn clone(&self) -> DataMember<T>
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<T: Debug> Debug for DataMember<T>
impl<T: Debug> Debug for DataMember<T>
Source§impl<T: Sized + Copy> Memory<T> for DataMember<T>
impl<T: Sized + Copy> Memory<T> for DataMember<T>
Source§fn 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 moreSource§fn 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 moreAuto 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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more