pub struct RuntimeMemoryImage {
    pub memory_segments: Vec<MemorySegment>,
    pub is_little_endian: bool,
    pub is_lkm: bool,
}
Expand description

A representation of the runtime image of a binary after being loaded into memory by the loader.

Fields§

§memory_segments: Vec<MemorySegment>

Sequence of memory segments.

§is_little_endian: bool

Endianness

§is_lkm: bool

True iff we are analyzing a Linux loadable kernel module.

Implementations§

source§

impl RuntimeMemoryImage

source

pub fn empty(is_little_endian: bool) -> RuntimeMemoryImage

Generate a runtime memory image containing no memory segments. Primarily useful in situations where any access to global memory would be an error.

source

pub fn new(binary: &[u8]) -> Result<Self, Error>

Generate a runtime memory image for a given binary.

The function can parse ELF and PE files as input.

source

pub fn new_from_bare_metal( binary: &[u8], bare_metal_config: &BareMetalConfig ) -> Result<Self, Error>

Generate a runtime memory image for a bare metal binary.

The generated runtime memory image contains:

  • one memory region corresponding to non-volatile memory
  • one memory region corresponding to volatile memory (RAM)

See BareMetalConfig for more information about the assumed memory layout for bare metal binaries.

source

pub fn get_base_address(binary: &[u8]) -> Result<u64, Error>

Get the base address for the image of a binary when loaded into memory.

source

pub fn is_little_endian_byte_order(&self) -> bool

Return whether values in the memory image should be interpreted in little-endian or big-endian byte order.

source

pub fn add_global_memory_offset(&mut self, offset: u64)

Add a global offset to the base addresses of all memory segments. Useful to align the addresses with those reported by Ghidra if the Ghidra backend added such an offset to all addresses.

source

pub fn read( &self, address: &Bitvector, size: ByteSize ) -> Result<Option<Bitvector>, Error>

Read the contents of the memory image at the given address to emulate a read instruction to global data at runtime.

The read method is endian-aware, i.e. values are interpreted with the endianness of the CPU architecture. If the address points to a writeable segment, the returned value is a Ok(None) value, since the data may change during program execution.

Returns an error if the address is not contained in the global data address range.

source

pub fn read_string_until_null_terminator( &self, address: &Bitvector ) -> Result<&str, Error>

Read the contents of memory from a given address onwards until a null byte is reached and checks whether the content is a valid UTF8 string.

source

pub fn is_global_memory_address(&self, constant: &Bitvector) -> bool

Checks whether the constant is a global memory address.

source

pub fn is_interval_readable( &self, start_address: u64, end_address: u64 ) -> Result<bool, Error>

Check whether all addresses in the given interval point to a readable segment in the runtime memory image.

Returns an error if the address interval intersects more than one memory segment or if it does not point to global memory at all.

source

pub fn get_ro_data_pointer_at_address( &self, address: &Bitvector ) -> Result<(&[u8], usize), Error>

For an address to global read-only memory, return the memory segment it points to and the index inside the segment, where the address points to.

Returns an error if the target memory segment is marked as writeable or if the pointer does not point to global memory.

source

pub fn is_address_writeable(&self, address: &Bitvector) -> Result<bool, Error>

Check whether the given address points to a writeable segment in the runtime memory image.

Returns an error if the address does not point to global memory.

source

pub fn is_interval_writeable( &self, start_address: u64, end_address: u64 ) -> Result<bool, Error>

Check whether all addresses in the given interval point to a writeable segment in the runtime memory image.

Returns an error if the address interval intersects more than one memory segment or if it does not point to global memory at all.

Trait Implementations§

source§

impl Clone for RuntimeMemoryImage

source§

fn clone(&self) -> RuntimeMemoryImage

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 Debug for RuntimeMemoryImage

source§

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

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

impl<'de> Deserialize<'de> for RuntimeMemoryImage

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Hash for RuntimeMemoryImage

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for RuntimeMemoryImage

source§

fn eq(&self, other: &RuntimeMemoryImage) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for RuntimeMemoryImage

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for RuntimeMemoryImage

source§

impl StructuralEq for RuntimeMemoryImage

source§

impl StructuralPartialEq for RuntimeMemoryImage

Auto Trait Implementations§

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
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,