Class PEParser
java.lang.Object
com.pnfsoftware.jeb.core.units.codeobject.PEParser
A simple PE/PE64 parser (not relying on the
IUnit interface) that may be used for
convenience purposes.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongadd(long address, long size) Add an address (unsigned) to a size (unsigned) and return a sanitized address.longconvertFileOffsetToRelativeAddress(long offset) Convert a file offset to a relative virtual address.longconvertRelativeAddressToFileOffset(long rva) Convert a relative virtual address to a file offset.Get the COFF header.Get the PE optional header.Get the COFF section headers.getSegment(int index) Get generic segment information by index.intGet the number of generic segments.Get the generic segment information.booleanisAddressInside(long a) Determine if a legal address is within the bounds of the mapped PE file.longsanitizeAddress(long address) Sanitize a long to a legal address rel.
-
Constructor Details
-
PEParser
Parse a PE file.- Parameters:
input- input file- Throws:
IOException- if the input cannot be parsed as a PE file
-
-
Method Details
-
add
public long add(long address, long size) Add an address (unsigned) to a size (unsigned) and return a sanitized address.Theoretically, this method should be used throughout the processing of various areas, eg imports, exports, etc. however, sanitizations are costly and clutter the code. Therefore, we limit them to filters before starting processing. Processing of a an area of the PE are wrapped in try-catch to avoid killing processing of the entire PE, should an error (eg, due to malformed structures) arise. This has the drawback of semi-neutering (only semi, because the exceptions are displayed and silently reported) parsing bugs that may be present.
- Parameters:
address- base addresssize- size to add- Returns:
- sanitized address
-
sanitizeAddress
public long sanitizeAddress(long address) Sanitize a long to a legal address rel. to the PE specifications (32-bit or 64-bit space).- Parameters:
address- address to sanitize- Returns:
- sanitized address
-
isAddressInside
public boolean isAddressInside(long a) Determine if a legal address is within the bounds of the mapped PE file.- Parameters:
a- address to test- Returns:
- true if the address is inside the mapped image
-
convertFileOffsetToRelativeAddress
public long convertFileOffsetToRelativeAddress(long offset) Convert a file offset to a relative virtual address.- Parameters:
offset- file offset- Returns:
- relative virtual address, or -1 if none maps to the offset
-
convertRelativeAddressToFileOffset
public long convertRelativeAddressToFileOffset(long rva) Convert a relative virtual address to a file offset.- Parameters:
rva- relative virtual address- Returns:
- file offset, or -1 if none maps to the address
-
getCOFFHeader
Get the COFF header.- Returns:
- COFF header
-
getPEOptionalHeader
Get the PE optional header.- Returns:
- PE optional header
-
getSectionHeaders
Get the COFF section headers.- Returns:
- section headers
-
getSegments
Get the generic segment information.- Returns:
- segment information
-
getSegmentCount
public int getSegmentCount()Get the number of generic segments.- Returns:
- segment count
-
getSegment
Get generic segment information by index.- Parameters:
index- segment index- Returns:
- segment information
-