public void ReadObjectReferenceFieldWithNonNullValue() { var environment = ExecutionContext.GetService <ICilRuntimeEnvironment>(); var fieldContents = new HleObjectValue(LookupTestType(typeof(SimpleClass)).ToTypeSignature(), environment.Is32Bit); var fieldValue = new ObjectReference(fieldContents, environment.Is32Bit); Verify(nameof(SimpleClass.SimpleClassField), fieldValue, new OValue(fieldValue.ReferencedObject, true, environment.Is32Bit)); }
public void WriteObjectReferenceFieldWithNonNullValue() { var environment = ExecutionContext.GetService <ICilRuntimeEnvironment>(); var fieldContents = new HleObjectValue(LookupTestType(typeof(SimpleClass)).ToTypeSignature(), environment.Is32Bit); var fieldValue = new ObjectReference(fieldContents, environment.Is32Bit); var stackValue = environment.CliMarshaller.ToCliValue(fieldValue, _module.CorLibTypeFactory.Object); Verify(nameof(SimpleClass.SimpleClassField), stackValue, fieldValue); }
/// <inheritdoc /> public IDotNetObjectValue AllocateObject(TypeSignature type) { IDotNetObjectValue result; if (type.IsValueType) { var memoryLayout = GetTypeMemoryLayout(type); var contents = AllocateMemory((int)memoryLayout.Size, true); result = new LleObjectValue(this, type, contents); } else { result = new HleObjectValue(type, Is32Bit); } return(result); }
private void Verify(string fieldName, ICliValue stackValue, IConcreteValue expectedValue) { var environment = ExecutionContext.GetService <ICilRuntimeEnvironment>(); var stack = ExecutionContext.ProgramState.Stack; // Look up relevant metadata. var simpleClassType = LookupTestType(typeof(SimpleClass)); var field = simpleClassType.Fields.First(f => f.Name == fieldName); // Create new virtual instance and push on stack. var value = new HleObjectValue(simpleClassType.ToTypeSignature(), environment.Is32Bit); stack.Push(environment.CliMarshaller.ToCliValue(value, simpleClassType.ToTypeSignature())); stack.Push(stackValue); // Test stfld. var result = Dispatcher.Execute(ExecutionContext, new CilInstruction(CilOpCodes.Stfld, field)); Assert.True(result.IsSuccess); Assert.Equal(expectedValue, value.GetFieldValue(field)); }