pub struct ProcessMemorySlice<'a> { /* private fields */ }process-memory only.Expand description
A unowned slice of a buffer in the memory space of a (remote) process.
Implementations§
Source§impl<'a> ProcessMemorySlice<'a>
impl<'a> ProcessMemorySlice<'a>
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 slice from the given raw parts.
§Safety
The caller must ensure that the designated region of memory
- is valid
- was allocated using
VirtualAllocEx - can be read using
ReadProcessMemory - can be written to using
WriteProcessMemory - will live as long as the slice is used
Sourcepub const fn process(&self) -> BorrowedProcess<'a>
pub const 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 const fn as_ptr(&self) -> *mut u8
pub const 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.
Trait Implementations§
Source§impl<'a> AsMut<ProcessMemorySlice<'a>> for ProcessMemoryBuffer<'a>
impl<'a> AsMut<ProcessMemorySlice<'a>> for ProcessMemoryBuffer<'a>
Source§fn as_mut(&mut self) -> &mut ProcessMemorySlice<'a>
fn as_mut(&mut self) -> &mut ProcessMemorySlice<'a>
Source§impl<'a> AsRef<ProcessMemorySlice<'a>> for ProcessMemoryBuffer<'a>
impl<'a> AsRef<ProcessMemorySlice<'a>> for ProcessMemoryBuffer<'a>
Source§fn as_ref(&self) -> &ProcessMemorySlice<'a>
fn as_ref(&self) -> &ProcessMemorySlice<'a>
Source§impl<'a> Clone for ProcessMemorySlice<'a>
impl<'a> Clone for ProcessMemorySlice<'a>
Source§fn clone(&self) -> ProcessMemorySlice<'a>
fn clone(&self) -> ProcessMemorySlice<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more