Table of Contents

Class TablesStream

Namespace
AsmResolver.PE.DotNet.Metadata
Assembly
AsmResolver.PE.dll

Represents the metadata stream containing tables defining each member in a .NET assembly.

public class TablesStream : SegmentBase, IMetadataStream, ISegment, IOffsetProvider, IWritable
Inheritance
TablesStream
Implements
Derived
Inherited Members

Constructors

TablesStream()

Creates a new, empty tables stream.

public TablesStream()

Fields

CompressedStreamName

The default name of a table stream using the compressed format.

public const string CompressedStreamName = "#~"

Field Value

string

EncStreamName

The default name of a table stream using the Edit-and-Continue, uncompressed format.

public const string EncStreamName = "#-"

Field Value

string

MinimalStreamName

The default name of a table stream using the minimal format.

public const string MinimalStreamName = "#JTD"

Field Value

string

UncompressedStreamName

The default name of a table stream using the uncompressed format.

public const string UncompressedStreamName = "#Schema"

Field Value

string

Properties

BlobIndexSize

Gets or sets a value indicating each blob index in the tables stream is a 4 byte integer instead of a 2 byte integer.

public IndexSize BlobIndexSize { get; set; }

Property Value

IndexSize

CanRead

Gets a value indicating whether the raw contents of the stream can be read using a binary stream reader.

public virtual bool CanRead { get; }

Property Value

bool

ExternalRowCounts

Gets or sets an array of row counts originating from an external .NET metadata file that this table stream should consider when encoding indices.

public uint[]? ExternalRowCounts { get; set; }

Property Value

uint[]

Remarks

This value is typically null, except for Portable PDB metadata table streams.

ExtraData

Gets or sets the extra 4 bytes data that is persisted after the row counts of the tables stream.

public uint ExtraData { get; set; }

Property Value

uint

Remarks

This value is not specified by the ECMA-335 and is only present when HasExtraData is set to true. Writing to this value does not automatically update HasExtraData, and is only persisted in the final output if HasExtraData is set to true.

Flags

Gets or sets the flags of the tables stream.

public TablesStreamFlags Flags { get; set; }

Property Value

TablesStreamFlags

ForceLargeColumns

Gets or sets a value whether to force large columns in the tables stream.

public bool ForceLargeColumns { get; set; }

Property Value

bool

Remarks

This value is typically false, it is intended to be true for cases when EnC metadata is used and a stream with the MinimalStreamName name is present.

GuidIndexSize

Gets or sets a value indicating each GUID index in the tables stream is a 4 byte integer instead of a 2 byte integer.

public IndexSize GuidIndexSize { get; set; }

Property Value

IndexSize

HasDeletedTokens

Gets or sets a value indicating the tables stream may contain _Delete tokens. This only occurs in ENC metadata.

public bool HasDeletedTokens { get; set; }

Property Value

bool

HasDeltaOnly

Gets or sets a value indicating the tables stream contains only deltas.

public bool HasDeltaOnly { get; set; }

Property Value

bool

HasExternalRowCounts

Gets a value indicating whether the tables stream is assigned with row counts that originate from an external .NET metadata file.

public bool HasExternalRowCounts { get; }

Property Value

bool

Remarks

This value is typically set to false, except for Portable PDB metadata table streams.

HasExtraData

Gets or sets a value indicating the tables stream persists an extra 4 bytes of data.

public bool HasExtraData { get; set; }

Property Value

bool

HasPaddingBit

Gets or sets a value indicating the tables were created with an extra bit in columns.

public bool HasPaddingBit { get; set; }

Property Value

bool

Log2LargestRid

Gets the bit-length of the largest relative identifier (RID) in the table stream.

public byte Log2LargestRid { get; protected set; }

Property Value

byte

Remarks

This value is ignored by the CoreCLR implementation of the runtime, and the standard compilers always set this value to 1.

MajorVersion

Gets or sets the major version number of the schema.

public byte MajorVersion { get; set; }

Property Value

byte

MinorVersion

Gets or sets the minor version number of the schema.

public byte MinorVersion { get; set; }

Property Value

byte

Name

Gets or sets the name of the metadata stream.

public string Name { get; set; }

Property Value

string

Reserved

Reserved, for future use.

public uint Reserved { get; set; }

Property Value

uint

Remarks

This field must be set to 0 by the CoreCLR implementation of the runtime.

StringIndexSize

Gets or sets a value indicating each string index in the tables stream is a 4 byte integer instead of a 2 byte integer.

public IndexSize StringIndexSize { get; set; }

Property Value

IndexSize

TableLayouts

Gets the layout of all tables in the stream.

protected IList<TableLayout> TableLayouts { get; }

Property Value

IList<TableLayout>

Tables

Gets a collection of all tables in the tables stream.

protected IList<IMetadataTable?> Tables { get; }

Property Value

IList<IMetadataTable>

Remarks

This collection always contains all tables, in the same order as TableIndex defines, regardless of whether a table actually has elements or not.

Methods

ComputeSortedBitmask()

Computes the sorted bitmask of the tables stream, which is a 64-bit integer where each bit specifies whether a table is sorted or not.

protected virtual ulong ComputeSortedBitmask()

Returns

ulong

The valid bitmask.

ComputeValidBitmask()

Computes the valid bitmask of the tables stream, which is a 64-bit integer where each bit specifies whether a table is present in the stream or not.

protected virtual ulong ComputeValidBitmask()

Returns

ulong

The valid bitmask.

CreateReader()

Creates a binary reader that reads the raw contents of the metadata stream.

public virtual BinaryStreamReader CreateReader()

Returns

BinaryStreamReader

The reader.

Exceptions

InvalidOperationException

Occurs when CanRead is false.

GetColumnSize(ColumnType)

Gets a value indicating the size of a column in a table.

protected virtual uint GetColumnSize(ColumnType columnType)

Parameters

columnType ColumnType

The column type to verify.

Returns

uint

The column size.

GetEventRange(uint)

Gets the range of metadata tokens referencing events that a event map row defines.

public MetadataRange GetEventRange(uint eventMapRid)

Parameters

eventMapRid uint

The row identifier of the event map to obtain the events from.

Returns

MetadataRange

The range of metadata tokens.

GetFieldRange(uint)

Gets the range of metadata tokens referencing fields that a type defines.

public MetadataRange GetFieldRange(uint typeDefRid)

Parameters

typeDefRid uint

The row identifier of the type definition to obtain the fields from.

Returns

MetadataRange

The range of metadata tokens.

GetIndexEncoder(CodedIndex)

Gets an encoder/decoder for a particular coded index.

public IndexEncoder GetIndexEncoder(CodedIndex index)

Parameters

index CodedIndex

The type of coded index to encode/decode.

Returns

IndexEncoder

The encoder.

GetMethodRange(uint)

Gets the range of metadata tokens referencing methods that a type defines.

public MetadataRange GetMethodRange(uint typeDefRid)

Parameters

typeDefRid uint

The row identifier of the type definition to obtain the methods from.

Returns

MetadataRange

The range of metadata tokens.

GetParameterRange(uint)

Gets the range of metadata tokens referencing parameters that a method defines.

public MetadataRange GetParameterRange(uint methodDefRid)

Parameters

methodDefRid uint

The row identifier of the method definition to obtain the parameters from.

Returns

MetadataRange

The range of metadata tokens.

GetPhysicalSize()

Computes the number of bytes that the structure contains.

public override uint GetPhysicalSize()

Returns

uint

The number of bytes.

GetPropertyRange(uint)

Gets the range of metadata tokens referencing properties that a property map row defines.

public MetadataRange GetPropertyRange(uint propertyMapRid)

Parameters

propertyMapRid uint

The row identifier of the property map to obtain the properties from.

Returns

MetadataRange

The range of metadata tokens.

GetTable(TableIndex)

Gets a table by its table index.

public virtual IMetadataTable GetTable(TableIndex index)

Parameters

index TableIndex

The table index.

Returns

IMetadataTable

The table.

GetTableIndexSize(TableIndex)

Obtains the implied table index size for the provided table index.

public IndexSize GetTableIndexSize(TableIndex table)

Parameters

table TableIndex

The table index.

Returns

IndexSize

The index size.

Remarks

This method takes any external row counts from ExternalRowCounts into account.

GetTableLayouts()

Gets an ordered collection of the current table layouts.

protected TableLayout[] GetTableLayouts()

Returns

TableLayout[]

The table layouts.

GetTableRowCount(TableIndex)

Obtains the implied table row count for the provided table index.

public uint GetTableRowCount(TableIndex table)

Parameters

table TableIndex

The table index.

Returns

uint

The row count.

Remarks

This method takes any external row counts from ExternalRowCounts into account.

GetTable<TRow>()

Gets a table by its row type.

public virtual MetadataTable<TRow> GetTable<TRow>() where TRow : struct, IMetadataRow

Returns

MetadataTable<TRow>

The table.

Type Parameters

TRow

The type of rows the table stores.

GetTable<TRow>(TableIndex)

Gets a table by its row type.

public virtual MetadataTable<TRow> GetTable<TRow>(TableIndex index) where TRow : struct, IMetadataRow

Parameters

index TableIndex

The table index.

Returns

MetadataTable<TRow>

The table.

Type Parameters

TRow

The type of rows the table stores.

GetTables()

Obtains the collection of tables in the tables stream.

protected virtual IList<IMetadataTable?> GetTables()

Returns

IList<IMetadataTable>

The tables, including empty tables if there are any.

Remarks

This method is called upon initialization of the Tables property.

GetTablesCount(ulong)

Gets a value indicating the total number of tables in the stream.

protected virtual int GetTablesCount(ulong validBitmask)

Parameters

validBitmask ulong

The valid bitmask, indicating all present tables in the stream.

Returns

int

The number of tables.

GetTablesSize(ulong)

Computes the total amount of bytes that each table combined needs.

protected virtual uint GetTablesSize(ulong validBitmask)

Parameters

validBitmask ulong

The valid bitmask, indicating all present tables in the stream.

Returns

uint

The total amount of bytes.

HasTable(ulong, TableIndex)

Determines whether a table is present in the tables stream, based on a valid bitmask.

protected static bool HasTable(ulong validMask, TableIndex table)

Parameters

validMask ulong

The valid bitmask, indicating all present tables in the stream.

table TableIndex

The table to verify existence of.

Returns

bool

true if the table is present, false otherwise.

IsSorted(ulong, TableIndex)

Determines whether a table is sorted in the tables stream, based on a sorted bitmask.

protected static bool IsSorted(ulong sortedMask, TableIndex table)

Parameters

sortedMask ulong

The sorted bitmask, indicating all sorted tables in the stream.

table TableIndex

The table to verify.

Returns

bool

true if the table is sorted, false otherwise.

SynchronizeTableLayoutsWithFlags()

Updates the layouts of each metadata table, according to the Flags property.

protected void SynchronizeTableLayoutsWithFlags()

Remarks

This method should be called after updating any of the index sizes in any of the Flags, StringIndexSize, BlobIndexSize or GuidIndexSize properties.

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.

WriteRowCounts(BinaryStreamWriter, ulong)

Writes for each present table the row count to the output stream.

protected virtual void WriteRowCounts(BinaryStreamWriter writer, ulong validBitmask)

Parameters

writer BinaryStreamWriter

The output stream to write to.

validBitmask ulong

The valid bitmask, indicating all present tables in the stream.

WriteTables(BinaryStreamWriter, ulong)

Writes each present table to the output stream.

protected virtual void WriteTables(BinaryStreamWriter writer, ulong validBitmask)

Parameters

writer BinaryStreamWriter

The output stream to write to.

validBitmask ulong

The valid bitmask, indicating all present tables in the stream.