[][src]Trait memflow::mem::phys_mem::PhysicalMemory

pub trait PhysicalMemory where
    Self: Send
{ fn phys_read_raw_list(
        &mut self,
        data: &mut [PhysicalReadData<'_>]
    ) -> Result<()>;
fn phys_write_raw_list(
        &mut self,
        data: &[PhysicalWriteData<'_>]
    ) -> Result<()>;
fn metadata(&self) -> PhysicalMemoryMetadata; fn phys_read_raw_into(
        &mut self,
        addr: PhysicalAddress,
        out: &mut [u8]
    ) -> Result<()> { ... }
fn phys_read_into<T: Pod + ?Sized>(
        &mut self,
        addr: PhysicalAddress,
        out: &mut T
    ) -> Result<()>
    where
        Self: Sized
, { ... }
fn phys_read_raw(
        &mut self,
        addr: PhysicalAddress,
        len: usize
    ) -> Result<Vec<u8>> { ... }
fn phys_read<T: Pod + Sized>(&mut self, addr: PhysicalAddress) -> Result<T>
    where
        Self: Sized
, { ... }
fn phys_write_raw(
        &mut self,
        addr: PhysicalAddress,
        data: &[u8]
    ) -> Result<()> { ... }
fn phys_write<T: Pod + ?Sized>(
        &mut self,
        addr: PhysicalAddress,
        data: &T
    ) -> Result<()>
    where
        Self: Sized
, { ... }
fn phys_batcher(&mut self) -> PhysicalMemoryBatcher<'_, Self>
    where
        Self: Sized
, { ... } }

The PhysicalMemory trait is implemented by memory backends and provides a generic way to read and write from/to physical memory.

All addresses are of the type PhysicalAddress and can contain additional information about the page the address resides in. This information is usually only needed when implementing caches.

There are only 2 methods which are required to be implemented by the provider of this trait.

Examples

Implementing PhysicalMemory for a memory backend:

use std::vec::Vec;

use memflow::mem::{
    PhysicalMemory,
    PhysicalReadData,
    PhysicalWriteData,
    PhysicalMemoryMetadata
};

use memflow::types::PhysicalAddress;
use memflow::error::Result;

pub struct MemoryBackend {
    mem: Box<[u8]>,
}

impl PhysicalMemory for MemoryBackend {
    fn phys_read_raw_list(
        &mut self,
        data: &mut [PhysicalReadData]
    ) -> Result<()> {
        data
            .iter_mut()
            .for_each(|PhysicalReadData(addr, out)| out
                .copy_from_slice(&self.mem[addr.as_usize()..(addr.as_usize() + out.len())])
            );
        Ok(())
    }

    fn phys_write_raw_list(
        &mut self,
        data: &[PhysicalWriteData]
    ) -> Result<()> {
        data
            .iter()
            .for_each(|PhysicalWriteData(addr, data)| self
                .mem[addr.as_usize()..(addr.as_usize() + data.len())].copy_from_slice(data)
            );
        Ok(())
    }

    fn metadata(&self) -> PhysicalMemoryMetadata {
        PhysicalMemoryMetadata {
            size: self.mem.len(),
            readonly: false
        }
    }
}

Reading from PhysicalMemory:

use memflow::types::Address;
use memflow::mem::PhysicalMemory;

fn read<T: PhysicalMemory>(mem: &mut T) {
    let mut addr = 0u64;
    mem.phys_read_into(Address::from(0x1000).into(), &mut addr).unwrap();
    println!("addr: {:x}", addr);
}

Required methods

fn phys_read_raw_list(
    &mut self,
    data: &mut [PhysicalReadData<'_>]
) -> Result<()>

fn phys_write_raw_list(&mut self, data: &[PhysicalWriteData<'_>]) -> Result<()>

fn metadata(&self) -> PhysicalMemoryMetadata

Retrieve metadata about the physical memory

This function will return metadata about the underlying physical memory object, currently including address space size and read-only status.

Examples

use memflow::types::size;
use memflow::mem::PhysicalMemory;

let metadata = mem.metadata();

assert_eq!(metadata.size, size::mb(16));
assert_eq!(metadata.readonly, false);
Loading content...

Provided methods

fn phys_read_raw_into(
    &mut self,
    addr: PhysicalAddress,
    out: &mut [u8]
) -> Result<()>

fn phys_read_into<T: Pod + ?Sized>(
    &mut self,
    addr: PhysicalAddress,
    out: &mut T
) -> Result<()> where
    Self: Sized

fn phys_read_raw(
    &mut self,
    addr: PhysicalAddress,
    len: usize
) -> Result<Vec<u8>>

fn phys_read<T: Pod + Sized>(&mut self, addr: PhysicalAddress) -> Result<T> where
    Self: Sized

Safety

this function will overwrite the contents of 'obj' so we can just allocate an unitialized memory section. this function should only be used with [repr(C)] structs.

fn phys_write_raw(&mut self, addr: PhysicalAddress, data: &[u8]) -> Result<()>

fn phys_write<T: Pod + ?Sized>(
    &mut self,
    addr: PhysicalAddress,
    data: &T
) -> Result<()> where
    Self: Sized

fn phys_batcher(&mut self) -> PhysicalMemoryBatcher<'_, Self> where
    Self: Sized

Loading content...

Implementors

impl<'a, F: AsRef<MemoryMap<&'a [u8]>> + Send> PhysicalMemory for MappedPhysicalMemory<&'a [u8], F>[src]

impl<'a, F: AsRef<MemoryMap<&'a mut [u8]>> + Send> PhysicalMemory for MappedPhysicalMemory<&'a mut [u8], F>[src]

impl<'a, T: PhysicalMemory, Q: CacheValidator> PhysicalMemory for CachedMemoryAccess<'a, T, Q>[src]

impl<T: PhysicalMemory + ?Sized, P: DerefMut<Target = T> + Send> PhysicalMemory for P[src]

impl<T: Seek + Read + Write + Send> PhysicalMemory for FileIOMemory<T>[src]

Loading content...