Expand description
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 object files and some executable files.
Raw struct definitions
Raw structs are defined for: ELF, Mach-O, PE/COFF, archive. Types and traits for zerocopy support are defined in pod and endian.
Unified read API
The read::Object trait defines the unified interace. This trait is implemented by read::File, which allows reading any file format, as well as implementations for each file format: ELF, Mach-O, COFF, PE, Wasm.
Low level read API
In addition to the unified read API, the various read
modules define helpers that
operate on the raw structs. These also provide traits that abstract over the differences
between 32-bit and 64-bit versions of the file format.
Unified write API
[write::Object] allows building a COFF/ELF/Mach-O object and then writing it out.
Low level executable writers
[write::elf::Writer] and [write::pe::Writer] allow writing executable files.
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(())
}