#tree #auditable #extract #binary #security #cargo #binaries

auditable-extract

Extract the dependency trees embedded in binaries by cargo auditable

9 releases

new 0.3.4 May 8, 2024
0.3.3 May 3, 2024
0.3.2 Oct 2, 2022
0.3.1 Aug 6, 2022
0.1.0 Sep 7, 2020

#312 in Encoding

Download history 7702/week @ 2024-01-24 9198/week @ 2024-01-31 9536/week @ 2024-02-07 11015/week @ 2024-02-14 8870/week @ 2024-02-21 9179/week @ 2024-02-28 9554/week @ 2024-03-06 9198/week @ 2024-03-13 8730/week @ 2024-03-20 7195/week @ 2024-03-27 8438/week @ 2024-04-03 7799/week @ 2024-04-10 7465/week @ 2024-04-17 8534/week @ 2024-04-24 8407/week @ 2024-05-01 7174/week @ 2024-05-08

32,996 downloads per month
Used in 4 crates (via auditable-info)

MIT/Apache

10KB
115 lines

Extracts the dependency tree information embedded in executables by cargo auditable.

This crate parses platform-specific binary formats (ELF, PE, Mach-O, WASM) and obtains the compressed audit data.

Unlike other binary parsing crates, it is specifically designed to be resilient to malicious input. It 100% safe Rust (including all dependencies) and performs no heap allocations.

Usage

Note: this is a low-level crate that only implements binary parsing. It rarely should be used directly. You probably want the higher-level auditable-info crate instead.

The following snippet demonstrates full extraction pipeline using this crate, including decompression using the safe-Rust miniz_oxide and optional JSON parsing via auditable-serde:

use std::io::{Read, BufReader};
use std::{error::Error, fs::File, str::FromStr};
!
fn main() -> Result<(), Box<dyn Error>> {
    // Read the input
    let f = File::open("target/release/hello-world")?;
    let mut f = BufReader::new(f);
    let mut input_binary = Vec::new();
    f.read_to_end(&mut input_binary)?;
    // Extract the compressed audit data
    let compressed_audit_data = auditable_extract::raw_auditable_data(&input_binary)?;
    // Decompress it with your Zlib implementation of choice. We recommend miniz_oxide
    use miniz_oxide::inflate::decompress_to_vec_zlib;
    let decompressed_data = decompress_to_vec_zlib(&compressed_audit_data)
        .map_err(|_| "Failed to decompress audit data")?;
    let decompressed_data = String::from_utf8(decompressed_data)?;
    println!("{}", decompressed_data);
    // Parse the audit data to Rust data structures
    let dependency_tree = auditable_serde::VersionInfo::from_str(&decompressed_data);
    Ok(())
}

Dependencies

~94–365KB