Struct LocalMember

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

This struct provides functions for modifying the memory of a program from within the address space of that program. This may be helpful for debug functions, or for an injected DLL.

§Examples:

// We have a variable with some value
let x = 4u32;

// We make a `LocalMember` that has an offset referring to its location in memory
let member = LocalMember::new_offset(vec![&x as *const _ as usize]);
// The memory refered to is now the same
assert_eq!(&x as *const _ as usize, member.get_offset().unwrap());
// The value of the member is the same as the variable
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();
assert_eq!(x, 6u32);

§Safety

These functions are technically not safe. Do not attempt to read or write to any local memory that you do not know is correct. If you’re trying to explore your entire address space or are testing to see if a pointer is allocated to you, use DataMember with your own PID.

Unfortunately it’s not possible to implement some traits safely (e.g. Memory on DataMember but implement it on other structures unsafely in Rust.

The implemented functions try to stop you from shooting yourself in the foot by checking none of the pointers end up at the null pointer, but this does not guarantee that you won’t be able to mess something up really badly in your program.

Implementations§

Source§

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

Source

pub fn new() -> Self

Creates a new LocalMember with no offsets. Any calls to Memory::read will attempt to read from a null pointer reference.

To set offsets, use Memory::set_offsetoffset), or create the LocalMember using new_offset.

Source

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

Create a new LocalMember with a given set of offsets.

Trait Implementations§

Source§

impl<T: Clone> Clone for LocalMember<T>

Source§

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

Returns a duplicate 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 LocalMember<T>

Source§

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

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

impl<T: Default> Default for LocalMember<T>

Source§

fn default() -> LocalMember<T>

Returns the “default value” for a type. Read more
Source§

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

Source§

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

This will only return a error if one of the offsets gives a null pointer. or give a non-aligned read

Source§

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

This will only return a error if one of the offsets gives a null pointer.

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

Auto Trait Implementations§

§

impl<T> Freeze for LocalMember<T>

§

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

§

impl<T> !Send for LocalMember<T>

§

impl<T> !Sync for LocalMember<T>

§

impl<T> Unpin for LocalMember<T>

§

impl<T> UnwindSafe for LocalMember<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.