Module coff

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

CoffComdat
A COMDAT section group in a CoffFile.
CoffComdatIterator
An iterator for the COMDAT section groups in a CoffFile.
CoffComdatSectionIterator
An iterator for the sections in a COMDAT section group in a CoffFile.
CoffFile
A COFF object file.
CoffRelocationIterator
An iterator for the relocations in a CoffSection.
CoffSection
A section in a CoffFile.
CoffSectionIterator
An iterator for the sections in a CoffFile.
CoffSegment
A loadable section in a CoffFile.
CoffSegmentIterator
An iterator for the loadable sections in a CoffFile.
CoffSymbol
A symbol in a CoffFile or PeFile.
CoffSymbolIterator
An iterator for the symbols in a CoffFile or PeFile.
CoffSymbolTable
A symbol table in a CoffFile or PeFile.
ImportFile
A Windows short form description of a symbol to import.
ImportObjectData
The data following pe::ImportObjectHeader.
SectionTable
The table of section headers in a COFF or PE file.
SymbolIterator
An iterator for symbol entries in a COFF or PE file.
SymbolTable
A table of symbol entries in a COFF or PE file.

Enums§

ImportName
The name or ordinal to import from a DLL.
ImportType
The kind of import symbol.

Traits§

CoffHeader
A trait for generic access to pe::ImageFileHeader and pe::AnonObjectHeaderBigobj.
ImageSymbol
A trait for generic access to pe::ImageSymbol and pe::ImageSymbolEx.

Functions§

anon_object_class_id
Read the class_id field from a pe::AnonObjectHeader.

Type Aliases§

CoffBigComdat
A COMDAT section group in a CoffBigFile.
CoffBigComdatIterator
An iterator for the COMDAT section groups in a CoffBigFile.
CoffBigComdatSectionIterator
An iterator for the sections in a COMDAT section group in a CoffBigFile.
CoffBigFile
A COFF bigobj object file with 32-bit section numbers.
CoffBigRelocationIterator
An iterator for the relocations in a CoffBigSection.
CoffBigSection
A section in a CoffBigFile.
CoffBigSectionIterator
An iterator for the sections in a CoffBigFile.
CoffBigSegment
A loadable section in a CoffBigFile.
CoffBigSegmentIterator
An iterator for the loadable sections in a CoffBigFile.
CoffBigSymbol
A symbol in a CoffBigFile.
CoffBigSymbolIterator
An iterator for the symbols in a CoffBigFile.
CoffBigSymbolTable
A symbol table in a CoffBigFile.