Crate zelf

source · []
Expand description

Zelf is a zero-allocation ELF parser designed for the “no_std” environment.

It defines ELF C structs and provides parsing functions and parsed Rust types. Fields in ELF C structs are byte arrays so that all structs are of alignment one to escape misaligned reading (it causes faults on some hardware).

“context::Context” is a trait for parsing context, uniquely identified by class (32/64 bit), data encoding (little/big), version (current is 1) given by the identification in the elf header. It determines the layout of ELF structs (e.g. “ProgramHeader”, “ArrayEntry”) and the parsed Rust types (e.g. “Context::Integer”, “Context::SectionFlags”, “Context::DynamicFlags”). There are four combinations of them, which are four phantom types “Little32”, “Little64”, “Big32”, “Big64”.

You need to call the corresponding parsing functions for sections and programs. There is a table for reference.

Section/Program Typeparsing function
Null, Probits, Nobits, Shlib, Load, Phdr, TlsN/A
Symtab, DynsymSymtab::parse
Strtab, Rela, Hash, Dynamic, Note, Rel, Group, Interp{type}::parse
InitArray, FiniArray, PreinitArrayArray::parse
SymtabShndxShndx::parse

You need to call “Compression::parse” for compressed sections.

You can read “examples/readelf” for a starter with this crate.

Modules

Enums

ELF class.

ELF data encoding.

ELF version.