Class MetadataDirectory
- Namespace
- AsmResolver.PE.DotNet.Metadata
- Assembly
- AsmResolver.PE.dll
Represents a data directory containing metadata for a managed executable, including fields from the metadata header, as well as the streams containing metadata tables and blob signatures.
public class MetadataDirectory : SegmentBase, ISegment, IOffsetProvider, IWritable
- Inheritance
-
MetadataDirectory
- Implements
- Derived
- Inherited Members
- Extension Methods
Properties
Flags
Reserved for future use.
public ushort Flags { get; set; }
Property Value
IsEncMetadata
Gets a value indicating whether the metadata directory is loaded as Edit-and-Continue metadata.
public bool IsEncMetadata { get; set; }
Property Value
MajorVersion
Gets or sets the major version of the metadata directory format.
public ushort MajorVersion { get; set; }
Property Value
Remarks
This field is usually set to 1.
MinorVersion
Gets or sets the minor version of the metadata directory format.
public ushort MinorVersion { get; set; }
Property Value
Remarks
This field is usually set to 1.
Reserved
Reserved for future use.
public uint Reserved { get; set; }
Property Value
Streams
Gets a collection of metadata streams that are defined in the metadata header.
public IList<IMetadataStream> Streams { get; }
Property Value
VersionString
Gets or sets the string containing the runtime version that the .NET binary was built for.
public string VersionString { get; set; }
Property Value
Methods
FromBytes(byte[])
Interprets the provided binary data as a .NET metadata directory.
public static MetadataDirectory FromBytes(byte[] data)
Parameters
data
byte[]The raw data.
Returns
- MetadataDirectory
The read metadata.
FromFile(IInputFile)
Reads a .NET metadata directory from a file.
public static MetadataDirectory FromFile(IInputFile file)
Parameters
file
IInputFileThe file to read.
Returns
- MetadataDirectory
The read metadata.
FromFile(string)
Reads a .NET metadata directory from a file.
public static MetadataDirectory FromFile(string path)
Parameters
path
stringThe path to the file.
Returns
- MetadataDirectory
The read metadata.
FromReader(BinaryStreamReader)
Interprets the provided binary stream as a .NET metadata directory.
public static MetadataDirectory FromReader(BinaryStreamReader reader)
Parameters
reader
BinaryStreamReaderThe input stream.
Returns
- MetadataDirectory
The read metadata.
FromReader(BinaryStreamReader, MetadataReaderContext)
Interprets the provided binary stream as a .NET metadata directory.
public static MetadataDirectory FromReader(BinaryStreamReader reader, MetadataReaderContext context)
Parameters
reader
BinaryStreamReaderThe input stream.
context
MetadataReaderContextThe context in which the reader is situated in.
Returns
- MetadataDirectory
The read metadata.
GetPhysicalSize()
Computes the number of bytes that the structure contains.
public override uint GetPhysicalSize()
Returns
- uint
The number of bytes.
GetStream(string)
Gets a stream by its name.
public virtual IMetadataStream GetStream(string name)
Parameters
name
stringThe name of the stream to search.
Returns
- IMetadataStream
The stream
Exceptions
- KeyNotFoundException
Occurs when the stream is not present in the metadata directory.
GetStreamHeaders(uint)
Constructs new metadata stream headers for all streams in the metadata directory.
protected virtual MetadataStreamHeader[] GetStreamHeaders(uint offset)
Parameters
offset
uintThe offset of the first stream header.
Returns
- MetadataStreamHeader[]
A list of stream headers.
GetStream<TStream>()
Gets a stream by its type.
public TStream GetStream<TStream>() where TStream : class, IMetadataStream
Returns
- TStream
The stream
Type Parameters
TStream
The type of the stream.
Exceptions
- KeyNotFoundException
Occurs when the stream is not present in the metadata directory.
GetStreams()
Obtains the list of streams defined in the data directory.
protected virtual IList<IMetadataStream> GetStreams()
Returns
- IList<IMetadataStream>
The streams.
Remarks
This method is called upon initialization of the Streams property.
TryGetStream(string, out IMetadataStream?)
Gets a stream by its name.
public bool TryGetStream(string name, out IMetadataStream? stream)
Parameters
name
stringThe name of the stream to search.
stream
IMetadataStreamThe found stream, or
null
if no match was found.
Returns
- bool
true
if a match was found,false
otherwise.
TryGetStream<TStream>(out TStream?)
Gets a stream by its name.
public bool TryGetStream<TStream>(out TStream? stream) where TStream : class, IMetadataStream
Parameters
stream
TStreamThe found stream, or
null
if no match was found.
Returns
- bool
true
if a match was found,false
otherwise.
Type Parameters
TStream
The type of the stream.
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.
WriteStreamHeaders(BinaryStreamWriter, MetadataStreamHeader[])
Writes a collection of stream headers to an output stream.
protected virtual void WriteStreamHeaders(BinaryStreamWriter writer, MetadataStreamHeader[] headers)
Parameters
writer
BinaryStreamWriterThe output stream to write to.
headers
MetadataStreamHeader[]The headers to write.
WriteStreams(BinaryStreamWriter)
Writes the contents of all streams to an output stream.
protected virtual void WriteStreams(BinaryStreamWriter writer)
Parameters
writer
BinaryStreamWriterThe output stream to write to.