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

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.

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

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
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
Gets the actual total offset from the offsets given by Memory::set_offset. Read more
Reads the value of the pointer from the offsets given by Memory::set_offset. Read more
Writes value to the pointer from the offsets given by Memory::set_offset. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.