pub struct Binary {
pub path: Option<String>,
pub format: BinaryFormat,
pub arch: String,
pub is_64: bool,
pub little_endian: bool,
pub bytes: Vec<u8>,
pub symbols: Vec<Symbol>,
/* private fields */
}Expand description
In-memory parsed object representing a single executable format.
File bytes are kept so that vaddrs can be resolved even if sections were
truncated on disk (NOBITS, sparse Mach-O, etc.) — readers return None
rather than panic when ranges fall outside the loaded segment.
Fields§
§path: Option<String>§format: BinaryFormat§arch: String§is_64: booltrue when the target pointer ABI is 64-bit, false when it is
32-bit. Analyzers size their pointer reads off this flag.
little_endian: bool§bytes: Vec<u8>§symbols: Vec<Symbol>Implementations§
Source§impl Binary
impl Binary
Sourcepub fn parse(path: Option<&str>, bytes: Vec<u8>) -> Result<Self>
pub fn parse(path: Option<&str>, bytes: Vec<u8>) -> Result<Self>
Parse a raw object file (ELF, PE, or single-arch Mach-O).
The input is cloned once internally so that the parsed object’s
&[u8] references (via Elf<'_>, PE<'_>, Mach<'_>) stay valid
until we finish copying them out into owned types.
§Errors
Returns Err when the input exceeds MAX_INPUT_BYTES, goblin cannot
recognize the format, the object is truncated, an ar archive is passed
(we do not dereference archive members in v0.1), or a Mach-O fat archive
is passed (we only support single-arch slices). Any panic raised by
goblin’s parser on a malformed object (e.g. Mach-O LC_MAIN load commands
that trigger subtract-with-overflow in goblin 0.8.2) is also converted
to Err, so a hostile object cannot abort the process.
Sourcepub fn vaddr_to_offset(&self, vaddr: u64) -> Option<(usize, usize)>
pub fn vaddr_to_offset(&self, vaddr: u64) -> Option<(usize, usize)>
Translate vaddr to (section_index, offset_within_section). Returns
None if vaddr falls outside the span of any loaded section. If
ranges overlap, the containing section with the highest start address
(then the smallest span) wins.
Sourcepub fn read_at_vaddr(&self, vaddr: u64, len: usize) -> Option<&[u8]>
pub fn read_at_vaddr(&self, vaddr: u64, len: usize) -> Option<&[u8]>
Read len bytes at vaddr. Returns None if any byte falls
outside the section bounds or the backing data is too short.
Sourcepub fn read_ptr(&self, vaddr: u64) -> Option<u64>
pub fn read_ptr(&self, vaddr: u64) -> Option<u64>
Read a pointer-sized value (4 bytes on 32-bit, 8 on 64-bit) at
vaddr, respecting the binary’s endianness.
Sourcepub fn read_u32(&self, vaddr: u64) -> Option<u32>
pub fn read_u32(&self, vaddr: u64) -> Option<u32>
Read a u32 (little- or big-endian per self.little_endian).
Sourcepub fn vaddr_in_string_section(&self, vaddr: u64, len: u64) -> bool
pub fn vaddr_in_string_section(&self, vaddr: u64, len: u64) -> bool
true if vaddr..vaddr+len lies entirely inside a section
classified as hosting string bytes (read-only data across formats).
Sourcepub fn string_section_indices(&self) -> &[usize]
pub fn string_section_indices(&self) -> &[usize]
Indices into self.sections of sections classified as hosting
string bytes (.rodata*, .rdata*, __cstring, …).
Sourcepub fn is_string_section_index(&self, index: usize) -> bool
pub fn is_string_section_index(&self, index: usize) -> bool
true when the section at index is classified as hosting string
bytes.