Exemplo n.º 1
0
 /// <inheritdoc />
 protected override DispatchResult Execute(ExecutionContext context, CilInstruction instruction,
                                           IntegerValue value, int shiftCount)
 {
     value.LeftShift(shiftCount);
     context.ProgramState.Stack.Push(value);
     return(DispatchResult.Success());
 }
Exemplo n.º 2
0
        /// <summary>
        /// Converts the provided trilean to an I4 stack value, pushes it onto the stack and returns the success
        /// dispatcher result.
        /// </summary>
        /// <param name="context">The current execution context.</param>
        /// <param name="result">The trilean value.</param>
        /// <returns>The dispatch result.</returns>
        protected static DispatchResult ConvertToI4AndReturnSuccess(CilExecutionContext context, Trilean result)
        {
            var i4Result = new I4Value(result.ToBooleanOrFalse() ? 1 : 0, 0xFFFFFFFEu | (result.IsKnown ? 1u : 0u));

            context.ProgramState.Stack.Push(i4Result);
            return(DispatchResult.Success());
        }
Exemplo n.º 3
0
 /// <inheritdoc />
 protected override DispatchResult Execute(CilExecutionContext context, CilInstruction instruction,
                                           IntegerValue value, int shiftCount)
 {
     value.RightShift(shiftCount, instruction.OpCode.Code == CilCode.Shr);
     context.ProgramState.Stack.Push((ICliValue)value);
     return(DispatchResult.Success());
 }
Exemplo n.º 4
0
 /// <inheritdoc />
 protected override DispatchResult Execute(CilExecutionContext context, CilInstruction instruction,
                                           IntegerValue left, IntegerValue right)
 {
     left.Xor(right);
     context.ProgramState.Stack.Push((ICliValue)left);
     return(DispatchResult.Success());
 }
Exemplo n.º 5
0
 /// <inheritdoc />
 protected override DispatchResult Execute(ExecutionContext context, CilInstruction instruction,
     IntegerValue left, IntegerValue right)
 {
     left.Add(right);
     context.ProgramState.Stack.Push(left);
     return DispatchResult.Success();
 }
Exemplo n.º 6
0
 /// <inheritdoc />
 protected override DispatchResult Execute(ExecutionContext context, CilInstruction instruction,
                                           FValue left, FValue right)
 {
     left.F64 *= right.F64;
     context.ProgramState.Stack.Push(left);
     return(DispatchResult.Success());
 }
Exemplo n.º 7
0
        /// <inheritdoc />
        public DispatchResult Execute(ExecutionContext context, CilInstruction instruction)
        {
            var result = VerifyCondition(context, instruction);

            int newOffset;

            if (result.IsKnown)
            {
                if (result)
                {
                    newOffset = ((ICilLabel)instruction.Operand).Offset;
                }
                else
                {
                    newOffset = instruction.Offset + instruction.Size;
                }
            }
            else
            {
                // TODO: dispatch event, allowing the user to handle unknown branch conditions.
                throw new DispatchException("Branch condition could not be evaluated.");
            }

            var stack = context.ProgramState.Stack;

            for (int i = 0; i < ArgumentCount; i++)
            {
                stack.Pop();
            }

            context.ProgramState.ProgramCounter = newOffset;
            return(DispatchResult.Success());
        }
Exemplo n.º 8
0
Arquivo: Ceq.cs Projeto: lanicon/Echo
        /// <inheritdoc />
        protected override DispatchResult Execute(CilExecutionContext context, CilInstruction instruction,
                                                  FValue left, FValue right)
        {
            // ReSharper disable once CompareOfFloatsByEqualityOperator
            var i4Result = new I4Value(left.F64 == right.F64 ? 1 : 0);

            context.ProgramState.Stack.Push(i4Result);
            return(DispatchResult.Success());
        }
Exemplo n.º 9
0
        private static DispatchResult ExecuteDefault(ExecutionContext context, IntegerValue value, IntegerValue left)
        {
            if (value.IsNonZero.IsUnknown)
            {
                value.MarkFullyUnknown();
            }

            context.ProgramState.Stack.Push(left);
            return(DispatchResult.Success());
        }
Exemplo n.º 10
0
        /// <inheritdoc />
        public override DispatchResult Execute(CilExecutionContext context, CilInstruction instruction)
        {
            var environment = context.GetService <ICilRuntimeEnvironment>();
            var stack       = context.ProgramState.Stack;

            // Pop address to dereference.
            var elementValue = stack.Pop();
            var addressValue = stack.Pop();

            if (!(addressValue is IPointerValue pointerValue))
            {
                return(DispatchResult.InvalidProgram());
            }

            // Determine type layout.
            var type         = ((ITypeDefOrRef)instruction.Operand).ToTypeSignature();
            var memoryLayout = environment.ValueFactory.GetTypeMemoryLayout(type);

            // Write
            pointerValue.WriteStruct(0, environment.ValueFactory, memoryLayout, elementValue);

            return(DispatchResult.Success());
        }
Exemplo n.º 11
0
        /// <inheritdoc />
        public override DispatchResult Execute(ExecutionContext context, CilInstruction instruction)
        {
            var environment = context.GetService <ICilRuntimeEnvironment>();
            var stack       = context.ProgramState.Stack;

            // Pop address to dereference.
            var addressValue = stack.Pop();

            if (!(addressValue is PointerValue pointerValue))
            {
                return(DispatchResult.InvalidProgram());
            }

            // Determine type layout.
            var type         = ((ITypeDefOrRef)instruction.Operand).ToTypeSignature();
            var memoryLayout = environment.MemoryAllocator.GetTypeMemoryLayout(type);

            // Dereference.
            var structureValue = pointerValue.ReadStruct(0, environment.MemoryAllocator, memoryLayout);

            stack.Push(environment.CliMarshaller.ToCliValue(structureValue, type));

            return(DispatchResult.Success());
        }
Exemplo n.º 12
0
 /// <inheritdoc />
 protected override DispatchResult Execute(ExecutionContext context, IntegerValue value)
 {
     value.Not();
     context.ProgramState.Stack.Push(value);
     return(DispatchResult.Success());
 }
Exemplo n.º 13
0
 /// <inheritdoc />
 public virtual DispatchResult Execute(ExecutionContext context, CilInstruction instruction)
 {
     context.ProgramState.ProgramCounter += instruction.Size;
     return(DispatchResult.Success());
 }
Exemplo n.º 14
0
Arquivo: Neg.cs Projeto: lanicon/Echo
 /// <inheritdoc />
 protected override DispatchResult Execute(CilExecutionContext context, IntegerValue value)
 {
     value.TwosComplement();
     context.ProgramState.Stack.Push((ICliValue)value);
     return(DispatchResult.Success());
 }
Exemplo n.º 15
0
Arquivo: Neg.cs Projeto: lanicon/Echo
 /// <inheritdoc />
 protected override DispatchResult Execute(CilExecutionContext context, FValue value)
 {
     value.F64 = -value.F64;
     context.ProgramState.Stack.Push(value);
     return(DispatchResult.Success());
 }