Class PESection
- Namespace
- AsmResolver.PE.File
- Assembly
- AsmResolver.PE.File.dll
Represents a single section in a portable executable (PE) file.
public class PESection : IReadableSegment, ISegment, IOffsetProvider, IWritable, IOffsetConverter
- Inheritance
-
PESection
- Implements
- Inherited Members
Constructors
PESection(PESection)
Copy a new section.
public PESection(PESection section)
Parameters
section
PESectionThe section to be copied.
PESection(SectionHeader, ISegment)
Creates a new section with the provided contents.
public PESection(SectionHeader header, ISegment contents)
Parameters
header
SectionHeaderThe header to associate to the section.
contents
ISegmentThe contents of the section.
PESection(Utf8String, SectionFlags)
Creates a new empty section.
public PESection(Utf8String name, SectionFlags characteristics)
Parameters
name
Utf8StringThe name of the section.
characteristics
SectionFlagsThe section flags.
PESection(Utf8String, SectionFlags, ISegment?)
Creates a new empty section.
public PESection(Utf8String name, SectionFlags characteristics, ISegment? contents)
Parameters
name
Utf8StringThe name of the section.
characteristics
SectionFlagsThe section flags.
contents
ISegmentThe contents of the section.
Properties
CanUpdateOffsets
Determines whether this structure can be relocated to another offset or virtual address.
public bool CanUpdateOffsets { get; }
Property Value
Characteristics
Gets or sets the characteristics of the section.
public SectionFlags Characteristics { get; set; }
Property Value
ContainingFile
Gets the portable executable file this section is part of.
public PEFile? ContainingFile { get; }
Property Value
Contents
Gets or sets the contents of the section.
public ISegment? Contents { get; set; }
Property Value
IsContentCode
Gets or sets a value indicating the section contains executable code.
public bool IsContentCode { get; set; }
Property Value
IsContentInitializedData
Gets or sets a value indicating the section contains initialized data.
public bool IsContentInitializedData { get; set; }
Property Value
IsContentUninitializedData
Gets or sets a value indicating the section contains uninitialized data.
public bool IsContentUninitializedData { get; set; }
Property Value
IsMemoryDiscardable
Gets or sets a value indicating the section can be discarded as needed.
public bool IsMemoryDiscardable { get; set; }
Property Value
IsMemoryExecute
Gets or sets a value indicating the section can be executed as code.
public bool IsMemoryExecute { get; set; }
Property Value
IsMemoryNotCached
Gets or sets a value indicating the section cannot be cached.
public bool IsMemoryNotCached { get; set; }
Property Value
IsMemoryNotPaged
Gets or sets a value indicating the section is not pageable.
public bool IsMemoryNotPaged { get; set; }
Property Value
IsMemoryRead
Gets or sets a value indicating the section can be read.
public bool IsMemoryRead { get; set; }
Property Value
IsMemoryShared
Gets or sets a value indicating the section can be shared in memory.
public bool IsMemoryShared { get; set; }
Property Value
IsMemoryWrite
Gets or sets a value indicating the section can be written.
public bool IsMemoryWrite { get; set; }
Property Value
IsReadable
Gets a value indicating whether the section is readable using a binary stream reader.
public bool IsReadable { get; }
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.
Offset
Gets the physical starting offset of the segment.
public ulong Offset { get; }
Property Value
Rva
Gets the virtual address relative to the beginning of the section that the segment is located in.
public uint Rva { get; }
Property Value
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.
CreateHeader()
Creates a new header for this section.
public SectionHeader CreateHeader()
Returns
CreateReader(ulong, uint)
Creates a new binary reader that reads the raw contents of the segment.
public BinaryStreamReader CreateReader(ulong fileOffset, uint size)
Parameters
Returns
- BinaryStreamReader
The created binary reader.
Exceptions
- ArgumentOutOfRangeException
Occurs when
fileOffset
is not within the range of the segment.- EndOfStreamException
Occurs when
size
indicates a too large length.
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.
GetPhysicalSize()
Computes the number of bytes that the structure contains.
public uint GetPhysicalSize()
Returns
- uint
The number of bytes.
GetVirtualSize()
Computes the number of bytes the segment will contain when it is mapped into memory.
public uint GetVirtualSize()
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.
UpdateOffsets(in RelocationParameters)
Assigns a new file and virtual offset to the segment and all its sub-components.
public void UpdateOffsets(in RelocationParameters parameters)
Parameters
parameters
RelocationParametersThe parameters containing the new offset information for the segment.
Write(BinaryStreamWriter)
Serializes the structure to an output stream.
public void Write(BinaryStreamWriter writer)
Parameters
writer
BinaryStreamWriterThe output stream to write the data to.