caver
ELF64 code cave injection library for Rust.
caver creates code caves in ELF64 binaries by appending a new loadable segment.
It handles only structural ELF modification — creating and labelling the space.
Assembly, trampolines, and hooking are left to your disassembler.
Supports x86_64, AArch64, and RISC-V 64 (little-endian ELF64 only).
Install
[]
= "0.3"
Cave types
Every cave has a fill pattern that controls both its contents and how disassemblers interpret it:
| Fill | Contents | ELF symbol type | Disassembler sees |
|---|---|---|---|
FillByte::ArchNop |
arch NOP sled | STT_FUNC |
function entry point |
FillByte::Zero |
null bytes | STT_OBJECT |
data variable |
Use ArchNop when you plan to write code into the cave. Use Zero when you
need a writable data region.
Naming
Each cave gets two names that serve different purposes:
name— the ELF section name (e.g..mycode). Must start with.. This is whatreadelf,objdump, andelf.sections()see.symbol— the exported symbol name (e.g.caverfn_mycode). This is what Binary Ninja, Ghidra, and IDA see when they auto-analyse the binary.
If you don't call .symbol(), caver derives one from the section name:
caverfn_<name> for NOP caves, caverobj_<name> for zero caves.
.mycode → caverfn_mycode (ArchNop, auto)
.mydata → caverobj_mydata (Zero, auto)
.hook → my_hook (ArchNop, overridden)
Usage
Inject a single cave
use ;
use ElfFile;
Inject multiple caves
use ;
use ElfFile;
Inspect a binary
use ElfFile;
License
MIT