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§
- Attribute
Index Iterator - An iterator over the indices in an
AttributesSubsubsection. - Attribute
Reader - A parser for the attributes in an
AttributesSubsubsection. - Attributes
Section - An ELF attributes section.
- Attributes
Subsection - A subsection in an
AttributesSection. - Attributes
Subsection Iterator - An iterator for the subsections in an
AttributesSection. - Attributes
Subsubsection - A sub-subsection in an
AttributesSubsection. - Attributes
Subsubsection Iterator - An iterator for the sub-subsections in an
AttributesSubsection. - ElfComdat
- A COMDAT section group in an
ElfFile. - ElfComdat
Iterator - An iterator for the COMDAT section groups in an
ElfFile. - ElfComdat
Section Iterator - An iterator for the sections in a COMDAT section group in an
ElfFile. - ElfDynamic
Relocation Iterator - An iterator for the dynamic relocations in an
ElfFile. - ElfFile
- A partially parsed ELF file.
- ElfSection
- A section in an
ElfFile. - ElfSection
Iterator - An iterator for the sections in an
ElfFile. - ElfSection
Relocation Iterator - An iterator for the relocations for an
ElfSection. - ElfSegment
- A segment in an
ElfFile. - ElfSegment
Iterator - An iterator for the segments in an
ElfFile. - ElfSymbol
- A symbol in an
ElfFile. - ElfSymbol
Iterator - An iterator for the symbols in an
ElfFile. - ElfSymbol
Table - A symbol table in an
ElfFile. - GnuHash
Table - A GNU symbol hash table in an ELF file.
- GnuProperty
- A property in a
elf::NT_GNU_PROPERTY_TYPE_0note. - GnuProperty
Iterator - An iterator for the properties in a
elf::NT_GNU_PROPERTY_TYPE_0note. - Hash
Table - A SysV symbol hash table in an ELF file.
- Note
- A parsed
NoteHeader. - Note
Iterator - An iterator over the notes in an ELF section or segment.
- Relocation
Sections - A mapping from section index to associated relocation sections.
- Relr
Iterator - An iterator over the relative relocations in an ELF
SHT_RELRsection. - Section
Table - The table of section headers in an ELF file.
- Symbol
Table - A table of symbol entries in an ELF file.
- Verdaux
Iterator - An iterator for the auxiliary records for an entry in an ELF
elf::SHT_GNU_VERDEFsection. - Verdef
Iterator - An iterator for the entries in an ELF
elf::SHT_GNU_VERDEFsection. - Vernaux
Iterator - An iterator for the auxiliary records for an entry in an ELF
elf::SHT_GNU_VERNEEDsection. - Verneed
Iterator - An iterator for the entries in an ELF
elf::SHT_GNU_VERNEEDsection. - Version
- A version definition or requirement.
- Version
Index - A version index.
- Version
Table - A table of version definitions and requirements.
Traits§
- Compression
Header - A trait for generic access to
elf::CompressionHeader32andelf::CompressionHeader64. - Dyn
- A trait for generic access to
elf::Dyn32andelf::Dyn64. - File
Header - A trait for generic access to
elf::FileHeader32andelf::FileHeader64. - Note
Header - A trait for generic access to
elf::NoteHeader32andelf::NoteHeader64. - Program
Header - A trait for generic access to
elf::ProgramHeader32andelf::ProgramHeader64. - Rel
- A trait for generic access to
elf::Rel32andelf::Rel64. - Rela
- A trait for generic access to
elf::Rela32andelf::Rela64. - Relr
- A trait for generic access to
elf::Relr32andelf::Relr64. - Section
Header - A trait for generic access to
elf::SectionHeader32andelf::SectionHeader64. - Sym
- A trait for generic access to
elf::Sym32andelf::Sym64.
Type Aliases§
- ElfComdat32
- A COMDAT section group in an
ElfFile32. - ElfComdat64
- A COMDAT section group in an
ElfFile64. - ElfComdat
Iterator32 - An iterator for the COMDAT section groups in an
ElfFile32. - ElfComdat
Iterator64 - An iterator for the COMDAT section groups in an
ElfFile64. - ElfComdat
Section Iterator32 - An iterator for the sections in a COMDAT section group in an
ElfFile32. - ElfComdat
Section Iterator64 - An iterator for the sections in a COMDAT section group in an
ElfFile64. - ElfDynamic
Relocation Iterator32 - An iterator for the dynamic relocations in an
ElfFile32. - ElfDynamic
Relocation Iterator64 - 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. - ElfSection
Iterator32 - An iterator for the sections in an
ElfFile32. - ElfSection
Iterator64 - An iterator for the sections in an
ElfFile64. - ElfSection
Relocation Iterator32 - An iterator for the relocations for an
ElfSection32. - ElfSection
Relocation Iterator64 - An iterator for the relocations for an
ElfSection64. - ElfSegment32
- A segment in an
ElfFile32. - ElfSegment64
- A segment in an
ElfFile64. - ElfSegment
Iterator32 - An iterator for the segments in an
ElfFile32. - ElfSegment
Iterator64 - An iterator for the segments in an
ElfFile64. - ElfSymbol32
- A symbol in an
ElfFile32. - ElfSymbol64
- A symbol in an
ElfFile64. - ElfSymbol
Iterator32 - An iterator for the symbols in an
ElfFile32. - ElfSymbol
Iterator64 - An iterator for the symbols in an
ElfFile64. - ElfSymbol
Table32 - A symbol table in an
ElfFile32. - ElfSymbol
Table64 - A symbol table in an
ElfFile32.