1 unstable release

0.1.0 Feb 28, 2022
0.0.1 Feb 27, 2022

#24 in #zero-allocation

MIT license

84KB
2K SLoC

Zelf

Crates.io Docs.rs

A zero-allocation ELF parser.


lib.rs:

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 Type parsing function
Null, Probits, Nobits, Shlib, Load, Phdr, Tls N/A
Symtab, Dynsym Symtab::parse
Strtab, Rela, Hash, Dynamic, Note, Rel, Group, Interp {type}::parse
InitArray, FiniArray, PreinitArray Array::parse
SymtabShndx Shndx::parse

You need to call "Compression::parse" for compressed sections.

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

Dependencies

~300–750KB
~17K SLoC