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
-
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
tableIndex
TableIndexThe index of the table.
layout
TableLayoutThe 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
TableIndexThe index of the table.
layout
TableLayoutThe layout of the table.
isSorted
boolIndicates 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
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
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
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
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
Version
Gets the version number of the list.
public int Version { get; }
Property Value
Methods
Add(TRow)
Adds an item to the ICollection<T>.
public void Add(TRow item)
Parameters
item
TRowThe 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
TRowThe 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
intThe 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 destinationarray
.
GetByRid(uint)
Gets the contents of a row by its row identifier.
public TRow GetByRid(uint rid)
Parameters
rid
uintThe 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
uintThe 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
uintThe 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
uintThe RID of the row to obtain a reference for.
version
intThe 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
intThe index to insert at.
item
TRowThe row to insert.
Remove(TRow)
Removes the first occurrence of a specific object from the ICollection<T>.
public bool Remove(TRow item)
Parameters
item
TRowThe 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 ifitem
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
uintThe row identifier.
row
TRowThe 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
uintThe row identifier.
row
TRowWhen 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
uintThe row identifier.
column
intThe column index.
value
uintWhen 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
intThe column number to get the key from.
key
uintThe key to search.
rid
uintWhen 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
intThe column number to get the key from.
key
uintThe key to search.
row
TRowWhen 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
TableLayoutThe 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
BinaryStreamWriterThe output stream to write the data to.