Crate elb

Source
Expand description

§elb

Crates.io Version Docs dependency status

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:

Modules§

host
Host parameters (byte order, class, machine).

Structs§

ArmFlags
ARM32-specific flags.
DynamicTable
Dynamic linking information.
Elf
ELF file.
ElfPatcher
ELF patcher.
Header
ELF header.
ProgramHeader
Segments.
Rel
Relocation without an addend.
RelA
Relocation with an addend.
RelTable
Relocation table.
RelaTable
Relocation table.
RiscvFlags
RISCV-specific flags.
Section
Section.
SectionFlags
Section flags.
SectionHeader
Sections.
Segment
Segment.
SegmentFlags
Segment flags.
SpaceAllocator
Allocator for in-file and in-memory space.
StringTable
A table that stores NUL-terminated strings.
Symbol
A symbol.
SymbolTable
Symbol table.

Enums§

ByteOrder
Data format (endiannes).
Class
Architecture.
DynamicTag
Dynamic table tag.
DynamicValue
Dynamic table entry’s value.
Error
ELF-specific error.
FileKind
ELF file type.
Machine
Architecture.
OsAbi
Operating system ABI.
RiscvFloatAbi
RISCV float ABI.
SectionKind
Section type.
SegmentKind
Segment type.
SymbolBinding
Symbol binding.
SymbolKind
Symbol type.
SymbolVisibility
Symbol visibility.

Traits§

BlockRead
Read a block of data from a file.
BlockWrite
Write a block of data to a file.
ElfRead
ELF-specific read functions.
ElfSeek
ELF-specific seek functions.
ElfWrite
ELF-specific write functions.
EntityIo
Read an entity from a file or write an entity to a file.