Table of Contents

Class RuntimeContext

Namespace
AsmResolver.DotNet
Assembly
AsmResolver.DotNet.dll

Describes a context in which a .NET runtime is active.

public class RuntimeContext
Inheritance
RuntimeContext
Inherited Members

Constructors

RuntimeContext(BundleManifest, IAssemblyResolver?, ModuleReaderParameters?)

Creates a new runtime context.

public RuntimeContext(BundleManifest manifest, IAssemblyResolver? assemblyResolver = null, ModuleReaderParameters? readerParameters = null)

Parameters

manifest BundleManifest

The bundle to create the runtime context for.

assemblyResolver IAssemblyResolver

The assembly resolver to use when resolving assemblies into this context, or the default resolver if null.

readerParameters ModuleReaderParameters

The parameters to use when reading modules in this context.

RuntimeContext(RuntimeConfiguration, string?, ModuleReaderParameters?, IEnumerable<string>?)

Creates a new .NET (Core) runtime context.

public RuntimeContext(RuntimeConfiguration configuration, string? sourceDirectory = null, ModuleReaderParameters? readerParameters = null, IEnumerable<string>? searchDirectories = null)

Parameters

configuration RuntimeConfiguration

The configuration file to base the runtime context on.

sourceDirectory string

The source directory to assume the main assemblies are stored in.

readerParameters ModuleReaderParameters

The parameters to use when reading modules in this context.

searchDirectories IEnumerable<string>

Additional search directories to be added to the assembly resolution system.

RuntimeContext(DotNetRuntimeInfo, IAssemblyResolver, AssemblyDescriptor?, ModuleReaderParameters?)

Creates a new runtime context.

public RuntimeContext(DotNetRuntimeInfo targetRuntime, IAssemblyResolver assemblyResolver, AssemblyDescriptor? corLibReference = null, ModuleReaderParameters? readerParameters = null)

Parameters

targetRuntime DotNetRuntimeInfo

The target runtime version.

assemblyResolver IAssemblyResolver

The assembly resolver to use when resolving assemblies into this context, or the default resolver if null.

corLibReference AssemblyDescriptor

The core library for this runtime context, or the assumed one from the version if null.

readerParameters ModuleReaderParameters

The parameters to use when reading modules in this context, or the default ones if null.

RuntimeContext(DotNetRuntimeInfo, bool?, AssemblyDescriptor?, ModuleReaderParameters?, IEnumerable<string>?)

Creates a new runtime context.

public RuntimeContext(DotNetRuntimeInfo targetRuntime, bool? is32Bit = null, AssemblyDescriptor? corLibReference = null, ModuleReaderParameters? readerParameters = null, IEnumerable<string>? searchDirectories = null)

Parameters

targetRuntime DotNetRuntimeInfo

The target runtime version.

is32Bit bool?

true if a 32-bit architecture is to be assumed, false if 64-bit, null if platform independent.

corLibReference AssemblyDescriptor

The core library for this runtime context, or the assumed one from the version if null.

readerParameters ModuleReaderParameters

The parameters to use when reading modules in this context.

searchDirectories IEnumerable<string>

Additional search directories to be added to the assembly resolution system.

RuntimeContext(PEImage, ModuleReaderParameters?, IEnumerable<string>?)

Creates a new runtime context based on a PE image.

public RuntimeContext(PEImage image, ModuleReaderParameters? readerParameters = null, IEnumerable<string>? searchDirectories = null)

Parameters

image PEImage

The executable file to base the runtime context on.

readerParameters ModuleReaderParameters

The parameters to use when reading modules in this context.

searchDirectories IEnumerable<string>

Additional search directories to be added to the assembly resolution system.

Properties

AssemblyResolver

Gets the assembly resolver that the context uses to resolve assemblies.

public IAssemblyResolver AssemblyResolver { get; }

Property Value

IAssemblyResolver

DefaultReaderParameters

Gets the default parameters that are used for reading .NET modules in the context.

public ModuleReaderParameters DefaultReaderParameters { get; }

Property Value

ModuleReaderParameters

RuntimeCorLib

Gets the corlib for this runtime

public AssemblyDescriptor? RuntimeCorLib { get; }

Property Value

AssemblyDescriptor

SignatureComparer

Gets the default signature comparer to use in this runtime context.

public SignatureComparer SignatureComparer { get; }

Property Value

SignatureComparer

TargetRuntime

Gets the runtime version this context is targeting.

public DotNetRuntimeInfo TargetRuntime { get; }

Property Value

DotNetRuntimeInfo

Methods

AddAssembly(AssemblyDefinition)

Registers an assembly in the context.

public void AddAssembly(AssemblyDefinition assembly)

Parameters

assembly AssemblyDefinition

The assembly to add

Exceptions

ArgumentException

Occurs when the assembly was already added to another context, or when there already exists an assembly with the same name in the context.

GetLoadedAssemblies()

Enumerates all assemblies that were loaded in the context.

public IEnumerable<AssemblyDefinition> GetLoadedAssemblies()

Returns

IEnumerable<AssemblyDefinition>

The assemblies.

LoadAssembly(BundleFile)

Loads a .NET assembly into the context from a file in an app-host bundle.

public AssemblyDefinition LoadAssembly(BundleFile file)

Parameters

file BundleFile

The file containing the .NET metadata.

Returns

AssemblyDefinition

The assembly.

Exceptions

BadImageFormatException

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

LoadAssembly(in BinaryStreamReader, PEMappingMode)

Loads a .NET assembly into the context from an input stream.

public AssemblyDefinition LoadAssembly(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

AssemblyDefinition

The assembly.

Exceptions

BadImageFormatException

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

LoadAssembly(IInputFile)

Loads a .NET assembly into the context from the provided input file.

public AssemblyDefinition LoadAssembly(IInputFile file)

Parameters

file IInputFile

The portable executable file to load.

Returns

AssemblyDefinition

The assembly.

Exceptions

BadImageFormatException

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

LoadAssembly(PEFile)

Loads a .NET assembly into the context from the provided input file.

public AssemblyDefinition LoadAssembly(PEFile file)

Parameters

file PEFile

The portable executable file to load.

Returns

AssemblyDefinition

The assembly.

Exceptions

BadImageFormatException

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

LoadAssembly(PEImage)

Loads a .NET assembly into the context from a PE image.

public AssemblyDefinition LoadAssembly(PEImage peImage)

Parameters

peImage PEImage

The image containing the .NET metadata.

Returns

AssemblyDefinition

The assembly.

Exceptions

BadImageFormatException

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

LoadAssembly(byte[])

Loads a .NET assembly into the context from the provided input buffer.

public AssemblyDefinition LoadAssembly(byte[] buffer)

Parameters

buffer byte[]

The raw contents of the executable file to load.

Returns

AssemblyDefinition

The assembly.

Exceptions

BadImageFormatException

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

LoadAssembly(Stream)

Loads a .NET assembly into the context from the provided input stream.

public AssemblyDefinition LoadAssembly(Stream stream)

Parameters

stream Stream

The raw contents of the executable file to load.

Returns

AssemblyDefinition

The assembly.

Exceptions

BadImageFormatException

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

LoadAssembly(string)

Loads a .NET assembly into the context from the provided input file.

public AssemblyDefinition LoadAssembly(string filePath)

Parameters

filePath string

The file path to the input executable to load.

Returns

AssemblyDefinition

The assembly.

Exceptions

BadImageFormatException

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

ResolveAssembly(AssemblyDescriptor, ModuleDefinition?, out AssemblyDefinition?)

Resolves an assembly descriptor in the current context.

public ResolutionStatus ResolveAssembly(AssemblyDescriptor assembly, ModuleDefinition? originModule, out AssemblyDefinition? definition)

Parameters

assembly AssemblyDescriptor

The assembly to resolve.

originModule ModuleDefinition

The module the assembly is assumed to be referenced in.

definition AssemblyDefinition

The resolved assembly, or null if resolution failed.

Returns

ResolutionStatus

A value describing the success or failure status of the assembly resolution.

ResolveField(IFieldDescriptor, ModuleDefinition?, out FieldDefinition?)

Resolves a reference to a field.

public ResolutionStatus ResolveField(IFieldDescriptor field, ModuleDefinition? originModule, out FieldDefinition? definition)

Parameters

field IFieldDescriptor

The field to resolve.

originModule ModuleDefinition

The module the reference is assumed to be in.

definition FieldDefinition

The field definition, or null if the field could not be resolved.

Returns

ResolutionStatus

A value describing the success or failure status of the field resolution.

ResolveMethod(IMethodDescriptor, ModuleDefinition?, out MethodDefinition?)

Resolves a reference to a method.

public ResolutionStatus ResolveMethod(IMethodDescriptor method, ModuleDefinition? originModule, out MethodDefinition? definition)

Parameters

method IMethodDescriptor

The method. to resolve.

originModule ModuleDefinition

The module the reference is assumed to be in.

definition MethodDefinition

The method definition, or null if the method could not be resolved.

Returns

ResolutionStatus

A value describing the success or failure status of the method resolution.

ResolveType(ITypeDescriptor?, ModuleDefinition?, out TypeDefinition?)

Resolves a reference to a type.

public ResolutionStatus ResolveType(ITypeDescriptor? type, ModuleDefinition? originModule, out TypeDefinition? definition)

Parameters

type ITypeDescriptor

The type to resolve.

originModule ModuleDefinition

The module the reference is assumed to be in.

definition TypeDefinition

The type definition, or null if the type could not be resolved.

Returns

ResolutionStatus

A value describing the success or failure status of the type resolution.