pub struct File<R: ReadBytesAt> {
pub ehdr: FileHeader,
/* private fields */
}
Fields
ehdr: FileHeader
Implementations
sourceimpl<R: ReadBytesAt> File<R>
impl<R: ReadBytesAt> File<R>
pub fn open_stream(reader: R) -> Result<File<R>, ParseError>
sourcepub fn segments(&mut self) -> Result<SegmentIterator<'_>, ParseError>
pub fn segments(&mut self) -> Result<SegmentIterator<'_>, ParseError>
Get an iterator over the Segments (ELF Program Headers) in the file
The underlying ELF bytes backing the segment table is read all at once when the iterator is requested, but parsing is deferred to be lazily parsed on demand on each Iterator::next() call.
Returns a ParseError if the data bytes for the segment table cannot be read i.e. if the ELF FileHeader’s e_phnum, e_phoff, e_phentsize are invalid and point to a range in the file data that does not actually exist.
sourcepub fn section_headers(
&mut self
) -> Result<SectionHeaderIterator<'_>, ParseError>
pub fn section_headers(
&mut self
) -> Result<SectionHeaderIterator<'_>, ParseError>
Get an iterator over the Section Headers in the file.
The underlying ELF bytes backing the section headers table are read all at once when the iterator is requested, but parsing is deferred to be lazily parsed on demand on each Iterator::next() call.
Returns a ParseError if the data bytes for the segment table cannot be read i.e. if the ELF FileHeader’s e_shnum, e_shoff, e_shentsize are invalid and point to a range in the file data that does not actually exist.
sourcepub fn section_header_by_index(
&mut self,
index: usize
) -> Result<SectionHeader, ParseError>
pub fn section_header_by_index(
&mut self,
index: usize
) -> Result<SectionHeader, ParseError>
Read and parse the SectionHeader at the given index into the section table.
sourcepub fn section_headers_with_strtab(
&mut self
) -> Result<(SectionHeaderIterator<'_>, StringTable<'_>), ParseError>
pub fn section_headers_with_strtab(
&mut self
) -> Result<(SectionHeaderIterator<'_>, StringTable<'_>), ParseError>
Get an iterator over the Section Headers and its associated StringTable.
The underlying ELF bytes backing the section headers and string table are read all at once as part of this method. Parsing of section headers and names from the string table are deferred to be done lazily on demand on each Iterator::next() and StringTable.get() call.
Returns a ParseError if the data bytes for these tables cannot be read i.e. if the ELF FileHeader’s e_shnum, e_shoff, e_shentsize, e_shstrndx are invalid and point to a ranges in the file data that does not actually exist.
sourcepub fn section_data_for_header(
&mut self,
shdr: &SectionHeader
) -> Result<&[u8], ParseError>
👎Deprecated: Deprecated in favor of File::section_data()
pub fn section_data_for_header(
&mut self,
shdr: &SectionHeader
) -> Result<&[u8], ParseError>
Read the section data for the given SectionHeader.
This returns the data as-is from the file. SHT_NOBITS sections yield an empty slice.
sourcepub fn section_data(
&mut self,
shdr: &SectionHeader
) -> Result<(&[u8], Option<CompressionHeader>), ParseError>
pub fn section_data(
&mut self,
shdr: &SectionHeader
) -> Result<(&[u8], Option<CompressionHeader>), ParseError>
Read the section data for the given SectionHeader. Returns both the secion data and an optional CompressionHeader.
No compression header signals that the section contents are uncompressed and can be used as-is.
Some(chdr) signals that the section contents are compressed and need to be uncompressed via the compression algorithm described in ch_type. The returned buffer represents the compressed section bytes as found in the file, without the CompressionHeader.
It is up to the user to perform the decompression themselves with the compression library of their choosing.
SHT_NOBITS sections yield an empty slice.
sourcepub fn section_data_as_strtab(
&mut self,
shdr: &SectionHeader
) -> Result<StringTable<'_>, ParseError>
pub fn section_data_as_strtab(
&mut self,
shdr: &SectionHeader
) -> Result<StringTable<'_>, ParseError>
Read the section data for the given SectionHeader and interpret it in-place as a StringTable.
Returns a ParseError if the sh_type is not SHT_STRTAB.
sourcepub fn section_strtab(&mut self) -> Result<StringTable<'_>, ParseError>
pub fn section_strtab(&mut self) -> Result<StringTable<'_>, ParseError>
Read and return the string table for the section headers.
If the file has no section header string table, then an empty StringTable is returned.
This is a convenience wrapper for interpreting the section at FileHeader.e_shstrndx as a StringTable via section_data_as_strtab().
sourcepub fn symbol_table(
&mut self
) -> Result<Option<(SymbolTable<'_>, StringTable<'_>)>, ParseError>
pub fn symbol_table(
&mut self
) -> Result<Option<(SymbolTable<'_>, StringTable<'_>)>, ParseError>
Get the symbol table (section of type SHT_SYMTAB) and its associated string table.
The GABI specifies that ELF object files may have zero or one sections of type SHT_SYMTAB.
sourcepub fn dynamic_symbol_table(
&mut self
) -> Result<Option<(SymbolTable<'_>, StringTable<'_>)>, ParseError>
pub fn dynamic_symbol_table(
&mut self
) -> Result<Option<(SymbolTable<'_>, StringTable<'_>)>, ParseError>
Get the dynamic symbol table (section of type SHT_DYNSYM) and its associated string table.
The GABI specifies that ELF object files may have zero or one sections of type SHT_DYNSYM.
sourcepub fn dynamic_section(&mut self) -> Result<Option<DynIterator<'_>>, ParseError>
pub fn dynamic_section(&mut self) -> Result<Option<DynIterator<'_>>, ParseError>
Get the .dynamic section/segment contents.
sourcepub fn symbol_version_table(
&mut self
) -> Result<Option<SymbolVersionTable<'_>>, ParseError>
pub fn symbol_version_table(
&mut self
) -> Result<Option<SymbolVersionTable<'_>>, ParseError>
Read the section data for the various GNU Symbol Versioning sections (if any) and return them in a SymbolVersionTable that which can interpret them in-place to yield SymbolRequirements and SymbolDefinitions
This is a GNU extension and not all objects use symbol versioning. Returns an empty Option if the object does not use symbol versioning.
sourcepub fn section_data_as_rels(
&mut self,
shdr: &SectionHeader
) -> Result<RelIterator<'_>, ParseError>
pub fn section_data_as_rels(
&mut self,
shdr: &SectionHeader
) -> Result<RelIterator<'_>, ParseError>
Read the section data for the given SectionHeader and interpret it in-place as a RelIterator.
Returns a ParseError if the sh_type is not SHT_REL.
sourcepub fn section_data_as_relas(
&mut self,
shdr: &SectionHeader
) -> Result<RelaIterator<'_>, ParseError>
pub fn section_data_as_relas(
&mut self,
shdr: &SectionHeader
) -> Result<RelaIterator<'_>, ParseError>
Read the section data for the given SectionHeader and interpret it in-place as a RelaIterator.
Returns a ParseError if the sh_type is not SHT_RELA.
sourcepub fn section_data_as_notes(
&mut self,
shdr: &SectionHeader
) -> Result<NoteIterator<'_>, ParseError>
pub fn section_data_as_notes(
&mut self,
shdr: &SectionHeader
) -> Result<NoteIterator<'_>, ParseError>
Read the section data for the given SectionHeader and interpret it in-place as a NoteIterator.
Returns a ParseError if the sh_type is not SHT_RELA.
sourcepub fn segment_data_as_notes(
&mut self,
phdr: &ProgramHeader
) -> Result<NoteIterator<'_>, ParseError>
pub fn segment_data_as_notes(
&mut self,
phdr: &ProgramHeader
) -> Result<NoteIterator<'_>, ParseError>
Read the segment data for the given Segment and interpret it in-place as a NoteIterator.
Returns a ParseError if the p_type is not PT_RELA.