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.
- DelayLoad Descriptor Iterator 
- A fallible iterator for the descriptors in the delay-load data directory.
- DelayLoad Import Table 
- Information for parsing a PE delay-load import table.
- Export
- An export from a PE file.
- ExportTable 
- A partially parsed PE export table.
- ImportDescriptor Iterator 
- A fallible iterator for the descriptors in the import data directory.
- ImportTable 
- Information for parsing a PE import table.
- ImportThunk List 
- A list of import thunks.
- PeComdat
- A COMDAT section group in a PeFile.
- PeComdatIterator 
- An iterator for the COMDAT section groups in a PeFile.
- PeComdatSection Iterator 
- 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 .relocsection of a PE file.
- RelocationBlock Iterator 
- An iterator over the relocation blocks in the .relocsection of a PE file.
- RelocationIterator 
- An iterator of the relocations in a block in the .relocsection of a PE file.
- ResourceDirectory 
- The .rsrcsection of a PE file.
- ResourceDirectory Table 
- A table of resource entries.
- ResourceName 
- A resource name.
- RichHeader Entry 
- A PE rich header entry after it has been unmasked.
- RichHeader Info 
- Parsed information about a Rich Header.
Enums§
- ExportTarget 
- Where an export is pointing to.
- Import
- A parsed import thunk.
- ResourceDirectory Entry Data 
- Data associated with a resource directory entry.
- ResourceName OrId 
- A resource name or ID.
Traits§
- ImageNtHeaders 
- A trait for generic access to pe::ImageNtHeaders32andpe::ImageNtHeaders64.
- ImageOptional Header 
- A trait for generic access to pe::ImageOptionalHeader32andpe::ImageOptionalHeader64.
- ImageThunk Data 
- A trait for generic access to pe::ImageThunkData32andpe::ImageThunkData64.
Functions§
- optional_header_ magic 
- Find the optional header and read its magicfield.
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.
- PeComdatSection Iterator32 
- An iterator for the sections in a COMDAT section group in a PeFile32.
- PeComdatSection Iterator64 
- 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.