public DispatcherTestBase(MockModuleFixture moduleFixture) { ModuleFixture = moduleFixture; const bool is32Bit = false; var dummyModule = moduleFixture.GetModule(); var dummyMethod = new MethodDefinition( "MockMethod", MethodAttributes.Static, MethodSignature.CreateStatic(dummyModule.CorLibTypeFactory.Void)); dummyMethod.CilMethodBody = new CilMethodBody(dummyMethod); var environment = new MockCilRuntimeEnvironment(dummyModule, is32Bit) { Architecture = new CilArchitecture(dummyMethod.CilMethodBody), }; var methodInvoker = new ReturnUnknownMethodInvoker(environment.ValueFactory); environment.MethodInvoker = new HookedMethodInvoker(methodInvoker); var container = new ServiceContainer(); container.AddService(typeof(ICilRuntimeEnvironment), environment); Dispatcher = new CilDispatcher(); ExecutionContext = new CilExecutionContext( container, new CilProgramState(environment.ValueFactory), default); }
/// <summary> /// Creates a new instance of the <see cref="CilVirtualMachine"/>. /// </summary> /// <param name="module">The module in which the CIL runs in.</param> /// <param name="instructions">The instructions to emulate..</param> /// <param name="is32Bit">Indicates whether the virtual machine should run in 32-bit mode or in 64-bit mode.</param> public CilVirtualMachine(ModuleDefinition module, IStaticInstructionProvider<CilInstruction> instructions, bool is32Bit) { Module = module; Instructions = instructions; Architecture = instructions.Architecture; Is32Bit = is32Bit; Status = VirtualMachineStatus.Idle; CurrentState = new CilProgramState(); Dispatcher = new DefaultCilDispatcher(); CliMarshaller = new DefaultCliMarshaller(this); MemoryAllocator = new DefaultMemoryAllocator(module, is32Bit); MethodInvoker = new ReturnUnknownMethodInvoker(new UnknownValueFactory(this)); StaticFieldFactory = new StaticFieldFactory(); _services[typeof(ICilRuntimeEnvironment)] = this; }
/// <summary> /// Creates a new instance of the <see cref="CilVirtualMachine"/>. /// </summary> /// <param name="module">The module in which the CIL runs in.</param> /// <param name="instructions">The instructions to emulate..</param> /// <param name="is32Bit">Indicates whether the virtual machine should run in 32-bit mode or in 64-bit mode.</param> public CilVirtualMachine(ModuleDefinition module, IStaticInstructionProvider <CilInstruction> instructions, bool is32Bit) { Module = module ?? throw new ArgumentNullException(nameof(module)); Instructions = instructions ?? throw new ArgumentNullException(nameof(instructions)); Architecture = instructions.Architecture; ValueFactory = new DefaultValueFactory(module, is32Bit); Is32Bit = is32Bit; Status = VirtualMachineStatus.Idle; CurrentState = new CilProgramState(ValueFactory); Dispatcher = new DefaultCilDispatcher(); CliMarshaller = new DefaultCliMarshaller(this); MethodInvoker = new ReturnUnknownMethodInvoker(ValueFactory); StaticFieldFactory = new StaticFieldFactory(ValueFactory); _services[typeof(ICilRuntimeEnvironment)] = this; }