Module object::read

source ·
Expand description

Interface for reading object files.

§Unified read API

The Object trait provides a unified read API for accessing common features of object files, such as sections and symbols. There is an implementation of this trait for File, which allows reading any file format, as well as implementations for each file format: ElfFile, MachOFile, CoffFile, PeFile, WasmFile, XcoffFile.

§Low level read API

The submodules for each file format define helpers that operate on the raw structs. These can be used instead of the unified API, or in conjunction with it to access details that are not available via the unified API.

See the submodules for examples of the low level read API.

§Naming Convention

Types that form part of the unified API for a file format are prefixed with the name of the file format.

§Example for unified read API

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

/// Reads a file and displays the name of each section.
fn main() -> Result<(), Box<dyn Error>> {
   let data = fs::read("path/to/binary")?;
   let file = object::File::parse(&*data)?;
   for section in file.sections() {
       println!("{}", section.name()?);
   }
   Ok(())
}

Modules§

  • Support for archive files.
  • Support for reading Windows COFF files.
  • Support for reading ELF files.
  • Support for reading Mach-O files.
  • Support for reading PE files.
  • Support for reading Wasm files.
  • Support for reading AIX XCOFF files.

Structs§

Enums§

Traits§

Type Aliases§

  • The native executable file for the target platform.
  • The result type used within the read module.