Table of Contents

Class CilVirtualMachine

Namespace
Echo.Platforms.AsmResolver.Emulation
Assembly
Echo.Platforms.AsmResolver.dll

Represents a machine that executes CIL instructions in a virtual environment.

public class CilVirtualMachine
Inheritance
CilVirtualMachine
Inherited Members

Constructors

CilVirtualMachine(ModuleDefinition, bool)

Creates a new CIL virtual machine.

public CilVirtualMachine(ModuleDefinition contextModule, bool is32Bit)

Parameters

contextModule ModuleDefinition

The main module to base the context on.

is32Bit bool

Indicates whether the virtual machine runs in 32-bit mode or 64-bit mode.

Properties

Allocator

Gets the service that is responsible for allocating new objects.

public IObjectAllocator Allocator { get; set; }

Property Value

IObjectAllocator

ContextModule

Gets the main module the emulator is executing instructions for.

public ModuleDefinition ContextModule { get; }

Property Value

ModuleDefinition

Dispatcher

Gets the service that is responsible for dispatching individual instructions to their respective handlers.

public CilDispatcher Dispatcher { get; }

Property Value

CilDispatcher

EmulationFlags

Gets or sets flags that control the behavior of the virtual machine.

public CilEmulationFlags EmulationFlags { get; set; }

Property Value

CilEmulationFlags

Heap

Gets the heap used for storing managed objects.

public ManagedObjectHeap Heap { get; }

Property Value

ManagedObjectHeap

Remarks

The heap is also addressable from Memory.

Invoker

Gets the service that is responsible for invoking external functions or methods.

public IMethodInvoker Invoker { get; set; }

Property Value

IMethodInvoker

Is32Bit

Gets a value indicating whether the environment is a 32-bit or 64-bit system.

public bool Is32Bit { get; }

Property Value

bool

Loader

Gets the service that is responsible for mapping executable files in memory.

public PELoader Loader { get; }

Property Value

PELoader

Memory

Gets the main memory interface of the virtual machine.

public VirtualMemory Memory { get; }

Property Value

VirtualMemory

ObjectMapMemory

Gets the memory manager that embeds managed objects into virtual memory.

public ObjectMapMemory ObjectMapMemory { get; }

Property Value

ObjectMapMemory

ObjectMarshaller

Gets or sets the service for marshalling managed objects into bitvectors and back.

public IObjectMarshaller ObjectMarshaller { get; set; }

Property Value

IObjectMarshaller

StaticFields

Gets the memory chunk responsible for storing static fields.

public StaticFieldStorage StaticFields { get; }

Property Value

StaticFieldStorage

Threads

Gets a collection of threads that are currently active in the machine.

public IReadOnlyList<CilThread> Threads { get; }

Property Value

IReadOnlyList<CilThread>

TypeManager

Gets the service that is responsible for the initialization and management of runtime types residing in the virtual machine.

public RuntimeTypeManager TypeManager { get; }

Property Value

RuntimeTypeManager

UnknownResolver

Gets or sets the service that is responsible for resolving unknown values on the stack in critical moments.

public IUnknownResolver UnknownResolver { get; set; }

Property Value

IUnknownResolver

ValueFactory

Gets the service that is responsible for managing types in the virtual machine.

public ValueFactory ValueFactory { get; }

Property Value

ValueFactory

Methods

CreateThread(uint)

Creates a new thread in the machine.

public CilThread CreateThread(uint stackSize = 1048576)

Parameters

stackSize uint

The amount of memory to allocate for the thread's stack.

Returns

CilThread

The created thread.

DestroyThread(CilThread)

Removes a thread and its stack from the machine.

public void DestroyThread(CilThread thread)

Parameters

thread CilThread

The thread to remove.

Remarks

This does not gracefully terminate a thread. Any code that is still running will remain executing, and may have unwanted side effects. Therefore, be sure to only call this method only when it is certain that no code is running.

Events

ThreadCreated

Fires when a new thread was created.

public event EventHandler<CilThread>? ThreadCreated

Event Type

EventHandler<CilThread>

ThreadDestroyed

Fires when a thread was destroyed.

public event EventHandler<CilThread>? ThreadDestroyed

Event Type

EventHandler<CilThread>