Struct memflow::mem::mem_map::MemoryMap

source ·
pub struct MemoryMap<M> { /* private fields */ }
Expand description

The MemoryMapstruct provides a mechanism to map addresses from the linear address space that memflow uses internally to hardware specific memory regions.

All memory addresses will be bounds checked.

Examples

use memflow::prelude::{MemoryMap, CTup2, umem};

let mut map = MemoryMap::new();
map.push_remap(0x1000.into(), 0x1000, 0.into());      // push region from 0x1000 - 0x1FFF
map.push_remap(0x3000.into(), 0x1000, 0x2000.into()); // push region from 0x3000 - 0x3FFFF

println!("{:?}", map);

// handle unmapped memory regions
let failed = &mut |CTup2(a, b)| {
    println!("Unmapped: {} {}", a, b);
    true
};

let hw_addr = map.map(0x10ff.into(), 8 as umem, Some(failed));

Implementations§

source§

impl<M: SplitAtIndex> MemoryMap<M>

source

pub fn new() -> Self

Constructs a new memory map.

This function is identical to MemoryMap::default().

source

pub fn is_empty(&self) -> bool

source

pub fn iter(&self) -> impl Iterator<Item = &MemoryMapping<M>>

Iterator over memory mappings

source

pub fn map<'a, T: 'a + SplitAtIndex, V: Callbackable<CTup2<Address, T>>>( &'a self, addr: Address, buf: T, out_fail: Option<&'a mut V> ) -> impl Iterator<Item = CTup3<M, Address, T>> + 'a

Maps a linear address range to a hardware address range.

Output element lengths will both match, so there is no need to do additonal clipping (for buf-to-buf copies).

Invalid regions get pushed to the out_fail parameter. This function requries self

source

pub fn map_base_iter<'a, T: 'a + SplitAtIndex, I: 'a + Iterator<Item = CTup3<Address, Address, T>>, V: Callbackable<CTup2<Address, T>>>( &'a self, iter: I, out_fail: Option<&'a mut V> ) -> MemoryMapIterator<'a, I, M, T, V>

Maps a address range iterator to an address range.

Output element lengths will both match, so there is no need to do additonal clipping (for buf-to-buf copies).

Invalid regions get pushed to the out_fail parameter

source

pub fn map_iter<'a, T: 'a + SplitAtIndex, I: 'a + Iterator<Item = CTup3<PhysicalAddress, Address, T>>, V: Callbackable<CTup2<Address, T>>>( &'a self, iter: I, out_fail: Option<&'a mut V> ) -> MemoryMapIterator<'a, impl Iterator<Item = CTup3<Address, Address, T>> + 'a, M, T, V>

Maps a address range iterator to a hardware address range.

Output element lengths will both match, so there is no need to do additonal clipping (for buf-to-buf copies).

Invalid regions get pushed to the out_fail parameter

source

pub fn push(&mut self, base: Address, output: M) -> &mut Self

Adds a new memory mapping to this memory map.

When adding overlapping memory regions this function will panic!

source§

impl MemoryMap<(Address, umem)>

source

pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>

Constructs a new memory map by parsing the mapping table from a TOML file.

The file must contain a mapping table in the following format:

[[range]]
base=0x1000
length=0x1000

[[range]]
base=0x2000
length=0x1000
real_base=0x3000

The real_base parameter is optional. If it is not set there will be no re-mapping.

source

pub fn max_address(&self) -> Address

Returns the highest memory address that can be read.

source

pub fn real_size(&self) -> umem

source

pub fn push_remap( &mut self, base: Address, size: umem, real_base: Address ) -> &mut Self

Adds a new memory mapping to this memory map by specifying base address and size of the mapping.

When adding overlapping memory regions this function will panic!

source

pub fn push_range( &mut self, base: Address, end: Address, real_base: Address ) -> &mut Self

Adds a new memory mapping to this memory map by specifying a range (base address and end addresses) of the mapping.

When adding overlapping memory regions this function will panic!

If end < base, the function will do nothing

source

pub unsafe fn into_bufmap_mut<'a>(self) -> MemoryMap<&'a mut [u8]>

Transform address mapping into mutable buffer mapping

It will take the output address-size pair, and create mutable slice references to them.

Safety

The address mappings must be valid for the given lifetime 'a, and should not be aliased by any other memory references for fully defined behaviour.

However, aliasing should be fine for volatile memory cases such as analyzing running VM, since there are no safety guarantees anyways.

source

pub unsafe fn into_bufmap<'a>(self) -> MemoryMap<&'a [u8]>

Transform address mapping buffer buffer mapping

It will take the output address-size pair, and create slice references to them.

Safety

The address mappings must be valid for the given lifetime 'a.

source

pub fn into_vec(self) -> Vec<PhysicalMemoryMapping>

source

pub fn from_vec(mem_map: Vec<PhysicalMemoryMapping>) -> Self

Trait Implementations§

source§

impl<'a> AsRef<MemoryMap<&'a [u8]>> for MmapInfo<'a>

source§

fn as_ref(&self) -> &MemoryMap<&'a [u8]>

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

impl<'a> AsRef<MemoryMap<&'a mut [u8]>> for MmapInfoMut<'a>

source§

fn as_ref(&self) -> &MemoryMap<&'a mut [u8]>

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

impl<M> AsRef<MemoryMap<M>> for MemoryMap<M>

source§

fn as_ref(&self) -> &Self

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

impl<M: Clone> Clone for MemoryMap<M>

source§

fn clone(&self) -> MemoryMap<M>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<M> Debug for MemoryMap<M>
where MemoryMapping<M>: Debug,

source§

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

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

impl<M: SplitAtIndex> Default for MemoryMap<M>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<M: SplitAtIndex> IntoIterator for MemoryMap<M>

§

type Item = (Address, M)

The type of the elements being iterated over.
§

type IntoIter = Map<IntoIter<MemoryMapping<M>>, fn(_: MemoryMapping<M>) -> <MemoryMap<M> as IntoIterator>::Item>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<M> !RefUnwindSafe for MemoryMap<M>

§

impl<M> Send for MemoryMap<M>
where M: Send,

§

impl<M> !Sync for MemoryMap<M>

§

impl<M> Unpin for MemoryMap<M>
where M: Unpin,

§

impl<M> UnwindSafe for MemoryMap<M>
where M: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<'a, T> BorrowOwned<'a> for T
where T: 'a + Clone,

§

type ROwned = T

The owned type, stored in RCow::Owned
§

type RBorrowed = &'a T

The borrowed type, stored in RCow::Borrowed
source§

fn r_borrow( this: &'a <T as BorrowOwned<'a>>::ROwned ) -> <T as BorrowOwned<'a>>::RBorrowed

source§

fn r_to_owned( this: <T as BorrowOwned<'a>>::RBorrowed ) -> <T as BorrowOwned<'a>>::ROwned

source§

fn deref_borrowed(this: &<T as BorrowOwned<'a>>::RBorrowed) -> &T

source§

fn deref_owned(this: &<T as BorrowOwned<'a>>::ROwned) -> &T

source§

fn from_cow_borrow(this: &'a T) -> <T as BorrowOwned<'a>>::RBorrowed

source§

fn from_cow_owned(this: <T as ToOwned>::Owned) -> <T as BorrowOwned<'a>>::ROwned

source§

fn into_cow_borrow(this: <T as BorrowOwned<'a>>::RBorrowed) -> &'a T

source§

fn into_cow_owned(this: <T as BorrowOwned<'a>>::ROwned) -> <T as ToOwned>::Owned

source§

impl<I, T> FeedCallback<T> for I
where I: IntoIterator<Item = T>,

source§

fn feed_into_mut(self, callback: &mut OpaqueCallback<'_, T>) -> usize

source§

fn feed_into(self, callback: OpaqueCallback<'_, T>) -> usize
where Self: Sized,

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, F> From2<T> for F
where T: Into<F>,

source§

fn from2(other: T) -> F

source§

impl<T> GetWithMetadata for T

§

type ForSelf = WithMetadata_<T, T>

This is always WithMetadata_<Self, Self>
source§

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

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.

§

impl<S> ROExtAcc for S

§

fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F

Gets a reference to a field, determined by offset. Read more
§

fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F

Gets a muatble reference to a field, determined by offset. Read more
§

fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F

Gets a const pointer to a field, the field is determined by offset. Read more
§

fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F

Gets a mutable pointer to a field, determined by offset. Read more
§

impl<S> ROExtOps<Aligned> for S

§

fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F

Replaces a field (determined by offset) with value, returning the previous value of the field. Read more
§

fn f_swap<F>(&mut self, offset: FieldOffset<S, F, Aligned>, right: &mut S)

Swaps a field (determined by offset) with the same field in right. Read more
§

fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> F
where F: Copy,

Gets a copy of a field (determined by offset). The field is determined by offset. Read more
§

impl<S> ROExtOps<Unaligned> for S

§

fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F

Replaces a field (determined by offset) with value, returning the previous value of the field. Read more
§

fn f_swap<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, right: &mut S)

Swaps a field (determined by offset) with the same field in right. Read more
§

fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> F
where F: Copy,

Gets a copy of a field (determined by offset). The field is determined by offset. Read more
§

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

§

fn eq_id(&self, other: &Self) -> bool

Compares the address of self with the address of other. Read more
§

fn piped<F, U>(self, f: F) -> U
where F: FnOnce(Self) -> U, Self: Sized,

Emulates the pipeline operator, allowing method syntax in more places. Read more
§

fn piped_ref<'a, F, U>(&'a self, f: F) -> U
where F: FnOnce(&'a Self) -> U,

The same as piped except that the function takes &Self Useful for functions that take &Self instead of Self. Read more
§

fn piped_mut<'a, F, U>(&'a mut self, f: F) -> U
where F: FnOnce(&'a mut Self) -> U,

The same as piped, except that the function takes &mut Self. Useful for functions that take &mut Self instead of Self.
§

fn mutated<F>(self, f: F) -> Self
where F: FnOnce(&mut Self), Self: Sized,

Mutates self using a closure taking self by mutable reference, passing it along the method chain. Read more
§

fn observe<F>(self, f: F) -> Self
where F: FnOnce(&Self), Self: Sized,

Observes the value of self, passing it along unmodified. Useful in long method chains. Read more
§

fn into_<T>(self) -> T
where Self: Into<T>,

Performs a conversion with Into. using the turbofish .into_::<_>() syntax. Read more
§

fn as_ref_<T>(&self) -> &T
where Self: AsRef<T>, T: ?Sized,

Performs a reference to reference conversion with AsRef, using the turbofish .as_ref_::<_>() syntax. Read more
§

fn as_mut_<T>(&mut self) -> &mut T
where Self: AsMut<T>, T: ?Sized,

Performs a mutable reference to mutable reference conversion with AsMut, using the turbofish .as_mut_::<_>() syntax. Read more
§

fn drop_(self)
where Self: Sized,

Drops self using method notation. Alternative to std::mem::drop. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<This> TransmuteElement for This
where This: ?Sized,

source§

unsafe fn transmute_element<T>(self) -> Self::TransmutedPtr
where Self: CanTransmuteElement<T>,

Transmutes the element type of this pointer.. Read more
source§

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

§

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>,

§

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.
§

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

§

type Type = T

This is always Self.
§

fn into_type(self) -> Self::Type
where Self: Sized, Self::Type: Sized,

Converts a value back to the original type.
§

fn as_type(&self) -> &Self::Type

Converts a reference back to the original type.
§

fn as_type_mut(&mut self) -> &mut Self::Type

Converts a mutable reference back to the original type.
§

fn into_type_box(self: Box<Self>) -> Box<Self::Type>

Converts a box back to the original type.
§

fn into_type_arc(this: Arc<Self>) -> Arc<Self::Type>

Converts an Arc back to the original type. Read more
§

fn into_type_rc(this: Rc<Self>) -> Rc<Self::Type>

Converts an Rc back to the original type. Read more
§

fn from_type(this: Self::Type) -> Self
where Self: Sized, Self::Type: Sized,

Converts a value back to the original type.
§

fn from_type_ref(this: &Self::Type) -> &Self

Converts a reference back to the original type.
§

fn from_type_mut(this: &mut Self::Type) -> &mut Self

Converts a mutable reference back to the original type.
§

fn from_type_box(this: Box<Self::Type>) -> Box<Self>

Converts a box back to the original type.
§

fn from_type_arc(this: Arc<Self::Type>) -> Arc<Self>

Converts an Arc back to the original type.
§

fn from_type_rc(this: Rc<Self::Type>) -> Rc<Self>

Converts an Rc back to the original type.