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

# Interface OptionalHeader

All Superinterfaces:
  `StructConverter`

All Known Implementing Classes:
  `OptionalHeaderImpl`

public interface OptionalHeader extends StructConverter

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final byte`
  `IMAGE_DIRECTORY_ENTRY_ARCHITECTURE`
  Architecture Specific Data directory index
  `static final byte`
  `IMAGE_DIRECTORY_ENTRY_BASERELOC`
  Base Relocation Table directory index
  `static final byte`
  `IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT`
  Bound Import directory index
  `static final byte`
  `IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR`
  COM Runtime Descriptor directory index
  `static final byte`
  `IMAGE_DIRECTORY_ENTRY_COMHEADER`
  New name for the COM Descriptor directory index
  `static final byte`
  `IMAGE_DIRECTORY_ENTRY_DEBUG`
  Debug directory index
  `static final byte`
  `IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT`
  Delay Load Import Descriptors directory index
  `static final byte`
  `IMAGE_DIRECTORY_ENTRY_EXCEPTION`
  Exception directory index
  `static final byte`
  `IMAGE_DIRECTORY_ENTRY_EXPORT`
  Export directory index
  `static final byte`
  `IMAGE_DIRECTORY_ENTRY_GLOBALPTR`
  Global Pointer directory index
  `static final byte`
  `IMAGE_DIRECTORY_ENTRY_IAT`
  Import Address Table directory index
  `static final byte`
  `IMAGE_DIRECTORY_ENTRY_IMPORT`
  Import directory index
  `static final byte`
  `IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG`
  Load Configuration directory index
  `static final byte`
  `IMAGE_DIRECTORY_ENTRY_RESOURCE`
  Resource directory index
  `static final byte`
  `IMAGE_DIRECTORY_ENTRY_SECURITY`
  Security directory index
  `static final byte`
  `IMAGE_DIRECTORY_ENTRY_TLS`
  TLS directory index
  `static final int`
  `IMAGE_DLLCHARACTERISTICS_APPCONTAINER`
  Image should execute in an AppContainer.
  `static final int`
  `IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE`
  The DLL can be relocated at load time.
  `static final int`
  `IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY`
  Code integrity checks are forced.
  `static final int`
  `IMAGE_DLLCHARACTERISTICS_GUARD_CF`
  Image supports Control Flow Guard.
  `static final int`
  `IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA`
  ASLR with 64 bit address space.
  `static final int`
  `IMAGE_DLLCHARACTERISTICS_NO_BIND`
  Do not bind the image.
  `static final int`
  `IMAGE_DLLCHARACTERISTICS_NO_ISOLATION`
  The image is isolation aware, but should not be isolated.
  `static final int`
  `IMAGE_DLLCHARACTERISTICS_NO_SEH`
  The image does not use structured exception handling (SEH).
  `static final int`
  `IMAGE_DLLCHARACTERISTICS_NX_COMPAT`
  The image is compatible with data execution prevention (DEP)
  `static final int`
  `IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE`
  The image is terminal server aware.
  `static final int`
  `IMAGE_DLLCHARACTERISTICS_WDM_DRIVER`
  A WDM driver.
  `static final byte`
  `IMAGE_NUMBEROF_DIRECTORY_ENTRIES`
  The count of data directories in the optional header.

  ### 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()`
  `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)`
  `void`
  `validateDataDirectories(Program program)`
  `void`
  `writeHeader(RandomAccessFile raf, DataConverter dc)`
  Writes this optional header to the specified random access file.

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

  `toDataType`

- ## Field Details

  - ### IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA

    static final int IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA
    ASLR with 64 bit address space.
    See Also:
      - Constant Field Values

  - ### IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE

    static final int IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE
    The DLL can be relocated at load time.
    See Also:
      - Constant Field Values

  - ### IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY

    static final int IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY
    Code integrity checks are forced.
    See Also:
      - Constant Field Values

  - ### IMAGE_DLLCHARACTERISTICS_NX_COMPAT

    static final int IMAGE_DLLCHARACTERISTICS_NX_COMPAT
    The image is compatible with data execution prevention (DEP)
    See Also:
      - Constant Field Values

  - ### IMAGE_DLLCHARACTERISTICS_NO_ISOLATION

    static final int IMAGE_DLLCHARACTERISTICS_NO_ISOLATION
    The image is isolation aware, but should not be isolated.
    See Also:
      - Constant Field Values

  - ### IMAGE_DLLCHARACTERISTICS_NO_SEH

    static final int IMAGE_DLLCHARACTERISTICS_NO_SEH
    The image does not use structured exception handling (SEH).
    See Also:
      - Constant Field Values

  - ### IMAGE_DLLCHARACTERISTICS_NO_BIND

    static final int IMAGE_DLLCHARACTERISTICS_NO_BIND
    Do not bind the image.
    See Also:
      - Constant Field Values

  - ### IMAGE_DLLCHARACTERISTICS_APPCONTAINER

    static final int IMAGE_DLLCHARACTERISTICS_APPCONTAINER
    Image should execute in an AppContainer.
    See Also:
      - Constant Field Values

  - ### IMAGE_DLLCHARACTERISTICS_WDM_DRIVER

    static final int IMAGE_DLLCHARACTERISTICS_WDM_DRIVER
    A WDM driver.
    See Also:
      - Constant Field Values

  - ### IMAGE_DLLCHARACTERISTICS_GUARD_CF

    static final int IMAGE_DLLCHARACTERISTICS_GUARD_CF
    Image supports Control Flow Guard.
    See Also:
      - Constant Field Values

  - ### IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE

    static final int IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE
    The image is terminal server aware.
    See Also:
      - Constant Field Values

  - ### IMAGE_NUMBEROF_DIRECTORY_ENTRIES

    static final byte IMAGE_NUMBEROF_DIRECTORY_ENTRIES
    The count of data directories in the optional header.
    See Also:
      - Constant Field Values

  - ### IMAGE_DIRECTORY_ENTRY_EXPORT

    static final byte IMAGE_DIRECTORY_ENTRY_EXPORT
    Export directory index
    See Also:
      - Constant Field Values

  - ### IMAGE_DIRECTORY_ENTRY_IMPORT

    static final byte IMAGE_DIRECTORY_ENTRY_IMPORT
    Import directory index
    See Also:
      - Constant Field Values

  - ### IMAGE_DIRECTORY_ENTRY_RESOURCE

    static final byte IMAGE_DIRECTORY_ENTRY_RESOURCE
    Resource directory index
    See Also:
      - Constant Field Values

  - ### IMAGE_DIRECTORY_ENTRY_EXCEPTION

    static final byte IMAGE_DIRECTORY_ENTRY_EXCEPTION
    Exception directory index
    See Also:
      - Constant Field Values

  - ### IMAGE_DIRECTORY_ENTRY_SECURITY

    static final byte IMAGE_DIRECTORY_ENTRY_SECURITY
    Security directory index
    See Also:
      - Constant Field Values

  - ### IMAGE_DIRECTORY_ENTRY_BASERELOC

    static final byte IMAGE_DIRECTORY_ENTRY_BASERELOC
    Base Relocation Table directory index
    See Also:
      - Constant Field Values

  - ### IMAGE_DIRECTORY_ENTRY_DEBUG

    static final byte IMAGE_DIRECTORY_ENTRY_DEBUG
    Debug directory index
    See Also:
      - Constant Field Values

  - ### IMAGE_DIRECTORY_ENTRY_ARCHITECTURE

    static final byte IMAGE_DIRECTORY_ENTRY_ARCHITECTURE
    Architecture Specific Data directory index
    See Also:
      - Constant Field Values

  - ### IMAGE_DIRECTORY_ENTRY_GLOBALPTR

    static final byte IMAGE_DIRECTORY_ENTRY_GLOBALPTR
    Global Pointer directory index
    See Also:
      - Constant Field Values

  - ### IMAGE_DIRECTORY_ENTRY_TLS

    static final byte IMAGE_DIRECTORY_ENTRY_TLS
    TLS directory index
    See Also:
      - Constant Field Values

  - ### IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG

    static final byte IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG
    Load Configuration directory index
    See Also:
      - Constant Field Values

  - ### IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT

    static final byte IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT
    Bound Import directory index
    See Also:
      - Constant Field Values

  - ### IMAGE_DIRECTORY_ENTRY_IAT

    static final byte IMAGE_DIRECTORY_ENTRY_IAT
    Import Address Table directory index
    See Also:
      - Constant Field Values

  - ### IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT

    static final byte IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT
    Delay Load Import Descriptors directory index
    See Also:
      - Constant Field Values

  - ### IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR

    static final byte IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR
    COM Runtime Descriptor directory index
    See Also:
      - Constant Field Values

  - ### IMAGE_DIRECTORY_ENTRY_COMHEADER

    static final byte IMAGE_DIRECTORY_ENTRY_COMHEADER
    New name for the COM Descriptor directory index
    See Also:
      - Constant Field Values

- ## Method Details

  - ### is64bit

    boolean is64bit()
    Returns true of this optional header is 64-bit.
    Returns:
      true of this optional header is 64-bit

  - ### getMajorLinkerVersion

    byte getMajorLinkerVersion()
    Return the major version number of the linker that built this binary.
    Returns:

  - ### getMinorLinkerVersion

    byte getMinorLinkerVersion()
    Return the minor version number of the linker that built this binary.
    Returns:

  - ### getMajorOperatingSystemVersion

    short getMajorOperatingSystemVersion()
    Return the major version number of the required operating system.
    Returns:

  - ### getMinorOperatingSystemVersion

    short getMinorOperatingSystemVersion()
    Return the minor version number of the required operating system.
    Returns:

  - ### getMajorImageVersion

    short getMajorImageVersion()
    Get the major version number of the image.
    Returns:

  - ### getMinorImageVersion

    short getMinorImageVersion()
    Get the minor version number of the image.
    Returns:

  - ### getMajorSubsystemVersion

    short getMajorSubsystemVersion()
    Get the major version number of the subsystem.

  - ### getMinorSubsystemVersion

    short getMinorSubsystemVersion()
    Get the minor version number of the subsystem.
    Returns:

  - ### getWin32VersionValue

    int getWin32VersionValue()
    This value is reserved, and must be 0

  - ### getChecksum

    int getChecksum()
    Get the image file checksum.
    Returns:

  - ### getSubsystem

    int getSubsystem()
    Get the subsystem that is required to run this image.
    Returns:

  - ### getDllCharacteristics

    short getDllCharacteristics()
    Return flags that describe properties of and features of this binary.
    Returns:
    See Also:
      - `DllCharacteristics`

  - ### getSizeOfStackReserve

    long getSizeOfStackReserve()
    Return the size of the stack reservation
    Returns:

  - ### getSizeOfStackCommit

    long getSizeOfStackCommit()
    Return the size of the stack to commit
    Returns:

  - ### getSizeOfHeapReserve

    long getSizeOfHeapReserve()
    Return the size of the heap reservation
    Returns:

  - ### getSizeOfHeapCommit

    long getSizeOfHeapCommit()
    Return the size of the heap to commit
    Returns:

  - ### getLoaderFlags

    int getLoaderFlags()
    Return the flags passed to the loader. Obsolete.
    Returns:

  - ### getAddressOfEntryPoint

    long getAddressOfEntryPoint()
    Returns:
      the RVA of the first code byte in the file that will be executed

  - ### getImageBase

    long getImageBase()
    Returns:
      the preferred load address of this file in memory

  - ### getSizeOfImage

    long getSizeOfImage()
    Returns:
      the RVA that would be assigned to the next section following the last section

  - ### setSizeOfImage

    void setSizeOfImage(long size)
    See Also:
      - `getSizeOfImage()`

  - ### getSizeOfHeaders

    long getSizeOfHeaders()
    Returns:
      the combined size of all headers

  - ### setSizeOfHeaders

    void setSizeOfHeaders(long size)
    See Also:
      - `getSizeOfHeaders()`

  - ### getSizeOfCode

    long getSizeOfCode()
    Returns the combined total size of all sections with the `IMAGE_SCN_CNT_CODE` attribute.
    Returns:
      the combined total size of all sections with the `IMAGE_SCN_CNT_CODE` attribute.

  - ### setSizeOfCode

    void setSizeOfCode(long size)
    See Also:
      - `getSizeOfCode()`

  - ### getNumberOfRvaAndSizes

    long getNumberOfRvaAndSizes()

  - ### getSizeOfInitializedData

    long getSizeOfInitializedData()
    Returns the combined size of all initialized data sections.
    Returns:
      the combined size of all initialized data sections

  - ### setSizeOfInitializedData

    void setSizeOfInitializedData(long size)
    See Also:
      - `getSizeOfInitializedData()`

  - ### getSizeOfUninitializedData

    long getSizeOfUninitializedData()
    Returns the size of all sections with the uninitialized data attributes.
    Returns:
      the size of all sections with the uninitialized data attributes

  - ### setSizeOfUninitializedData

    void setSizeOfUninitializedData(long size)
    See Also:
      - `getSizeOfUninitializedData()`

  - ### getBaseOfCode

    long getBaseOfCode()
    Returns the RVA of the first byte of code when loaded in memory.
    Returns:
      the RVA of the first byte of code when loaded in memory

  - ### getBaseOfData

    long getBaseOfData()
    Returns:
      the RVA of the first byte of data when loaded into memory

  - ### processDataDirectories

    void processDataDirectories(TaskMonitor monitor) throws IOException
    This methods tells this optional header to process its data directories.
    Throws:
      `IOException`

  - ### getDataDirectories

    DataDirectory[] getDataDirectories()
    Returns the array of data directories.
    Returns:
      the array of data directories

  - ### getSectionAlignment

    int getSectionAlignment()
    Returns:
      the section alignment

  - ### getFileAlignment

    int getFileAlignment()
    Returns:
      the file alignment

  - ### writeHeader

    void writeHeader(RandomAccessFile raf, DataConverter dc) throws IOException
    Writes this optional header to the specified random access file.
    Parameters:
      `raf` - the random access file
      `dc` - the data converter
    Throws:
      `IOException`

  - ### validateDataDirectories

    void validateDataDirectories(Program program)

  - ### isCLI

    boolean isCLI() throws IOException
    Returns:
      true if the PE uses predominantly CLI code; otherwise, false.
    Throws:
      `IOException`