#elf #reader #lib #elf64

no-std elf_rs

A simple no_std ELF file reader for ELF32 and ELF64

5 releases

0.2.0 Dec 8, 2021
0.1.3 May 30, 2020
0.1.2 Apr 19, 2020
0.1.1 May 24, 2019
0.1.0 Apr 3, 2019

#4 in No standard library

Download history 60/week @ 2021-10-06 89/week @ 2021-10-13 38/week @ 2021-10-20 104/week @ 2021-10-27 270/week @ 2021-11-03 528/week @ 2021-11-10 181/week @ 2021-11-17 46/week @ 2021-11-24 246/week @ 2021-12-01 862/week @ 2021-12-08 726/week @ 2021-12-15 2565/week @ 2021-12-22 6770/week @ 2021-12-29 8958/week @ 2022-01-05 7527/week @ 2022-01-12 6239/week @ 2022-01-19

29,654 downloads per month
Used in 2 crates

Custom license

72KB
998 lines

elf_rs

Build Status Crates.io

This is a no_std library for ELF file handling. It supports ELF32 and ELF64 format.

Usage

To read an elf file, supply elf_rs::Elf with a &[u8] memory:

extern crate elf_rs;

use std::io::Read;
use std::fs::File;
use std::env;

use elf_rs::*;

fn read_elf(filename: &String) {
    let mut elf_file = File::open(filename).expect("open file failed");
    let mut elf_buf = Vec::<u8>::new();
    elf_file.read_to_end(&mut elf_buf).expect("read file failed");

    let elf = Elf::from_bytes(&elf_buf).expect("load elf file failed");

    println!("{:?} header: {:?}", elf, elf.elf_header());

    for p in elf.program_header_iter() {
        println!("{:x?}", p);
    }

    for s in elf.section_header_iter() {
        println!("{:x?}", s);
    }

    let s = elf.lookup_section(b".text");
    println!("s {:?}", s);
}

Under example directory there is a demo readelf to read an ELF file.

$ cargo run --example readelf <path_to_elf_file>

License

it is distributed under the terms of the MIT license.

Please see LICENSE file for details.

Dependencies

~170KB