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
manifestBundleManifestThe bundle to create the runtime context for.
assemblyResolverIAssemblyResolverThe assembly resolver to use when resolving assemblies into this context, or the default resolver if null.
readerParametersModuleReaderParametersThe 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
configurationRuntimeConfigurationThe configuration file to base the runtime context on.
sourceDirectorystringThe source directory to assume the main assemblies are stored in.
readerParametersModuleReaderParametersThe parameters to use when reading modules in this context.
searchDirectoriesIEnumerable<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
targetRuntimeDotNetRuntimeInfoThe target runtime version.
assemblyResolverIAssemblyResolverThe assembly resolver to use when resolving assemblies into this context, or the default resolver if null.
corLibReferenceAssemblyDescriptorThe core library for this runtime context, or the assumed one from the version if null.
readerParametersModuleReaderParametersThe 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
targetRuntimeDotNetRuntimeInfoThe target runtime version.
is32Bitbool?trueif a 32-bit architecture is to be assumed,falseif 64-bit,nullif platform independent.corLibReferenceAssemblyDescriptorThe core library for this runtime context, or the assumed one from the version if null.
readerParametersModuleReaderParametersThe parameters to use when reading modules in this context.
searchDirectoriesIEnumerable<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
imagePEImageThe executable file to base the runtime context on.
readerParametersModuleReaderParametersThe parameters to use when reading modules in this context.
searchDirectoriesIEnumerable<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
DefaultReaderParameters
Gets the default parameters that are used for reading .NET modules in the context.
public ModuleReaderParameters DefaultReaderParameters { get; }
Property Value
RuntimeCorLib
Gets the corlib for this runtime
public AssemblyDescriptor? RuntimeCorLib { get; }
Property Value
SignatureComparer
Gets the default signature comparer to use in this runtime context.
public SignatureComparer SignatureComparer { get; }
Property Value
TargetRuntime
Gets the runtime version this context is targeting.
public DotNetRuntimeInfo TargetRuntime { get; }
Property Value
Methods
AddAssembly(AssemblyDefinition)
Registers an assembly in the context.
public void AddAssembly(AssemblyDefinition assembly)
Parameters
assemblyAssemblyDefinitionThe 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
fileBundleFileThe 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
readerBinaryStreamReaderThe input stream pointing at the beginning of the executable to load.
modePEMappingModeIndicates 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
fileIInputFileThe 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
filePEFileThe 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
peImagePEImageThe 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
bufferbyte[]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
streamStreamThe 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
filePathstringThe 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
assemblyAssemblyDescriptorThe assembly to resolve.
originModuleModuleDefinitionThe module the assembly is assumed to be referenced in.
definitionAssemblyDefinitionThe resolved assembly, or
nullif 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
fieldIFieldDescriptorThe field to resolve.
originModuleModuleDefinitionThe module the reference is assumed to be in.
definitionFieldDefinitionThe field definition, or
nullif 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
methodIMethodDescriptorThe method. to resolve.
originModuleModuleDefinitionThe module the reference is assumed to be in.
definitionMethodDefinitionThe method definition, or
nullif 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
typeITypeDescriptorThe type to resolve.
originModuleModuleDefinitionThe module the reference is assumed to be in.
definitionTypeDefinitionThe type definition, or
nullif the type could not be resolved.
Returns
- ResolutionStatus
A value describing the success or failure status of the type resolution.