A simple ELF file loader and parser written in Rust. This library allows you to parse and examine ELF (Executable and Linkable Format) files.
- Parse 32-bit and 64-bit ELF files
- Support for big and little endian
- Extract and examine ELF headers
- Parse program headers (segments)
- Parse section headers
- Resolve section names
- Extract section data
- Basic interpreter path identification
Add this to your Cargo.toml:
[dependencies]
elf-loader = { git = "https://github.com/yourusername/elf-loader.git" }use elf_loader::ElfFile;
fn main() {
// Load an ELF file
let elf_file = ElfFile::open("path/to/your/executable").unwrap();
// Print basic information
println!("Architecture: {:?}", elf_file.header.e_machine);
println!("Type: {:?}", elf_file.header.e_type);
println!("Entry point: 0x{:x}", elf_file.header.e_entry);
// Iterate through program headers
for (i, ph) in elf_file.program_headers.iter().enumerate() {
println!("Program Header {}: Type: {:?}, Flags: {}", i, ph.p_type, ph.p_flags);
}
// Iterate through section headers
for (i, sh) in elf_file.section_headers.iter().enumerate() {
println!("Section {}: Name: {:?}, Type: {:?}",
i, sh.name, sh.sh_type);
}
// Get data from a specific section
if let Some((index, _)) = elf_file.find_section_by_name(".text") {
let section_data = elf_file.get_section_data(index).unwrap();
println!("Size of .text section: {} bytes", section_data.len());
}
}The package also includes a command-line tool for examining ELF files:
cargo run -- path/to/your/executableThis will display detailed information about the ELF file.
cargo buildcargo testcargo run -- path/to/your/executableThis project is licensed under the MIT License - see the LICENSE file for details.
- Support for dynamic loading
- Symbol table parsing
- Relocation handling
- Memory mapping and execution
- Debugging support