3 unstable releases

new 0.16.0 Dec 10, 2024
0.15.1 Jul 23, 2024
0.15.0 Jul 21, 2024
0.0.2 Apr 28, 2024
0.0.1 Jul 3, 2022

#639 in Parser implementations

Download history 12/week @ 2024-08-20 6/week @ 2024-09-10 6/week @ 2024-09-17 31/week @ 2024-09-24 51/week @ 2024-10-01 30/week @ 2024-10-08 14/week @ 2024-10-15 26/week @ 2024-10-22 5/week @ 2024-10-29 16/week @ 2024-11-05 13/week @ 2024-11-12 3/week @ 2024-11-19 7/week @ 2024-11-26 204/week @ 2024-12-03

232 downloads per month

Apache-2.0

4MB
133K SLoC

LIEF Rust Bindings

These are the offical rust bindings for LIEF.

LIEF Architecture

Getting Started

[dependencies]
lief = "0.16.0"

The bindings require Rust edition 2021 and rustc >= 1.74.0

use lief;

if let Some(lief::Binary::ELF(elf)) = lief::Binary::from(&mut file) {
    println!("Dependencies:");
    for entry in elf.dynamic_entries() {
        if let dynamic::Entries::Library(lib) = entry {
            println!("  - {}", lib.name());
        }
    }
    println!("Versions:");
    for version in elf.symbols_version_requirement() {
        println!("  From {}", version.name());
        for aux in version.auxiliary_symbols() {
            println!("    - {}", aux.name());
        }
    }
}

Documentation


lib.rs:

LIEF

LIEF Design

This package provides Rust bindings for LIEF. It exposes most of the LIEF API to read these formats:

  • ELF
  • PE
  • Mach-O

The bindings require at least Rust version 1.74.0 with the 2021 edition and support:

  • Windows x86-64 (support /MT and /MD linking)
  • Linux x86-64/aarch64/musl (Ubuntu 19.10, Almalinux 8, Debian 10, Fedora 29)
  • macOS (x86-64 and aarch64 with at least OSX Big Sur: 11.0)
  • iOS (aarch64)

Getting Started

[package]
name    = "my-awesome-project"
version = "0.0.1"
edition = "2021"

[dependencies]
# For nightly
lief = { git = "https://github.com/lief-project/LIEF", branch = "main" }
# For releases
lief = 0.16.0
fn main() {
   let path = std::env::args().last().unwrap();
   let mut file = std::fs::File::open(path).expect("Can't open the file");
   match lief::Binary::from(&mut file) {
       Some(lief::Binary::ELF(elf)) => {
           // Process ELF file
       },
       Some(lief::Binary::PE(pe)) => {
           // Process PE file
       },
       Some(lief::Binary::MachO(macho)) => {
           // Process Mach-O file (including FatMachO)
       },
       None => {
           // Parsing error
       }
   }
   return;
}

Note that the generic module implements the different traits shared by different structure of executable formats (symbols, relocations, ...)

Additional Information

For more details about the install procedure and the configuration, please check: https://lief.re/doc/latest/api/rust/index.html

Dependencies

~5–17MB
~259K SLoC