pub struct MemoryCursor<T> { /* private fields */ }Expand description
MemoryCursor implments a Cursor around the MemoryView trait.
The cursor provides the Read,
Write and Seek traits
for the underlying MemoryView object.
§Examples:
use std::io::{self, Read, Write, Seek};
use memflow::dummy::{DummyOs, DummyMemory};
use memflow::types::size;
use memflow::mem::{DirectTranslate, VirtualDma, MemoryCursor};
use memflow::architecture::x86::x64;
fn main() -> io::Result<()> {
// setup a pseudo virtual memory reader
let phys_mem = DummyMemory::new(size::mb(16));
let mut os = DummyOs::new(phys_mem);
let (dtb, virt_base) = os.alloc_dtb(size::mb(8), &[]);
let phys_mem = os.into_inner();
let translator = x64::new_translator(dtb);
let virt_mem = VirtualDma::new(phys_mem, x64::ARCH, translator);
// create the actual cursor and seek it to the dummy virt_base
let mut cursor = MemoryCursor::new(virt_mem);
cursor.seek(io::SeekFrom::Start(virt_base.to_umem() as u64))?;
// read up to 10 bytes
let mut buffer = [0; 10];
cursor.read(&mut buffer)?;
// write the previously read 10 bytes again
cursor.seek(io::SeekFrom::Start(virt_base.to_umem() as u64))?;
cursor.write(&buffer)?;
Ok(())
}Implementations§
Source§impl<T: MemoryView> MemoryCursor<T>
impl<T: MemoryView> MemoryCursor<T>
Sourcepub fn new(mem: T) -> Self
pub fn new(mem: T) -> Self
Creates a new MemoryCursor by wrapping around a MemoryView object.
Cursor initial position is 0.
§Examples:
Borrowing a MemoryView object:
use memflow::dummy::DummyMemory;
use memflow::types::size;
use memflow::mem::MemoryCursor;
let mut virt_mem = VirtualDma::new(phys_mem, x64::ARCH, translator);
let mut cursor = MemoryCursor::new(virt_mem);Taking (temporary) ownership of a MemoryView object:
use memflow::dummy::DummyMemory;
use memflow::types::size;
use memflow::mem::MemoryCursor;
let virt_mem = VirtualDma::new(phys_mem, x64::ARCH, translator);
let mut cursor = MemoryCursor::new(virt_mem);Sourcepub fn at(mem: T, address: Address) -> Self
pub fn at(mem: T, address: Address) -> Self
Creates a new MemoryCursor by wrapping around a MemoryView object
at the desired starting position.
Cursor initial position is * address.
§Examples:
Borrowing a MemoryView object:
use memflow::dummy::DummyMemory;
use memflow::types::size;
use memflow::mem::MemoryCursor;
let mut virt_mem = VirtualDma::new(phys_mem, x64::ARCH, translator);
let mut cursor = MemoryCursor::at(virt_mem, 0x1000.into());Taking (temporary) ownership of a MemoryView object:
use memflow::dummy::DummyMemory;
use memflow::types::size;
use memflow::mem::MemoryCursor;
let virt_mem = VirtualDma::new(phys_mem, x64::ARCH, translator);
let mut cursor = MemoryCursor::at(virt_mem, 0x1000.into());Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consumes this cursor, returning the underlying MemoryView object.
§Examples
use memflow::dummy::DummyMemory;
use memflow::types::size;
use memflow::mem::MemoryCursor;
let mut cursor = MemoryCursor::new(VirtualDma::new(phys_mem, x64::ARCH, translator));
let phys_mem = cursor.into_inner();Sourcepub fn get_ref(&self) -> &T
pub fn get_ref(&self) -> &T
Gets a reference to the underlying MemoryView object in this cursor.
§Examples
use memflow::dummy::DummyMemory;
use memflow::types::size;
use memflow::mem::MemoryCursor;
let mut cursor = MemoryCursor::new(VirtualDma::new(phys_mem, x64::ARCH, translator));
let reference = cursor.get_ref();Sourcepub fn get_mut(&mut self) -> &mut T
pub fn get_mut(&mut self) -> &mut T
Gets a mutable reference to the underlying MemoryView object in this cursor.
§Examples
use memflow::dummy::DummyMemory;
use memflow::types::size;
use memflow::mem::MemoryCursor;
let mut cursor = MemoryCursor::new(VirtualDma::new(phys_mem, x64::ARCH, translator));
let reference = cursor.get_mut();Sourcepub fn address(&self) -> Address
pub fn address(&self) -> Address
Returns the current address of this cursor.
§Examples
use std::io::{Seek, SeekFrom};
use memflow::dummy::DummyMemory;
use memflow::types::{Address, size};
use memflow::mem::MemoryCursor;
let mut cursor = MemoryCursor::new(VirtualDma::new(phys_mem, x64::ARCH, translator));
assert_eq!(cursor.address(), Address::NULL);
cursor.seek(SeekFrom::Current(2)).unwrap();
assert_eq!(cursor.address(), Address::from(2));
cursor.seek(SeekFrom::Current(-1)).unwrap();
assert_eq!(cursor.address(), Address::from(1));Sourcepub fn set_address(&mut self, address: Address)
pub fn set_address(&mut self, address: Address)
Sets the address of this cursor.
§Examples
use memflow::dummy::DummyMemory;
use memflow::types::{Address, size};
use memflow::mem::MemoryCursor;
let mut cursor = MemoryCursor::new(VirtualDma::new(phys_mem, x64::ARCH, translator));
assert_eq!(cursor.address(), Address::NULL);
cursor.set_address(Address::from(2));
assert_eq!(cursor.address(), Address::from(2));
cursor.set_address(Address::from(4));
assert_eq!(cursor.address(), Address::from(4));Trait Implementations§
Source§impl<T: MemoryView> Read for MemoryCursor<T>
impl<T: MemoryView> Read for MemoryCursor<T>
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read moreSource§impl<T: MemoryView> Seek for MemoryCursor<T>
impl<T: MemoryView> Seek for MemoryCursor<T>
Source§fn seek(&mut self, pos: SeekFrom) -> Result<u64>
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
1.55.0 · Source§fn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
Source§fn stream_len(&mut self) -> Result<u64, Error>
fn stream_len(&mut self) -> Result<u64, Error>
seek_stream_len)Source§impl<T: MemoryView> Write for MemoryCursor<T>
impl<T: MemoryView> Write for MemoryCursor<T>
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)Auto Trait Implementations§
impl<T> Freeze for MemoryCursor<T>where
T: Freeze,
impl<T> RefUnwindSafe for MemoryCursor<T>where
T: RefUnwindSafe,
impl<T> Send for MemoryCursor<T>where
T: Send,
impl<T> Sync for MemoryCursor<T>where
T: Sync,
impl<T> Unpin for MemoryCursor<T>where
T: Unpin,
impl<T> UnwindSafe for MemoryCursor<T>where
T: UnwindSafe,
Blanket Implementations§
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> GetWithMetadata for T
impl<T> GetWithMetadata for T
Source§type ForSelf = WithMetadata_<T, T>
type ForSelf = WithMetadata_<T, T>
WithMetadata_<Self, Self>Source§impl<Ctx, R> IOread<Ctx> for R
impl<Ctx, R> IOread<Ctx> for R
Source§impl<Ctx, W> IOwrite<Ctx> for W
impl<Ctx, W> IOwrite<Ctx> for W
Source§fn iowrite<N>(&mut self, n: N) -> Result<(), Error>
fn iowrite<N>(&mut self, n: N) -> Result<(), Error>
N into Self, with the parsing context ctx.
NB: this will panic if the type you’re writing has a size greater than 256. Plans are to have this allocate in larger cases. Read moreSource§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<S> ROExtAcc for S
impl<S> ROExtAcc for S
Source§fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
offset. Read moreSource§fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
offset. Read moreSource§fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
offset. Read moreSource§fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
offset. Read moreSource§impl<S> ROExtOps<Aligned> for S
impl<S> ROExtOps<Aligned> for S
Source§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
offset) with value,
returning the previous value of the field. Read moreSource§fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
Source§impl<S> ROExtOps<Unaligned> for S
impl<S> ROExtOps<Unaligned> for S
Source§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
offset) with value,
returning the previous value of the field. Read moreSource§fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
Source§impl<T> SelfOps for Twhere
T: ?Sized,
impl<T> SelfOps for Twhere
T: ?Sized,
Source§fn piped<F, U>(self, f: F) -> U
fn piped<F, U>(self, f: F) -> U
Source§fn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
fn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
piped except that the function takes &Self
Useful for functions that take &Self instead of Self. Read moreSource§fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
piped, except that the function takes &mut Self.
Useful for functions that take &mut Self instead of Self.Source§fn mutated<F>(self, f: F) -> Self
fn mutated<F>(self, f: F) -> Self
Source§fn observe<F>(self, f: F) -> Self
fn observe<F>(self, f: F) -> Self
Source§fn as_ref_<T>(&self) -> &T
fn as_ref_<T>(&self) -> &T
AsRef,
using the turbofish .as_ref_::<_>() syntax. Read more