pub trait Memory<T> {
    fn set_offset(&mut self, new_offsets: Vec<usize>);
    fn get_offset(&self) -> Result<usize>;
    unsafe fn read(&self) -> Result<T>;
    fn write(&self, value: &T) -> Result<()>;
}
Expand description

A trait that refers to and allows writing to a region of memory in a running program.

Required Methods

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>.

For those sorts of data structures, to access data you need to go via multiple pointers, so that if an inner region reallocates its size, the variable that is being modified will be correctly modified.

Gets the actual total offset from the offsets given by Memory::set_offset.

This function is safe because it should never internally allow for a null pointer deference, and instead should return a std::io::Error with a std::io::ErrorKind of Other.

Errors

Returns an error if copying memory fails or if a null pointer dereference would otherwise occur.

Reads the value of the pointer from the offsets given by Memory::set_offset.

This function should never internally allow for a null pointer deference, and instead should return a std::io::Error with a std::io::ErrorKind of Other.

Safety

This function is marked as unsafe as it may cause undefined behavior.

The function will attempt to read a T from uncontrolled memory, and so may produce an invalid value (e.g. a value of 2 for a bool, which is undefined. The caller must ensure that the data being read is valid for a T, or should get an equivalent integer representation and check the bit pattern themselves.

Errors

Returns an error if copying memory fails or if a null pointer dereference would otherwise occur.

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

This function is safe because it should never internally allow for a null pointer deference, and instead should return a std::io::Error with a std::io::ErrorKind of Other.

This function takes a reference instead of taking ownership so if the caller passes in a String or a Vec, it does not have to be cloned.

Errors

Returns an error if copying memory fails or if a null pointer dereference would otherwise occur.

Implementors