Skip to main content

ProcessMemoryBuffer

Struct ProcessMemoryBuffer 

Source
pub struct ProcessMemoryBuffer<'a>(/* private fields */);
Available on crate feature process-memory only.
Expand description

A owned buffer in the memory space of a (remote) process.

Implementations§

Source§

impl<'a> ProcessMemoryBuffer<'a>

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source

pub fn into_raw_parts(self) -> (*mut u8, usize, BorrowedProcess<'a>)

Constructs a new buffer from the given raw parts.

Source

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.

Source

pub fn leak(self) -> ProcessMemorySlice<'a>

Leaks the buffer and returns a ProcessMemorySlice spanning this buffer.

Source

pub fn as_slice(&self) -> &ProcessMemorySlice<'a>

Constructs a new slice spanning the whole buffer.

Source

pub fn as_mut_slice(&mut self) -> &mut ProcessMemorySlice<'a>

Constructs a new mutable slice spanning the whole buffer.

Source

pub fn free(self) -> Result<(), (Self, Error)>

Frees the buffer.

Source

pub fn os_page_size() -> usize

Returns the memory page size of the operating system.

Methods from Deref<Target = ProcessMemorySlice<'a>>§

Source

pub fn is_local(&self) -> bool

Returns whether the memory is allocated in the current process.

Source

pub fn is_remote(&self) -> bool

Returns whether the memory is allocated in another process.

Source

pub fn process(&self) -> BorrowedProcess<'a>

Returns the process the buffer is allocated in.

Source

pub fn len(&self) -> usize

Returns the length of the buffer.

Source

pub fn is_empty(&self) -> bool

Returns whether the buffer is empty.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn slice(&self, bounds: impl RangeBounds<usize>) -> Self

Returns a slice of this buffer.

Source

pub fn as_local_slice(&self) -> Option<&[u8]>

Constructs a new slice spanning the whole buffer.

Source

pub fn as_local_slice_mut(&mut self) -> Option<&mut [u8]>

Constructs a new mutable slice spanning the whole buffer.

Source

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>

Source§

fn as_mut(&mut self) -> &mut ProcessMemorySlice<'a>

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<'a> AsRef<ProcessMemorySlice<'a>> for ProcessMemoryBuffer<'a>

Source§

fn as_ref(&self) -> &ProcessMemorySlice<'a>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'a> Debug for ProcessMemoryBuffer<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Deref for ProcessMemoryBuffer<'a>

Source§

type Target = ProcessMemorySlice<'a>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &ProcessMemorySlice<'a>

Dereferences the value.
Source§

impl<'a> DerefMut for ProcessMemoryBuffer<'a>

Source§

fn deref_mut(&mut self) -> &mut ProcessMemorySlice<'a>

Mutably dereferences the value.
Source§

impl Drop for ProcessMemoryBuffer<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<'a> !Send for ProcessMemoryBuffer<'a>

Available on Windows only.
§

impl<'a> !Sync for ProcessMemoryBuffer<'a>

Available on Windows only.
§

impl<'a> Freeze for ProcessMemoryBuffer<'a>

Available on Windows only.
§

impl<'a> RefUnwindSafe for ProcessMemoryBuffer<'a>

Available on Windows only.
§

impl<'a> Unpin for ProcessMemoryBuffer<'a>

Available on Windows only.
§

impl<'a> UnsafeUnpin for ProcessMemoryBuffer<'a>

Available on Windows only.
§

impl<'a> UnwindSafe for ProcessMemoryBuffer<'a>

Available on Windows only.

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Available on Windows only.
Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Available on Windows only.
Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Available on Windows only.
Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> DropFlavorWrapper<T> for T

Available on Windows only.
Source§

type Flavor = MayDrop

The DropFlavor that wraps T into Self
Source§

impl<T> From<T> for T

Available on Windows only.
Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Available on Windows only.
Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> Identity for T
where T: ?Sized,

Available on Windows only.
Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Available on Windows only.
Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Available on Windows only.
Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Available on Windows only.
Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Available on Windows only.
Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.