Package ghidra.app.util.bin.format.pe
Class OptionalHeader
java.lang.Object
ghidra.app.util.bin.format.pe.OptionalHeader
- All Implemented Interfaces:
StructConverter
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
FieldsModifier and TypeFieldDescriptionprotected intprotected intprotected intprotected intprotected DataDirectory[]protected shortprotected intstatic final byteArchitecture Specific Data directory indexstatic final byteBase Relocation Table directory indexstatic final byteBound Import directory indexstatic final byteCOM Runtime Descriptor directory indexstatic final byteNew name for the COM Descriptor directory indexstatic final byteDebug directory indexstatic final byteDelay Load Import Descriptors directory indexstatic final byteException directory indexstatic final byteExport directory indexstatic final byteGlobal Pointer directory indexstatic final byteImport Address Table directory indexstatic final byteImport directory indexstatic final byteLoad Configuration directory indexstatic final byteResource directory indexstatic final byteSecurity directory indexstatic final byteTLS directory indexstatic final intImage should execute in an AppContainer.static final intThe DLL can be relocated at load time.static final intCode integrity checks are forced.static final intImage supports Control Flow Guard.static final intASLR with 64 bit address space.static final intDo not bind the image.static final intThe image is isolation aware, but should not be isolated.static final intThe image does not use structured exception handling (SEH).static final intThe image is compatible with data execution prevention (DEP)static final intThe image is terminal server aware.static final intA WDM driver.static final byteThe count of data directories in the optional header.protected longprotected intprotected shortprotected shortprotected byteprotected shortprotected shortprotected shortprotected byteprotected shortprotected shortprotected NTHeaderprotected intprotected BinaryReaderprotected intprotected intprotected intprotected longprotected longprotected intprotected intprotected longprotected longprotected intprotected intprotected shortprotected int -
Method Summary
Modifier and TypeMethodDescriptionlongReturns the RVA of the first code byte in the file that will be executed.longReturns the RVA of the first byte of code when loaded in memory..longReturns the RVA of the first byte of data when loaded into memory..intReturns the image file checksum..Returns the array of data directories..shortReturns the flags that describe properties of and features of this binary..intReturns the file alignment.longReturns the preferred load address of this file in memory.intReturns the flags passed to the loader. Obsolete..shortReturns the major version number of the image..byteReturns the major version number of the linker that built this binary..shortReturns the major version number of the required operating system..shortReturns the major version number of the subsystem..shortReturns the minor version number of the image..byteReturns the minor version number of the linker that built this binary..shortReturns the minor version number of the required operating system..shortReturns the minor version number of the subsystem..longReturns the number of data-directory entries in the remainder of the optional header..intReturns the section alignment.longReturns the combined total size of all sections with IMAGE_SCN_CNT_CODE attribute..longReturns the combined size of all headers.longReturns the size of the heap to commit.longReturns the size of the heap reservation.longReturns the RVA that would be assigned to the next section following the last section.longReturns the combined size of all initialized data sections..longReturns the size of the stack to commit.longReturns the size of the stack reservation.longReturns the size of all sections with the uninitialized data attributes..intReturns the subsystem that is required to run this image..intReturns the reserved value, which must be 0.booleanis64bit()Returns true of this optional header is 64-bit..booleanisCLI()Returns true if the PE uses predominantly CLI code; otherwise, false..protected voidparse()voidprocessDataDirectories(MessageLog log, TaskMonitor monitor) This methods tells this optional header to process its data directories.voidsetSizeOfCode(long size) Sets the combined total size of all sections with the IMAGE_SCN_CNT_CODE attribute.voidsetSizeOfHeaders(long size) Sets the combined size of all headersvoidsetSizeOfImage(long size) Sets the RVA that would be assigned to the next section following the last sectionvoidsetSizeOfInitializedData(long size) Sets the combined size of all initialized data sections}voidsetSizeOfUninitializedData(long size) Sets the size of all sections with the uninitialized data attributes.}Returns a structure datatype representing the contents of the implementor of this interface.voidvalidateDataDirectories(Program program) voidwriteHeader(RandomAccessFile raf, DataConverter dc) Writes this optional header to the specified random access file.
-
Field Details
-
IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA
public static final int IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VAASLR with 64 bit address space.- See Also:
-
IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE
public static final int IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASEThe DLL can be relocated at load time.- See Also:
-
IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY
public static final int IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITYCode integrity checks are forced.- See Also:
-
IMAGE_DLLCHARACTERISTICS_NX_COMPAT
public static final int IMAGE_DLLCHARACTERISTICS_NX_COMPATThe image is compatible with data execution prevention (DEP)- See Also:
-
IMAGE_DLLCHARACTERISTICS_NO_ISOLATION
public static final int IMAGE_DLLCHARACTERISTICS_NO_ISOLATIONThe image is isolation aware, but should not be isolated.- See Also:
-
IMAGE_DLLCHARACTERISTICS_NO_SEH
public static final int IMAGE_DLLCHARACTERISTICS_NO_SEHThe image does not use structured exception handling (SEH).- See Also:
-
IMAGE_DLLCHARACTERISTICS_NO_BIND
public static final int IMAGE_DLLCHARACTERISTICS_NO_BINDDo not bind the image.- See Also:
-
IMAGE_DLLCHARACTERISTICS_APPCONTAINER
public static final int IMAGE_DLLCHARACTERISTICS_APPCONTAINERImage should execute in an AppContainer.- See Also:
-
IMAGE_DLLCHARACTERISTICS_WDM_DRIVER
public static final int IMAGE_DLLCHARACTERISTICS_WDM_DRIVERA WDM driver.- See Also:
-
IMAGE_DLLCHARACTERISTICS_GUARD_CF
public static final int IMAGE_DLLCHARACTERISTICS_GUARD_CFImage supports Control Flow Guard.- See Also:
-
IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE
public static final int IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWAREThe image is terminal server aware.- See Also:
-
IMAGE_NUMBEROF_DIRECTORY_ENTRIES
public static final byte IMAGE_NUMBEROF_DIRECTORY_ENTRIESThe count of data directories in the optional header.- See Also:
-
IMAGE_DIRECTORY_ENTRY_EXPORT
public static final byte IMAGE_DIRECTORY_ENTRY_EXPORTExport directory index- See Also:
-
IMAGE_DIRECTORY_ENTRY_IMPORT
public static final byte IMAGE_DIRECTORY_ENTRY_IMPORTImport directory index- See Also:
-
IMAGE_DIRECTORY_ENTRY_RESOURCE
public static final byte IMAGE_DIRECTORY_ENTRY_RESOURCEResource directory index- See Also:
-
IMAGE_DIRECTORY_ENTRY_EXCEPTION
public static final byte IMAGE_DIRECTORY_ENTRY_EXCEPTIONException directory index- See Also:
-
IMAGE_DIRECTORY_ENTRY_SECURITY
public static final byte IMAGE_DIRECTORY_ENTRY_SECURITYSecurity directory index- See Also:
-
IMAGE_DIRECTORY_ENTRY_BASERELOC
public static final byte IMAGE_DIRECTORY_ENTRY_BASERELOCBase Relocation Table directory index- See Also:
-
IMAGE_DIRECTORY_ENTRY_DEBUG
public static final byte IMAGE_DIRECTORY_ENTRY_DEBUGDebug directory index- See Also:
-
IMAGE_DIRECTORY_ENTRY_ARCHITECTURE
public static final byte IMAGE_DIRECTORY_ENTRY_ARCHITECTUREArchitecture Specific Data directory index- See Also:
-
IMAGE_DIRECTORY_ENTRY_GLOBALPTR
public static final byte IMAGE_DIRECTORY_ENTRY_GLOBALPTRGlobal Pointer directory index- See Also:
-
IMAGE_DIRECTORY_ENTRY_TLS
public static final byte IMAGE_DIRECTORY_ENTRY_TLSTLS directory index- See Also:
-
IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG
public static final byte IMAGE_DIRECTORY_ENTRY_LOAD_CONFIGLoad Configuration directory index- See Also:
-
IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT
public static final byte IMAGE_DIRECTORY_ENTRY_BOUND_IMPORTBound Import directory index- See Also:
-
IMAGE_DIRECTORY_ENTRY_IAT
public static final byte IMAGE_DIRECTORY_ENTRY_IATImport Address Table directory index- See Also:
-
IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT
public static final byte IMAGE_DIRECTORY_ENTRY_DELAY_IMPORTDelay Load Import Descriptors directory index- See Also:
-
IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR
public static final byte IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTORCOM Runtime Descriptor directory index- See Also:
-
IMAGE_DIRECTORY_ENTRY_COMHEADER
public static final byte IMAGE_DIRECTORY_ENTRY_COMHEADERNew name for the COM Descriptor directory index- See Also:
-
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
-
ntHeader
-
reader
-
startIndex
protected int startIndex
-
-
Method Details
-
parse
- Throws:
IOException
-
processDataDirectories
This methods tells this optional header to process its data directories.- Parameters:
log- The logmonitor- The monitor
-
is64bit
public boolean is64bit()Returns true of this optional header is 64-bit..- Returns:
- true of this optional header is 64-bit.
-
getMajorLinkerVersion
public byte getMajorLinkerVersion()Returns the major version number of the linker that built this binary..- Returns:
- the major version number of the linker that built this binary.
-
getMinorLinkerVersion
public byte getMinorLinkerVersion()Returns the minor version number of the linker that built this binary..- Returns:
- the minor version number of the linker that built this binary.
-
getSizeOfCode
public long getSizeOfCode()Returns the combined total size of all sections with IMAGE_SCN_CNT_CODE attribute..- Returns:
- the combined total size of all sections with IMAGE_SCN_CNT_CODE attribute.
-
setSizeOfCode
public void setSizeOfCode(long size) Sets the combined total size of all sections with the IMAGE_SCN_CNT_CODE attribute.- Parameters:
size- The size to set
-
getSizeOfInitializedData
public long getSizeOfInitializedData()Returns the combined size of all initialized data sections..- Returns:
- the combined size of all initialized data sections.
-
setSizeOfInitializedData
public void setSizeOfInitializedData(long size) Sets the combined size of all initialized data sections}- Parameters:
size- The size to set
-
getSizeOfUninitializedData
public 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
public void setSizeOfUninitializedData(long size) Sets the size of all sections with the uninitialized data attributes.}- Parameters:
size- The size to set
-
getAddressOfEntryPoint
public long getAddressOfEntryPoint()Returns the RVA of the first code byte in the file that will be executed.- Returns:
- the RVA of the first code byte in the file that will be executed
-
getBaseOfCode
public 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
public long getBaseOfData()Returns the RVA of the first byte of data when loaded into memory..- Returns:
- the RVA of the first byte of data when loaded into memory.
-
getImageBase
public long getImageBase()Returns the preferred load address of this file in memory.- Returns:
- the preferred load address of this file in memory
-
getSectionAlignment
public int getSectionAlignment()Returns the section alignment.- Returns:
- the section alignment
-
getFileAlignment
public int getFileAlignment()Returns the file alignment.- Returns:
- the file alignment
-
getMajorOperatingSystemVersion
public short getMajorOperatingSystemVersion()Returns the major version number of the required operating system..- Returns:
- the major version number of the required operating system.
-
getMinorOperatingSystemVersion
public short getMinorOperatingSystemVersion()Returns the minor version number of the required operating system..- Returns:
- the minor version number of the required operating system.
-
getMajorImageVersion
public short getMajorImageVersion()Returns the major version number of the image..- Returns:
- the major version number of the image.
-
getMinorImageVersion
public short getMinorImageVersion()Returns the minor version number of the image..- Returns:
- the minor version number of the image.
-
getMajorSubsystemVersion
public short getMajorSubsystemVersion()Returns the major version number of the subsystem..- Returns:
- the major version number of the subsystem.
-
getMinorSubsystemVersion
public short getMinorSubsystemVersion()Returns the minor version number of the subsystem..- Returns:
- the minor version number of the subsystem.
-
getWin32VersionValue
public int getWin32VersionValue()Returns the reserved value, which must be 0.- Returns:
- the reserved value, which must be 0
-
getSizeOfImage
public long getSizeOfImage()Returns the RVA that would be assigned to the next section following the last section.- Returns:
- the RVA that would be assigned to the next section following the last section
-
setSizeOfImage
public void setSizeOfImage(long size) Sets the RVA that would be assigned to the next section following the last section- Parameters:
size- The size to set
-
getSizeOfHeaders
public long getSizeOfHeaders()Returns the combined size of all headers.- Returns:
- the combined size of all headers
-
setSizeOfHeaders
public void setSizeOfHeaders(long size) Sets the combined size of all headers- Parameters:
size- The size to set
-
getChecksum
public int getChecksum()Returns the image file checksum..- Returns:
- the image file checksum.
-
getSubsystem
public int getSubsystem()Returns the subsystem that is required to run this image..- Returns:
- the subsystem that is required to run this image.
-
getDllCharacteristics
public short getDllCharacteristics()Returns the flags that describe properties of and features of this binary..- Returns:
- the flags that describe properties of and features of this binary.
- See Also:
-
getSizeOfStackReserve
public long getSizeOfStackReserve()Returns the size of the stack reservation.- Returns:
- the size of the stack reservation
-
getSizeOfStackCommit
public long getSizeOfStackCommit()Returns the size of the stack to commit.- Returns:
- the size of the stack to commit
-
getSizeOfHeapReserve
public long getSizeOfHeapReserve()Returns the size of the heap reservation.- Returns:
- the size of the heap reservation
-
getSizeOfHeapCommit
public long getSizeOfHeapCommit()Returns the size of the heap to commit.- Returns:
- the size of the heap to commit
-
getLoaderFlags
public int getLoaderFlags()Returns the flags passed to the loader. Obsolete..- Returns:
- the flags passed to the loader. Obsolete.
-
getNumberOfRvaAndSizes
public long getNumberOfRvaAndSizes()Returns the number of data-directory entries in the remainder of the optional header..- Returns:
- the number of data-directory entries in the remainder of the optional header.
-
getDataDirectories
Returns the array of data directories..- Returns:
- the array of data directories.
-
toDataType
Description copied from interface:StructConverterReturns 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:
toDataTypein interfaceStructConverter- Returns:
- returns a structure datatype representing the implementor of this interface
- Throws:
DuplicateNameException- when a datatype of the same name already exists- See Also:
-
writeHeader
Writes this optional header to the specified random access file.- Parameters:
raf- the random access filedc- the data converter- Throws:
IOException- if an IO-related error occurred
-
validateDataDirectories
-
isCLI
Returns true if the PE uses predominantly CLI code; otherwise, false..- Returns:
- true if the PE uses predominantly CLI code; otherwise, false.
- Throws:
IOException- if an IO-related error occurred
-