Struct processes::memory::ProcessMemorySlice
source · pub struct ProcessMemorySlice<'a> { /* private fields */ }
memory
only.Expand description
A unowned slice of a buffer in the memory space of a 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
- can be read using
ReadProcessMemory
- can be written to using
WriteProcessMemory
- will live as long as the slice is used
sourcepub fn is_local(&self) -> bool
pub fn is_local(&self) -> bool
Returns whether this slice is in the memory space of the current process.
sourcepub fn is_remote(&self) -> bool
pub fn is_remote(&self) -> bool
Returns whether this slice is in the memory space of another process.
sourcepub const fn process(&self) -> BorrowedProcess<'a>
pub const fn process(&self) -> BorrowedProcess<'a>
Returns the process that owns the memory of this slice.
sourcepub fn read(&self, buf: &mut [u8]) -> Result<(), ProcessError>
pub fn read(&self, buf: &mut [u8]) -> Result<(), ProcessError>
Copies the contents of this slice to the given local buffer.
Panics
This function will panic if this slice is smaller than the given buffer.
sourcepub unsafe fn read_struct<T: Copy>(&self) -> Result<T, ProcessError>
pub unsafe fn read_struct<T: Copy>(&self) -> Result<T, ProcessError>
sourcepub fn write(&self, buf: &[u8]) -> Result<(), ProcessError>
pub fn write(&self, buf: &[u8]) -> Result<(), ProcessError>
Copies the contents of the given local buffer to this slice.
Panics
This function will panic if the size of the local buffer exceeds this slice’s length.
sourcepub fn write_buf<T: Copy>(&self, buf: &[T]) -> Result<(), ProcessError>
pub fn write_buf<T: Copy>(&self, buf: &[T]) -> Result<(), ProcessError>
Copies the contents of the given local buffer to the memory region of this slice.
Panics
This function will panic if the size of the local buffer exceeds this slice’s length.
sourcepub fn write_struct<T: ?Sized + Copy>(&self, s: &T) -> Result<(), ProcessError>
pub fn write_struct<T: ?Sized + Copy>(&self, s: &T) -> Result<(), ProcessError>
Writes a value of type T
to the start of this slice.
Panics
This function will panic if the value’s size 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 this slice.
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 new slice spanning a subregion of this slice.
sourcepub fn as_local_slice(&self) -> Option<&[u8]>
pub fn as_local_slice(&self) -> Option<&[u8]>
Constructs a new local slice spanning the memory of this slice. This function will return None for remote memory slices.
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 memory of this slice. This function will return None for remote memory slices.
sourcepub fn flush_instruction_cache(&self) -> Result<(), ProcessError>
pub fn flush_instruction_cache(&self) -> Result<(), ProcessError>
Flushes the CPU instruction cache for the whole slice.
This may be necesary if the memory 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 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more