Expand description
§elb
ELF reader/patcher library that features
- reading and writing ELF files,
- patching
RPATH
,RUNPATH
and interpreter via high-level API, - verifying correctness of ELF files,
- custom patching via low-level API.
To resolve dependencies without loading and executing files,
you can use elb-dl
that is based on this crate.
There is also an accompanying command-line utility.
§Usage
use elb::{DynamicTag, Elf, ElfPatcher, Error};
use std::fs::{File, OpenOptions};
fn read_elf() -> Result<(), Error> {
let mut file = File::open("/bin/ls")?;
let page_size = 4096;
let elf = Elf::read(&mut file, page_size)?;
eprintln!("{:#?}", elf.header);
Ok(())
}
fn patch_elf() -> Result<(), Error> {
let mut file = OpenOptions::new().read(true).write(true).open("/chroot/bin/ls")?;
let page_size = 4096;
let elf = Elf::read(&mut file, page_size)?;
let mut patcher = ElfPatcher::new(elf, file);
patcher.set_interpreter(c"/chroot/lib64/ld-linux-x86-64.so.2")?;
patcher.set_library_search_path(DynamicTag::Runpath, c"/chroot/lib64:/chroot/usr/lib64")?;
patcher.finish()?;
Ok(())
}
§References
Other ELF readers/patchers:
Dynamic linkers:
Man pages:
Linters:
- ELFUTILS
eu-elflint
. - Binutils
readelf --lint
.
Modules§
- host
- Host parameters (byte order, class, machine).
Structs§
- ArmFlags
- ARM32-specific flags.
- Dynamic
Table - Dynamic linking information.
- Elf
- ELF file.
- ElfPatcher
- ELF patcher.
- Header
- ELF header.
- Program
Header - Segments.
- Rel
- Relocation without an addend.
- RelA
- Relocation with an addend.
- RelTable
- Relocation table.
- Rela
Table - Relocation table.
- Riscv
Flags - RISCV-specific flags.
- Section
- Section.
- Section
Flags - Section flags.
- Section
Header - Sections.
- Segment
- Segment.
- Segment
Flags - Segment flags.
- Space
Allocator - Allocator for in-file and in-memory space.
- String
Table - A table that stores NUL-terminated strings.
- Symbol
- A symbol.
- Symbol
Table - Symbol table.
Enums§
- Byte
Order - Data format (endiannes).
- Class
- Architecture.
- Dynamic
Tag - Dynamic table tag.
- Dynamic
Value - Dynamic table entry’s value.
- Error
- ELF-specific error.
- File
Kind - ELF file type.
- Machine
- Architecture.
- OsAbi
- Operating system ABI.
- Riscv
Float Abi - RISCV float ABI.
- Section
Kind - Section type.
- Segment
Kind - Segment type.
- Symbol
Binding - Symbol binding.
- Symbol
Kind - Symbol type.
- Symbol
Visibility - Symbol visibility.