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
impl RuntimeMemoryImage
sourcepub fn empty(is_little_endian: bool) -> RuntimeMemoryImage
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.
sourcepub fn new(binary: &[u8]) -> Result<Self, Error>
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.
sourcepub fn new_from_bare_metal(
binary: &[u8],
bare_metal_config: &BareMetalConfig
) -> Result<Self, Error>
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.
sourcepub fn get_base_address(binary: &[u8]) -> Result<u64, Error>
pub fn get_base_address(binary: &[u8]) -> Result<u64, Error>
Get the base address for the image of a binary when loaded into memory.
sourcepub fn is_little_endian_byte_order(&self) -> bool
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.
sourcepub fn add_global_memory_offset(&mut self, offset: u64)
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.
sourcepub fn read(
&self,
address: &Bitvector,
size: ByteSize
) -> Result<Option<Bitvector>, Error>
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.
sourcepub fn read_string_until_null_terminator(
&self,
address: &Bitvector
) -> Result<&str, Error>
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.
sourcepub fn is_global_memory_address(&self, constant: &Bitvector) -> bool
pub fn is_global_memory_address(&self, constant: &Bitvector) -> bool
Checks whether the constant is a global memory address.
sourcepub fn is_interval_readable(
&self,
start_address: u64,
end_address: u64
) -> Result<bool, Error>
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.
sourcepub fn get_ro_data_pointer_at_address(
&self,
address: &Bitvector
) -> Result<(&[u8], usize), Error>
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.
sourcepub fn is_address_writeable(&self, address: &Bitvector) -> Result<bool, Error>
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.
sourcepub fn is_interval_writeable(
&self,
start_address: u64,
end_address: u64
) -> Result<bool, Error>
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
impl Clone for RuntimeMemoryImage
source§fn clone(&self) -> RuntimeMemoryImage
fn clone(&self) -> RuntimeMemoryImage
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for RuntimeMemoryImage
impl Debug for RuntimeMemoryImage
source§impl<'de> Deserialize<'de> for RuntimeMemoryImage
impl<'de> Deserialize<'de> for RuntimeMemoryImage
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl Hash for RuntimeMemoryImage
impl Hash for RuntimeMemoryImage
source§impl PartialEq for RuntimeMemoryImage
impl PartialEq for RuntimeMemoryImage
source§fn eq(&self, other: &RuntimeMemoryImage) -> bool
fn eq(&self, other: &RuntimeMemoryImage) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl Serialize for RuntimeMemoryImage
impl Serialize for RuntimeMemoryImage
impl Eq for RuntimeMemoryImage
impl StructuralEq for RuntimeMemoryImage
impl StructuralPartialEq for RuntimeMemoryImage
Auto Trait Implementations§
impl RefUnwindSafe for RuntimeMemoryImage
impl Send for RuntimeMemoryImage
impl Sync for RuntimeMemoryImage
impl Unpin for RuntimeMemoryImage
impl UnwindSafe for RuntimeMemoryImage
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
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.