Table of Contents

Class PatchedSegment

Namespace
AsmResolver.Patching
Assembly
AsmResolver.dll

Provides a wrapper around an instance of a ISegment that patches its binary representation while it is being serialized to an output stream.

public class PatchedSegment : IReadableSegment, ISegment, IOffsetProvider, IWritable
Inheritance
PatchedSegment
Implements
Inherited Members
Extension Methods

Constructors

PatchedSegment(ISegment)

Wraps a segment into a new instance of the PatchedSegment class.

public PatchedSegment(ISegment contents)

Parameters

contents ISegment

The segment to patch.

Properties

CanUpdateOffsets

Determines whether this structure can be relocated to another offset or virtual address.

public bool CanUpdateOffsets { get; }

Property Value

bool

Contents

Gets the original segment that is being patched.

public ISegment Contents { get; }

Property Value

ISegment

Offset

Gets the physical starting offset of the segment.

public ulong Offset { get; }

Property Value

ulong

Patches

Gets a list of patches to apply to the segment.

public IList<IPatch> Patches { get; }

Property Value

IList<IPatch>

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

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.

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.

Patch(IPatch)

Adds a patch to the list of patches to apply.

public PatchedSegment Patch(IPatch patch)

Parameters

patch IPatch

The patch to apply.

Returns

PatchedSegment

The current PatchedSegment instance.

Patch(uint, ISegment)

Adds a segment patch to the list of patches to apply.

public PatchedSegment Patch(uint relativeOffset, ISegment newSegment)

Parameters

relativeOffset uint

The offset to start patching at, relative to the start of the base segment.

newSegment ISegment

The new segment to write.

Returns

PatchedSegment

The current PatchedSegment instance.

Patch(uint, byte[])

Adds a bytes patch to the list of patches to apply.

public PatchedSegment Patch(uint relativeOffset, byte[] newData)

Parameters

relativeOffset uint

The offset to start patching at, relative to the start of the segment.

newData byte[]

The new data to write.

Returns

PatchedSegment

The current PatchedSegment instance.

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.