Module elf

Source
Expand description

Support for reading ELF files.

Traits are used to abstract over the difference between 32-bit and 64-bit ELF. The primary trait for this is FileHeader.

§High level API

ElfFile implements the Object trait for ELF files. ElfFile is parameterised by FileHeader to allow reading both 32-bit and 64-bit ELF. There are type aliases for these parameters (ElfFile32 and ElfFile64).

§Low level API

The FileHeader trait can be directly used to parse both elf::FileHeader32 and elf::FileHeader64.

§Example for low level API

use object::elf;
use object::read::elf::{FileHeader, Sym};
use std::error::Error;
use std::fs;

/// Reads a file and displays the name of each symbol.
fn main() -> Result<(), Box<dyn Error>> {
   let data = fs::read("path/to/binary")?;
   let elf = elf::FileHeader64::<object::Endianness>::parse(&*data)?;
   let endian = elf.endian()?;
   let sections = elf.sections(endian, &*data)?;
   let symbols = sections.symbols(endian, &*data, elf::SHT_SYMTAB)?;
   for symbol in symbols.iter() {
       let name = symbol.name(endian, symbols.strings())?;
       println!("{}", String::from_utf8_lossy(name));
   }
   Ok(())
}

Structs§

AttributeIndexIterator
An iterator over the indices in an AttributesSubsubsection.
AttributeReader
A parser for the attributes in an AttributesSubsubsection.
AttributesSection
An ELF attributes section.
AttributesSubsection
A subsection in an AttributesSection.
AttributesSubsectionIterator
An iterator for the subsections in an AttributesSection.
AttributesSubsubsection
A sub-subsection in an AttributesSubsection.
AttributesSubsubsectionIterator
An iterator for the sub-subsections in an AttributesSubsection.
ElfComdat
A COMDAT section group in an ElfFile.
ElfComdatIterator
An iterator for the COMDAT section groups in an ElfFile.
ElfComdatSectionIterator
An iterator for the sections in a COMDAT section group in an ElfFile.
ElfDynamicRelocationIterator
An iterator for the dynamic relocations in an ElfFile.
ElfFile
A partially parsed ELF file.
ElfSection
A section in an ElfFile.
ElfSectionIterator
An iterator for the sections in an ElfFile.
ElfSectionRelocationIterator
An iterator for the relocations for an ElfSection.
ElfSegment
A segment in an ElfFile.
ElfSegmentIterator
An iterator for the segments in an ElfFile.
ElfSymbol
A symbol in an ElfFile.
ElfSymbolIterator
An iterator for the symbols in an ElfFile.
ElfSymbolTable
A symbol table in an ElfFile.
GnuHashTable
A GNU symbol hash table in an ELF file.
GnuProperty
A property in a elf::NT_GNU_PROPERTY_TYPE_0 note.
GnuPropertyIterator
An iterator for the properties in a elf::NT_GNU_PROPERTY_TYPE_0 note.
HashTable
A SysV symbol hash table in an ELF file.
Note
A parsed NoteHeader.
NoteIterator
An iterator over the notes in an ELF section or segment.
RelocationSections
A mapping from section index to associated relocation sections.
SectionTable
The table of section headers in an ELF file.
SymbolTable
A table of symbol entries in an ELF file.
VerdauxIterator
An iterator for the auxiliary records for an entry in an ELF elf::SHT_GNU_VERDEF section.
VerdefIterator
An iterator for the entries in an ELF elf::SHT_GNU_VERDEF section.
VernauxIterator
An iterator for the auxiliary records for an entry in an ELF elf::SHT_GNU_VERNEED section.
VerneedIterator
An iterator for the entries in an ELF elf::SHT_GNU_VERNEED section.
Version
A version definition or requirement.
VersionIndex
A version index.
VersionTable
A table of version definitions and requirements.

Traits§

CompressionHeader
A trait for generic access to elf::CompressionHeader32 and elf::CompressionHeader64.
Dyn
A trait for generic access to elf::Dyn32 and elf::Dyn64.
FileHeader
A trait for generic access to elf::FileHeader32 and elf::FileHeader64.
NoteHeader
A trait for generic access to elf::NoteHeader32 and elf::NoteHeader64.
ProgramHeader
A trait for generic access to elf::ProgramHeader32 and elf::ProgramHeader64.
Rel
A trait for generic access to elf::Rel32 and elf::Rel64.
Rela
A trait for generic access to elf::Rela32 and elf::Rela64.
SectionHeader
A trait for generic access to elf::SectionHeader32 and elf::SectionHeader64.
Sym
A trait for generic access to elf::Sym32 and elf::Sym64.

Type Aliases§

ElfComdat32
A COMDAT section group in an ElfFile32.
ElfComdat64
A COMDAT section group in an ElfFile64.
ElfComdatIterator32
An iterator for the COMDAT section groups in an ElfFile32.
ElfComdatIterator64
An iterator for the COMDAT section groups in an ElfFile64.
ElfComdatSectionIterator32
An iterator for the sections in a COMDAT section group in an ElfFile32.
ElfComdatSectionIterator64
An iterator for the sections in a COMDAT section group in an ElfFile64.
ElfDynamicRelocationIterator32
An iterator for the dynamic relocations in an ElfFile32.
ElfDynamicRelocationIterator64
An iterator for the dynamic relocations in an ElfFile64.
ElfFile32
A 32-bit ELF object file.
ElfFile64
A 64-bit ELF object file.
ElfSection32
A section in an ElfFile32.
ElfSection64
A section in an ElfFile64.
ElfSectionIterator32
An iterator for the sections in an ElfFile32.
ElfSectionIterator64
An iterator for the sections in an ElfFile64.
ElfSectionRelocationIterator32
An iterator for the relocations for an ElfSection32.
ElfSectionRelocationIterator64
An iterator for the relocations for an ElfSection64.
ElfSegment32
A segment in an ElfFile32.
ElfSegment64
A segment in an ElfFile64.
ElfSegmentIterator32
An iterator for the segments in an ElfFile32.
ElfSegmentIterator64
An iterator for the segments in an ElfFile64.
ElfSymbol32
A symbol in an ElfFile32.
ElfSymbol64
A symbol in an ElfFile64.
ElfSymbolIterator32
An iterator for the symbols in an ElfFile32.
ElfSymbolIterator64
An iterator for the symbols in an ElfFile64.
ElfSymbolTable32
A symbol table in an ElfFile32.
ElfSymbolTable64
A symbol table in an ElfFile32.