/// <inheritdoc /> public void WriteInteger16(int offset, Integer16Value value) { if (IsKnown) { ReferencedMemory.WriteInteger16(CurrentOffset + offset, value); } }
public void IsEqualTo(string a, string b, TrileanValue expected) { var value1 = new Integer16Value(a); var value2 = new Integer16Value(b); Assert.Equal(expected, value1.IsEqualTo(value2)); }
/// <inheritdoc /> public void WriteInteger16(int offset, Integer16Value value) { if (IsKnown) { BasePointer.WriteInteger16(CurrentOffset + offset, value); } }
/// <inheritdoc /> public void WriteInteger16(int offset, Integer16Value value) { AssertOffsetValidity(offset, sizeof(ushort)); BinaryPrimitives.WriteUInt16LittleEndian(_memory.Span.Slice(offset, 2), value.U16); BinaryPrimitives.WriteUInt16LittleEndian(_knownBitMask.Span.Slice(offset, 2), value.Mask); }
public void SetBit(int index, TrileanValue expected) { var value = new Integer16Value(0); value.SetBit(index, expected); Assert.Equal(expected, value.GetBit(index)); }
public void IsGreaterThan(string a, string b, bool signed, TrileanValue expected) { var value1 = new Integer16Value(a); var value2 = new Integer16Value(b); Assert.Equal(expected, value1.IsGreaterThan(value2, signed)); }
public void Not(string input, string expected) { var value1 = new Integer16Value(input); value1.Not(); Assert.Equal(new Integer16Value(expected), value1); }
public void KnownValueSignUnsignedDifferent() { var value = new Integer16Value(0x8000); Assert.True(value.IsKnown); Assert.Equal(Integer16Value.FullyKnownMask, value.Mask); Assert.Equal(0x8000, value.U16); Assert.Equal(-0x8000, value.I16); }
public void Add(string a, string b, string expected) { var value1 = new Integer16Value(a); var value2 = new Integer16Value(b); value1.Add(value2); Assert.Equal(new Integer16Value(expected), value1); }
public void KnownValueSignUnsignedSame() { var value = new Integer16Value(0x1234); Assert.True(value.IsKnown); Assert.Equal(Integer16Value.FullyKnownMask, value.Mask); Assert.Equal(0x1234, value.U16); Assert.Equal(0x1234, value.I16); }
public void ReadInteger16() { var ptrValue = new MemoryBlockValue(2); var value = new Integer16Value("00001111????0000"); ptrValue.WriteInteger16(0, value); Assert.Equal(value, ptrValue.ReadInteger16(0)); }
public void WriteInteger16ShouldBeLittleEndian() { var ptrValue = new MemoryBlockValue(2); var value = new Integer16Value("00001111????0000"); ptrValue.WriteInteger16(0, value); Assert.Equal(new Integer8Value("????0000"), ptrValue.ReadInteger8(0)); Assert.Equal(new Integer8Value("00001111"), ptrValue.ReadInteger8(1)); }
public void ReadInteger16() { using var memoryOwner = MemoryPool <byte> .Shared.Rent(2); using var bitmaskOwner = MemoryPool <byte> .Shared.Rent(2); var ptrValue = new MemoryPointerValue(memoryOwner.Memory, bitmaskOwner.Memory, true); var value = new Integer16Value("00001111????0000"); ptrValue.WriteInteger16(0, value); Assert.Equal(value, ptrValue.ReadInteger16(0)); }
public void WriteInteger16ShouldBeLittleEndian() { using var memoryOwner = MemoryPool <byte> .Shared.Rent(2); using var bitmaskOwner = MemoryPool <byte> .Shared.Rent(2); var ptrValue = new MemoryPointerValue(memoryOwner.Memory, bitmaskOwner.Memory, true); var value = new Integer16Value("00001111????0000"); ptrValue.WriteInteger16(0, value); Assert.Equal(new Integer8Value("????0000"), ptrValue.ReadInteger8(0)); Assert.Equal(new Integer8Value("00001111"), ptrValue.ReadInteger8(1)); }
/// <inheritdoc /> public void WriteInteger16(int offset, Integer16Value value) => Contents.WriteInteger16(offset, value);
public void ReadFromInt16EnumShouldResultInI4() { var fieldValue = new Integer16Value(1); SetAndVerify(nameof(SimpleClass.StaticInt16Enum), fieldValue, new I4Value(fieldValue.I16)); }
public void IsNonZero(string input, TrileanValue expected) { var value = new Integer16Value(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; } } } } }