Table of Contents

Class MetadataTable<TRow>

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

Provides a base implementation of a metadata table in the table stream of a managed executable file.

public class MetadataTable<TRow> : SegmentBase, IMetadataTable, ICollection, ISegment, IOffsetProvider, IWritable, ICollection<TRow>, IEnumerable<TRow>, IEnumerable where TRow : struct, IMetadataRow

Type Parameters

TRow

The type of rows that this table stores.

Inheritance
MetadataTable<TRow>
Implements
Derived
Inherited Members

Constructors

MetadataTable(TableIndex, TableLayout)

Creates a new metadata table using the provided layout.

public MetadataTable(TableIndex tableIndex, TableLayout layout)

Parameters

tableIndex TableIndex

The index of the table.

layout TableLayout

The layout of the table.

MetadataTable(TableIndex, TableLayout, bool)

Creates a new metadata table using the provided layout.

public MetadataTable(TableIndex tableIndex, TableLayout layout, bool isSorted)

Parameters

tableIndex TableIndex

The index of the table.

layout TableLayout

The layout of the table.

isSorted bool

Indicates the table is sorted or not.

Properties

Capacity

Gets or sets the total number of rows that the underlying array can store.

public int Capacity { get; set; }

Property Value

int

Count

Gets the number of elements contained in the ICollection<T>.

public virtual int Count { get; }

Property Value

int

The number of elements contained in the ICollection<T>.

IsInitialized

Gets a value indicating the Rows property is initialized or not.

protected bool IsInitialized { get; }

Property Value

bool

IsReadOnly

Gets a value indicating whether the ICollection<T> is read-only.

public bool IsReadOnly { get; }

Property Value

bool

true if the ICollection<T> is read-only; otherwise, false.

IsSorted

Gets or sets a value indicating whether the table is considered sorted.

public bool IsSorted { get; set; }

Property Value

bool

IsSynchronized

Gets a value indicating whether access to the ICollection is synchronized (thread safe).

public bool IsSynchronized { get; }

Property Value

bool

true if access to the ICollection is synchronized (thread safe); otherwise, false.

this[int]

Represents a metadata table stored in the tables stream of a managed executable.

public TRow this[int index] { get; set; }

Parameters

index int

Property Value

TRow

Layout

Gets the layout of the table.

public TableLayout Layout { get; }

Property Value

TableLayout

Rows

Gets the internal list of rows that are stored in the metadata table.

protected RefList<TRow> Rows { get; }

Property Value

RefList<TRow>

SyncRoot

Gets an object that can be used to synchronize access to the ICollection.

public object SyncRoot { get; }

Property Value

object

An object that can be used to synchronize access to the ICollection.

TableIndex

Gets the index of the table in the tables stream.

public TableIndex TableIndex { get; }

Property Value

TableIndex

Version

Gets the version number of the list.

public int Version { get; }

Property Value

int

Methods

Add(TRow)

Adds an item to the ICollection<T>.

public void Add(TRow item)

Parameters

item TRow

The object to add to the ICollection<T>.

Exceptions

NotSupportedException

The ICollection<T> is read-only.

Clear()

Removes all items from the ICollection<T>.

public void Clear()

Exceptions

NotSupportedException

The ICollection<T> is read-only.

Contains(TRow)

Determines whether the ICollection<T> contains a specific value.

public bool Contains(TRow item)

Parameters

item TRow

The object to locate in the ICollection<T>.

Returns

bool

true if item is found in the ICollection<T>; otherwise, false.

CopyTo(TRow[], int)

Copies the elements of the ICollection<T> to an Array, starting at a particular Array index.

public void CopyTo(TRow[] array, int arrayIndex)

Parameters

array TRow[]

The one-dimensional Array that is the destination of the elements copied from ICollection<T>. The Array must have zero-based indexing.

arrayIndex int

The zero-based index in array at which copying begins.

Exceptions

ArgumentNullException

array is null.

ArgumentOutOfRangeException

arrayIndex is less than 0.

ArgumentException

The number of elements in the source ICollection<T> is greater than the available space from arrayIndex to the end of the destination array.

GetByRid(uint)

Gets the contents of a row by its row identifier.

public TRow GetByRid(uint rid)

Parameters

rid uint

The row identifier.

Returns

TRow

The row.

GetEnumerator()

Returns an enumerator that iterates through the collection.

public IEnumerator<TRow> GetEnumerator()

Returns

IEnumerator<TRow>

An enumerator that can be used to iterate through the collection.

GetPhysicalSize()

Computes the number of bytes that the structure contains.

public override uint GetPhysicalSize()

Returns

uint

The number of bytes.

GetRowBounds(uint)

Calculates the offset range of a row within the table.

public OffsetRange GetRowBounds(uint rid)

Parameters

rid uint

The identifier of the row to get the bounds of.

Returns

OffsetRange

The bounds.

Remarks

This method does not do any verification on whether rid is a valid row in the table.

GetRowRef(uint)

Gets a mutable reference to a row within the table.

public ref TRow GetRowRef(uint rid)

Parameters

rid uint

The RID of the row to obtain a reference for.

Returns

TRow

The row reference.

GetRowRef(uint, out int)

Gets a mutable reference to a row within the table.

public ref TRow GetRowRef(uint rid, out int version)

Parameters

rid uint

The RID of the row to obtain a reference for.

version int

The version of the underlying buffer upon obtaining the reference.

Returns

TRow

The row reference.

GetRows()

Obtains all rows in the metadata table.

protected virtual RefList<TRow> GetRows()

Returns

RefList<TRow>

The rows.

Remarks

This method is called upon initialization of the Rows property.

Insert(int, TRow)

Inserts a row in the table at the provided index.

public void Insert(int index, TRow item)

Parameters

index int

The index to insert at.

item TRow

The row to insert.

Remove(TRow)

Removes the first occurrence of a specific object from the ICollection<T>.

public bool Remove(TRow item)

Parameters

item TRow

The object to remove from the ICollection<T>.

Returns

bool

true if item was successfully removed from the ICollection<T>; otherwise, false. This method also returns false if item is not found in the original ICollection<T>.

Exceptions

NotSupportedException

The ICollection<T> is read-only.

SetByRid(uint, TRow)

Sets the contents of a row by its row identifier.

public void SetByRid(uint rid, TRow row)

Parameters

rid uint

The row identifier.

row TRow

The new contents of the row.

TryGetByRid(uint, out TRow)

Attempts to get the contents of a row by its row identifier.

public bool TryGetByRid(uint rid, out TRow row)

Parameters

rid uint

The row identifier.

row TRow

When successful, the read row.

Returns

bool

true if the RID existed an the row was obtained successfully, false otherwise.

TryGetCell(uint, int, out uint)

Attempts to get the contents of a cell in the table by its row identifier and column index.

public bool TryGetCell(uint rid, int column, out uint value)

Parameters

rid uint

The row identifier.

column int

The column index.

value uint

When successful, the contents of the cell, converted to an unsigned integer.

Returns

bool

true if the cell existed and was obtained successfully, false otherwise.

TryGetRidByKey(int, uint, out uint)

Attempts to find a row index in a table by a key. This requires the table to be sorted.

public bool TryGetRidByKey(int keyColumnIndex, uint key, out uint rid)

Parameters

keyColumnIndex int

The column number to get the key from.

key uint

The key to search.

rid uint

When this functions returns true, this parameter contains the RID of the row that contains the given key.

Returns

bool

true if the row was found, false otherwise.

TryGetRowByKey(int, uint, out TRow)

Gets a single row in a table by a key. This requires the table to be sorted.

public bool TryGetRowByKey(int keyColumnIndex, uint key, out TRow row)

Parameters

keyColumnIndex int

The column number to get the key from.

key uint

The key to search.

row TRow

When this functions returns true, this parameter contains the first row that contains the given key.

Returns

bool

true if the row was found, false otherwise.

UpdateTableLayout(TableLayout)

Updates the table layout.

public virtual void UpdateTableLayout(TableLayout layout)

Parameters

layout TableLayout

The new table layout.

Remarks

This method is used to update the sizes of each column, and therefore requires the new layout to have the same names and column types as the original one.

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.