yaxpeax_core/memory/
mod.rs

1use std::ops::Range;
2
3pub mod repr;
4pub mod reader;
5
6pub use memory::repr::MemoryReprReader;
7use memory::repr::flat::FlatMemoryRepr;
8use memory::repr::cursor::ReadCursor;
9use memory::repr::process::ModuleInfo;
10
11use yaxpeax_arch::Arch;
12
13#[derive(Debug)]
14pub enum LayoutError {
15    AddressConflict,
16    Unsupported
17}
18
19pub trait MemoryRange<A: Arch + ?Sized> where Self: MemoryRepr<A> {
20    /// a cursor to read data contained in `range`. this willfully misinterprets `std::ops::Range`
21    /// to be inclusive on both ends, rather than `[inclusive, exclusive)` as the docs say. this
22    /// is, for the time being, necessary because yaxpeax consistently uses ranges that are
23    /// inclusive on both ends. yaxpeax must represent `[inclusive, exclusive)` ranges most clearly
24    /// because this significantly simplifies expressing a basic block that ends at the end of its
25    /// architecture's address space.
26    fn range<'a>(&'a self, range: Range<A::Address>) -> Option<ReadCursor<'a, A, Self>>;
27    fn range_from<'a>(&'a self, start: A::Address) -> Option<ReadCursor<'a, A, Self>>;
28}
29
30pub trait MemoryRepr<A: Arch + ?Sized>: Named {
31    fn module_info(&self) -> Option<&ModuleInfo>;
32    fn read(&self, addr: A::Address) -> Option<u8>;
33    fn as_flat(&self) -> Option<FlatMemoryRepr>;
34    fn module_for(&self, addr: A::Address) -> Option<&dyn MemoryRepr<A>>;
35    fn size(&self) -> Option<u64>;
36    fn start(&self) -> Option<u64> { None }
37    fn end(&self) -> Option<u64> { self.start().and_then(|x| self.size().map(|y| x + y)) }
38}
39
40pub trait Named {
41    fn name(&self) -> &str;
42}
43
44pub trait PatchyMemoryRepr<A: Arch> {
45    fn add(&mut self, data: Vec<u8>, addr: A::Address) -> Result<(), LayoutError>;
46}