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.
- Code
View - PDB information from the debug directory in a PE file.
- Comdat
- A COMDAT section group in a
File
. - Comdat
Iterator - An iterator for the COMDAT section groups in a
File
. - Comdat
Section Iterator - An iterator for the sections in a
Comdat
. - Compressed
Data - Data that may be compressed.
- Compressed
File Range - A range in a file that may be compressed.
- Dynamic
Relocation Iterator - 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.
- NoDynamic
Relocation Iterator - An iterator for files that don’t have dynamic relocations.
- Object
Map - A map from addresses to symbol names and object files.
- Object
MapEntry - A symbol in an
ObjectMap
. - Object
MapFile - An object file name in an
ObjectMap
. - Read
Cache - An implementation of
ReadRef
for data in a stream that implementsRead + Seek
. - Read
Cache Range - An implementation of
ReadRef
for a range of data in a stream that implementsRead + Seek
. - Relocation
- A relocation entry.
- Relocation
Map - A map from section offsets to relocation information.
- Section
- A section in a
File
. - Section
Index - The index used to identify a section in a file.
- Section
Iterator - An iterator for the sections in a
File
. - Section
Relocation Iterator - An iterator for the relocation entries in a
Section
. - Segment
- A loadable segment in a
File
. - Segment
Iterator - An iterator for the loadable segments in a
File
. - String
Table - A table of zero-terminated strings.
- Symbol
- An symbol in a
SymbolTable
. - Symbol
Index - The index used to identify a symbol in a symbol table.
- Symbol
Iterator - An iterator for the symbols in a
SymbolTable
. - Symbol
Map - A map from addresses to symbol information.
- Symbol
MapName - The type used for entries in a
SymbolMap
that maps from addresses to names. - Symbol
Table - A symbol table in a
File
.
Enums§
- Address
Size - The size of an address value for an architecture.
- Architecture
- A CPU architecture.
- Binary
Format - A binary file format.
- Comdat
Kind - The selection kind for a COMDAT section group.
- Compression
Format - A data compression format.
- File
- An object file that can be any supported file format.
- File
Flags - File flags that are specific to each file format.
- File
Kind - A file format kind.
- Object
Kind - An object kind.
- Relocation
Encoding - Information about how the result of the relocation operation is encoded in the place.
- Relocation
Flags - Relocation fields that are specific to each file format and architecture.
- Relocation
Kind - The operation used to calculate the result of the relocation.
- Relocation
Target - The target referenced by a
Relocation
. - Section
Flags - Section flags that are specific to each file format.
- Section
Kind - The kind of a section.
- Segment
Flags - Segment flags that are specific to each file format.
- SubArchitecture
- A CPU sub-architecture.
- Symbol
Flags - Symbol flags that are specific to each file format.
- Symbol
Kind - The kind of a symbol.
- Symbol
Scope - A symbol scope.
- Symbol
Section - The section where an
ObjectSymbol
is defined.
Traits§
- Object
- An object file.
- Object
Comdat - A COMDAT section group in an
Object
. - Object
Section - A section in an
Object
. - Object
Segment - A loadable segment in an
Object
. - Object
Symbol - A symbol table entry in an
Object
. - Object
Symbol Table - A symbol table in an
Object
. - Read
Cache Ops - Operations required to implement
ReadCache
. - ReadRef
- A trait for reading references to
Pod
types from a block of data. - Symbol
MapEntry - An entry in a
SymbolMap
.
Type Aliases§
- Native
File - The native executable file for the target platform.
- Result
- The result type used within the read module.