pub struct ProcessMemoryBuffer<'a>(/* private fields */);process-memory only.Expand description
A owned buffer in the memory space of a (remote) process.
Implementations§
Source§impl<'a> ProcessMemoryBuffer<'a>
impl<'a> ProcessMemoryBuffer<'a>
Sourcepub fn allocate(process: BorrowedProcess<'a>, len: usize) -> Result<Self, Error>
pub fn allocate(process: BorrowedProcess<'a>, len: usize) -> Result<Self, Error>
Allocates a new buffer of the given length in the given process. Both data and code can be stored in the buffer.
Sourcepub fn allocate_page(process: BorrowedProcess<'a>) -> Result<Self, Error>
pub fn allocate_page(process: BorrowedProcess<'a>) -> Result<Self, Error>
Allocates a new buffer with the size of a memory page in the given process.
Sourcepub fn allocate_data(
process: BorrowedProcess<'a>,
len: usize,
) -> Result<Self, Error>
pub fn allocate_data( process: BorrowedProcess<'a>, len: usize, ) -> Result<Self, Error>
Allocates a new data buffer of the given length in the given process.
Sourcepub fn allocate_data_page(process: BorrowedProcess<'a>) -> Result<Self, Error>
pub fn allocate_data_page(process: BorrowedProcess<'a>) -> Result<Self, Error>
Allocates a new data buffer with the size of a memory page in the given process.
Sourcepub fn allocate_code(
process: BorrowedProcess<'a>,
len: usize,
) -> Result<Self, Error>
pub fn allocate_code( process: BorrowedProcess<'a>, len: usize, ) -> Result<Self, Error>
Allocates a new codea buffer of the given length in the given process.
Sourcepub fn allocate_code_page(process: BorrowedProcess<'a>) -> Result<Self, Error>
pub fn allocate_code_page(process: BorrowedProcess<'a>) -> Result<Self, Error>
Allocates a new code buffer with the size of a memory page in the given process.
Sourcepub fn allocate_for<T>(process: BorrowedProcess<'a>) -> Result<Self, Error>
pub fn allocate_for<T>(process: BorrowedProcess<'a>) -> Result<Self, Error>
Allocates a new buffer with enough space to store a value of type T in the given process.
Sourcepub fn allocate_and_write<T: ?Sized>(
process: BorrowedProcess<'a>,
s: &T,
) -> Result<Self, Error>
pub fn allocate_and_write<T: ?Sized>( process: BorrowedProcess<'a>, s: &T, ) -> Result<Self, Error>
Allocates a new buffer with enough space to store a value of type T in the given process.
Sourcepub const unsafe fn from_raw_parts(
ptr: *mut u8,
len: usize,
process: BorrowedProcess<'a>,
) -> Self
pub const unsafe fn from_raw_parts( ptr: *mut u8, len: usize, process: BorrowedProcess<'a>, ) -> Self
Constructs a new buffer from the given raw parts.
§Safety
The caller must ensure that the designated region of memory
- is valid
- was allocated using
VirtualAllocEx - can be deallocated using
VirtualFreeEx - can be read using
ReadProcessMemory - can be written to using
WriteProcessMemory - will not be deallocated by other code
Sourcepub fn into_raw_parts(self) -> (*mut u8, usize, BorrowedProcess<'a>)
pub fn into_raw_parts(self) -> (*mut u8, usize, BorrowedProcess<'a>)
Constructs a new buffer from the given raw parts.
Sourcepub fn into_dangling_local_slice(self) -> Result<&'static mut [u8], Self>
pub fn into_dangling_local_slice(self) -> Result<&'static mut [u8], Self>
Leaks the buffer and returns the underlying memory slice if the buffer is allocated in the current process.
Sourcepub fn leak(self) -> ProcessMemorySlice<'a>
pub fn leak(self) -> ProcessMemorySlice<'a>
Leaks the buffer and returns a ProcessMemorySlice spanning this buffer.
Sourcepub fn as_slice(&self) -> &ProcessMemorySlice<'a>
pub fn as_slice(&self) -> &ProcessMemorySlice<'a>
Constructs a new slice spanning the whole buffer.
Sourcepub fn as_mut_slice(&mut self) -> &mut ProcessMemorySlice<'a>
pub fn as_mut_slice(&mut self) -> &mut ProcessMemorySlice<'a>
Constructs a new mutable slice spanning the whole buffer.
Sourcepub fn os_page_size() -> usize
pub fn os_page_size() -> usize
Returns the memory page size of the operating system.
Methods from Deref<Target = ProcessMemorySlice<'a>>§
Sourcepub fn process(&self) -> BorrowedProcess<'a>
pub fn process(&self) -> BorrowedProcess<'a>
Returns the process the buffer is allocated in.
Sourcepub fn read(&self, offset: usize, buf: &mut [u8]) -> Result<(), Error>
pub fn read(&self, offset: usize, buf: &mut [u8]) -> Result<(), Error>
Copies the contents of this buffer starting from the given offset to the given local buffer.
§Panics
This function will panic if the given offset plus the given buffer length exceeds this buffer’s length.
Sourcepub unsafe fn read_struct<T>(&self, offset: usize) -> Result<T, Error>
pub unsafe fn read_struct<T>(&self, offset: usize) -> Result<T, Error>
Reads a value of type T from this buffer starting from the given offset.
§Panics
This function will panic if the given offset plus the size of the value exceeds this buffer’s length.
§Safety
The caller must ensure that the designated region of memory contains a valid instance of type T at the given offset.
Sourcepub fn write(&self, offset: usize, buf: &[u8]) -> Result<(), Error>
pub fn write(&self, offset: usize, buf: &[u8]) -> Result<(), Error>
Copies the contents of the given local buffer to this buffer at the given offset.
§Panics
This function will panic if the given offset plus the size of the local buffer exceeds this buffer’s length.
Sourcepub fn write_struct<T: ?Sized>(&self, offset: usize, s: &T) -> Result<(), Error>
pub fn write_struct<T: ?Sized>(&self, offset: usize, s: &T) -> Result<(), Error>
Writes a value of type T to this buffer at the given offset.
§Panics
This function will panic if the given offset plus the given buffer length exceeds this buffer’s length.
Sourcepub fn as_ptr(&self) -> *mut u8
pub fn as_ptr(&self) -> *mut u8
Returns a pointer to the start of the buffer.
§Note
The returned pointer is only valid in the target process.
Sourcepub fn slice(&self, bounds: impl RangeBounds<usize>) -> Self
pub fn slice(&self, bounds: impl RangeBounds<usize>) -> Self
Returns a slice of this buffer.
Sourcepub fn as_local_slice(&self) -> Option<&[u8]>
pub fn as_local_slice(&self) -> Option<&[u8]>
Constructs a new slice spanning the whole buffer.
Sourcepub fn as_local_slice_mut(&mut self) -> Option<&mut [u8]>
pub fn as_local_slice_mut(&mut self) -> Option<&mut [u8]>
Constructs a new mutable slice spanning the whole buffer.
Sourcepub fn flush_instruction_cache(&self) -> Result<(), Error>
pub fn flush_instruction_cache(&self) -> Result<(), Error>
Flushes the CPU instruction cache for the whole buffer.
This may be necesary if the buffer is used to store dynamically generated code. For details see FlushInstructionCache.