Beispiel #1
0
        /// <inheritdoc />
        public void SetFieldValue(IFieldDescriptor field, IConcreteValue value)
        {
            var typeMemoryLayout  = _memoryAllocator.GetTypeMemoryLayout(field.DeclaringType);
            var fieldMemoryLayout = typeMemoryLayout[field.Resolve()];

            this.WriteStruct((int)fieldMemoryLayout.Offset, _memoryAllocator, fieldMemoryLayout.ContentsLayout, value);
        }
Beispiel #2
0
        private void SetAndVerify(IFieldDescriptor field, IConcreteValue fieldValue, ICliValue expectedValue)
        {
            var environment = ExecutionContext.GetService <ICilRuntimeEnvironment>();

            environment.StaticFieldFactory.Get(field).Value = fieldValue;
            Verify(field, expectedValue);
        }
Beispiel #3
0
        private void SetAndVerify(string fieldName, IConcreteValue fieldValue, ICliValue expectedValue)
        {
            var module = ModuleDefinition.FromFile(typeof(SimpleClass).Assembly.Location);
            var type   = (TypeDefinition)module.LookupMember(typeof(SimpleClass).MetadataToken);
            var field  = type.Fields.First(f => f.Name == fieldName);

            SetAndVerify(field, fieldValue, expectedValue);
        }
Beispiel #4
0
        public void CreateNewArrayFromExistingArray()
        {
            var elements = new IConcreteValue[]
            {
                new Integer32Value(0), new Integer32Value(1), new Integer32Value(2),
            };

            var array = new ArrayValue(elements);

            Assert.Equal(elements, array);
        }
Beispiel #5
0
        private void Verify(string fieldName, ICliValue newValue, IConcreteValue expectedValue)
        {
            var module = ModuleDefinition.FromFile(typeof(SimpleClass).Assembly.Location);
            var type   = (TypeDefinition)module.LookupMember(typeof(SimpleClass).MetadataToken);
            var field  = type.Fields.First(f => f.Name == fieldName);

            var environment = ExecutionContext.GetService <ICilRuntimeEnvironment>();
            var staticField = environment.StaticFieldFactory.Get(field);

            ExecutionContext.ProgramState.Stack.Push(newValue);
            var result = Dispatcher.Execute(ExecutionContext, new CilInstruction(CilOpCodes.Stsfld, field));

            Assert.True(result.IsSuccess);
            Assert.Equal(expectedValue, staticField.Value);
        }
Beispiel #6
0
        private void VerifyUndocumentedWriteStatic(IConcreteValue instanceObject, ICliValue stackValue, IConcreteValue expectedValue)
        {
            var environment = ExecutionContext.GetService <ICilRuntimeEnvironment>();
            var stack       = ExecutionContext.ProgramState.Stack;

            // Set initial field value.
            var simpleClassType = LookupTestType(typeof(SimpleClass));
            var field           = simpleClassType.Fields.First(f => f.Name == nameof(SimpleClass.StaticIntField));

            // Push random object.
            stack.Push(instanceObject);
            stack.Push(stackValue);

            // Test.
            var result = Dispatcher.Execute(ExecutionContext, new CilInstruction(CilOpCodes.Stfld, field));

            Assert.True(result.IsSuccess);
            Assert.Equal(expectedValue, environment.StaticFieldFactory.Get(field).Value);
        }
Beispiel #7
0
        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));
        }
Beispiel #8
0
 /// <inheritdoc />
 public ICliValue ToCliValue(IConcreteValue value, TypeSignature originalType)
 {
     return(originalType.ElementType switch
     {
         ElementType.I1 => Int8ToI4(value as IntegerValue, true),
         ElementType.U1 => Int8ToI4(value as IntegerValue, false),
         ElementType.I2 => Int16ToI4(value as IntegerValue, true),
         ElementType.Char => Int16ToI4(value as IntegerValue, false),
         ElementType.U2 => Int16ToI4(value as IntegerValue, false),
         ElementType.Boolean => BoolToI4(value as IntegerValue),
         ElementType.I4 => Int32ToI4(value as IntegerValue),
         ElementType.U4 => Int32ToI4(value as IntegerValue),
         ElementType.I8 => Int64ToI8(value as IntegerValue),
         ElementType.U8 => Int64ToI8(value as IntegerValue),
         ElementType.R4 => Float32ToR4((Float32Value)value),
         ElementType.R8 => Float64ToR8((Float64Value)value),
         ElementType.I => IntToI(value as IntegerValue),
         ElementType.U => IntToI(value as IntegerValue),
         ElementType.Ptr => PtrToPointerValue(value as IPointerValue),
         ElementType.ValueType => ObjectToStruct(value, originalType),
         _ => ObjectToO(value)
     });
Beispiel #9
0
        private void Verify(string fieldName, IConcreteValue fieldValue, ICliValue 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 objectRef = environment.ValueFactory.CreateObject(simpleClassType.ToTypeSignature(), true);
            var contents  = (IDotNetStructValue)objectRef.ReferencedObject;

            contents.SetFieldValue(field, fieldValue);
            stack.Push(environment.CliMarshaller.ToCliValue(objectRef, simpleClassType.ToTypeSignature()));

            // Test ldfld.
            var result = Dispatcher.Execute(ExecutionContext, new CilInstruction(CilOpCodes.Ldfld, field));

            Assert.True(result.IsSuccess);
            Assert.Equal(expectedValue, stack.Top);
        }
Beispiel #10
0
 public IConcreteValue InvokeIndirect(IConcreteValue address, MethodSignature methodSig,
                                      IEnumerable <IConcreteValue> arguments)
 {
     return(_original.InvokeIndirect(address, methodSig, arguments));
 }
Beispiel #11
0
 /// <summary>
 /// Creates a new reference to an object.
 /// </summary>
 /// <param name="referencedObject">The referenced object.</param>
 /// <param name="isKnown">Indicates the referenced object is known.</param>
 /// <param name="is32Bit">Indicates the pointer to the referenced object is 32 or 64 bits wide.</param>
 public ObjectReference(IConcreteValue referencedObject, bool isKnown, bool is32Bit)
 {
     Is32Bit          = is32Bit;
     ReferencedObject = referencedObject;
     IsKnown          = isKnown;
 }
Beispiel #12
0
 /// <summary>
 /// Creates a new fully known reference to an object.
 /// </summary>
 /// <param name="referencedObject">The referenced object.</param>
 /// <param name="is32Bit">Indicates the pointer to the referenced object is 32 or 64 bits wide.</param>
 public ObjectReference(IConcreteValue referencedObject, bool is32Bit)
     : this(referencedObject, true, is32Bit)
 {
 }
Beispiel #13
0
 /// <summary>
 /// Creates a new object reference value.
 /// </summary>
 /// <param name="referencedObject">The referenced value.</param>
 /// <param name="isKnown">Indicates whether the value is known.</param>
 /// <param name="is32Bit">Indicates whether the reference to the object is 32 or 64 bits wide.</param>
 public OValue(IConcreteValue referencedObject, bool isKnown, bool is32Bit)
     : base(referencedObject, isKnown, is32Bit)
 {
 }
Beispiel #14
0
 /// <inheritdoc />
 public IConcreteValue InvokeIndirect(IConcreteValue address, MethodSignature methodSig,
                                      IEnumerable <IConcreteValue> arguments)
 {
     return(CreateReturnValue(methodSig));
 }
 public ConcreteValueEqualityComparer(IConcreteValue a1)
 {
     this.a1 = a1;
 }
Beispiel #16
0
 public LhsConcreteValueUnifier(IConcreteValue lhsConcreteValue, BoundVariableSet boundVariables)
 {
     this.lhsConcreteValue = lhsConcreteValue;
     this.boundVariables   = boundVariables;
 }
Beispiel #17
0
 public bool Visit(IConcreteValue lhsConcreteValue)
 {
     return(rhsValue.Accept(new LhsConcreteValueUnifier(lhsConcreteValue, boundVariables)));
 }
Beispiel #18
0
 public Unifier(IConcreteValue lhs, BoundVariableSet boundVariables)
 {
     this.lhs            = lhs;
     this.boundVariables = boundVariables;
 }