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
TRowThe type of rows that this table stores.
- Inheritance
-
MetadataTable<TRow>
- Implements
-
ICollection<TRow>IEnumerable<TRow>
- Derived
- Inherited Members
Constructors
MetadataTable(TableIndex, TableLayout)
Creates a new metadata table using the provided layout.
public MetadataTable(TableIndex tableIndex, TableLayout layout)
Parameters
tableIndexTableIndexThe index of the table.
layoutTableLayoutThe 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
tableIndexTableIndexThe index of the table.
layoutTableLayoutThe layout of the table.
isSortedboolIndicates 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
Count
public virtual int Count { get; }
Property Value
IsInitialized
Gets a value indicating the Rows property is initialized or not.
protected bool IsInitialized { get; }
Property Value
IsReadOnly
public bool IsReadOnly { get; }
Property Value
IsSorted
Gets or sets a value indicating whether the table is considered sorted.
public bool IsSorted { get; set; }
Property Value
IsSynchronized
public bool IsSynchronized { get; }
Property Value
this[int]
Represents a metadata table stored in the tables stream of a managed executable.
public TRow this[int index] { get; set; }
Parameters
indexint
Property Value
- TRow
Layout
Gets the layout of the table.
public TableLayout Layout { get; }
Property Value
Rows
Gets the internal list of rows that are stored in the metadata table.
protected RefList<TRow> Rows { get; }
Property Value
- RefList<TRow>
SyncRoot
public object SyncRoot { get; }
Property Value
TableIndex
Gets the index of the table in the tables stream.
public TableIndex TableIndex { get; }
Property Value
Version
Gets the version number of the list.
public int Version { get; }
Property Value
Methods
Add(TRow)
public void Add(TRow item)
Parameters
itemTRow
Clear()
public void Clear()
Contains(TRow)
public bool Contains(TRow item)
Parameters
itemTRow
Returns
CopyTo(TRow[], int)
public void CopyTo(TRow[] array, int arrayIndex)
Parameters
arrayTRow[]arrayIndexint
GetByRid(uint)
Gets the contents of a row by its row identifier.
public TRow GetByRid(uint rid)
Parameters
riduintThe row identifier.
Returns
- TRow
The row.
GetEnumerator()
public IEnumerator<TRow> GetEnumerator()
Returns
- IEnumerator<TRow>
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
riduintThe 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
riduintThe 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
riduintThe RID of the row to obtain a reference for.
versionintThe 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
indexintThe index to insert at.
itemTRowThe row to insert.
Remove(TRow)
public bool Remove(TRow item)
Parameters
itemTRow
Returns
SetByRid(uint, TRow)
Sets the contents of a row by its row identifier.
public void SetByRid(uint rid, TRow row)
Parameters
riduintThe row identifier.
rowTRowThe 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
riduintThe row identifier.
rowTRowWhen successful, the read row.
Returns
- bool
trueif the RID existed an the row was obtained successfully,falseotherwise.
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
riduintThe row identifier.
columnintThe column index.
valueuintWhen successful, the contents of the cell, converted to an unsigned integer.
Returns
- bool
trueif the cell existed and was obtained successfully,falseotherwise.
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
keyColumnIndexintThe column number to get the key from.
keyuintThe key to search.
riduintWhen this functions returns
true, this parameter contains the RID of the row that contains the given key.
Returns
- bool
trueif the row was found,falseotherwise.
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
keyColumnIndexintThe column number to get the key from.
keyuintThe key to search.
rowTRowWhen this functions returns
true, this parameter contains the first row that contains the given key.
Returns
- bool
trueif the row was found,falseotherwise.
UpdateTableLayout(TableLayout)
Updates the table layout.
public virtual void UpdateTableLayout(TableLayout layout)
Parameters
layoutTableLayoutThe 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
writerBinaryStreamWriterThe output stream to write the data to.