Class OptionalHeader
- Namespace
- AsmResolver.PE.File
- Assembly
- AsmResolver.PE.File.dll
Represents a 32-bit or 64-bit optional header in a portable executable (PE) file.
public class OptionalHeader : SegmentBase, ISegment, IOffsetProvider, IWritable
- Inheritance
-
OptionalHeader
- Implements
- Inherited Members
Fields
DefaultNumberOfRvasAndSizes
Indicates the default number of data directory entries in an optional header.
public const int DefaultNumberOfRvasAndSizes = 16
Field Value
OptionalHeader32SizeExcludingDataDirectories
Indicates the static size of an optional header in a 32-bit portable executable file, excluding the data directory entries.
public const uint OptionalHeader32SizeExcludingDataDirectories = 96
Field Value
OptionalHeader64SizeExcludingDataDirectories
Indicates the static size of an optional header in a 64-bit portable executable file, excluding the data directory entries.
public const uint OptionalHeader64SizeExcludingDataDirectories = 112
Field Value
OptionalHeaderSizeOfImageFieldOffset
Indicates the offset of the SizeOfImage field in the optional header.
public const uint OptionalHeaderSizeOfImageFieldOffset = 56
Field Value
Properties
AddressOfEntryPoint
Gets or sets the relative virtual address to the entry point of the portable executable (PE) file.
public uint AddressOfEntryPoint { get; set; }
Property Value
BaseOfCode
Gets or sets the relative virtual address (RVA) to the beginning of the code section, when loaded into memory.
public uint BaseOfCode { get; set; }
Property Value
BaseOfData
Gets or sets the relative virtual address to the begin of the data section, when loaded into memory.
public uint BaseOfData { get; set; }
Property Value
CheckSum
Gets or sets the checksum of the portable executable (PE) file.
public uint CheckSum { get; set; }
Property Value
DataDirectories
Gets the data directory headers defined in the optional header.
public IList<DataDirectory> DataDirectories { get; }
Property Value
DllCharacteristics
Gets or sets the dynamic linked library characteristics of the portable executable (PE) file.
public DllCharacteristics DllCharacteristics { get; set; }
Property Value
FileAlignment
Gets or sets the alignment of the raw data of sections in the image file. Must be a power of 2 between 512 and 64,000.
public uint FileAlignment { get; set; }
Property Value
ImageBase
Gets or sets the preferred address of the first byte of the image when loaded into memory. Must be a multiple of 64,000.
public ulong ImageBase { get; set; }
Property Value
LoaderFlags
Obsolete.
public uint LoaderFlags { get; set; }
Property Value
Magic
Gets or sets the magic optional header signature, determining whether the image is a PE32 (32-bit) or a PE32+ (64-bit) image.
public OptionalHeaderMagic Magic { get; set; }
Property Value
MajorImageVersion
Gets or sets the major image version.
public ushort MajorImageVersion { get; set; }
Property Value
MajorLinkerVersion
Gets or sets the major linker version used to link the portable executable (PE) file.
public byte MajorLinkerVersion { get; set; }
Property Value
MajorOperatingSystemVersion
Gets or sets the minimum major version of the operating system required to run the portable executable (PE) file.
public ushort MajorOperatingSystemVersion { get; set; }
Property Value
MajorSubsystemVersion
Gets or sets the major version of the subsystem.
public ushort MajorSubsystemVersion { get; set; }
Property Value
MinorImageVersion
Gets or sets the minor image version.
public ushort MinorImageVersion { get; set; }
Property Value
MinorLinkerVersion
Gets or sets the minor linker version used to link the portable executable (PE) file.
public byte MinorLinkerVersion { get; set; }
Property Value
MinorOperatingSystemVersion
Gets or sets the minimum minor version of the operating system required to run the portable executable (PE) file.
public ushort MinorOperatingSystemVersion { get; set; }
Property Value
MinorSubsystemVersion
Gets or sets the minor version of the subsystem.
public ushort MinorSubsystemVersion { get; set; }
Property Value
NumberOfRvaAndSizes
Gets or sets the number of data directory headers defined in the optional header.
public uint NumberOfRvaAndSizes { get; set; }
Property Value
SectionAlignment
Gets or sets the alignment of the sections when loaded into memory. Must be greater or equal to FileAlignment. Default is the page size for the architecture.
public uint SectionAlignment { get; set; }
Property Value
SizeOfCode
Gets or sets the total amount of bytes the code sections consist of.
public uint SizeOfCode { get; set; }
Property Value
SizeOfHeaders
Gets or sets the size of the headers of the portable executable (PE) file, including the DOS-, PE- and section headers, rounded to FileAlignment.
public uint SizeOfHeaders { get; set; }
Property Value
SizeOfHeapCommit
Gets or sets the size of the heap to commit.
public ulong SizeOfHeapCommit { get; set; }
Property Value
SizeOfHeapReserve
Gets or sets the size of the heap to reserve.
public ulong SizeOfHeapReserve { get; set; }
Property Value
SizeOfImage
Gets or sets the size in bytes of the portable executable (PE) file, including all headers. Must be a multiple of SectionAlignment.
public uint SizeOfImage { get; set; }
Property Value
SizeOfInitializedData
Gets or sets the total amount of bytes the initialized data sections consist of.
public uint SizeOfInitializedData { get; set; }
Property Value
SizeOfStackCommit
Gets or sets the size of the stack to commit.
public ulong SizeOfStackCommit { get; set; }
Property Value
SizeOfStackReserve
Gets or sets the size of the stack to reserve.
public ulong SizeOfStackReserve { get; set; }
Property Value
SizeOfUninitializedData
Gets or sets the total amount of bytes the uninitialized data sections consist of.
public uint SizeOfUninitializedData { get; set; }
Property Value
SubSystem
Gets or sets the subsystem to use when running the portable executable (PE) file.
public SubSystem SubSystem { get; set; }
Property Value
Win32VersionValue
Reserved, should be zero.
public uint Win32VersionValue { get; set; }
Property Value
Methods
EnsureDataDirectoryCount(int)
Ensures the provided number of data directories are present in DataDirectories.
public void EnsureDataDirectoryCount(int count)
Parameters
count
intThe number of data directories.
FromReader(ref BinaryStreamReader, bool)
Reads an optional header from the provided input stream.
public static OptionalHeader FromReader(ref BinaryStreamReader reader, bool ignoreNumberOfRvasAndSizes = true)
Parameters
reader
BinaryStreamReaderThe input stream.
ignoreNumberOfRvasAndSizes
boolIndicates whether the number of data directories should be ignored and DefaultNumberOfRvasAndSizes should be used instead.
Returns
- OptionalHeader
The optional header.
Exceptions
- BadImageFormatException
Occurs when the input stream is malformed.
GetDataDirectory(DataDirectoryIndex)
Gets a data directory by its index.
public DataDirectory GetDataDirectory(DataDirectoryIndex index)
Parameters
index
DataDirectoryIndexThe index.
Returns
- DataDirectory
The data directory entry.
GetPhysicalSize()
Computes the number of bytes that the structure contains.
public override uint GetPhysicalSize()
Returns
- uint
The number of bytes.
SetDataDirectory(DataDirectoryIndex, ISegment?)
Maps a segment to a data directory.
public void SetDataDirectory(DataDirectoryIndex index, ISegment? contents)
Parameters
index
DataDirectoryIndexThe index.
contents
ISegmentThe contents of the data directory, or
null
to indicate an absence of the directory.
SetDataDirectory(DataDirectoryIndex, DataDirectory)
Sets a data directory by its index.
public void SetDataDirectory(DataDirectoryIndex index, DataDirectory directory)
Parameters
index
DataDirectoryIndexThe index.
directory
DataDirectoryThe new data directory entry.
Write(BinaryStreamWriter)
Serializes the structure to an output stream.
public override void Write(BinaryStreamWriter writer)
Parameters
writer
BinaryStreamWriterThe output stream to write the data to.