Table of Contents

Class ModuleDefinition

Namespace
AsmResolver.DotNet
Assembly
AsmResolver.DotNet.dll

Represents a single module in a .NET assembly. A module definition is the root object of any .NET module and defines types, as well as any resources and referenced assemblies.

public class ModuleDefinition : MetadataMember, IResolutionScope, INameProvider, IModuleProvider, IImportable, IHasCustomAttribute, IMetadataMember, IOwnedCollectionElement<AssemblyDefinition>
Inheritance
ModuleDefinition
Implements
Derived
Inherited Members
Extension Methods

Constructors

ModuleDefinition(MetadataToken)

Initializes a new empty module with the provided metadata token.

protected ModuleDefinition(MetadataToken token)

Parameters

token MetadataToken

The metadata token.

ModuleDefinition(Utf8String?)

Defines a new .NET module that references mscorlib version 4.0.0.0.

public ModuleDefinition(Utf8String? name)

Parameters

name Utf8String

The name of the module.

ModuleDefinition(string?)

Defines a new .NET module that references mscorlib version 4.0.0.0.

public ModuleDefinition(string? name)

Parameters

name string

The name of the module.

Remarks

This constructor co-exists with the Utf8String overload for backwards compatibility.

ModuleDefinition(string?, AssemblyReference)

Defines a new .NET module.

public ModuleDefinition(string? name, AssemblyReference corLib)

Parameters

name string

The name of the module.

corLib AssemblyReference

The reference to the common object runtime (COR) library that this module will use.

Properties

Assembly

Gets the parent assembly that defines this module.

public AssemblyDefinition? Assembly { get; }

Property Value

AssemblyDefinition

AssemblyReferences

Gets a collection of references to .NET assemblies that the module uses.

public IList<AssemblyReference> AssemblyReferences { get; }

Property Value

IList<AssemblyReference>

Attributes

Gets or sets the attributes associated to the underlying .NET directory of this module.

public DotNetDirectoryFlags Attributes { get; set; }

Property Value

DotNetDirectoryFlags

CorLibTypeFactory

Gets the common object runtime library type factory for this module, containing element type signatures used in blob signatures.

public CorLibTypeFactory CorLibTypeFactory { get; protected set; }

Property Value

CorLibTypeFactory

CustomAttributes

Gets a collection of custom attributes assigned to this member.

public IList<CustomAttribute> CustomAttributes { get; }

Property Value

IList<CustomAttribute>

DebugData

Gets a collection of data entries stored in the debug data directory of the PE image (if available).

public IList<DebugDataEntry> DebugData { get; }

Property Value

IList<DebugDataEntry>

DefaultImporter

Gets the default importer instance for this module.

public ReferenceImporter DefaultImporter { get; }

Property Value

ReferenceImporter

DllCharacteristics

Gets or sets the dynamic linked library characteristics of the underlying portable executable (PE) file.

public DllCharacteristics DllCharacteristics { get; set; }

Property Value

DllCharacteristics

Remarks

This property is in direct relation with the DLL characteristics field in the optional header of a portable executable file.

DotNetDirectory

Gets the underlying object providing access to the data directory containing .NET metadata (if available).

public virtual DotNetDirectory? DotNetDirectory { get; }

Property Value

DotNetDirectory

Remarks

When this property is null, the module is a new module that is not yet assembled.

EncBaseId

Gets or sets the base identifier of an edit-and-continue generation.

public Guid EncBaseId { get; set; }

Property Value

Guid

Remarks

This property corresponds to the EncBaseId column in the module definition table.

EncId

Gets or sets the unique identifier to distinguish between two edit-and-continue generations.

public Guid EncId { get; set; }

Property Value

Guid

Remarks

This property corresponds to the EncId column in the module definition table.

ExportedTypes

Gets a collection of types that are forwarded to another .NET module.

public IList<ExportedType> ExportedTypes { get; }

Property Value

IList<ExportedType>

FileCharacteristics

Gets or sets the attributes assigned to the underlying executable file.

public Characteristics FileCharacteristics { get; set; }

Property Value

Characteristics

Remarks

This property is in direct relation with the characteristics field in the file header of a portable executable file.

FilePath

When this module was read from the disk, gets the file path to the module.

public string? FilePath { get; }

Property Value

string

FileReferences

Gets a collection of references to external files that the module uses.

public IList<FileReference> FileReferences { get; }

Property Value

IList<FileReference>

Generation

Gets or sets the generation number of the module.

public ushort Generation { get; set; }

Property Value

ushort

Remarks

This value is reserved and should be set to zero.

This property corresponds to the Generation column in the module definition table.

HasNativeEntryPoint

Gets or sets a value indicating whether the .NET module has a native entry point or not.

public bool HasNativeEntryPoint { get; set; }

Property Value

bool

IsBit32Preferred

Gets or sets a value indicating whether the .NET module prefers a 32-bit environment to run in.

public bool IsBit32Preferred { get; set; }

Property Value

bool

IsBit32Required

Gets or sets a value indicating whether the .NET module requires a 32-bit environment to run.

public bool IsBit32Required { get; set; }

Property Value

bool

IsILLibrary

Gets or sets a value indicating whether the .NET module is a library.

public bool IsILLibrary { get; set; }

Property Value

bool

IsILOnly

Gets or sets a value indicating whether the .NET module only contains CIL code or also contains code targeting other architectures.

public bool IsILOnly { get; set; }

Property Value

bool

IsStrongNameSigned

Gets or sets a value indicating whether the .NET module is signed with a strong name.

public bool IsStrongNameSigned { get; set; }

Property Value

bool

MachineType

Gets or sets the machine type that the underlying PE image of the .NET module image is targeting.

public MachineType MachineType { get; set; }

Property Value

MachineType

Remarks

This property is in direct relation with the machine type field in the file header of a portable executable file.

ManagedEntryPoint

Gets or sets the managed entry point that is invoked when the .NET module is initialized. This is either a method, or a reference to a secondary module containing the entry point method.

public IManagedEntryPoint? ManagedEntryPoint { get; set; }

Property Value

IManagedEntryPoint

ManagedEntryPointMethod

Gets or sets the managed method that is invoked after the .NET module is loaded and initialized.

public MethodDefinition? ManagedEntryPointMethod { get; set; }

Property Value

MethodDefinition

MetadataResolver

Gets or sets the object responsible for resolving references to external .NET assemblies.

public IMetadataResolver MetadataResolver { get; set; }

Property Value

IMetadataResolver

ModuleReferences

Gets a collection of references to external modules that the module uses.

public IList<ModuleReference> ModuleReferences { get; }

Property Value

IList<ModuleReference>

Mvid

Gets or sets the unique identifier to distinguish between two versions of the same module.

public Guid Mvid { get; set; }

Property Value

Guid

Remarks

This property corresponds to the MVID column in the module definition table.

Name

Gets or sets the name of the module.

public Utf8String? Name { get; set; }

Property Value

Utf8String

Remarks

This property corresponds to the Name column in the module definition table.

NativeResourceDirectory

Gets or sets the contents of the native Win32 resources data directory of the underlying portable executable (PE) file.

public ResourceDirectory? NativeResourceDirectory { get; set; }

Property Value

ResourceDirectory

OriginalTargetRuntime

Gets the runtime that this module was targeted for at compile-time.

public DotNetRuntimeInfo OriginalTargetRuntime { get; protected set; }

Property Value

DotNetRuntimeInfo

PEKind

Gets or sets the magic optional header signature, determining whether the underlying PE image is a PE32 (32-bit) or a PE32+ (64-bit) image.

public OptionalHeaderMagic PEKind { get; set; }

Property Value

OptionalHeaderMagic

Remarks

This property is in direct relation with the magic field in the optional header of a portable executable file.

Resources

Gets a collection of resources stored in the module.

public IList<ManifestResource> Resources { get; }

Property Value

IList<ManifestResource>

RuntimeContext

Gets the object describing the current active runtime context the module is loaded in.

public RuntimeContext RuntimeContext { get; protected set; }

Property Value

RuntimeContext

RuntimeVersion

Gets or sets the runtime version string

public string RuntimeVersion { get; set; }

Property Value

string

SubSystem

Gets or sets the subsystem to use when running the underlying portable executable (PE) file.

public SubSystem SubSystem { get; set; }

Property Value

SubSystem

Remarks

This property is in direct relation with the subsystem field in the optional header of a portable executable file.

TimeDateStamp

Gets or sets the date and time the module was created.

public DateTime TimeDateStamp { get; set; }

Property Value

DateTime

Remarks

This property is in direct relation with the TimeDateStamp field in the file header of a portable executable file.

TokenAllocator

Gets an object responsible for assigning new MetadataToken to members

public TokenAllocator TokenAllocator { get; }

Property Value

TokenAllocator

TopLevelTypes

Gets a collection of top-level (not nested) types defined in the module.

public IList<TypeDefinition> TopLevelTypes { get; }

Property Value

IList<TypeDefinition>

TrackDebugData

Gets or sets a value indicating whether debug data is tracked in this .NET module.

public bool TrackDebugData { get; set; }

Property Value

bool

Methods

DetectTargetRuntime()

Detects the runtime that this module targets.

protected DotNetRuntimeInfo DetectTargetRuntime()

Returns

DotNetRuntimeInfo

Remarks

This method is called to initialize the OriginalTargetRuntime property. It should be called before the assembly resolver is initialized.

EnumerateTableMembers(TableIndex)

Enumerates all metadata members stored in the module.

public virtual IEnumerable<IMetadataMember> EnumerateTableMembers(TableIndex tableIndex)

Parameters

tableIndex TableIndex

The table to enumerate the members for.

Returns

IEnumerable<IMetadataMember>

The members.

Remarks

The return value of this method does not update when new members are added or imported into the module. This method only serves as a way to easily get all the member references that were imported during the last compilation or assembly process. This method can also only enumerate members in a table for which there is an explicit IMetadataMember implementation available, and will return an empty collection for tables that do not have one.

EnumerateTableMembers<TMember>(TableIndex)

Enumerates all metadata members stored in the module.

public virtual IEnumerable<TMember> EnumerateTableMembers<TMember>(TableIndex tableIndex) where TMember : IMetadataMember

Parameters

tableIndex TableIndex

The table to enumerate the members for.

Returns

IEnumerable<TMember>

The members.

Type Parameters

TMember

The type of members to return.

Remarks

The return value of this method does not update when new members are added or imported into the module. This method only serves as a way to easily get all the member references that were imported during the last compilation or assembly process. This method can also only enumerate members in a table for which there is an explicit IMetadataMember implementation available, and will return an empty collection for tables that do not have one.

FromBytes(byte[])

Reads a .NET module from the provided input buffer.

public static ModuleDefinition FromBytes(byte[] buffer)

Parameters

buffer byte[]

The raw contents of the executable file to load.

Returns

ModuleDefinition

The module.

Exceptions

BadImageFormatException

Occurs when the image does not contain a valid .NET metadata directory.

FromBytes(byte[], ModuleReaderParameters)

Reads a .NET module from the provided input buffer.

public static ModuleDefinition FromBytes(byte[] buffer, ModuleReaderParameters readerParameters)

Parameters

buffer byte[]

The raw contents of the executable file to load.

readerParameters ModuleReaderParameters

The parameters to use while reading the module.

Returns

ModuleDefinition

The module.

Exceptions

BadImageFormatException

Occurs when the image does not contain a valid .NET metadata directory.

FromDataSource(IDataSource, PEMappingMode)

Reads a .NET module from the provided data source.

public static ModuleDefinition FromDataSource(IDataSource dataSource, PEMappingMode mode = PEMappingMode.Unmapped)

Parameters

dataSource IDataSource

The data source to read from.

mode PEMappingMode

Indicates how the input PE file is mapped.

Returns

ModuleDefinition

The module that was read.

Exceptions

BadImageFormatException

Occurs when the file does not follow the PE file format.

FromDataSource(IDataSource, PEMappingMode, ModuleReaderParameters)

Reads a .NET module from the provided data source.

public static ModuleDefinition FromDataSource(IDataSource dataSource, PEMappingMode mode, ModuleReaderParameters readerParameters)

Parameters

dataSource IDataSource

The data source to read from.

mode PEMappingMode

Indicates how the input PE file is mapped.

readerParameters ModuleReaderParameters

The parameters to use while reading the module.

Returns

ModuleDefinition

The module that was read.

Exceptions

BadImageFormatException

Occurs when the file does not follow the PE file format.

FromFile(IInputFile)

Reads a .NET module from the provided input file.

public static ModuleDefinition FromFile(IInputFile file)

Parameters

file IInputFile

The portable executable file to load.

Returns

ModuleDefinition

The module.

Exceptions

BadImageFormatException

Occurs when the image does not contain a valid .NET metadata directory.

FromFile(IInputFile, ModuleReaderParameters)

Reads a .NET module from the provided input file.

public static ModuleDefinition FromFile(IInputFile file, ModuleReaderParameters readerParameters)

Parameters

file IInputFile

The portable executable file to load.

readerParameters ModuleReaderParameters

The parameters to use while reading the module.

Returns

ModuleDefinition

The module.

Exceptions

BadImageFormatException

Occurs when the image does not contain a valid .NET metadata directory.

FromFile(PEFile)

Reads a .NET module from the provided input file.

public static ModuleDefinition FromFile(PEFile file)

Parameters

file PEFile

The portable executable file to load.

Returns

ModuleDefinition

The module.

Exceptions

BadImageFormatException

Occurs when the image does not contain a valid .NET metadata directory.

FromFile(PEFile, ModuleReaderParameters)

Reads a .NET module from the provided input file.

public static ModuleDefinition FromFile(PEFile file, ModuleReaderParameters readerParameters)

Parameters

file PEFile

The portable executable file to load.

readerParameters ModuleReaderParameters

The parameters to use while reading the module.

Returns

ModuleDefinition

The module.

Exceptions

BadImageFormatException

Occurs when the image does not contain a valid .NET metadata directory.

FromFile(string)

Reads a .NET module from the provided input file.

public static ModuleDefinition FromFile(string filePath)

Parameters

filePath string

The file path to the input executable to load.

Returns

ModuleDefinition

The module.

Exceptions

BadImageFormatException

Occurs when the image does not contain a valid .NET metadata directory.

FromFile(string, ModuleReaderParameters)

Reads a .NET module from the provided input file.

public static ModuleDefinition FromFile(string filePath, ModuleReaderParameters readerParameters)

Parameters

filePath string

The file path to the input executable to load.

readerParameters ModuleReaderParameters

The parameters to use while reading the module.

Returns

ModuleDefinition

The module.

Exceptions

BadImageFormatException

Occurs when the image does not contain a valid .NET metadata directory.

FromImage(PEImage)

Initializes a .NET module from a PE image.

public static ModuleDefinition FromImage(PEImage peImage)

Parameters

peImage PEImage

The image containing the .NET metadata.

Returns

ModuleDefinition

The module.

Exceptions

BadImageFormatException

Occurs when the image does not contain a valid .NET metadata directory.

FromImage(PEImage, ModuleReaderParameters)

Initializes a .NET module from a PE image.

public static ModuleDefinition FromImage(PEImage peImage, ModuleReaderParameters readerParameters)

Parameters

peImage PEImage

The image containing the .NET metadata.

readerParameters ModuleReaderParameters

The parameters to use while reading the module.

Returns

ModuleDefinition

The module.

Exceptions

BadImageFormatException

Occurs when the image does not contain a valid .NET data directory.

FromModule(Module)

Opens a module from an instance of a Module.

public static ModuleDefinition FromModule(Module module)

Parameters

module Module

The reflection module to load.

Returns

ModuleDefinition

The module.

FromModule(Module, ModuleReaderParameters)

Opens a module from an instance of a Module.

public static ModuleDefinition FromModule(Module module, ModuleReaderParameters readerParameters)

Parameters

module Module

The reflection module to load.

readerParameters ModuleReaderParameters

The parameters to use while reading the module.

Returns

ModuleDefinition

The module.

FromModuleBaseAddress(nint)

Reads a mapped .NET module starting at the provided module base address (HINSTANCE).

public static ModuleDefinition FromModuleBaseAddress(nint hInstance)

Parameters

hInstance nint

The HINSTANCE or base address of the module.

Returns

ModuleDefinition

The module.

Exceptions

BadImageFormatException

Occurs when the image does not contain a valid .NET metadata directory.

FromModuleBaseAddress(nint, ModuleReaderParameters)

Reads a mapped .NET module starting at the provided module base address (HINSTANCE).

public static ModuleDefinition FromModuleBaseAddress(nint hInstance, ModuleReaderParameters readerParameters)

Parameters

hInstance nint

The HINSTANCE or base address of the module.

readerParameters ModuleReaderParameters

The parameters to use while reading the module.

Returns

ModuleDefinition

The module.

Exceptions

BadImageFormatException

Occurs when the image does not contain a valid .NET metadata directory.

FromModuleBaseAddress(nint, PEMappingMode, ModuleReaderParameters)

Reads a .NET module starting at the provided module base address (HINSTANCE).

public static ModuleDefinition FromModuleBaseAddress(nint hInstance, PEMappingMode mode, ModuleReaderParameters readerParameters)

Parameters

hInstance nint

The HINSTANCE or base address of the module.

mode PEMappingMode

Indicates how the input PE file is mapped.

readerParameters ModuleReaderParameters

The parameters to use while reading the module.

Returns

ModuleDefinition

The module.

Exceptions

BadImageFormatException

Occurs when the image does not contain a valid .NET metadata directory.

FromReader(in BinaryStreamReader, PEMappingMode)

Reads a .NET module from an input stream.

public static ModuleDefinition FromReader(in BinaryStreamReader reader, PEMappingMode mode = PEMappingMode.Unmapped)

Parameters

reader BinaryStreamReader

The input stream pointing at the beginning of the executable to load.

mode PEMappingMode

Indicates the input PE is mapped or unmapped.

Returns

ModuleDefinition

The module.

Exceptions

BadImageFormatException

Occurs when the image does not contain a valid .NET metadata directory.

FromReader(in BinaryStreamReader, PEMappingMode, ModuleReaderParameters)

Reads a .NET module from an input stream.

public static ModuleDefinition FromReader(in BinaryStreamReader reader, PEMappingMode mode, ModuleReaderParameters readerParameters)

Parameters

reader BinaryStreamReader

The input stream pointing at the beginning of the executable to load.

mode PEMappingMode

Indicates the input PE is mapped or unmapped.

readerParameters ModuleReaderParameters

The parameters to use while reading the module.

Returns

ModuleDefinition

The module.

Exceptions

BadImageFormatException

Occurs when the image does not contain a valid .NET metadata directory.

GetAllTypes()

Enumerates all types (including nested types) defined in the module.

public IEnumerable<TypeDefinition> GetAllTypes()

Returns

IEnumerable<TypeDefinition>

The types.

GetAssemblyReferences()

Obtains the list of references to .NET assemblies that the module uses.

protected virtual IList<AssemblyReference> GetAssemblyReferences()

Returns

IList<AssemblyReference>

The references to the assemblies..

Remarks

This method is called upon initialization of the AssemblyReferences property.

GetCustomAttributes()

Obtains the list of custom attributes assigned to the member.

protected virtual IList<CustomAttribute> GetCustomAttributes()

Returns

IList<CustomAttribute>

The attributes

Remarks

This method is called upon initialization of the CustomAttributes property.

GetDebugData()

Obtains the native debug data directory of the underlying PE image (if available).

protected virtual IList<DebugDataEntry> GetDebugData()

Returns

IList<DebugDataEntry>

The debug directory.

Remarks

This method is called upon initialization of the DebugData property.

GetDefaultImporter()

Obtains the default reference importer assigned to this module.

protected virtual ReferenceImporter GetDefaultImporter()

Returns

ReferenceImporter

The importer.

Remarks

This method is called upon initialization of the DefaultImporter property.

GetEncBaseId()

Obtains the edit-and-continue base identifier of the module definition.

protected virtual Guid GetEncBaseId()

Returns

Guid

The identifier.

Remarks

This method is called upon initialization of the EncBaseId property.

GetEncId()

Obtains the edit-and-continue identifier of the module definition.

protected virtual Guid GetEncId()

Returns

Guid

The identifier.

Remarks

This method is called upon initialization of the EncId property.

GetExportedTypes()

Obtains the list of types that are redirected to another external module.

protected virtual IList<ExportedType> GetExportedTypes()

Returns

IList<ExportedType>

The exported types.

Remarks

This method is called upon initialization of the ExportedTypes property.

GetFileReferences()

Obtains the list of references to external files that the module uses.

protected virtual IList<FileReference> GetFileReferences()

Returns

IList<FileReference>

The references to the files.

Remarks

This method is called upon initialization of the FileReferences property.

GetImportedMemberReferences()

Obtains a list of member references that were imported into the module.

public virtual IEnumerable<MemberReference> GetImportedMemberReferences()

Returns

IEnumerable<MemberReference>

The type references.

Remarks

The return value of this method does not update when the ReferenceImporter class is used to import new member references into the module. This method only serves as a way to easily get all the member references that were imported during the last compilation or assembly process.

GetImportedTypeReferences()

Obtains a list of type references that were imported into the module.

public virtual IEnumerable<TypeReference> GetImportedTypeReferences()

Returns

IEnumerable<TypeReference>

The type references.

Remarks

The return value of this method does not update when the ReferenceImporter class is used to import new type references into the module. This method only serves as a way to easily get all the type references that were imported during the last compilation or assembly process.

GetIndexEncoder(CodedIndex)

Obtains an object that can be used to decode coded indices to metadata tokens.

public virtual IndexEncoder GetIndexEncoder(CodedIndex codedIndex)

Parameters

codedIndex CodedIndex

The type of indices to get the encoder for.

Returns

IndexEncoder

The index encoder.

Exceptions

InvalidOperationException

Occurs when the module does not support index encoders.

GetManagedEntryPoint()

Obtains the managed entry point of this module.

protected virtual IManagedEntryPoint? GetManagedEntryPoint()

Returns

IManagedEntryPoint

The entry point.

Remarks

This method is called upon initialization of the ManagedEntryPoint property.

GetModuleConstructor()

Gets the module static constructor of this metadata image. That is, the first method that is executed upon loading the .NET module.

public MethodDefinition? GetModuleConstructor()

Returns

MethodDefinition

The module constructor, or null if none is present.

GetModuleReferences()

Obtains the list of references to external modules that the module uses.

protected virtual IList<ModuleReference> GetModuleReferences()

Returns

IList<ModuleReference>

The references to the modules.

Remarks

This method is called upon initialization of the ModuleReferences property.

GetModuleType()

Obtains the global scope type of the .NET module.

public TypeDefinition? GetModuleType()

Returns

TypeDefinition

The module type.

GetMvid()

Obtains the MVID of the module definition.

protected virtual Guid GetMvid()

Returns

Guid

The MVID.

Remarks

This method is called upon initialization of the Mvid property.

GetName()

Obtains the name of the module definition.

protected virtual Utf8String? GetName()

Returns

Utf8String

The name.

Remarks

This method is called upon initialization of the Name property.

GetNativeResources()

Obtains the native win32 resources directory of the underlying PE image (if available).

protected virtual ResourceDirectory? GetNativeResources()

Returns

ResourceDirectory

The resources directory.

Remarks

This method is called upon initialization of the NativeResourceDirectory property.

GetOrCreateModuleConstructor()

Gets or creates the module static constructor of this metadata image. That is, the first method that is executed upon loading the .NET module.

public MethodDefinition GetOrCreateModuleConstructor()

Returns

MethodDefinition

The module constructor.

Remarks

If the static constructor was not present in the image, the new one is automatically added.

GetOrCreateModuleType()

Obtains or creates the global scope type of the .NET module.

public TypeDefinition GetOrCreateModuleType()

Returns

TypeDefinition

The module type.

GetResources()

Obtains the list of resources stored in the module.

protected virtual IList<ManifestResource> GetResources()

Returns

IList<ManifestResource>

The resources.

Remarks

This method is called upon initialization of the Resources property.

GetRuntimeVersion()

Obtains the version string of the runtime.

protected virtual string GetRuntimeVersion()

Returns

string

The runtime version.

Remarks

This method is called upon initialization of the RuntimeVersion property.

GetTopLevelTypes()

Obtains the list of top-level types the module defines.

protected virtual IList<TypeDefinition> GetTopLevelTypes()

Returns

IList<TypeDefinition>

The types.

Remarks

This method is called upon initialization of the TopLevelTypes property.

ImportWith(ReferenceImporter)

Imports the module using the provided reference importer object.

public ModuleReference ImportWith(ReferenceImporter importer)

Parameters

importer ReferenceImporter

The reference importer to use.

Returns

ModuleReference

The imported module.

IsLoadedAs32Bit()

Determines whether the module is loaded as a 32-bit process.

public bool IsLoadedAs32Bit()

Returns

bool

true if the module is loaded as a 32-bit process, false if it is loaded as a 64-bit process.

IsLoadedAs32Bit(bool, bool)

Determines whether the module is loaded as a 32-bit process.

public bool IsLoadedAs32Bit(bool assume32BitSystem, bool canLoadAs32Bit)

Parameters

assume32BitSystem bool

true if a 32-bit system should be assumed.

canLoadAs32Bit bool

true if the application can be loaded as a 32-bit process.

Returns

bool

true if the module is loaded as a 32-bit process, false if it is loaded as a 64-bit process.

LookupMember(MetadataToken)

Looks up a member by its metadata token.

public virtual IMetadataMember LookupMember(MetadataToken token)

Parameters

token MetadataToken

The token of the member to look up.

Returns

IMetadataMember

The member.

Exceptions

InvalidOperationException

Occurs when the module does not support looking up members by its token.

NotSupportedException

Occurs when a metadata token indexes a table that cannot be converted to a metadata member.

LookupMember<T>(MetadataToken)

Looks up a member by its metadata token, and casts it to the provided metadata member type.

public T LookupMember<T>(MetadataToken token) where T : class, IMetadataMember

Parameters

token MetadataToken

The token of the member to look up.

Returns

T

The casted member.

Type Parameters

T

The type of member to look up.

Exceptions

InvalidOperationException

Occurs when the module does not support looking up members by its token.

NotSupportedException

Occurs when a metadata token indexes a table that cannot be converted to a metadata member.

LookupString(MetadataToken)

Looks up a user string by its string token.

public virtual string LookupString(MetadataToken token)

Parameters

token MetadataToken

The token of the string to look up.

Returns

string

The member.

Exceptions

InvalidOperationException

Occurs when the module does not support looking up string by its token.

ArgumentOutOfRangeException

Occurs when a metadata token indexes an invalid string.

ToPEImage()

Rebuilds the .NET module to a portable executable file and returns the IPEImage.

public PEImage ToPEImage()

Returns

PEImage

IPEImage built using ManagedPEImageBuilder by default

Exceptions

AggregateException

Occurs when the construction of the image threw exceptions.

ToPEImage(IPEImageBuilder)

Rebuilds the .NET module to a portable executable file and returns the IPEImage.

public PEImage ToPEImage(IPEImageBuilder imageBuilder)

Parameters

imageBuilder IPEImageBuilder

The engine to use for reconstructing a PE image.

Returns

PEImage

IPEImage built by the specified IPEImageBuilder

Exceptions

AggregateException

Occurs when the construction of the image threw exceptions, and the used error listener is an instance of a DiagnosticBag.

MetadataBuilderException

Occurs when the construction of the PE image failed completely.

ToPEImage(IPEImageBuilder, bool)

Rebuilds the .NET module to a portable executable file and returns the IPEImage.

public PEImage ToPEImage(IPEImageBuilder imageBuilder, bool throwOnNonFatalError)

Parameters

imageBuilder IPEImageBuilder

The engine to use for reconstructing a PE image.

throwOnNonFatalError bool

true if non-fatal errors should be thrown as an exception, false otherwise.

Returns

PEImage

IPEImage built by the specified IPEImageBuilder

Exceptions

AggregateException

Occurs when the construction of the image threw exceptions, and the used error listener is an instance of a DiagnosticBag.

MetadataBuilderException

Occurs when the construction of the PE image failed completely.

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.

TryLookupMember(MetadataToken, out IMetadataMember?)

Attempts to look up a member by its metadata token.

public virtual bool TryLookupMember(MetadataToken token, out IMetadataMember? member)

Parameters

token MetadataToken

The token of the member to look up.

member IMetadataMember

The member, or null if the lookup failed.

Returns

bool

true if the member was successfully looked up, false otherwise.

TryLookupMember<T>(MetadataToken, out T?)

Attempts to look up a member by its metadata token, and cast it to the specified metadata member type.

public bool TryLookupMember<T>(MetadataToken token, out T? member) where T : class, IMetadataMember

Parameters

token MetadataToken

The token of the member to look up.

member T

The member, or null if the lookup failed.

Returns

bool

true if the member was successfully looked up and of the correct type, false otherwise.

Type Parameters

T

The type of member to look up.

TryLookupString(MetadataToken, out string?)

Attempts to look up a user string by its metadata token.

public virtual bool TryLookupString(MetadataToken token, out string? value)

Parameters

token MetadataToken

The token of the member to lookup.

value string

The string, or null if the lookup failed.

Returns

bool

true if the string was successfully looked up, false otherwise.

Write(BinaryStreamWriter, IPEImageBuilder, IPEFileBuilder)

Rebuilds the .NET module to a portable executable file and writes it to the file system.

public void Write(BinaryStreamWriter writer, IPEImageBuilder imageBuilder, IPEFileBuilder fileBuilder)

Parameters

writer BinaryStreamWriter

The output stream of the manifest module file.

imageBuilder IPEImageBuilder

The engine to use for reconstructing a PE image.

fileBuilder IPEFileBuilder

The engine to use for reconstructing a PE file.

Exceptions

AggregateException

Occurs when the construction of the image threw exceptions.

Write(Stream)

Rebuilds the .NET module to a portable executable file and writes it to an output stream.

public void Write(Stream outputStream)

Parameters

outputStream Stream

The output stream of the manifest module file.

Exceptions

AggregateException

Occurs when the construction of the image threw exceptions.

Write(Stream, IPEImageBuilder)

Rebuilds the .NET module to a portable executable file and writes it to an output stream.

public void Write(Stream outputStream, IPEImageBuilder imageBuilder)

Parameters

outputStream Stream

The output stream of the manifest module file.

imageBuilder IPEImageBuilder

The engine to use for reconstructing a PE image.

Exceptions

AggregateException

Occurs when the construction of the image threw exceptions.

Write(Stream, IPEImageBuilder, IPEFileBuilder)

Rebuilds the .NET module to a portable executable file and writes it to an output stream.

public void Write(Stream outputStream, IPEImageBuilder imageBuilder, IPEFileBuilder fileBuilder)

Parameters

outputStream Stream

The output stream of the manifest module file.

imageBuilder IPEImageBuilder

The engine to use for reconstructing a PE image.

fileBuilder IPEFileBuilder

The engine to use for reconstructing a PE file.

Exceptions

AggregateException

Occurs when the construction of the image threw exceptions.

Write(string)

Rebuilds the .NET module to a portable executable file and writes it to the file system.

public void Write(string filePath)

Parameters

filePath string

The output path of the manifest module file.

Exceptions

AggregateException

Occurs when the construction of the image threw exceptions.

Write(string, IPEImageBuilder)

Rebuilds the .NET module to a portable executable file and writes it to the file system.

public void Write(string filePath, IPEImageBuilder imageBuilder)

Parameters

filePath string

The output path of the manifest module file.

imageBuilder IPEImageBuilder

The engine to use for reconstructing a PE image.

Exceptions

AggregateException

Occurs when the construction of the image threw exceptions.

Write(string, IPEImageBuilder, IPEFileBuilder)

Rebuilds the .NET module to a portable executable file and writes it to the file system.

public void Write(string filePath, IPEImageBuilder imageBuilder, IPEFileBuilder fileBuilder)

Parameters

filePath string

The output path of the manifest module file.

imageBuilder IPEImageBuilder

The engine to use for reconstructing a PE image.

fileBuilder IPEFileBuilder

The engine to use for reconstructing a PE file.

Exceptions

AggregateException

Occurs when the construction of the image threw exceptions.