public void CallVirtOverrideParameterizedMethod() { var environment = ExecutionContext.GetService <ICilRuntimeEnvironment>(); var stack = ExecutionContext.ProgramState.Stack; // Create instance of the derived type. var objectTypeDef = (TypeDefinition)_type.Module.LookupMember(typeof(DerivedSimpleClass).MetadataToken); var objectTypeSig = objectTypeDef.ToTypeSignature(); var objectRef = environment.ValueFactory.CreateObject(objectTypeSig, true); // Push object. stack.Push(environment.CliMarshaller.ToCliValue(objectRef, objectTypeSig)); stack.Push(new I4Value(123)); stack.Push(OValue.Null(environment.Is32Bit)); // Invoke base method using virtual dispatch. var method = _type.Methods.First(m => m.Name == nameof(SimpleClass.VirtualParameterizedInstanceMethod)); var result = Dispatcher.Execute(ExecutionContext, new CilInstruction(CilOpCodes.Callvirt, method)); Assert.True(result.IsSuccess); Assert.Equal( objectTypeDef.Methods.First(m => m.Name == method.Name), ((HookedMethodInvoker)environment.MethodInvoker).LastInvokedMethod); }
/// <inheritdoc /> protected override Trilean VerifyCondition(CilExecutionContext context, CilInstruction instruction, OValue left, OValue right) { return(left.IsKnown && right.IsKnown ? ReferenceEquals(left.ReferencedObject, right.ReferencedObject) : Trilean.Unknown); }
/// <inheritdoc /> protected override DispatchResult Execute(CilExecutionContext context, CilInstruction instruction, OValue left, OValue right) { var result = left.IsEqualTo(right); return(ConvertToI4AndReturnSuccess(context, result)); }
public void WriteStaticStringField() { var environment = ExecutionContext.GetService <ICilRuntimeEnvironment>(); var fieldContents = environment.ValueFactory.GetStringValue("Hello, World!"); var fieldValue = new OValue(fieldContents, true, environment.Is32Bit); Verify(nameof(SimpleClass.StaticStringField), fieldValue, new ObjectReference(fieldContents, environment.Is32Bit)); }
public void UndocumentedWriteStaticFromNullReferenceShouldNotThrow() { var environment = ExecutionContext.GetService <ICilRuntimeEnvironment>(); VerifyUndocumentedWriteStatic( OValue.Null(environment.Is32Bit), new I4Value(0x12345678), new Integer32Value(0x12345678)); }
public void UndocumentedReadStaticFromNullReferenceShouldNotThrow() { var environment = ExecutionContext.GetService <ICilRuntimeEnvironment>(); VerifyUndocumentedLoadStatic( nameof(SimpleClass.StaticIntField), OValue.Null(environment.Is32Bit), new Integer32Value(0x12345678), new I4Value(0x12345678)); }
public void UndocumentedWriteStaticFromAnyObjectReferenceShouldNotThrow() { var environment = ExecutionContext.GetService <ICilRuntimeEnvironment>(); var instanceObject = new OValue( environment.ValueFactory.GetStringValue("Hello, world"), true, environment.Is32Bit); VerifyUndocumentedWriteStatic(instanceObject, new I4Value(0x12345678), new Integer32Value(0x12345678)); }
public void LdLenOnNullShouldThrowNullReferenceException() { var environment = ExecutionContext.GetService <ICilRuntimeEnvironment>(); var stack = ExecutionContext.ProgramState.Stack; stack.Push(OValue.Null(environment.Is32Bit)); var result = Dispatcher.Execute(ExecutionContext, new CilInstruction(CilOpCodes.Ldlen)); Assert.False(result.IsSuccess); Assert.IsAssignableFrom <NullReferenceException>(result.Exception); }
/// <inheritdoc /> public void StoreElementRef(int index, OValue value, ICliMarshaller marshaller) { AssertIndexValidity(index); if (Contents.Is32Bit) { Contents.WriteInteger32(index * sizeof(uint), new Integer32Value(0, 0)); } else { Contents.WriteInteger64(index * sizeof(uint), new Integer64Value(0, 0)); } }
public void CallVirtOnNullReferenceShouldThrow() { var environment = ExecutionContext.GetService <ICilRuntimeEnvironment>(); var stack = ExecutionContext.ProgramState.Stack; stack.Push(OValue.Null(environment.Is32Bit)); var method = _type.Methods.First(m => m.Name == nameof(SimpleClass.InstanceMethod)); var result = Dispatcher.Execute(ExecutionContext, new CilInstruction(CilOpCodes.Callvirt, method)); Assert.False(result.IsSuccess); Assert.IsAssignableFrom <NullReferenceException>(result.Exception); }
public static IDList <int> ParseIntValues(String values) { IDList <int> OResult = new IDList <int>(); foreach (String OValue in values.Split(',')) { int OIntValue; if (int.TryParse(OValue.Trim(), out OIntValue)) { OResult.Append(OIntValue); } } return(OResult); }
public static IDList <long> ParseLongValues(String values) { IDList <long> OResult = new IDList <long>(); foreach (String OValue in values.Split(',')) { long OLongValue; if (long.TryParse(OValue.Trim(), out OLongValue)) { OResult.Append(OLongValue); } } return(OResult); }
/// <inheritdoc /> protected override Trilean VerifyCondition(ExecutionContext context, CilInstruction instruction, OValue left, OValue right) { var equal = left.IsEqualTo(right); var greaterThan = left.IsGreaterThan(right); if (equal.ToBooleanOrFalse() || greaterThan.ToBooleanOrFalse()) { return(Trilean.True); } if (!equal.IsKnown || !greaterThan.IsKnown) { return(Trilean.Unknown); } return(Trilean.False); }
/// <inheritdoc /> protected override Trilean VerifyCondition(ExecutionContext context, CilInstruction instruction, OValue left, OValue right) { var equal = left.IsEqualTo(right); var lessThan = left.IsLessThan(right); if (equal.ToBooleanOrFalse() || lessThan.ToBooleanOrFalse()) { return(true); } if (!equal.IsKnown || !lessThan.IsKnown) { return(null); } return(false); }
public void ObjectWithNullComparison() { var environment = ExecutionContext.GetService <ICilRuntimeEnvironment>(); var marshaller = environment.CliMarshaller; var stack = ExecutionContext.ProgramState.Stack; var stringValue = environment.ValueFactory.GetStringValue("Hello, world!"); stack.Push(marshaller.ToCliValue(stringValue, environment.Module.CorLibTypeFactory.String)); stack.Push(OValue.Null(environment.Is32Bit)); var result = Dispatcher.Execute(ExecutionContext, new CilInstruction(CilOpCodes.Cgt_Un)); Assert.True(result.IsSuccess); Assert.Equal(Trilean.True, ((I4Value)stack.Top).IsNonZero); }
public void ReadFromNullReferenceShouldThrow() { var environment = ExecutionContext.GetService <ICilRuntimeEnvironment>(); var stack = ExecutionContext.ProgramState.Stack; // Look up relevant metadata. var simpleClassType = LookupTestType(typeof(SimpleClass)); var intField = simpleClassType.Fields.First(f => f.Name == nameof(SimpleClass.IntField)); // Push null. stack.Push(OValue.Null(environment.Is32Bit)); // Test. var result = Dispatcher.Execute(ExecutionContext, new CilInstruction(CilOpCodes.Ldfld, intField)); Assert.False(result.IsSuccess); Assert.IsAssignableFrom <NullReferenceException>(result.Exception); }
public void WriteValue(OValue val) { switch (val.type) { case OValueType.Int: WriteValue(val.getInt()); break; case OValueType.Long: WriteValue(val.getLong()); break; case OValueType.Double: WriteValue(val.getDouble()); break; case OValueType.String: WriteValue(val.getString()); break; case OValueType.Boolean: WriteValue(val.getBoolean()); break; case OValueType.DateTime: WriteValue(val.getDate()); break; case OValueType.Null: WriteValue(""); break; } }
public void DifferentObjectsOnStack() { var environment = ExecutionContext.GetService <ICilRuntimeEnvironment>(); var marshaller = environment.CliMarshaller; var instruction = new CilInstruction(CilOpCodes.Beq, new CilOffsetLabel(0x1234)); var stringValue = environment.ValueFactory.GetStringValue("Hello, World!"); var stack = ExecutionContext.ProgramState.Stack; stack.Push(marshaller.ToCliValue(stringValue, environment.Module.CorLibTypeFactory.String)); stack.Push(OValue.Null(environment.Is32Bit)); var result = Dispatcher.Execute(ExecutionContext, instruction); Assert.True(result.IsSuccess); Assert.Equal(0, stack.Size); Assert.Equal(instruction.Offset + instruction.Size, ExecutionContext.ProgramState.ProgramCounter); }
/// <inheritdoc /> public override DispatchResult Execute(ExecutionContext context, CilInstruction instruction) { var environment = context.GetService <ICilRuntimeEnvironment>(); var method = instruction.Operand as IMethodDescriptor; //Allocate Object var allocatedObject = environment.MemoryAllocator.AllocateObject(method.DeclaringType.ToTypeSignature()); ICliValue cilValueObject = new OValue(allocatedObject, false, environment.Is32Bit); // Pop arguments. int argumentCount = environment.Architecture.GetStackPopCount(instruction); var arguments = context.ProgramState.Stack .Pop(argumentCount, true) .Cast <ICliValue>() .ToList(); arguments.Insert(0, cilValueObject); // Dispatch var methodDispatch = new MethodDevirtualizationResult((IMethodDescriptor)instruction.Operand); if (methodDispatch.Exception != null) { return(new DispatchResult(methodDispatch.Exception)); } // Invoke. var result = environment.MethodInvoker.Invoke(method, arguments); if (result == null) { context.ProgramState.Stack.Push(cilValueObject); } else { context.ProgramState.Stack.Push(result); } return(base.Execute(context, instruction)); }
public static IEnumerable <Node> ToIEnumerableNodeList(this List <Dictionary <string, string> > Source, ref double[] BoundingBox) { List <Node> Result = new List <Node>(); string IdValue; string XValue; string YValue; string OValue; double X = 0, Y = 0, O = 0; Source[0].TryGetValue(ComXLabel, out XValue); Source[0].TryGetValue(ComYLabel, out YValue); BoundingBox[0] = BoundingBox[0] - 5; BoundingBox[1] = BoundingBox[1] - 5; BoundingBox[2] = BoundingBox[2] + 5; BoundingBox[3] = BoundingBox[3] + 5; if (XValue != null && XValue.Length > 1) { if (XValue.Contains(".")) { XValue = XValue.Replace(".", ","); } double.TryParse(XValue, out X); } if (YValue != null && YValue.Length > 1) { if (YValue.Contains(".")) { YValue = YValue.Replace(".", ","); } double.TryParse(YValue, out Y); } BoundingBox[2] = X / ScaleX; BoundingBox[0] = X / ScaleX; BoundingBox[3] = Y / ScaleY; BoundingBox[1] = Y / ScaleY; foreach (Dictionary <string, string> elem in Source) { elem.TryGetValue(UniqIDLabel, out IdValue); elem.TryGetValue(ComXLabel, out XValue); elem.TryGetValue(ComYLabel, out YValue); elem.TryGetValue(ComOrientationLabel, out OValue); if (IdValue == null) { IdValue = ""; } if (XValue != null && XValue.Length > 1) { if (XValue.Contains(".")) { XValue = XValue.Replace(".", ","); } double.TryParse(XValue, out X); } if (YValue != null && YValue.Length > 1) { if (YValue.Contains(".")) { YValue = YValue.Replace(".", ","); } double.TryParse(YValue, out Y); } if (OValue != null && OValue.Length > 1) { if (OValue.Contains(".")) { OValue = OValue.Replace(".", ","); } double.TryParse(OValue, out O); } if ((X / ScaleX) > BoundingBox[2]) { BoundingBox[2] = X / ScaleX; } else if ((X / ScaleX) < BoundingBox[0]) { BoundingBox[0] = X / ScaleX; } if ((Y / ScaleY) > BoundingBox[3]) { BoundingBox[3] = Y / ScaleY; } else if ((Y / ScaleY) < BoundingBox[1]) { BoundingBox[1] = Y / ScaleY; } Result.Add(new Node(IdValue, X / ScaleX, Y / ScaleY, O)); } BoundingBox[0] = BoundingBox[0] - 5; BoundingBox[1] = BoundingBox[1] - 5; BoundingBox[2] = BoundingBox[2] + 5; BoundingBox[3] = BoundingBox[3] + 5; return(Result); }
/// <inheritdoc /> public void StoreElementRef(int index, OValue value, ICliMarshaller marshaller) => _values[index] = marshaller.ToCtsValue(value, CorLibTypeFactory.Object);
/// <inheritdoc /> protected override Trilean VerifyCondition(ExecutionContext context, CilInstruction instruction, OValue left, OValue right) { return(left.IsGreaterThan(right)); }
/// <inheritdoc /> protected override DispatchResult Execute(ExecutionContext context, CilInstruction instruction, OValue left, OValue right) { return DispatchResult.InvalidProgram(); }