Module read
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>> {
# #[cfg(all(feature = "read", feature = "std"))] {
let data = fs::read("path/to/binary")?;
let file = object::File::parse(&*data)?;
for section in file.sections() {
println!("{}", section.name()?);
}
# }
Ok(())
}
Modules
Structs
- CodeView PDB information from the debug directory in a PE file.
- CompressedData Data that may be compressed.
- CompressedFileRange A range in a file that may be compressed.
- Error The error type used within the read module.
- Export An exported symbol.
- Import An imported symbol.
- 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. - Relocation A relocation entry.
- RelocationMap A map from section offsets to relocation information.
- SectionIndex The index used to identify a section in a file.
- SymbolIndex The index used to identify a symbol in a symbol table.
- SymbolMap A map from addresses to symbol information.
-
SymbolMapName
The type used for entries in a
SymbolMapthat maps from addresses to names.
Enums
- CompressionFormat A data compression format.
- FileKind A file format kind.
- ObjectKind An object kind.
-
RelocationTarget
The target referenced by a
Relocation. -
SymbolSection
The section where an
ObjectSymbolis defined.
Traits
-
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.