Expand description
ELF reader and writer with byte-identical round-trip.
Handles both ELFCLASS32 and ELFCLASS64 little-endian images. The
parsed representation always uses 64-bit-shaped headers (Ehdr64,
Phdr64, Shdr64) regardless of input class — 32-bit fields are
zero-extended on parse and truncated on write. The on-disk format
is recorded in Elf64File::class and used to dispatch the right
header layout when serialising.
The contract: for any supported input bytes,
Elf64File::parse(bytes)?.write_to_vec() == bytes.
Anything not in scope for this crate is preserved as opaque bytes and
re-emitted verbatim. Section contents (bytes inside .text, .rodata,
.symtab, etc.) are never interpreted here — that belongs to the arch
backends and analysis crates.
Structs§
- Ehdr64
- Parsed ELF64 ELF header.
- Elf64
File - A parsed ELF64 file in a form that round-trips byte-identically.
- Phdr64
- Parsed ELF64 program header entry.
- Shdr64
- Parsed ELF64 section header entry.
Enums§
- ElfClass
- Whether the on-disk image used 32-bit or 64-bit headers. Recorded at parse time and consulted on write to round-trip the original byte layout exactly.
- Error
- Errors surfaced when parsing or writing an ELF64 file.
Constants§
- EM_386
e_machinevalue for i386 (32-bit x86).- EM_
AARC H64 e_machinevalue forAArch64.- EM_
X86_ 64 e_machinevalue for x86-64.- SHF_
EXECINSTR sh_flagsbit indicating the section contains executable instructions.- SHT_
DYNSYM sh_typefor the dynamic-linking symbol table (always present in dynamic executables and shared objects).- SHT_
RELA sh_typefor a relocation table with explicit addends (Elf64_Rela).- SHT_
STRTAB sh_typefor a string table.- SHT_
SYMTAB sh_typefor a fully-linked symbol table.
Functions§
- is_elf
- Returns true if
bytesstart with the ELF magic. - is_
elf64_ le - Returns true iff
bytesare an ELF little-endian image of either class — the flavorsElf64File::parsehandles. Callers that route by format (e.g. the CLI’s round-trip pipeline) should gate on this and fall through to a byte-copy for unsupported variants so the round-trip contract still holds.