Module 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§

archive
Support for archive files.
coff
Support for reading Windows COFF files.
elf
Support for reading ELF files.
macho
Support for reading Mach-O files.
pe
Support for reading PE files.
xcoff
Support for reading AIX XCOFF files.

Structs§

Bytes
A newtype for byte slices.
CodeView
PDB information from the debug directory in a PE file.
Comdat
A COMDAT section group in a File.
ComdatIterator
An iterator for the COMDAT section groups in a File.
ComdatSectionIterator
An iterator for the sections in a Comdat.
CompressedData
Data that may be compressed.
CompressedFileRange
A range in a file that may be compressed.
DynamicRelocationIterator
An iterator for the dynamic relocation entries in a File.
Error
The error type used within the read module.
Export
An exported symbol.
Import
An imported symbol.
NoDynamicRelocationIterator
An iterator for files that don’t have dynamic relocations.
ObjectMap
A map from addresses to symbol names and object files.
ObjectMapEntry
A symbol in an ObjectMap.
ObjectMapFile
An object file name in an ObjectMap.
ReadCache
An implementation of ReadRef for data in a stream that implements Read + Seek.
ReadCacheRange
An implementation of ReadRef for a range of data in a stream that implements Read + Seek.
Relocation
A relocation entry.
RelocationMap
A map from section offsets to relocation information.
Section
A section in a File.
SectionIndex
The index used to identify a section in a file.
SectionIterator
An iterator for the sections in a File.
SectionRelocationIterator
An iterator for the relocation entries in a Section.
Segment
A loadable segment in a File.
SegmentIterator
An iterator for the loadable segments in a File.
StringTable
A table of zero-terminated strings.
Symbol
An symbol in a SymbolTable.
SymbolIndex
The index used to identify a symbol in a symbol table.
SymbolIterator
An iterator for the symbols in a SymbolTable.
SymbolMap
A map from addresses to symbol information.
SymbolMapName
The type used for entries in a SymbolMap that maps from addresses to names.
SymbolTable
A symbol table in a File.

Enums§

AddressSize
The size of an address value for an architecture.
Architecture
A CPU architecture.
BinaryFormat
A binary file format.
ComdatKind
The selection kind for a COMDAT section group.
CompressionFormat
A data compression format.
File
An object file that can be any supported file format.
FileFlags
File flags that are specific to each file format.
FileKind
A file format kind.
ObjectKind
An object kind.
RelocationEncoding
Information about how the result of the relocation operation is encoded in the place.
RelocationFlags
Relocation fields that are specific to each file format and architecture.
RelocationKind
The operation used to calculate the result of the relocation.
RelocationTarget
The target referenced by a Relocation.
SectionFlags
Section flags that are specific to each file format.
SectionKind
The kind of a section.
SegmentFlags
Segment flags that are specific to each file format.
SubArchitecture
A CPU sub-architecture.
SymbolFlags
Symbol flags that are specific to each file format.
SymbolKind
The kind of a symbol.
SymbolScope
A symbol scope.
SymbolSection
The section where an ObjectSymbol is defined.

Traits§

Object
An object file.
ObjectComdat
A COMDAT section group in an Object.
ObjectSection
A section in an Object.
ObjectSegment
A loadable segment in an Object.
ObjectSymbol
A symbol table entry in an Object.
ObjectSymbolTable
A symbol table in an Object.
ReadCacheOps
Operations required to implement ReadCache.
ReadRef
A trait for reading references to Pod types from a block of data.
SymbolMapEntry
An entry in a SymbolMap.

Type Aliases§

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