Elfkit
an elf read and manipulation library in pure rust (no bfd, no gnu code), intended to be used in binary manipulation utils such as strip, objcopy, link editors, etc.
Some gnu binutils replacements are included as example code.
cargo run --example readelf ./tests/samples/amd64_exe
strip can be implemented like:
extern crate elfkit;
use env;
use OpenOptions;
use ;
api design
lower level
everything is based on std::io::{Read,Write}. This is most convenient for userspace editors. For writing a kernel check alternatives below.
Every type implements from_reader and to_writer. You can use them individually, but you'll always need a Header to tell the de/serializers about things like endianness, bitwidth,..
structured elf
the most versatile api is propably Elf::from_reader/to_writer. You can use it as is, which will hold all sectionc content in Vec or call Elf::load_all() which will parse the sections into their detailed specific structures, such as symbols, relocations, dynamic linker instructions, etc..
implementation status
section specific parsers
type | read | write |
---|---|---|
symtab | ok | ok |
rela | ok | ok |
dynamic | ok | ok |
rel | - | - |
note | - | - |
gnu_hash | - | - |
versym | - | - |
verneed | - | - |
architectures
abi | headers | relocations |
---|---|---|
x86_64 | ok | wip |
mips32r2 o32 | ok | |
arm eabi | ok |
alternatives
- goblin mach-o and archive support, no-std support, very low level
- elf most popular, most generic use case, no writing, no section parsing
- xmas-elf zero alloc (good for writing an OS), read only
references
- https://en.wikipedia.org/wiki/Executable_and_Linkable_Format
- https://software.intel.com/sites/default/files/article/402129/mpx-linux64-abi.pdf
- http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044f/IHI0044F_aaelf.pdf
- https://dmz-portal.imgtec.com/wiki/MIPS_ABI_Project
- https://dmz-portal.imgtec.com/wiki/MIPS_O32_ABI_-_FR0_and_FR1_Interlinking