Class SectionHeader
- Namespace
- AsmResolver.PE.File
- Assembly
- AsmResolver.PE.File.dll
Represents a single section header in the portable executable (PE) file format.
public class SectionHeader : SegmentBase, ISegment, IOffsetProvider, IWritable, IOffsetConverter
- Inheritance
-
SectionHeader
- Implements
- Inherited Members
Constructors
SectionHeader(SectionHeader)
Creates a copy of the provided section header.
public SectionHeader(SectionHeader value)
Parameters
value
SectionHeaderThe section header to base information on.
SectionHeader(Utf8String, SectionFlags)
Creates a new section header with the provided name.
public SectionHeader(Utf8String name, SectionFlags characteristics)
Parameters
name
Utf8StringThe name of the new section.
characteristics
SectionFlagsThe section flags to assign.
Fields
SectionHeaderSize
Indicates the static size of a single section header.
public const uint SectionHeaderSize = 40
Field Value
Properties
Characteristics
Gets or sets the characteristics of the section.
public SectionFlags Characteristics { get; set; }
Property Value
Name
Gets or sets the name of the section.
public Utf8String Name { get; set; }
Property Value
Remarks
The name of the section is a UTF-8 string that can be no longer than 8 characters long.
NumberOfLineNumbers
Gets or sets the total amount of line numbers table referenced by PointerToLineNumbers for the section.
public ushort NumberOfLineNumbers { get; set; }
Property Value
Remarks
This field is not used in a normal PE image.
NumberOfRelocations
Gets or sets the number of relocations in the relocation table of the section.
public ushort NumberOfRelocations { get; set; }
Property Value
Remarks
This field is set to zero for executable files.
PointerToLineNumbers
Gets or sets the file offset to the beginning of the line numbers table for the section.
public uint PointerToLineNumbers { get; set; }
Property Value
Remarks
This field is set to zero in a normal PE image.
PointerToRawData
Gets or sets the file offset to the beginning of the section on disk.
public uint PointerToRawData { get; set; }
Property Value
PointerToRelocations
Gets or sets the file offset to the beginning of the relocations table for the section.
public uint PointerToRelocations { get; set; }
Property Value
Remarks
This field is set to zero in a normal PE image.
SizeOfRawData
Gets or sets the number of bytes the section consists of on disk.
public uint SizeOfRawData { get; set; }
Property Value
VirtualAddress
Gets or sets the virtual address (relative to the image base) of the section.
public uint VirtualAddress { get; set; }
Property Value
VirtualSize
Gets or sets the total number of bytes the section consists of when it is loaded into memory.
public uint VirtualSize { get; set; }
Property Value
Remarks
If the value is greater than SizeOfRawData, it is zero-padded when loaded into memory.
Methods
ContainsFileOffset(ulong)
Determines whether the provided file offset falls within the section that the header describes.
public bool ContainsFileOffset(ulong fileOffset)
Parameters
fileOffset
ulongThe offset to check.
Returns
- bool
true
if the file offset falls within the section,false
otherwise.
ContainsRva(uint)
Determines whether the provided virtual address falls within the section that the header describes.
public bool ContainsRva(uint rva)
Parameters
rva
uintThe virtual address to check.
Returns
- bool
true
if the virtual address falls within the section,false
otherwise.
FileOffsetToRva(ulong)
Converts a file offset to the virtual address when it is loaded into memory.
public uint FileOffsetToRva(ulong fileOffset)
Parameters
fileOffset
ulongThe file offset to convert.
Returns
- uint
The virtual address, relative to the image base.
Exceptions
- ArgumentOutOfRangeException
Occurs when the file offset falls outside of the range of the convertible file offsets.
FromReader(ref BinaryStreamReader)
Reads a single section header at the current position of the provided input stream.
public static SectionHeader FromReader(ref BinaryStreamReader reader)
Parameters
reader
BinaryStreamReaderThe input stream to read from.
Returns
- SectionHeader
The section header that was read.
GetPhysicalSize()
Computes the number of bytes that the structure contains.
public override uint GetPhysicalSize()
Returns
- uint
The number of bytes.
RvaToFileOffset(uint)
Converts a virtual address to the physical file offset.
public ulong RvaToFileOffset(uint rva)
Parameters
rva
uintThe virtual address, relative to the image base, to convert.
Returns
- ulong
The file offset.
Exceptions
- ArgumentOutOfRangeException
Occurs when the virtual address falls outside of the range of the convertible addresses.
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.
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.