pub struct StructReader(/* private fields */);Expand description
A handler for reading structured data from guest memory.
Provides safe access to structured data (like C structs) read from guest memory, with proper bounds checking and endianness handling. It reads the data as a byte buffer and provides methods to safely access fields at specific offsets and sizes.
§Examples
offsets! {
#[derive(Debug)]
pub struct Offsets {
struct _UNICODE_STRING {
Length: Field, // USHORT
MaximumLength: Field, // USHORT
Buffer: Field, // PWSTR
}
}
}
let offsets = Offsets::new(profile)?;
let UNICODE_STRING = &offsets._UNICODE_STRING;
// Read the structure from memory.
let us = StructReader::new(vmi, va, UNICODE_STRING.effective_len())?;
// Access the field values.
let length = us.read(UNICODE_STRING.Length)?;
let buffer = us.read(UNICODE_STRING.Buffer)?;
Implementations§
Source§impl StructReader
impl StructReader
Sourcepub fn new<Os>(
vmi: &VmiState<'_, Os>,
va: Va,
len: usize,
) -> Result<Self, VmiError>
pub fn new<Os>( vmi: &VmiState<'_, Os>, va: Va, len: usize, ) -> Result<Self, VmiError>
Creates a new structure reader.
Reads len bytes from the guest memory at the specified address into
a new StructReader instance. The data can then be accessed using the
read method with appropriate field descriptors.
Sourcepub fn new_in<Driver>(
vmi: &VmiCore<Driver>,
ctx: impl Into<AccessContext>,
len: usize,
) -> Result<Self, VmiError>where
Driver: VmiRead,
pub fn new_in<Driver>(
vmi: &VmiCore<Driver>,
ctx: impl Into<AccessContext>,
len: usize,
) -> Result<Self, VmiError>where
Driver: VmiRead,
Creates a new structure reader.
Reads len bytes from the guest memory at the specified address into
a new StructReader instance. The data can then be accessed using the
read method with appropriate field descriptors.
Sourcepub fn read(&self, field: Field) -> Result<u64, VmiError>
pub fn read(&self, field: Field) -> Result<u64, VmiError>
Reads a field value from the data buffer.
Extracts a value from the buffer using the provided field descriptor,
which specifies the offset and size of the field.
The value is interpreted as a little-endian integer of the appropriate
size and returned as a u64.
§Endianness
Values are always read as little-endian integers. The returned u64
will contain the zero-extended value.
Auto Trait Implementations§
impl Freeze for StructReader
impl RefUnwindSafe for StructReader
impl Send for StructReader
impl Sync for StructReader
impl Unpin for StructReader
impl UnsafeUnpin for StructReader
impl UnwindSafe for StructReader
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.