public void SetBit(int index, TrileanValue expected) { var value = new Integer32Value(0); value.SetBit(index, expected); Assert.Equal(expected, value.GetBit(index)); }
/// <inheritdoc /> public void WriteInteger32(int offset, Integer32Value value) { AssertOffsetValidity(offset, sizeof(uint)); BinaryPrimitives.WriteUInt32LittleEndian(_memory.Span.Slice(offset, 4), value.U32); BinaryPrimitives.WriteUInt32LittleEndian(_knownBitMask.Span.Slice(offset, 4), value.Mask); }
public void IsGreaterThan(string a, string b, bool signed, TrileanValue expected) { var value1 = new Integer32Value(a); var value2 = new Integer32Value(b); Assert.Equal(expected, value1.IsGreaterThan(value2, signed)); }
public void IsEqualTo(string a, string b, TrileanValue expected) { var value1 = new Integer32Value(a); var value2 = new Integer32Value(b); Assert.Equal(expected, value1.IsEqualTo(value2)); }
public void ReadStaticIntField() { var environment = ExecutionContext.GetService <ICilRuntimeEnvironment>(); var fieldValue = new Integer32Value(0x12345678); Verify(nameof(SimpleClass.StaticIntField), fieldValue, new I4Value(fieldValue.I32)); }
/// <inheritdoc /> public void WriteInteger32(int offset, Integer32Value value) { if (IsKnown) { ReferencedMemory.WriteInteger32(CurrentOffset + offset, value); } }
/// <inheritdoc /> public void WriteInteger32(int offset, Integer32Value value) { if (IsKnown) { BasePointer.WriteInteger32(CurrentOffset + offset, value); } }
public void Not(string input, string expected) { var value1 = new Integer32Value(input); value1.Not(); Assert.Equal(new Integer32Value(expected), value1); }
public void RemainderWithUnknownNumbersShouldNotResultInInfiniteLoop() { var value1 = new Integer32Value("11111111"); var value2 = new Integer32Value(0, 0); value1.Remainder(value2); Assert.False(value1.IsKnown); }
public void Add(string a, string b, string expected) { var value1 = new Integer32Value(a); var value2 = new Integer32Value(b); value1.Add(value2); Assert.Equal(new Integer32Value(expected), value1); }
public void KnownValueSignUnsignedSame() { var value = new Integer32Value(0x12345678); Assert.True(value.IsKnown); Assert.Equal(Integer32Value.FullyKnownMask, value.Mask); Assert.Equal(0x12345678u, value.U32); Assert.Equal(0x12345678, value.I32); }
public void ReadInteger64() { var ptrValue = new MemoryBlockValue(8); var value = new Integer32Value("00001111????0011001100??00??0101"); ptrValue.WriteInteger32(0, value); Assert.Equal(value, ptrValue.ReadInteger32(0)); }
/// <summary> /// When the value is fully known, gets the raw integer value stored in this native integer as an int64. /// </summary> /// <returns>The integer, sign extended to a 64 bit integer.</returns> /// <exception cref="InvalidOperationException"></exception> public long ToKnownI64() { if (IsKnown) { throw new InvalidOperationException("Value is not fully known."); } return(_value switch { Integer32Value int32 => int32.I32, Integer64Value int64 => int64.I64, _ => throw new ArgumentOutOfRangeException() });
public void WriteInteger32ShouldBeLittleEndian() { var ptrValue = new MemoryBlockValue(4); var value = new Integer32Value("00001111" + "????0011" + "001100??" + "00??0101"); ptrValue.WriteInteger32(0, value); Assert.Equal(new Integer8Value("00??0101"), ptrValue.ReadInteger8(0)); Assert.Equal(new Integer8Value("001100??"), ptrValue.ReadInteger8(1)); Assert.Equal(new Integer8Value("????0011"), ptrValue.ReadInteger8(2)); Assert.Equal(new Integer8Value("00001111"), ptrValue.ReadInteger8(3)); }
public void ReadInteger64() { using var memoryOwner = MemoryPool <byte> .Shared.Rent(8); using var bitmaskOwner = MemoryPool <byte> .Shared.Rent(8); var ptrValue = new MemoryPointerValue(memoryOwner.Memory, bitmaskOwner.Memory, true); var value = new Integer32Value("00001111????0011001100??00??0101"); ptrValue.WriteInteger32(0, value); Assert.Equal(value, ptrValue.ReadInteger32(0)); }
public void ShallowCopyShouldReferenceSameArray() { var array = new ArrayValue(new IConcreteValue[] { new Integer32Value(0), new Integer32Value(1), new Integer32Value(2), }); var copy = (ArrayValue)array.Copy(); Assert.NotSame(array, copy); Assert.Equal((IEnumerable <IConcreteValue>)array, copy); copy[0] = new Integer32Value(1234); Assert.Equal(new Integer32Value(1234), array[0]); }
public void WriteInteger32ShouldBeLittleEndian() { using var memoryOwner = MemoryPool <byte> .Shared.Rent(4); using var bitmaskOwner = MemoryPool <byte> .Shared.Rent(4); var ptrValue = new MemoryPointerValue(memoryOwner.Memory, bitmaskOwner.Memory, true); var value = new Integer32Value("00001111" + "????0011" + "001100??" + "00??0101"); ptrValue.WriteInteger32(0, value); Assert.Equal(new Integer8Value("00??0101"), ptrValue.ReadInteger8(0)); Assert.Equal(new Integer8Value("001100??"), ptrValue.ReadInteger8(1)); Assert.Equal(new Integer8Value("????0011"), ptrValue.ReadInteger8(2)); Assert.Equal(new Integer8Value("00001111"), ptrValue.ReadInteger8(3)); }
public void ReadStaticIntField() { var fieldValue = new Integer32Value(0x12345678); SetAndVerify(nameof(SimpleClass.StaticIntField), fieldValue, new I4Value(fieldValue.I32)); }
public void ReadFromInt32EnumShouldResultInI4() { var fieldValue = new Integer32Value(1); SetAndVerify(nameof(SimpleClass.StaticInt32Enum), fieldValue, new I4Value(fieldValue.I32)); }
/// <inheritdoc /> public void WriteInteger32(int offset, Integer32Value value) => Contents.WriteInteger32(offset, value);
public void IsNonZero(string input, TrileanValue expected) { var value = new Integer32Value(input); Assert.Equal(expected, value.IsNonZero); }
public override void Execute(Context context, IEnumerable <MetadataMember> targets) { if (!context.IsReflectionCorlibSafe) { return; } foreach (var Method in targets.OfType <MethodDefinition>().Where(m => m.CilMethodBody is not null)) { var Instructions = Method.CilMethodBody.Instructions; Method.CilMethodBody.ConstructSymbolicFlowGraph(out var DFG); /* Dfg Constructing. */ for (int x = 0; x < Instructions.Count; x++) { var Instr = Instructions[x]; /* Some People Make It Callvirt To Deafet Public tools :p */ if ((Instr.IsCode(CilCode.Call) || Instr.IsCode(CilCode.Callvirt)) && Instr.IsFromNS("System", "Math") && DFG.Nodes.Contains(Instr.Offset)) { var CallNode = DFG.Nodes[Instr.Offset] .GetOrderedDependencies(DependencyCollectionFlags.IncludeStackDependencies) .ToList(); if (CallNode.Any(x => x.Contents.OpCode.OperandType == CilOperandType.InlineMethod)) { continue; } var vm = new CilVirtualMachine(Method.CilMethodBody, context.Module.Is32Module()); var ex = new CilExecutionContext(vm, vm.CurrentState, default); foreach (var Dep in CallNode) { var CInstr = Dep.Contents; vm.Dispatcher.Execute(ex, CInstr); CInstr.Nop(); } var ISlot = new object[((IMethodDescriptor)Instr.Operand) .Signature.GetTotalParameterCount()]; for (int i = 0; i < ISlot.Length; i++) { var Value = vm.CurrentState.Stack.Pop(); ISlot[i] = Value switch { I4Value I4 => I4.I32, I8Value I8 => I8.I64, FValue F => F.F64, Float32Value F32 => F32.F32, Float64Value F64 => F64.F64, Integer16Value I6 => I6.I16, Integer32Value I32 => I32.I32, Integer64Value I64 => I64.I64, _ => throw new NotSupportedException(nameof(Value)) }; } var InvocationValue = context.ReflectionCorlib.ResolveMethod(((IMethodDescriptor)Instr.Operand).MetadataToken.ToInt32()) .Invoke(null, ISlot); Instr.OpCode = ((IMethodDescriptor)Instr.Operand).Signature.ReturnType.ElementType switch { ElementType.I4 => CilOpCodes.Ldc_I4, ElementType.I8 => CilOpCodes.Ldc_I8, ElementType.R4 => CilOpCodes.Ldc_R4, ElementType.R8 => CilOpCodes.Ldc_R8, _ => CilOpCodes.Ldc_I4, }; Instr.Operand = InvocationValue; } } } } }