Exemplo n.º 1
0
 /// <inheritdoc />
 public void WriteFloat64(int offset, Float64Value value)
 {
     if (IsKnown)
     {
         BasePointer.WriteFloat64(CurrentOffset + offset, value);
     }
 }
Exemplo n.º 2
0
 /// <inheritdoc />
 public void WriteFloat64(int offset, Float64Value value)
 {
     if (IsKnown)
     {
         ReferencedMemory.WriteFloat64(CurrentOffset + offset, value);
     }
 }
Exemplo n.º 3
0
        public void ReadWriteFloat64()
        {
            var ptrValue = new MemoryBlockValue(8);

            var value = new Float64Value(0.12345678d);

            ptrValue.WriteFloat64(0, value);
            Assert.Equal(value.F64, ptrValue.ReadFloat64(0).F64);
        }
Exemplo n.º 4
0
        /// <inheritdoc />
        public unsafe void WriteFloat64(int offset, Float64Value value)
        {
            AssertOffsetValidity(offset, sizeof(double));

            // Note: There is unfortunately no BinaryPrimitives method for writing single or double values in
            // .NET Standard 2.0. Hence we go the unsafe route.

            using var handle = _memory.Pin();
            *(double *)((byte *)handle.Pointer + offset) = value.F64;
            _knownBitMask.Span.Slice(offset, 8).Fill(0xFF);
        }
Exemplo n.º 5
0
        public void ReadWriteFloat64()
        {
            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 Float64Value(0.12345678d);

            ptrValue.WriteFloat64(0, value);
            Assert.Equal(value.F64, ptrValue.ReadFloat64(0).F64);
        }
Exemplo n.º 6
0
        public void PersistentBits()
        {
            const double testValue = 0.123D;

            var value = new Float64Value(testValue);

            Span <byte> buffer = stackalloc byte[sizeof(double)];
            Span <byte> mask   = stackalloc byte[sizeof(double)];

            value.GetBits(buffer);
            value.GetMask(mask);

            value.SetBits(buffer, mask);

            Assert.Equal(testValue, value.F64);
        }
Exemplo n.º 7
0
 /// <inheritdoc />
 protected override DispatchResult Execute(ExecutionContext context, Float64Value value) =>
 DispatchResult.InvalidProgram();
 /// <inheritdoc />
 public void WriteFloat64(int offset, Float64Value value) => Contents.WriteFloat64(offset, value);
Exemplo n.º 9
0
 /// <inheritdoc />
 protected override DispatchResult Execute(ExecutionContext context, Float64Value value)
 {
     value.F64 = -value.F64;
     context.ProgramState.Stack.Push(value);
     return(DispatchResult.Success());
 }
Exemplo n.º 10
0
        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;
                    }
                }
            }
        }
    }
Exemplo n.º 11
0
 /// <summary>
 /// Performs the operation on the pushed floating point value.
 /// </summary>
 /// <param name="context">The context to execute the instruction in.</param>
 /// <param name="value">The pushed value to perform the operation on.</param>
 /// <returns>The result of the operation.</returns>
 protected abstract DispatchResult Execute(ExecutionContext context, Float64Value value);