Table of Contents

Class CilRawFatMethodBody

Namespace
AsmResolver.PE.DotNet.Cil
Assembly
AsmResolver.PE.dll

Represents a CIL method body using the fat format.

public class CilRawFatMethodBody : CilRawMethodBody, ISegment, IOffsetProvider, IWritable
Inheritance
CilRawFatMethodBody
Implements
Inherited Members

Remarks

The fat method body format is used when a CIL method body's code size is larger than 64 bytes, has local variables, its max stack size is greater than 8, or uses extra sections (e.g. for storing exception handlers).

This class does not do any encoding/decoding of the bytes that make up the actual CIL instructions, nor does it do any verification of the code.

Constructors

CilRawFatMethodBody(CilMethodBodyAttributes, ushort, MetadataToken, IReadableSegment)

Creates a new fat method body.

public CilRawFatMethodBody(CilMethodBodyAttributes attributes, ushort maxStack, MetadataToken localVarSigToken, IReadableSegment code)

Parameters

attributes CilMethodBodyAttributes

The attributes associated to the method body.

maxStack ushort

The maximum amount of values that can be pushed onto the stack.

localVarSigToken MetadataToken

The metadata token that defines the local variables for the method body.

code IReadableSegment

The raw code of the method.

Properties

Attributes

Gets or sets the attributes associated to the method body.

public CilMethodBodyAttributes Attributes { get; set; }

Property Value

CilMethodBodyAttributes

Remarks

This property always has the Fat flag set.

ExtraSections

Gets a collection of extra metadata sections that are appended to the method body.

public IList<CilExtraSection> ExtraSections { get; }

Property Value

IList<CilExtraSection>

Remarks

These sections are used to encode any exception handler in the method body.

HasSections

Gets or sets a value indicating whether the method body stores extra sections.

public bool HasSections { get; set; }

Property Value

bool

Remarks

This property does not automatically update when ExtraSections is changed.

InitLocals

Gets or sets a value indicating whether all locals defined by this method body should be initialized to zero by the runtime upon starting execution of the method body.

public bool InitLocals { get; set; }

Property Value

bool

IsFat

Gets a value indicating whether the method body is using the fat format.

public override bool IsFat { get; }

Property Value

bool

LocalVarSigToken

Gets or sets the metadata token referencing a signature that defines all local variables in the method body.

public MetadataToken LocalVarSigToken { get; set; }

Property Value

MetadataToken

MaxStack

Gets or sets a value indicating the maximum amount of values that can be pushed onto the stack by the code stored in the method body.

public ushort MaxStack { get; set; }

Property Value

ushort

Methods

FromReader(IErrorListener, ref BinaryStreamReader)

Reads a raw method body from the given binary input stream using the fat method body format.

public static CilRawFatMethodBody? FromReader(IErrorListener errorListener, ref BinaryStreamReader reader)

Parameters

errorListener IErrorListener

The object responsible for recording parser errors.

reader BinaryStreamReader

The binary input stream to read from.

Returns

CilRawFatMethodBody

The raw method body.

Exceptions

FormatException

Occurs when the method header indicates an method body that is not in the fat format.

GetPhysicalSize()

Computes the number of bytes that the structure contains.

public override uint GetPhysicalSize()

Returns

uint

The number of bytes.

UpdateOffsets(in RelocationParameters)

Assigns a new file and virtual offset to the segment and all its sub-components.

public override 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 override void Write(BinaryStreamWriter writer)

Parameters

writer BinaryStreamWriter

The output stream to write the data to.