Table of Contents

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 PESection

The section to be copied.

PESection(SectionHeader, ISegment)

Creates a new section with the provided contents.

public PESection(SectionHeader header, ISegment contents)

Parameters

header SectionHeader

The header to associate to the section.

contents ISegment

The contents of the section.

PESection(Utf8String, SectionFlags)

Creates a new empty section.

public PESection(Utf8String name, SectionFlags characteristics)

Parameters

name Utf8String

The name of the section.

characteristics SectionFlags

The section flags.

PESection(Utf8String, SectionFlags, ISegment?)

Creates a new empty section.

public PESection(Utf8String name, SectionFlags characteristics, ISegment? contents)

Parameters

name Utf8String

The name of the section.

characteristics SectionFlags

The section flags.

contents ISegment

The 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

bool

Characteristics

Gets or sets the characteristics of the section.

public SectionFlags Characteristics { get; set; }

Property Value

SectionFlags

ContainingFile

Gets the portable executable file this section is part of.

public PEFile? ContainingFile { get; }

Property Value

PEFile

Contents

Gets or sets the contents of the section.

public ISegment? Contents { get; set; }

Property Value

ISegment

IsContentCode

Gets or sets a value indicating the section contains executable code.

public bool IsContentCode { get; set; }

Property Value

bool

IsContentInitializedData

Gets or sets a value indicating the section contains initialized data.

public bool IsContentInitializedData { get; set; }

Property Value

bool

IsContentUninitializedData

Gets or sets a value indicating the section contains uninitialized data.

public bool IsContentUninitializedData { get; set; }

Property Value

bool

IsMemoryDiscardable

Gets or sets a value indicating the section can be discarded as needed.

public bool IsMemoryDiscardable { get; set; }

Property Value

bool

IsMemoryExecute

Gets or sets a value indicating the section can be executed as code.

public bool IsMemoryExecute { get; set; }

Property Value

bool

IsMemoryNotCached

Gets or sets a value indicating the section cannot be cached.

public bool IsMemoryNotCached { get; set; }

Property Value

bool

IsMemoryNotPaged

Gets or sets a value indicating the section is not pageable.

public bool IsMemoryNotPaged { get; set; }

Property Value

bool

IsMemoryRead

Gets or sets a value indicating the section can be read.

public bool IsMemoryRead { get; set; }

Property Value

bool

IsMemoryShared

Gets or sets a value indicating the section can be shared in memory.

public bool IsMemoryShared { get; set; }

Property Value

bool

IsMemoryWrite

Gets or sets a value indicating the section can be written.

public bool IsMemoryWrite { get; set; }

Property Value

bool

IsReadable

Gets a value indicating whether the section is readable using a binary stream reader.

public bool IsReadable { get; }

Property Value

bool

Name

Gets or sets the name of the section.

public Utf8String Name { get; set; }

Property Value

Utf8String

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

ulong

Rva

Gets the virtual address relative to the beginning of the section that the segment is located in.

public uint Rva { get; }

Property Value

uint

Methods

ContainsFileOffset(ulong)

Determines whether the provided file offset falls within the section that the header describes.

public bool ContainsFileOffset(ulong fileOffset)

Parameters

fileOffset ulong

The 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 uint

The 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

SectionHeader

CreateReader(ulong, uint)

Creates a new binary reader that reads the raw contents of the segment.

public BinaryStreamReader CreateReader(ulong fileOffset, uint size)

Parameters

fileOffset ulong

The starting file offset of the reader.

size uint

The number of bytes to read.

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 ulong

The 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 uint

The 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 RelocationParameters

The 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 BinaryStreamWriter

The output stream to write the data to.