47 releases (29 breaking)

0.30.3 Jan 23, 2023
0.30.0 Nov 22, 2022
0.29.0 Jun 23, 2022
0.28.3 Jan 19, 2022
0.1.0 Aug 20, 2016

#8 in Parser implementations

Download history 632028/week @ 2022-10-12 624465/week @ 2022-10-19 580006/week @ 2022-10-26 624663/week @ 2022-11-02 632881/week @ 2022-11-09 616982/week @ 2022-11-16 523999/week @ 2022-11-23 597704/week @ 2022-11-30 568876/week @ 2022-12-07 573991/week @ 2022-12-14 392950/week @ 2022-12-21 347931/week @ 2022-12-28 595668/week @ 2023-01-04 631640/week @ 2023-01-11 666977/week @ 2023-01-18 712331/week @ 2023-01-25

2,706,345 downloads per month
Used in 4,658 crates (92 directly)

Apache-2.0 OR MIT

1.5MB
28K SLoC

object

The object crate provides a unified interface to working with object files across platforms. It supports reading object files and executable files, and writing COFF/ELF/Mach-O object files and ELF/PE executable files.

For reading files, it provides multiple levels of support:

  • raw struct definitions suitable for zero copy access
  • low level APIs for accessing the raw structs (example)
  • a higher level unified API for accessing common features of object files, such as sections and symbols (example)

Supported file formats: ELF, Mach-O, Windows PE/COFF, Wasm, and Unix archive.

Example for unified read API

use object::{Object, ObjectSection};
use std::error::Error;
use std::fs;

/// Reads a file and displays the content of the ".boot" section.
fn main() -> Result<(), Box<dyn Error>> {
  let bin_data = fs::read("./multiboot2-binary.elf")?;
  let obj_file = object::File::parse(&*bin_data)?;
  if let Some(section) = obj_file.section_by_name(".boot") {
    println!("{:#x?}", section.data()?);
  } else {
    eprintln!("section not available");
  }
  Ok(())
}

See crates/examples for more examples.

Minimum Supported Rust Version (MSRV)

Changes to MSRV are considered breaking changes. We are conservative about changing the MSRV, but sometimes are required to due to dependencies. The MSRV is:

  • 1.52.0 for the read feature and its dependencies.
  • 1.61.0 for the write feature and its dependencies.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~0.1–0.8MB
~16K SLoC