Module pe

Source
Expand description

Support for reading PE files.

Traits are used to abstract over the difference between PE32 and PE32+. The primary trait for this is ImageNtHeaders.

§High level API

PeFile implements the Object trait for PE files. PeFile is parameterised by ImageNtHeaders to allow reading both PE32 and PE32+. There are type aliases for these parameters (PeFile32 and PeFile64).

§Low level API

The ImageNtHeaders trait can be directly used to parse both pe::ImageNtHeaders32 and pe::ImageNtHeaders64.

§Example for low level API

use object::pe;
use object::read::pe::ImageNtHeaders;
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 dos_header = pe::ImageDosHeader::parse(&*data)?;
   let mut offset = dos_header.nt_headers_offset().into();
   let (nt_headers, data_directories) = pe::ImageNtHeaders64::parse(&*data, &mut offset)?;
   let sections = nt_headers.sections(&*data, offset)?;
   let symbols = nt_headers.symbols(&*data)?;
   for section in sections.iter() {
       println!("{}", String::from_utf8_lossy(section.name(symbols.strings())?));
   }
   Ok(())
}

Re-exports§

pub use super::coff::SectionTable;
pub use super::coff::SymbolTable;

Structs§

DataDirectories
The table of data directories in a PE file.
DelayLoadDescriptorIterator
A fallible iterator for the descriptors in the delay-load data directory.
DelayLoadImportTable
Information for parsing a PE delay-load import table.
Export
An export from a PE file.
ExportTable
A partially parsed PE export table.
ImportDescriptorIterator
A fallible iterator for the descriptors in the import data directory.
ImportTable
Information for parsing a PE import table.
ImportThunkList
A list of import thunks.
PeComdat
A COMDAT section group in a PeFile.
PeComdatIterator
An iterator for the COMDAT section groups in a PeFile.
PeComdatSectionIterator
An iterator for the sections in a COMDAT section group in a PeFile.
PeFile
A PE image file.
PeRelocationIterator
An iterator for the relocations in an PeSection.
PeSection
A section in a PeFile.
PeSectionIterator
An iterator for the sections in a PeFile.
PeSegment
A loadable section in a PeFile.
PeSegmentIterator
An iterator for the loadable sections in a PeFile.
Relocation
A relocation in the .reloc section of a PE file.
RelocationBlockIterator
An iterator over the relocation blocks in the .reloc section of a PE file.
RelocationIterator
An iterator of the relocations in a block in the .reloc section of a PE file.
ResourceDirectory
The .rsrc section of a PE file.
ResourceDirectoryTable
A table of resource entries.
ResourceName
A resource name.
RichHeaderEntry
A PE rich header entry after it has been unmasked.
RichHeaderInfo
Parsed information about a Rich Header.

Enums§

ExportTarget
Where an export is pointing to.
Import
A parsed import thunk.
ResourceDirectoryEntryData
Data associated with a resource directory entry.
ResourceNameOrId
A resource name or ID.

Traits§

ImageNtHeaders
A trait for generic access to pe::ImageNtHeaders32 and pe::ImageNtHeaders64.
ImageOptionalHeader
A trait for generic access to pe::ImageOptionalHeader32 and pe::ImageOptionalHeader64.
ImageThunkData
A trait for generic access to pe::ImageThunkData32 and pe::ImageThunkData64.

Functions§

optional_header_magic
Find the optional header and read its magic field.

Type Aliases§

PeComdat32
A COMDAT section group in a PeFile32.
PeComdat64
A COMDAT section group in a PeFile64.
PeComdatIterator32
An iterator for the COMDAT section groups in a PeFile32.
PeComdatIterator64
An iterator for the COMDAT section groups in a PeFile64.
PeComdatSectionIterator32
An iterator for the sections in a COMDAT section group in a PeFile32.
PeComdatSectionIterator64
An iterator for the sections in a COMDAT section group in a PeFile64.
PeFile32
A PE32 (32-bit) image file.
PeFile64
A PE32+ (64-bit) image file.
PeSection32
A section in a PeFile32.
PeSection64
A section in a PeFile64.
PeSectionIterator32
An iterator for the sections in a PeFile32.
PeSectionIterator64
An iterator for the sections in a PeFile64.
PeSegment32
A loadable section in a PeFile32.
PeSegment64
A loadable section in a PeFile64.
PeSegmentIterator32
An iterator for the loadable sections in a PeFile32.
PeSegmentIterator64
An iterator for the loadable sections in a PeFile64.