pub struct MemoryImage { /* private fields */ }Expand description
The initialized memory of a loaded binary, as a set of mapped segments kept sorted by start address.
Implementations§
Source§impl MemoryImage
impl MemoryImage
Sourcepub fn add_segment(
&mut self,
start: u64,
bytes: Vec<u8>,
executable: bool,
writable: bool,
)
pub fn add_segment( &mut self, start: u64, bytes: Vec<u8>, executable: bool, writable: bool, )
Add a mapped region. Segments are kept sorted by start address; callers need not insert in order.
Sourcepub fn read_bytes(&self, addr: u64, n: usize) -> Option<Vec<u8>>
pub fn read_bytes(&self, addr: u64, n: usize) -> Option<Vec<u8>>
Read n bytes starting at addr, all from a single mapped segment.
Returns None if any byte in [addr, addr + n) is unmapped.
Sourcepub fn read_uint(&self, addr: u64, size: usize) -> Option<u64>
pub fn read_uint(&self, addr: u64, size: usize) -> Option<u64>
Read a little-endian unsigned integer of size bytes (1..=8) at addr.
Endianness is fixed to little-endian for now (x86/x64); a big-endian / arch-driven variant is a TODO.
Sourcepub fn is_executable(&self, addr: u64) -> bool
pub fn is_executable(&self, addr: u64) -> bool
True if addr lies in an executable mapped region (per the raw segment
flag, regardless of whether protections have been established).
Sourcepub fn is_known_writable(&self, addr: u64) -> bool
pub fn is_known_writable(&self, addr: u64) -> bool
True only if addr is mapped in a region known to be writable: the
per-segment protection flags must be established (see
protections_known) and the containing segment
writable. Before protections are known the segment flags are not
authoritative, so this conservatively returns false (“not proven
writable”). Callers use it to refuse to treat mutable memory (e.g. a GOT
slot the dynamic linker rewrites) as a constant.
Sourcepub fn segment_bounds(&self, addr: u64) -> Option<(u64, u64)>
pub fn segment_bounds(&self, addr: u64) -> Option<(u64, u64)>
The [start, end) bounds of the segment containing addr, if any.
Sourcepub fn protections_known(&self) -> bool
pub fn protections_known(&self) -> bool
Whether the per-segment executable flags are authoritative (the
memory_protections pass has run).
Sourcepub fn mark_protections_known(&mut self)
pub fn mark_protections_known(&mut self)
Mark the per-segment protection flags as authoritative, so the lifter narrows from the permissive default to the real flags.
Trait Implementations§
Source§impl BinaryFormat for MemoryImage
The persistence/test backing of the byte surface: a reloaded .harbinger
snapshot (or a qcode!-DSL test that seeded segments) wraps its
MemoryImage in an Arc and hands it to PipelineEnv.binary, so passes
read initialized memory through one trait regardless of whether a live
container format is behind it.
impl BinaryFormat for MemoryImage
The persistence/test backing of the byte surface: a reloaded .harbinger
snapshot (or a qcode!-DSL test that seeded segments) wraps its
MemoryImage in an Arc and hands it to PipelineEnv.binary, so passes
read initialized memory through one trait regardless of whether a live
container format is behind it.
Source§fn entry_points(&self) -> Vec<u64>
fn entry_points(&self) -> Vec<u64>
An image records mapped bytes, not entry metadata.
Source§fn architecture(&self) -> Arch
fn architecture(&self) -> Arch
Images do not record an architecture; x86-64 is the workspace default
(mirrors Blob’s placeholder). Consumers of PipelineEnv.binary
read bytes and permissions, never the architecture.
Source§fn is_known_writable(&self, addr: u64) -> bool
fn is_known_writable(&self, addr: u64) -> bool
Answers straight from the per-segment flag: an image is only ever built
from an authoritative container format’s mapped_regions (or a test’s
explicit add_segment), so the flags need no separate establishment
step. (The inherent MemoryImage::is_known_writable keeps the legacy
protections_known gate for its remaining callers.)
Source§fn is_known_read_only(&self, addr: u64) -> bool
fn is_known_read_only(&self, addr: u64) -> bool
The mirror of is_known_writable: a mapped
segment whose recorded flag says “not writable” is proven read-only. The
flags come from the container format’s mapped_regions, so this is only
as authoritative as the format that filled them.
Source§fn load_address(&self) -> u64
fn load_address(&self) -> u64
Source§fn byte_at(&self, addr: u64) -> Option<u8>
fn byte_at(&self, addr: u64) -> Option<u8>
addr, or None if the address is unmapped.Source§fn bytes_at(&self, addr: u64) -> Option<&[u8]>
fn bytes_at(&self, addr: u64) -> Option<&[u8]>
addr. Read moreSource§fn segment_bounds(&self, addr: u64) -> Option<(u64, u64)>
fn segment_bounds(&self, addr: u64) -> Option<(u64, u64)>
[start, end) bounds of the mapped region containing addr, if
any. Used to key per-segment facts (e.g. executability propositions)
so repeated queries in one region collapse to a single entry. Defaults
to None for formats that do not expose their segments.Source§fn is_executable(&self, addr: u64) -> bool
fn is_executable(&self, addr: u64) -> bool
true if addr lies in an executable region of this binary
image. Defaults to “mapped” for formats that don’t track per-region
permissions; formats with permission information (e.g. ELF segment
flags) should override this.Source§fn mapped_regions(&self) -> Vec<(u64, Vec<u8>, bool, bool)>
fn mapped_regions(&self) -> Vec<(u64, Vec<u8>, bool, bool)>
(start, bytes, executable, writable). Read moreSource§fn entrypoint(&self) -> Option<u64>
fn entrypoint(&self) -> Option<u64>
e_entry), if the format
designates one. Unlike entry_points, this is the single address where
execution begins. Returns None for formats with no distinguished entry.Source§fn os(&self) -> TargetOs
fn os(&self) -> TargetOs
TargetOs::Unknown; PE returns Windows, ELF Linux.Source§fn linked_libraries(&self) -> Vec<String>
fn linked_libraries(&self) -> Vec<String>
DT_NEEDED sonames,
PE import-directory DLL names (original case; matching is
case-insensitive). Empty when the format has no such notion (Blob).Source§fn symbol_name(&self, _addr: u64) -> Option<&str>
fn symbol_name(&self, _addr: u64) -> Option<&str>
addr, if the
binary format has one (e.g. from an ELF symbol table).
Returns None for formats with no symbol information.Source§fn is_external_symbol(&self, _addr: u64) -> bool
fn is_external_symbol(&self, _addr: u64) -> bool
true if addr is an external (imported) function stub,
e.g. a PLT thunk. The recursive disassembler will not lift the body
of external functions. Defaults to false.Source§fn import_library(&self, _addr: u64) -> Option<&str>
fn import_library(&self, _addr: u64) -> Option<&str>
addr: the PE import-directory DLL, or the ELF .gnu.version_r soname
the symbol’s version requirement points at. None when the format does
not record a per-symbol source library (e.g. an unversioned ELF import).Source§fn import_symbol_name(&self, _addr: u64) -> Option<&str>
fn import_symbol_name(&self, _addr: u64) -> Option<&str>
addr, if any. Read moreSource§fn hex_rows(
&self,
addr: u64,
len: usize,
width: usize,
) -> Vec<(u64, Vec<Option<u8>>)>
fn hex_rows( &self, addr: u64, len: usize, width: usize, ) -> Vec<(u64, Vec<Option<u8>>)>
Source§impl Clone for MemoryImage
impl Clone for MemoryImage
Source§fn clone(&self) -> MemoryImage
fn clone(&self) -> MemoryImage
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more