[−][src]Trait memflow::mem::virt_mem::VirtualMemory
The VirtualMemory
trait implements access to virtual memory for a specific process
and provides a generic way to read and write from/to that processes virtual memory.
The CPU accesses virtual memory by setting the CR3 register to the appropiate Directory Table Base (DTB) for that process. The ntoskrnl.exe Kernel Process has it's own DTB. Using the DTB it is possible to resolve the physical memory location of a virtual address page. After the address has been resolved the physical memory page can then be read or written to.
There are 3 methods which are required to be implemented by the provider of this trait.
Examples
Reading from VirtualMemory
:
use memflow::types::Address; use memflow::mem::VirtualMemory; fn read<T: VirtualMemory>(virt_mem: &mut T, read_addr: Address) { let mut addr = 0u64; virt_mem.virt_read_into(read_addr, &mut addr).unwrap(); println!("addr: {:x}", addr); }
Required methods
fn virt_read_raw_list(
&mut self,
data: &mut [VirtualReadData<'_>]
) -> PartialResult<()>
&mut self,
data: &mut [VirtualReadData<'_>]
) -> PartialResult<()>
fn virt_write_raw_list(
&mut self,
data: &[VirtualWriteData<'_>]
) -> PartialResult<()>
&mut self,
data: &[VirtualWriteData<'_>]
) -> PartialResult<()>
fn virt_page_info(&mut self, addr: Address) -> Result<Page>
fn virt_translation_map_range(
&mut self,
start: Address,
end: Address
) -> Vec<(Address, usize, PhysicalAddress)>
&mut self,
start: Address,
end: Address
) -> Vec<(Address, usize, PhysicalAddress)>
fn virt_page_map_range(
&mut self,
gap_size: usize,
start: Address,
end: Address
) -> Vec<(Address, usize)>
&mut self,
gap_size: usize,
start: Address,
end: Address
) -> Vec<(Address, usize)>
Provided methods
fn virt_read_raw_into(
&mut self,
addr: Address,
out: &mut [u8]
) -> PartialResult<()>
&mut self,
addr: Address,
out: &mut [u8]
) -> PartialResult<()>
fn virt_read_into<T: Pod + ?Sized>(
&mut self,
addr: Address,
out: &mut T
) -> PartialResult<()> where
Self: Sized,
&mut self,
addr: Address,
out: &mut T
) -> PartialResult<()> where
Self: Sized,
fn virt_read_raw(&mut self, addr: Address, len: usize) -> PartialResult<Vec<u8>>
fn virt_read<T: Pod + Sized>(&mut self, addr: Address) -> PartialResult<T> where
Self: Sized,
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 virt_write_raw(&mut self, addr: Address, data: &[u8]) -> PartialResult<()>
fn virt_write<T: Pod + ?Sized>(
&mut self,
addr: Address,
data: &T
) -> PartialResult<()> where
Self: Sized,
&mut self,
addr: Address,
data: &T
) -> PartialResult<()> where
Self: Sized,
fn virt_translation_map(&mut self) -> Vec<(Address, usize, PhysicalAddress)>
fn virt_page_map(&mut self, gap_size: usize) -> Vec<(Address, usize)>
fn virt_read_addr32(&mut self, addr: Address) -> PartialResult<Address> where
Self: Sized,
Self: Sized,
fn virt_read_addr64(&mut self, addr: Address) -> PartialResult<Address> where
Self: Sized,
Self: Sized,
fn virt_read_addr_arch(
&mut self,
arch: ArchitectureObj,
addr: Address
) -> PartialResult<Address> where
Self: Sized,
&mut self,
arch: ArchitectureObj,
addr: Address
) -> PartialResult<Address> where
Self: Sized,
fn virt_read_ptr32_into<U: Pod + ?Sized>(
&mut self,
ptr: Pointer32<U>,
out: &mut U
) -> PartialResult<()> where
Self: Sized,
&mut self,
ptr: Pointer32<U>,
out: &mut U
) -> PartialResult<()> where
Self: Sized,
fn virt_read_ptr32<U: Pod + Sized>(
&mut self,
ptr: Pointer32<U>
) -> PartialResult<U> where
Self: Sized,
&mut self,
ptr: Pointer32<U>
) -> PartialResult<U> where
Self: Sized,
fn virt_read_ptr64_into<U: Pod + ?Sized>(
&mut self,
ptr: Pointer64<U>,
out: &mut U
) -> PartialResult<()> where
Self: Sized,
&mut self,
ptr: Pointer64<U>,
out: &mut U
) -> PartialResult<()> where
Self: Sized,
fn virt_read_ptr64<U: Pod + Sized>(
&mut self,
ptr: Pointer64<U>
) -> PartialResult<U> where
Self: Sized,
&mut self,
ptr: Pointer64<U>
) -> PartialResult<U> where
Self: Sized,
fn virt_read_cstr(&mut self, addr: Address, len: usize) -> PartialResult<String>
fn virt_batcher(&mut self) -> VirtualMemoryBatcher<'_, Self> where
Self: Sized,
Self: Sized,
Implementors
impl<T: PhysicalMemory, V: VirtualTranslate, D: ScopedVirtualTranslate> VirtualMemory for VirtualDMA<T, V, D>
[src]
fn virt_read_raw_list(
&mut self,
data: &mut [VirtualReadData<'_>]
) -> PartialResult<()>
[src]
&mut self,
data: &mut [VirtualReadData<'_>]
) -> PartialResult<()>
fn virt_write_raw_list(
&mut self,
data: &[VirtualWriteData<'_>]
) -> PartialResult<()>
[src]
&mut self,
data: &[VirtualWriteData<'_>]
) -> PartialResult<()>
fn virt_page_info(&mut self, addr: Address) -> Result<Page>
[src]
fn virt_translation_map_range(
&mut self,
start: Address,
end: Address
) -> Vec<(Address, usize, PhysicalAddress)>
[src]
&mut self,
start: Address,
end: Address
) -> Vec<(Address, usize, PhysicalAddress)>
fn virt_page_map_range(
&mut self,
gap_length: usize,
start: Address,
end: Address
) -> Vec<(Address, usize)>
[src]
&mut self,
gap_length: usize,
start: Address,
end: Address
) -> Vec<(Address, usize)>
impl<T: VirtualMemory + ?Sized, P: DerefMut<Target = T> + Send> VirtualMemory for P
[src]
fn virt_read_raw_list(
&mut self,
data: &mut [VirtualReadData<'_>]
) -> PartialResult<()>
[src]
&mut self,
data: &mut [VirtualReadData<'_>]
) -> PartialResult<()>
fn virt_write_raw_list(
&mut self,
data: &[VirtualWriteData<'_>]
) -> PartialResult<()>
[src]
&mut self,
data: &[VirtualWriteData<'_>]
) -> PartialResult<()>
fn virt_page_info(&mut self, addr: Address) -> Result<Page>
[src]
fn virt_translation_map_range(
&mut self,
start: Address,
end: Address
) -> Vec<(Address, usize, PhysicalAddress)>
[src]
&mut self,
start: Address,
end: Address
) -> Vec<(Address, usize, PhysicalAddress)>
fn virt_page_map_range(
&mut self,
gap_size: usize,
start: Address,
end: Address
) -> Vec<(Address, usize)>
[src]
&mut self,
gap_size: usize,
start: Address,
end: Address
) -> Vec<(Address, usize)>