Package ghidra.app.util.bin.format.pe

# Class OptionalHeaderImpl

java.lang.Object
ghidra.app.util.bin.format.pe.OptionalHeaderImpl

All Implemented Interfaces:
  `OptionalHeader`, `StructConverter`

public class OptionalHeaderImpl extends Object implements OptionalHeader

     typedef struct _IMAGE_OPTIONAL_HEADER {
         WORD    Magic;                                                                     // MANDATORY
         BYTE    MajorLinkerVersion;
         BYTE    MinorLinkerVersion;
         DWORD   SizeOfCode;
         DWORD   SizeOfInitializedData;
         DWORD   SizeOfUninitializedData;
         DWORD   AddressOfEntryPoint;                                               // MANDATORY
         DWORD   BaseOfCode;
         DWORD   BaseOfData;
         DWORD   ImageBase;                                                         // MANDATORY
         DWORD   SectionAlignment;                                          // MANDATORY
         DWORD   FileAlignment;                                                     // MANDATORY
         WORD    MajorOperatingSystemVersion;                               // MANDATORY
         WORD    MinorOperatingSystemVersion;
         WORD    MajorImageVersion;
         WORD    MinorImageVersion;
         WORD    MajorSubsystemVersion;
         WORD    MinorSubsystemVersion;
         DWORD   Win32VersionValue;
         DWORD   SizeOfImage;                                                               // MANDATORY
         DWORD   SizeOfHeaders;                                                     // MANDATORY
         DWORD   CheckSum;
         WORD    Subsystem;                                                         // MANDATORY
         WORD    DllCharacteristics;
         DWORD   SizeOfStackReserve;
         DWORD   SizeOfStackCommit;
         DWORD   SizeOfHeapReserve;
         DWORD   SizeOfHeapCommit;
         DWORD   LoaderFlags;
         DWORD   NumberOfRvaAndSizes;                                               // USED
         IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
     };

     typedef struct _IMAGE_OPTIONAL_HEADER64 {
         WORD        Magic;
         BYTE        MajorLinkerVersion;
         BYTE        MinorLinkerVersion;
         DWORD       SizeOfCode;
         DWORD       SizeOfInitializedData;
         DWORD       SizeOfUninitializedData;
         DWORD       AddressOfEntryPoint;
         DWORD       BaseOfCode;
         ULONGLONG   ImageBase;
         DWORD       SectionAlignment;
         DWORD       FileAlignment;
         WORD        MajorOperatingSystemVersion;
         WORD        MinorOperatingSystemVersion;
         WORD        MajorImageVersion;
         WORD        MinorImageVersion;
         WORD        MajorSubsystemVersion;
         WORD        MinorSubsystemVersion;
         DWORD       Win32VersionValue;
         DWORD       SizeOfImage;
         DWORD       SizeOfHeaders;
         DWORD       CheckSum;
         WORD        Subsystem;
         WORD        DllCharacteristics;
         ULONGLONG   SizeOfStackReserve;
         ULONGLONG   SizeOfStackCommit;
         ULONGLONG   SizeOfHeapReserve;
         ULONGLONG   SizeOfHeapCommit;
         DWORD       LoaderFlags;
         DWORD       NumberOfRvaAndSizes;
         IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
     };

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected int`
  `addressOfEntryPoint`
  `protected int`
  `baseOfCode`
  `protected int`
  `baseOfData`
  `protected int`
  `checkSum`
  `protected DataDirectory[]`
  `dataDirectory`
  `protected short`
  `dllCharacteristics`
  `protected int`
  `fileAlignment`
  `protected long`
  `imageBase`
  `protected int`
  `loaderFlags`
  `protected short`
  `magic`
  `protected short`
  `majorImageVersion`
  `protected byte`
  `majorLinkerVersion`
  `protected short`
  `majorOperatingSystemVersion`
  `protected short`
  `majorSubsystemVersion`
  `protected short`
  `minorImageVersion`
  `protected byte`
  `minorLinkerVersion`
  `protected short`
  `minorOperatingSystemVersion`
  `protected short`
  `minorSubsystemVersion`
  `protected NTHeader`
  `ntHeader`
  `protected int`
  `numberOfRvaAndSizes`
  `protected BinaryReader`
  `reader`
  `protected int`
  `sectionAlignment`
  `protected int`
  `sizeOfCode`
  `protected int`
  `sizeOfHeaders`
  `protected long`
  `sizeOfHeapCommit`
  `protected long`
  `sizeOfHeapReserve`
  `protected int`
  `sizeOfImage`
  `protected int`
  `sizeOfInitializedData`
  `protected long`
  `sizeOfStackCommit`
  `protected long`
  `sizeOfStackReserve`
  `protected int`
  `sizeOfUninitializedData`
  `protected int`
  `startIndex`
  `protected short`
  `subsystem`
  `protected int`
  `win32VersionValue`

  ### Fields inherited from interface ghidra.app.util.bin.format.pe.OptionalHeader

  `IMAGE_DIRECTORY_ENTRY_ARCHITECTURE, IMAGE_DIRECTORY_ENTRY_BASERELOC, IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT, IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR, IMAGE_DIRECTORY_ENTRY_COMHEADER, IMAGE_DIRECTORY_ENTRY_DEBUG, IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT, IMAGE_DIRECTORY_ENTRY_EXCEPTION, IMAGE_DIRECTORY_ENTRY_EXPORT, IMAGE_DIRECTORY_ENTRY_GLOBALPTR, IMAGE_DIRECTORY_ENTRY_IAT, IMAGE_DIRECTORY_ENTRY_IMPORT, IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG, IMAGE_DIRECTORY_ENTRY_RESOURCE, IMAGE_DIRECTORY_ENTRY_SECURITY, IMAGE_DIRECTORY_ENTRY_TLS, IMAGE_DLLCHARACTERISTICS_APPCONTAINER, IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE, IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY, IMAGE_DLLCHARACTERISTICS_GUARD_CF, IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA, IMAGE_DLLCHARACTERISTICS_NO_BIND, IMAGE_DLLCHARACTERISTICS_NO_ISOLATION, IMAGE_DLLCHARACTERISTICS_NO_SEH, IMAGE_DLLCHARACTERISTICS_NX_COMPAT, IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE, IMAGE_DLLCHARACTERISTICS_WDM_DRIVER, IMAGE_NUMBEROF_DIRECTORY_ENTRIES`

  ### Fields inherited from interface ghidra.app.util.bin.StructConverter

  `ASCII, BYTE, DWORD, IBO32, IBO64, POINTER, QWORD, SLEB128, STRING, ULEB128, UTF16, UTF8, VOID, WORD`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `long`
  `getAddressOfEntryPoint()`
  `long`
  `getBaseOfCode()`
  Returns the RVA of the first byte of code when loaded in memory.
  `long`
  `getBaseOfData()`
  `int`
  `getChecksum()`
  Get the image file checksum.
  `DataDirectory[]`
  `getDataDirectories()`
  Returns the array of data directories.
  `short`
  `getDllCharacteristics()`
  Return flags that describe properties of and features of this binary.
  `int`
  `getFileAlignment()`
  `long`
  `getImageBase()`
  `int`
  `getLoaderFlags()`
  Return the flags passed to the loader.
  `short`
  `getMajorImageVersion()`
  Get the major version number of the image.
  `byte`
  `getMajorLinkerVersion()`
  Return the major version number of the linker that built this binary.
  `short`
  `getMajorOperatingSystemVersion()`
  Return the major version number of the required operating system.
  `short`
  `getMajorSubsystemVersion()`
  Get the major version number of the subsystem.
  `short`
  `getMinorImageVersion()`
  Get the minor version number of the image.
  `byte`
  `getMinorLinkerVersion()`
  Return the minor version number of the linker that built this binary.
  `short`
  `getMinorOperatingSystemVersion()`
  Return the minor version number of the required operating system.
  `short`
  `getMinorSubsystemVersion()`
  Get the minor version number of the subsystem.
  `long`
  `getNumberOfRvaAndSizes()`
  `int`
  `getSectionAlignment()`
  `long`
  `getSizeOfCode()`
  Returns the combined total size of all sections with the `IMAGE_SCN_CNT_CODE` attribute.
  `long`
  `getSizeOfHeaders()`
  `long`
  `getSizeOfHeapCommit()`
  Return the size of the heap to commit
  `long`
  `getSizeOfHeapReserve()`
  Return the size of the heap reservation
  `long`
  `getSizeOfImage()`
  `long`
  `getSizeOfInitializedData()`
  Returns the combined size of all initialized data sections.
  `long`
  `getSizeOfStackCommit()`
  Return the size of the stack to commit
  `long`
  `getSizeOfStackReserve()`
  Return the size of the stack reservation
  `long`
  `getSizeOfUninitializedData()`
  Returns the size of all sections with the uninitialized data attributes.
  `int`
  `getSubsystem()`
  Get the subsystem that is required to run this image.
  `int`
  `getWin32VersionValue()`
  This value is reserved, and must be 0
  `boolean`
  `is64bit()`
  Returns true of this optional header is 64-bit.
  `boolean`
  `isCLI()`
  `protected void`
  `parse()`
  `void`
  `processDataDirectories(TaskMonitor monitor)`
  This methods tells this optional header to process its data directories.
  `void`
  `setSizeOfCode(long size)`
  `void`
  `setSizeOfHeaders(long size)`
  `void`
  `setSizeOfImage(long size)`
  `void`
  `setSizeOfInitializedData(long size)`
  `void`
  `setSizeOfUninitializedData(long size)`
  `DataType`
  `toDataType()`
  Returns a structure datatype representing the contents of the implementor of this interface.
  `void`
  `validateDataDirectories(Program program)`
  `void`
  `writeHeader(RandomAccessFile raf, DataConverter dc)`
  Writes this optional header to the specified random access file.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### magic

    protected short magic

  - ### majorLinkerVersion

    protected byte majorLinkerVersion

  - ### minorLinkerVersion

    protected byte minorLinkerVersion

  - ### sizeOfCode

    protected int sizeOfCode

  - ### sizeOfInitializedData

    protected int sizeOfInitializedData

  - ### sizeOfUninitializedData

    protected int sizeOfUninitializedData

  - ### addressOfEntryPoint

    protected int addressOfEntryPoint

  - ### baseOfCode

    protected int baseOfCode

  - ### baseOfData

    protected int baseOfData

  - ### imageBase

    protected long imageBase

  - ### sectionAlignment

    protected int sectionAlignment

  - ### fileAlignment

    protected int fileAlignment

  - ### majorOperatingSystemVersion

    protected short majorOperatingSystemVersion

  - ### minorOperatingSystemVersion

    protected short minorOperatingSystemVersion

  - ### majorImageVersion

    protected short majorImageVersion

  - ### minorImageVersion

    protected short minorImageVersion

  - ### majorSubsystemVersion

    protected short majorSubsystemVersion

  - ### minorSubsystemVersion

    protected short minorSubsystemVersion

  - ### win32VersionValue

    protected int win32VersionValue

  - ### sizeOfImage

    protected int sizeOfImage

  - ### sizeOfHeaders

    protected int sizeOfHeaders

  - ### checkSum

    protected int checkSum

  - ### subsystem

    protected short subsystem

  - ### dllCharacteristics

    protected short dllCharacteristics

  - ### sizeOfStackReserve

    protected long sizeOfStackReserve

  - ### sizeOfStackCommit

    protected long sizeOfStackCommit

  - ### sizeOfHeapReserve

    protected long sizeOfHeapReserve

  - ### sizeOfHeapCommit

    protected long sizeOfHeapCommit

  - ### loaderFlags

    protected int loaderFlags

  - ### numberOfRvaAndSizes

    protected int numberOfRvaAndSizes

  - ### dataDirectory

    protected DataDirectory[] dataDirectory

  - ### ntHeader

    protected NTHeader ntHeader

  - ### reader

    protected BinaryReader reader

  - ### startIndex

    protected int startIndex

- ## Method Details

  - ### is64bit

    public boolean is64bit()
    Description copied from interface: `OptionalHeader`
    Returns true of this optional header is 64-bit.
    Specified by:
      `is64bit` in interface `OptionalHeader`
    Returns:
      true of this optional header is 64-bit

  - ### getImageBase

    public long getImageBase()
    Specified by:
      `getImageBase` in interface `OptionalHeader`
    Returns:
      the preferred load address of this file in memory

  - ### getAddressOfEntryPoint

    public long getAddressOfEntryPoint()
    Specified by:
      `getAddressOfEntryPoint` in interface `OptionalHeader`
    Returns:
      the RVA of the first code byte in the file that will be executed

  - ### getSizeOfCode

    public long getSizeOfCode()
    Description copied from interface: `OptionalHeader`
    Returns the combined total size of all sections with the `IMAGE_SCN_CNT_CODE` attribute.
    Specified by:
      `getSizeOfCode` in interface `OptionalHeader`
    Returns:
      the combined total size of all sections with the `IMAGE_SCN_CNT_CODE` attribute.

  - ### setSizeOfCode

    public void setSizeOfCode(long size)
    Specified by:
      `setSizeOfCode` in interface `OptionalHeader`
    See Also:
      - `OptionalHeader.getSizeOfCode()`

  - ### getSizeOfInitializedData

    public long getSizeOfInitializedData()
    Description copied from interface: `OptionalHeader`
    Returns the combined size of all initialized data sections.
    Specified by:
      `getSizeOfInitializedData` in interface `OptionalHeader`
    Returns:
      the combined size of all initialized data sections

  - ### setSizeOfInitializedData

    public void setSizeOfInitializedData(long size)
    Specified by:
      `setSizeOfInitializedData` in interface `OptionalHeader`
    See Also:
      - `OptionalHeader.getSizeOfInitializedData()`

  - ### getSizeOfUninitializedData

    public long getSizeOfUninitializedData()
    Description copied from interface: `OptionalHeader`
    Returns the size of all sections with the uninitialized data attributes.
    Specified by:
      `getSizeOfUninitializedData` in interface `OptionalHeader`
    Returns:
      the size of all sections with the uninitialized data attributes

  - ### setSizeOfUninitializedData

    public void setSizeOfUninitializedData(long size)
    Specified by:
      `setSizeOfUninitializedData` in interface `OptionalHeader`
    See Also:
      - `OptionalHeader.getSizeOfUninitializedData()`

  - ### getBaseOfCode

    public long getBaseOfCode()
    Description copied from interface: `OptionalHeader`
    Returns the RVA of the first byte of code when loaded in memory.
    Specified by:
      `getBaseOfCode` in interface `OptionalHeader`
    Returns:
      the RVA of the first byte of code when loaded in memory

  - ### getBaseOfData

    public long getBaseOfData()
    Specified by:
      `getBaseOfData` in interface `OptionalHeader`
    Returns:
      the RVA of the first byte of data when loaded into memory

  - ### getSizeOfImage

    public long getSizeOfImage()
    Specified by:
      `getSizeOfImage` in interface `OptionalHeader`
    Returns:
      the RVA that would be assigned to the next section following the last section

  - ### setSizeOfImage

    public void setSizeOfImage(long size)
    Specified by:
      `setSizeOfImage` in interface `OptionalHeader`
    See Also:
      - `OptionalHeader.getSizeOfImage()`

  - ### getSizeOfHeaders

    public long getSizeOfHeaders()
    Specified by:
      `getSizeOfHeaders` in interface `OptionalHeader`
    Returns:
      the combined size of all headers

  - ### setSizeOfHeaders

    public void setSizeOfHeaders(long size)
    Specified by:
      `setSizeOfHeaders` in interface `OptionalHeader`
    See Also:
      - `OptionalHeader.getSizeOfHeaders()`

  - ### getNumberOfRvaAndSizes

    public long getNumberOfRvaAndSizes()
    Specified by:
      `getNumberOfRvaAndSizes` in interface `OptionalHeader`

  - ### getMajorOperatingSystemVersion

    public short getMajorOperatingSystemVersion()
    Description copied from interface: `OptionalHeader`
    Return the major version number of the required operating system.
    Specified by:
      `getMajorOperatingSystemVersion` in interface `OptionalHeader`
    Returns:

  - ### getMinorOperatingSystemVersion

    public short getMinorOperatingSystemVersion()
    Description copied from interface: `OptionalHeader`
    Return the minor version number of the required operating system.
    Specified by:
      `getMinorOperatingSystemVersion` in interface `OptionalHeader`
    Returns:

  - ### processDataDirectories

    public void processDataDirectories(TaskMonitor monitor) throws IOException
    Description copied from interface: `OptionalHeader`
    This methods tells this optional header to process its data directories.
    Specified by:
      `processDataDirectories` in interface `OptionalHeader`
    Throws:
      `IOException`

  - ### getDataDirectories

    public DataDirectory[] getDataDirectories()
    Description copied from interface: `OptionalHeader`
    Returns the array of data directories.
    Specified by:
      `getDataDirectories` in interface `OptionalHeader`
    Returns:
      the array of data directories

  - ### getSectionAlignment

    public int getSectionAlignment()
    Specified by:
      `getSectionAlignment` in interface `OptionalHeader`
    Returns:
      the section alignment

  - ### getFileAlignment

    public int getFileAlignment()
    Specified by:
      `getFileAlignment` in interface `OptionalHeader`
    Returns:
      the file alignment

  - ### parse

    protected void parse() throws IOException
    Throws:
      `IOException`

  - ### toDataType

    public DataType toDataType() throws DuplicateNameException
    Description copied from interface: `StructConverter`
    Returns a structure datatype representing the contents of the implementor of this interface.

    For example, given:

         class A {
             int foo;
             double bar;
         }

    The return value should be a structure data type with two data type components; an INT and a DOUBLE. The structure should contain field names and, if possible, field comments.

    Specified by:
      `toDataType` in interface `StructConverter`
    Returns:
      returns a structure datatype representing the implementor of this interface
    Throws:
      `DuplicateNameException` - when a datatype of the same name already exists
    See Also:
      - `StructConverter.toDataType()`

  - ### writeHeader

    public void writeHeader(RandomAccessFile raf, DataConverter dc) throws IOException
    Description copied from interface: `OptionalHeader`
    Writes this optional header to the specified random access file.
    Specified by:
      `writeHeader` in interface `OptionalHeader`
    Parameters:
      `raf` - the random access file
      `dc` - the data converter
    Throws:
      `IOException`

  - ### validateDataDirectories

    public void validateDataDirectories(Program program)
    Specified by:
      `validateDataDirectories` in interface `OptionalHeader`

  - ### isCLI

    public boolean isCLI() throws IOException
    Specified by:
      `isCLI` in interface `OptionalHeader`
    Returns:
      true if the PE uses predominantly CLI code; otherwise, false.
    Throws:
      `IOException`

  - ### getMajorLinkerVersion

    public byte getMajorLinkerVersion()
    Description copied from interface: `OptionalHeader`
    Return the major version number of the linker that built this binary.
    Specified by:
      `getMajorLinkerVersion` in interface `OptionalHeader`
    Returns:

  - ### getMinorLinkerVersion

    public byte getMinorLinkerVersion()
    Description copied from interface: `OptionalHeader`
    Return the minor version number of the linker that built this binary.
    Specified by:
      `getMinorLinkerVersion` in interface `OptionalHeader`
    Returns:

  - ### getMajorImageVersion

    public short getMajorImageVersion()
    Description copied from interface: `OptionalHeader`
    Get the major version number of the image.
    Specified by:
      `getMajorImageVersion` in interface `OptionalHeader`
    Returns:

  - ### getMinorImageVersion

    public short getMinorImageVersion()
    Description copied from interface: `OptionalHeader`
    Get the minor version number of the image.
    Specified by:
      `getMinorImageVersion` in interface `OptionalHeader`
    Returns:

  - ### getMajorSubsystemVersion

    public short getMajorSubsystemVersion()
    Description copied from interface: `OptionalHeader`
    Get the major version number of the subsystem.
    Specified by:
      `getMajorSubsystemVersion` in interface `OptionalHeader`

  - ### getMinorSubsystemVersion

    public short getMinorSubsystemVersion()
    Description copied from interface: `OptionalHeader`
    Get the minor version number of the subsystem.
    Specified by:
      `getMinorSubsystemVersion` in interface `OptionalHeader`
    Returns:

  - ### getWin32VersionValue

    public int getWin32VersionValue()
    Description copied from interface: `OptionalHeader`
    This value is reserved, and must be 0
    Specified by:
      `getWin32VersionValue` in interface `OptionalHeader`

  - ### getChecksum

    public int getChecksum()
    Description copied from interface: `OptionalHeader`
    Get the image file checksum.
    Specified by:
      `getChecksum` in interface `OptionalHeader`
    Returns:

  - ### getSubsystem

    public int getSubsystem()
    Description copied from interface: `OptionalHeader`
    Get the subsystem that is required to run this image.
    Specified by:
      `getSubsystem` in interface `OptionalHeader`
    Returns:

  - ### getDllCharacteristics

    public short getDllCharacteristics()
    Description copied from interface: `OptionalHeader`
    Return flags that describe properties of and features of this binary.
    Specified by:
      `getDllCharacteristics` in interface `OptionalHeader`
    Returns:
    See Also:
      - `DllCharacteristics`

  - ### getSizeOfStackReserve

    public long getSizeOfStackReserve()
    Description copied from interface: `OptionalHeader`
    Return the size of the stack reservation
    Specified by:
      `getSizeOfStackReserve` in interface `OptionalHeader`
    Returns:

  - ### getSizeOfStackCommit

    public long getSizeOfStackCommit()
    Description copied from interface: `OptionalHeader`
    Return the size of the stack to commit
    Specified by:
      `getSizeOfStackCommit` in interface `OptionalHeader`
    Returns:

  - ### getSizeOfHeapReserve

    public long getSizeOfHeapReserve()
    Description copied from interface: `OptionalHeader`
    Return the size of the heap reservation
    Specified by:
      `getSizeOfHeapReserve` in interface `OptionalHeader`
    Returns:

  - ### getSizeOfHeapCommit

    public long getSizeOfHeapCommit()
    Description copied from interface: `OptionalHeader`
    Return the size of the heap to commit
    Specified by:
      `getSizeOfHeapCommit` in interface `OptionalHeader`
    Returns:

  - ### getLoaderFlags

    public int getLoaderFlags()
    Description copied from interface: `OptionalHeader`
    Return the flags passed to the loader. Obsolete.
    Specified by:
      `getLoaderFlags` in interface `OptionalHeader`
    Returns: