pub trait MemoryRegion: Debug {
    fn address_range(&self) -> Range<u64>;
fn read_slice(&self, address_range: Range<u64>) -> Option<&[u8]>;
fn bytes(&self) -> MemoryRegionIterator<'_>Notable traits for MemoryRegionIterator<'a>impl<'a> Iterator for MemoryRegionIterator<'a> type Item = u8;;
unsafe fn copy_from_memory(&mut self, data_ptr: *const u8, data_len: usize); fn read_u8(&self, address: u64) -> Option<u8> { ... }
fn read_u32(&self, address: u64, endianness: RunTimeEndian) -> Option<u32> { ... } }
Expand description

A collection of bytes that capture a memory region

Required methods

The address range of the region where the start is the first address that the region captures

Returns the slice of memory that can be found at the given address_range. If the given address range is not fully within the captured region, then None is returned.

Get a byte iterator for this region.

This iterator can be used to store the region as bytes or to stream over a network. The iterated bytes include the length so that if you use the FromIterator implementation, it consumes only the bytes that are part of the collection. This means you can chain multiple of these iterators after each other.

use arrayvec::ArrayVec;
use stackdump_core::memory_region::{ArrayMemoryRegion, MemoryRegion};

let region1 = ArrayMemoryRegion::<4>::new(0, ArrayVec::from([1, 2, 3, 4]));
let region2 = ArrayMemoryRegion::<4>::new(100, ArrayVec::from([5, 6, 7, 8]));

let mut intermediate_buffer = Vec::new();

intermediate_buffer.extend(region1.bytes());
intermediate_buffer.extend(region2.bytes());

let mut intermediate_iter = intermediate_buffer.iter();

assert_eq!(region1, ArrayMemoryRegion::<4>::from_iter(&mut intermediate_iter));
assert_eq!(region2, ArrayMemoryRegion::<4>::from_iter(&mut intermediate_iter));

Clears the existing memory data and copies the new data from the given pointer

If the data_len is greater than the capacity of this memory region, then this function will panic.

Safety

The entire block of memory from data_ptr .. data_ptr + data_len must be readable. (A memcpy must be possible with the pointer as source)

Provided methods

Reads a byte from the given address if it is present in the region

Reads a u32 from the given address if it is present in the region

Implementors