Expand description
Support for reading Windows COFF files.
Traits are used to abstract over the difference between COFF object files
and COFF bigobj files. The primary trait for this is CoffHeader.
§High level API
CoffFile implements the Object trait for
COFF files. CoffFile is parameterised by CoffHeader.
The default parameter allows reading regular COFF object files,
while the type alias CoffBigFile allows reading COFF bigobj files.
ImportFile allows reading COFF short imports that are used in import
libraries. Currently these are not integrated with the unified read API.
§Low level API
The CoffHeader trait can be directly used to parse both COFF
object files (which start with pe::ImageFileHeader) and COFF bigobj
files (which start with pe::AnonObjectHeaderBigobj).
§Example for low level API
use object::pe;
use object::read::coff::{CoffHeader, ImageSymbol as _};
use std::error::Error;
use std::fs;
/// Reads a file and displays the name of each section and symbol.
fn main() -> Result<(), Box<dyn Error>> {
let data = fs::read("path/to/binary")?;
let mut offset = 0;
let header = pe::ImageFileHeader::parse(&*data, &mut offset)?;
let sections = header.sections(&*data, offset)?;
let symbols = header.symbols(&*data)?;
for section in sections.iter() {
println!("{}", String::from_utf8_lossy(section.name(symbols.strings())?));
}
for (_index, symbol) in symbols.iter() {
println!("{}", String::from_utf8_lossy(symbol.name(symbols.strings())?));
}
Ok(())
}Structs§
- Coff
Comdat - A COMDAT section group in a
CoffFile. - Coff
Comdat Iterator - An iterator for the COMDAT section groups in a
CoffFile. - Coff
Comdat Section Iterator - An iterator for the sections in a COMDAT section group in a
CoffFile. - Coff
File - A COFF object file.
- Coff
Relocation Iterator - An iterator for the relocations in a
CoffSection. - Coff
Section - A section in a
CoffFile. - Coff
Section Iterator - An iterator for the sections in a
CoffFile. - Coff
Segment - A loadable section in a
CoffFile. - Coff
Segment Iterator - An iterator for the loadable sections in a
CoffFile. - Coff
Symbol - A symbol in a
CoffFileorPeFile. - Coff
Symbol Iterator - An iterator for the symbols in a
CoffFileorPeFile. - Coff
Symbol Table - A symbol table in a
CoffFileorPeFile. - Import
File - A Windows short form description of a symbol to import.
- Import
Object Data - The data following
pe::ImportObjectHeader. - Section
Table - The table of section headers in a COFF or PE file.
- Symbol
Iterator - An iterator for symbol entries in a COFF or PE file.
- Symbol
Table - A table of symbol entries in a COFF or PE file.
Enums§
- Import
Name - The name or ordinal to import from a DLL.
- Import
Type - The kind of import symbol.
Traits§
- Coff
Header - A trait for generic access to
pe::ImageFileHeaderandpe::AnonObjectHeaderBigobj. - Image
Symbol - A trait for generic access to
pe::ImageSymbolandpe::ImageSymbolEx.
Functions§
- anon_
object_ class_ id - Read the
class_idfield from ape::AnonObjectHeader.
Type Aliases§
- Coff
BigComdat - A COMDAT section group in a
CoffBigFile. - Coff
BigComdat Iterator - An iterator for the COMDAT section groups in a
CoffBigFile. - Coff
BigComdat Section Iterator - An iterator for the sections in a COMDAT section group in a
CoffBigFile. - Coff
BigFile - A COFF bigobj object file with 32-bit section numbers.
- Coff
BigRelocation Iterator - An iterator for the relocations in a
CoffBigSection. - Coff
BigSection - A section in a
CoffBigFile. - Coff
BigSection Iterator - An iterator for the sections in a
CoffBigFile. - Coff
BigSegment - A loadable section in a
CoffBigFile. - Coff
BigSegment Iterator - An iterator for the loadable sections in a
CoffBigFile. - Coff
BigSymbol - A symbol in a
CoffBigFile. - Coff
BigSymbol Iterator - An iterator for the symbols in a
CoffBigFile. - Coff
BigSymbol Table - A symbol table in a
CoffBigFile.