# Class: com.pnfsoftware.jeb.core.units.codeobject.PEParser

A simple PE/PE64 parser \(not relying on the [IUnit](IUnit) interface\) that may be used for convenience purposes.

## Constructor: PEParser
- parameter: `input`, type: `com.pnfsoftware.jeb.core.input.IInput`

Description: Parse a PE file.
parameter: input: input file
throws: if the input cannot be parsed as a PE file

## Method: add
- parameter: `address`, type: `long`
- parameter: `size`, type: `long`
- return type: `long`

Description: 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.
parameter: address: base address
parameter: size: size to add
return: sanitized address

## Method: convertFileOffsetToRelativeAddress
- parameter: `offset`, type: `long`
- return type: `long`

Description: Convert a file offset to a relative virtual address.
parameter: offset: file offset
return: relative virtual address, or \-1 if none maps to the offset

## Method: convertRelativeAddressToFileOffset
- parameter: `rva`, type: `long`
- return type: `long`

Description: Convert a relative virtual address to a file offset.
parameter: rva: relative virtual address
return: file offset, or \-1 if none maps to the address

## Method: getCOFFHeader
- return type: `com.pnfsoftware.jeb.core.units.codeobject.ICOFFHeader`

Description: Get the COFF header.
return: COFF header

## Method: getPEOptionalHeader
- return type: `com.pnfsoftware.jeb.core.units.codeobject.IPEOptionalHeader`

Description: Get the PE optional header.
return: PE optional header

## Method: getSectionHeaders
- return type: `com.pnfsoftware.jeb.core.units.codeobject.ICOFFSectionHeader[]`

Description: Get the COFF section headers.
return: section headers

## Method: getSegment
- parameter: `index`, type: `int`
- return type: `com.pnfsoftware.jeb.core.units.codeobject.ISegmentInformation`

Description: Get generic segment information by index.
parameter: index: segment index
return: segment information

## Method: getSegmentCount
- return type: `int`

Description: Get the number of generic segments.
return: segment count

## Method: getSegments
- return type: `java.util.List<com.pnfsoftware.jeb.core.units.codeobject.ISegmentInformation>`

Description: Get the generic segment information.
return: segment information

## Method: isAddressInside
- parameter: `a`, type: `long`
- return type: `boolean`

Description: Determine if a legal address is within the bounds of the mapped PE file.
parameter: a: address to test
return: true if the address is inside the mapped image

## Method: sanitizeAddress
- parameter: `address`, type: `long`
- return type: `long`

Description: Sanitize a long to a legal address rel. to the PE specifications \(32\-bit or 64\-bit space\).
parameter: address: address to sanitize
return: sanitized address

