pub struct ElfBinary {
pub load_address: u64,
pub segments: Vec<LoadSegment>,
pub analysis: ElfAnalysis,
pub architecture: Arch,
pub endian: Endian,
pub is_64: bool,
pub sections: Vec<ElfSection>,
pub needed_libraries: Vec<String>,
pub kind: ElfKind,
pub program_headers: ProgramHeaderTable,
pub tls: Option<TlsSegment>,
/* private fields */
}Expand description
A parsed and loaded ELF binary.
Every PT_LOAD segment is recorded as a mapped region. File-backed bytes
are preserved per segment, and any p_memsz > p_filesz tail is modeled as
implicit zero-fill rather than materialized up front.
ElfBinary::analysis is populated by two analysis passes run at parse
time:
- Entrypoint:
e_entryfrom the ELF header. - Known functions: all
STT_FUNCsymbols found in.symtabor.dynsym, PLT stubs, and every.eh_frameFDE start (nameless, but they survivestrip).
known_functions and imported_symbols are sorted by address with one
entry per address, and a name index is built alongside them, which is
what the BinaryFormat::symbol_name / BinaryFormat::symbol_address
lookups search. Both hold once parsing returns; mutating the tables
afterwards is not supported.
Fields§
§load_address: u64§segments: Vec<LoadSegment>§analysis: ElfAnalysis§architecture: Arch§endian: EndianEI_DATA: the byte order every multi-byte field was read with.
is_64: boolEI_CLASS: true for ELF64, false for ELF32.
sections: Vec<ElfSection>The allocated section headers in address order, empty when the
section table was stripped. What BinaryFormat::sections reports.
needed_libraries: Vec<String>Shared-library sonames from the .dynamic section’s DT_NEEDED entries,
in link order (e.g. libc.so.6).
kind: ElfKindThe file type.
program_headers: ProgramHeaderTableThe program header table’s location.
tls: Option<TlsSegment>The thread-local storage template, if the file has one.
Implementations§
Trait Implementations§
Source§impl BinaryFormat for ElfBinary
impl BinaryFormat for ElfBinary
Source§fn sections(&self) -> Vec<Section>
fn sections(&self) -> Vec<Section>
The allocated section headers, or, for a file whose section table
was stripped, the PT_LOAD segments named LOAD0, LOAD1, … so the
layout is still enumerable.
Source§fn is_known_read_only(&self, addr: u64) -> bool
fn is_known_read_only(&self, addr: u64) -> bool
ELF program headers carry PF_W, so a mapped segment without it is
proven read-only for the lifetime of the process.
Source§fn symbol_address(&self, name: &str) -> Option<u64>
fn symbol_address(&self, name: &str) -> Option<u64>
The inverse of symbol_name, including
the synthetic _start it gives an unnamed entrypoint.
Source§fn entry_points(&self) -> Vec<u64>
fn entry_points(&self) -> Vec<u64>
Entry points are the ELF entrypoint plus all known function starts.
Source§fn entrypoint(&self) -> Option<u64>
fn entrypoint(&self) -> Option<u64>
The ELF entry point (e_entry from the header).
Source§fn load_address(&self) -> u64
fn load_address(&self) -> u64
Source§fn architecture(&self) -> Arch
fn architecture(&self) -> Arch
Source§fn os(&self) -> TargetOs
fn os(&self) -> TargetOs
TargetOs::Unknown; PE returns Windows, ELF Linux.Source§fn endianness(&self) -> Endian
fn endianness(&self) -> Endian
EI_DATA); PE is always
little-endian. Defaults to little-endian for formats that record none.Source§fn bits(&self) -> u32
fn bits(&self) -> u32
EI_CLASS, PE32 vs
PE32+). Defaults to 64 for formats that record none.Source§fn symbols(&self) -> Vec<Symbol>
fn symbols(&self) -> Vec<Symbol>
symbol_name would answer for each address, with
the size and import provenance the container records. Empty for
formats with no symbol information.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 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 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_known_writable(&self, addr: u64) -> bool
fn is_known_writable(&self, addr: u64) -> bool
true only if addr lies in a region known to be writable
(from the container’s segment flags). Passes that fold a value out of
initialized memory use this to refuse mutable memory — e.g. a GOT slot
the dynamic linker overwrites at load time. Defaults to false
(“not proven writable”); Blob keeps the default.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 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 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. Read moreSource§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_symbol_name(&self, addr: u64) -> Option<&str>
fn import_symbol_name(&self, addr: u64) -> Option<&str>
addr, if any. Read moreSource§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).