Table of Contents

Class DotNetDirectoryBuffer

Namespace
AsmResolver.DotNet.Builder
Assembly
AsmResolver.DotNet.dll

Provides a mutable buffer for building up a .NET data directory, containing all metadata relevant for the execution of a .NET assembly.

public class DotNetDirectoryBuffer : ITypeCodedIndexProvider, IMetadataTokenProvider
Inheritance
DotNetDirectoryBuffer
Implements
Inherited Members

Constructors

DotNetDirectoryBuffer(ModuleDefinition, IMethodBodySerializer, INativeSymbolsProvider, IMetadataBuffer, IErrorListener)

Creates a new .NET data directory buffer.

public DotNetDirectoryBuffer(ModuleDefinition module, IMethodBodySerializer methodBodySerializer, INativeSymbolsProvider symbolsProvider, IMetadataBuffer metadata, IErrorListener errorListener)

Parameters

module ModuleDefinition

The module for which this .NET directory is built.

methodBodySerializer IMethodBodySerializer

The method body serializer to use for constructing method bodies.

symbolsProvider INativeSymbolsProvider

The object responsible for providing references to native symbols.

metadata IMetadataBuffer

The metadata builder

errorListener IErrorListener

The object responsible for collecting all diagnostic information during the building process.

Properties

ErrorListener

Gets the object responsible for collecting all diagnostic information during the building process.

public IErrorListener ErrorListener { get; }

Property Value

IErrorListener

Metadata

Gets the metadata directory buffer, containing the metadata stream buffers.

public IMetadataBuffer Metadata { get; }

Property Value

IMetadataBuffer

MethodBodySerializer

Gets the method body serializer to use for constructing method bodies.

public IMethodBodySerializer MethodBodySerializer { get; }

Property Value

IMethodBodySerializer

Module

Gets the module for which this .NET directory is built.

public ModuleDefinition Module { get; }

Property Value

ModuleDefinition

Resources

Gets the .NET resources data directory buffer, containing all the resources data stored in the .NET module.

public DotNetResourcesDirectoryBuffer Resources { get; }

Property Value

DotNetResourcesDirectoryBuffer

StrongNameSize

Gets or sets the size of the strong name directory to be emitted. A value of 0 indicates no strong name directory will be emitted.

public int StrongNameSize { get; set; }

Property Value

int

SymbolsProvider

Gets the object responsible for providing references to native symbols.

public INativeSymbolsProvider SymbolsProvider { get; }

Property Value

INativeSymbolsProvider

VTableFixups

Gets the buffer used to store VTable fixups and register unmanaged symbols.

public VTableFixupsBuffer VTableFixups { get; }

Property Value

VTableFixupsBuffer

Methods

AddAssemblyReference(AssemblyReference?, bool, bool)

Adds an assembly reference to the buffer.

public MetadataToken AddAssemblyReference(AssemblyReference? assembly, bool allowDuplicates, bool preserveRid)

Parameters

assembly AssemblyReference

The reference to add.

allowDuplicates bool

true if the row is always to be added to the end of the buffer, false if a duplicated row is supposed to be removed and the token of the original should be returned instead.

preserveRid bool

true if the metadata token of the assembly should be preserved, false otherwise.

Returns

MetadataToken

The newly assigned metadata token.

AddMemberReference(MemberReference?, bool)

Adds a member reference to the buffer.

public MetadataToken AddMemberReference(MemberReference? member, bool allowDuplicates)

Parameters

member MemberReference

The reference to add.

allowDuplicates bool

true if the row is always to be added to the end of the buffer, false if a duplicated row is supposed to be removed and the token of the original should be returned instead.

Returns

MetadataToken

The newly assigned metadata token.

AddMethodSpecification(MethodSpecification?, bool)

Adds a method specification to the buffer.

public MetadataToken AddMethodSpecification(MethodSpecification? method, bool allowDuplicates)

Parameters

method MethodSpecification

The specification to add.

allowDuplicates bool

true if the row is always to be added to the end of the buffer, false if a duplicated row is supposed to be removed and the token of the original should be returned instead.

Returns

MetadataToken

The newly assigned metadata token.

AddModuleReference(ModuleReference?, bool, bool)

Adds a module reference to the buffer.

public MetadataToken AddModuleReference(ModuleReference? reference, bool allowDuplicates, bool preserveRid)

Parameters

reference ModuleReference

The reference to add.

allowDuplicates bool

true if the row is always to be added to the end of the buffer, false if a duplicated row is supposed to be removed and the token of the original should be returned instead.

preserveRid bool

true if the metadata token of the module should be preserved, false otherwise.

Returns

MetadataToken

The newly assigned metadata token.

AddStandAloneSignature(StandAloneSignature?, bool)

Adds a stand-alone signature to the buffer.

public MetadataToken AddStandAloneSignature(StandAloneSignature? signature, bool allowDuplicates)

Parameters

signature StandAloneSignature

The signature to add.

allowDuplicates bool

true if the row is always to be added to the end of the buffer, false if a duplicated row is supposed to be removed and the token of the original should be returned instead.

Returns

MetadataToken

The newly assigned metadata token.

AddTypeReference(TypeReference?, bool, bool)

Adds a type reference to the buffer.

public MetadataToken AddTypeReference(TypeReference? type, bool allowDuplicates, bool preserveRid)

Parameters

type TypeReference

The reference to add.

allowDuplicates bool

true if the row is always to be added to the end of the buffer, false if a duplicated row is supposed to be removed and the token of the original should be returned instead.

preserveRid bool

true if the metadata token of the type should be preserved, false otherwise.

Returns

MetadataToken

The newly assigned metadata token.

AddTypeSpecification(TypeSpecification?, bool)

Adds a type specification to the buffer.

public MetadataToken AddTypeSpecification(TypeSpecification? type, bool allowDuplicates)

Parameters

type TypeSpecification

The specification to add.

allowDuplicates bool

true if the row is always to be added to the end of the buffer, false if a duplicated row is supposed to be removed and the token of the original should be returned instead.

Returns

MetadataToken

The newly assigned metadata token.

CreateDirectory()

Builds the .NET data directory from the buffer.

public DotNetDirectoryBuildResult CreateDirectory()

Returns

DotNetDirectoryBuildResult

DefineAssembly(AssemblyDefinition)

Adds an assembly, its entire manifest module, and all secondary module file references, to the buffer.

public void DefineAssembly(AssemblyDefinition assembly)

Parameters

assembly AssemblyDefinition

The assembly to add.

DefineEvents(IEnumerable<EventDefinition>)

Allocates metadata rows for the provided event definitions in the buffer.

public void DefineEvents(IEnumerable<EventDefinition> events)

Parameters

events IEnumerable<EventDefinition>

The events to define.

DefineFields(IEnumerable<FieldDefinition>)

Allocates metadata rows for the provided field definitions in the buffer.

public void DefineFields(IEnumerable<FieldDefinition> fields)

Parameters

fields IEnumerable<FieldDefinition>

The fields to define.

DefineManifestResource(ManifestResource, bool)

Adds a single manifest resource to the buffer.

public MetadataToken DefineManifestResource(ManifestResource resource, bool deduplicateData = true)

Parameters

resource ManifestResource

The resource to add.

deduplicateData bool

true if resource data can be reused when identical, false when each embedded resource should get its own data offset.

Returns

MetadataToken

The new metadata token of the resource.

DefineManifestResources(IEnumerable<ManifestResource>, bool)

Adds a collection of manifest resources to the directory buffer.

public void DefineManifestResources(IEnumerable<ManifestResource> resources, bool deduplicateData = true)

Parameters

resources IEnumerable<ManifestResource>

The resources to add.

deduplicateData bool

true if resource data can be reused when identical, false when each embedded resource should get its own data offset.

DefineMethods(IEnumerable<MethodDefinition>)

Allocates metadata rows for the provided method definitions in the buffer.

public void DefineMethods(IEnumerable<MethodDefinition> methods)

Parameters

methods IEnumerable<MethodDefinition>

The methods to define.

DefineModule(ModuleDefinition)

Adds a module metadata row to the buffer.

public void DefineModule(ModuleDefinition module)

Parameters

module ModuleDefinition

The module to add.

Remarks

This method only adds the metadata row of the module definition to the module table buffer, it does not add any type definition to the buffer, nor does it add custom attributes or any other metadata model object related to this module to the buffer.

DefineParameters(IEnumerable<ParameterDefinition>)

Allocates metadata rows for the provided parameter definitions in the buffer.

public void DefineParameters(IEnumerable<ParameterDefinition> parameters)

Parameters

parameters IEnumerable<ParameterDefinition>

The parameters to define.

DefineProperties(IEnumerable<PropertyDefinition>)

Allocates metadata rows for the provided property definitions in the buffer.

public void DefineProperties(IEnumerable<PropertyDefinition> properties)

Parameters

properties IEnumerable<PropertyDefinition>

The properties to define.

DefineTypes(IEnumerable<TypeDefinition>)

Allocates metadata rows for the provided type definitions in the buffer.

public void DefineTypes(IEnumerable<TypeDefinition> types)

Parameters

types IEnumerable<TypeDefinition>

The types to define.

Remarks

This method does not define any member defined in the type, except for nested types.

FinalizeModule(ModuleDefinition)

Finalizes the module definition.

public void FinalizeModule(ModuleDefinition module)

Parameters

module ModuleDefinition

The module to finalize.

FinalizeTypes()

Finalizes all type definitions added in the buffer.

public void FinalizeTypes()

GetAssemblyReferenceToken(AssemblyReference?)

Gets the newly assigned metadata token of a assembly reference stored in a tables stream or tables stream buffer.

public MetadataToken GetAssemblyReferenceToken(AssemblyReference? assembly)

Parameters

assembly AssemblyReference

The reference to the assembly to add.

Returns

MetadataToken

The metadata token of the added assembly reference.

GetEventDefinitionToken(EventDefinition?)

Gets the newly assigned metadata token of an event definition stored in a tables stream or tables stream buffer.

public MetadataToken GetEventDefinitionToken(EventDefinition? @event)

Parameters

event EventDefinition

The reference to the event to add.

Returns

MetadataToken

The metadata token of the added event definition.

GetFieldDefinitionToken(FieldDefinition?)

Gets the newly assigned metadata token of a type definition stored in a tables stream or tables stream buffer.

public MetadataToken GetFieldDefinitionToken(FieldDefinition? field)

Parameters

field FieldDefinition

The reference to the field to add.

Returns

MetadataToken

The metadata token of the added field definition.

GetMemberReferenceToken(MemberReference?)

Gets the newly assigned metadata token of a member reference stored in a tables stream or tables stream buffer.

public MetadataToken GetMemberReferenceToken(MemberReference? member)

Parameters

member MemberReference

The reference to the member to add.

Returns

MetadataToken

The metadata token of the added member reference.

GetMethodDefinitionToken(MethodDefinition?)

Gets the newly assigned metadata token of a method definition stored in a tables stream or tables stream buffer.

public MetadataToken GetMethodDefinitionToken(MethodDefinition? method)

Parameters

method MethodDefinition

The reference to the method to add.

Returns

MetadataToken

The metadata token of the added method definition.

GetMethodSpecificationToken(MethodSpecification?)

Gets the newly assigned metadata token of a method specification stored in a tables stream or tables stream buffer.

public MetadataToken GetMethodSpecificationToken(MethodSpecification? method)

Parameters

method MethodSpecification

The reference to the method to add.

Returns

MetadataToken

The metadata token of the added method specification.

GetModuleReferenceToken(ModuleReference?)

Adds a single module reference to the buffer.

public MetadataToken GetModuleReferenceToken(ModuleReference? reference)

Parameters

reference ModuleReference

The reference to add.

Returns

MetadataToken

The new metadata token assigned to the module reference.

GetParameterDefinitionToken(ParameterDefinition?)

Gets the newly assigned metadata token of a parameter definition stored in a tables stream or tables stream buffer.

public MetadataToken GetParameterDefinitionToken(ParameterDefinition? parameter)

Parameters

parameter ParameterDefinition

The reference to the parameter to add.

Returns

MetadataToken

The metadata token of the added parameter definition.

GetPropertyDefinitionToken(PropertyDefinition?)

Gets the newly assigned metadata token of a property definition stored in a tables stream or tables stream buffer.

public MetadataToken GetPropertyDefinitionToken(PropertyDefinition? property)

Parameters

property PropertyDefinition

The reference to the property to add.

Returns

MetadataToken

The metadata token of the added property definition.

GetStandAloneSignatureToken(StandAloneSignature?)

Gets the newly assigned metadata token of a stand-alone signature stored in a tables stream or tables stream buffer.

public MetadataToken GetStandAloneSignatureToken(StandAloneSignature? signature)

Parameters

signature StandAloneSignature

The reference to the signature to add.

Returns

MetadataToken

The metadata token of the added signature.

GetTypeDefOrRefIndex(ITypeDefOrRef?)

Obtains a coded index to the provided type reference.

public uint GetTypeDefOrRefIndex(ITypeDefOrRef? type)

Parameters

type ITypeDefOrRef

The type.

Returns

uint

The coded index.

GetTypeDefinitionToken(TypeDefinition?)

Gets the newly assigned metadata token of a type definition stored in a tables stream or tables stream buffer.

public MetadataToken GetTypeDefinitionToken(TypeDefinition? type)

Parameters

type TypeDefinition

The reference to the type to add.

Returns

MetadataToken

The metadata token of the added type definition.

GetTypeReferenceToken(TypeReference?)

Gets the newly assigned metadata token of a type reference stored in a tables stream or tables stream buffer.

public MetadataToken GetTypeReferenceToken(TypeReference? type)

Parameters

type TypeReference

The reference to the type to add.

Returns

MetadataToken

The metadata token of the added type reference.

GetTypeSpecificationToken(TypeSpecification?)

Gets the newly assigned metadata token of a type specification. stored in a tables stream or tables stream buffer.

public MetadataToken GetTypeSpecificationToken(TypeSpecification? type)

Parameters

type TypeSpecification

The reference to the type to add.

Returns

MetadataToken

The metadata token of the added type specification.

GetUserStringIndex(string)

Gets the index to a user-string referenced in a CIL method body.

public uint GetUserStringIndex(string value)

Parameters

value string

The string value.

Returns

uint

The index.