Ejemplo n.º 1
0
        private void OpMax(ParsedOpCode obj)
        {
            var a = MainStack.PopInt32();
            var b = MainStack.PopInt32();

            MainStack.Push(Math.Max(a, b));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Multiplies top two numbers on the stack.
        /// </summary>
        /// <param name="obj"></param>
        private void OpMul(ParsedOpCode obj)
        {
            var a = MainStack.PopInt32();
            var b = MainStack.PopInt32();

            MainStack.Push(a * b);
        }
Ejemplo n.º 3
0
        private void OpSub(ParsedOpCode obj)
        {
            var a = MainStack.PopInt32();
            var b = MainStack.PopInt32();

            MainStack.Push(b - a);
        }
Ejemplo n.º 4
0
        private void OpNumEqual(ParsedOpCode op)
        {
            var a = MainStack.PopInt32();
            var b = MainStack.PopInt32();

            MainStack.Push(a == b ? 1 : 0);
        }
Ejemplo n.º 5
0
        private void OpBoolOr(ParsedOpCode obj)
        {
            var a = MainStack.PopInt32();
            var b = MainStack.PopInt32();

            MainStack.Push(a != 0 || b != 0 ? 1 : 0);
        }
Ejemplo n.º 6
0
        private void OpNumNotEqual(ParsedOpCode obj)
        {
            var a = MainStack.PopInt32();
            var b = MainStack.PopInt32();

            MainStack.Push(a != b ? 1 : 0);
        }
Ejemplo n.º 7
0
        private void OpXor(ParsedOpCode op)
        {
            var a = MainStack.PopInt32();
            var b = MainStack.PopInt32();

            MainStack.Push(a ^ b);
        }
Ejemplo n.º 8
0
        private void OpLessThan(ParsedOpCode obj)
        {
            var a = MainStack.PopInt32();
            var b = MainStack.PopInt32();

            MainStack.Push(b < a ? 1 : 0);
        }
Ejemplo n.º 9
0
        private void OpLeft(ParsedOpCode op)
        {
            var high = MainStack.PopInt32();
            var data = MainStack.Pop();

            if (data.Length == 0 || high == 0)
            {
                MainStack.Push(new byte[0]);
            }
            else if (high < 0)
            {
                throw new ScriptIndexOutOfRangeException(op.Code, "upper boundary less than zero");
            }
            else if (high > data.Length)
            {
                throw new ScriptIndexOutOfRangeException(op.Code, "upper boundary greater than array length");
            }
            else if (high < 0)
            {
                throw new ScriptIndexOutOfRangeException(op.Code, "upper boundary less than zero");
            }
            else
            {
                var bytes = data.Take(high).ToArray();
                MainStack.Push(bytes);
            }
        }
Ejemplo n.º 10
0
        private void OpSubStr(ParsedOpCode op)
        {
            var startIndex        = MainStack.PopInt32();
            var endIndexExclusive = MainStack.PopInt32();
            var array             = MainStack.Pop();

            if (array.Length == 0)
            {
                MainStack.Push(new byte[0]);
            }
            else if (startIndex < 0 || endIndexExclusive < 0)
            {
                throw new ScriptIndexOutOfRangeException(op.Code, "Negative substring index");
            }
            else if (startIndex > array.Length || endIndexExclusive > array.Length)
            {
                throw new ScriptIndexOutOfRangeException(op.Code, "Substring index out of bounds");
            }
            else if (startIndex > endIndexExclusive)
            {
                throw new ScriptIndexOutOfRangeException(op.Code, "Start index is greater than end index");
            }
            else if (startIndex == endIndexExclusive)
            {
                MainStack.Push(new byte[0]);
            }
            else
            {
                var substr = array.Skip(startIndex).Take(endIndexExclusive - startIndex).ToArray();
                MainStack.Push(substr);
            }
        }
Ejemplo n.º 11
0
        private void OpRoll()
        {
            var n   = MainStack.PopInt32();
            var val = MainStack.Pop(n);

            MainStack.Push(val);
        }
Ejemplo n.º 12
0
        private void OpGreaterThanOrEqual(ParsedOpCode obj)
        {
            var a = MainStack.PopInt32();
            var b = MainStack.PopInt32();

            MainStack.Push(b > a ? 1 : 0);
        }
Ejemplo n.º 13
0
        private void OpWithin(ParsedOpCode obj)
        {
            var max  = MainStack.PopInt32();
            var min  = MainStack.PopInt32();
            var test = MainStack.PopInt32();

            MainStack.Push(min <= test && test < max ? 1 : 0);
        }
Ejemplo n.º 14
0
        private void OpMod(ParsedOpCode op)
        {
            var a = MainStack.PopInt32();
            var b = MainStack.PopInt32();

            if (a == 0)
            {
                throw new ArithemeticException(op.Code, "Division by zero");
            }

            MainStack.Push(b % a);
        }
Ejemplo n.º 15
0
        private void OpRShift(ParsedOpCode op)
        {
            var a = MainStack.PopInt32();
            var b = MainStack.PopInt32();

            if (a < 0)
            {
                throw new ScriptIndexOutOfRangeException(op.Code, "Negative shift");
            }
            if (a > 32)
            {
                throw new ScriptIndexOutOfRangeException(op.Code, "Shift overflow");
            }

            MainStack.Push(b >> a);
        }
Ejemplo n.º 16
0
        private void OpRotl(ParsedOpCode op)
        {
            var rotate = MainStack.PopInt32();
            var value  = MainStack.PopInt32();

            if (rotate < 0)
            {
                throw new ScriptIndexOutOfRangeException(op.Code, "attempted to rotate by negative value");
            }
            if (rotate > 31)
            {
                throw new ScriptIndexOutOfRangeException(op.Code, "attempted to rotate by value > 31");
            }

            var rotatedValue = (value << rotate) | (value >> (32 - rotate));

            MainStack.Push(rotatedValue);
        }
Ejemplo n.º 17
0
        private void OpRight(ParsedOpCode op)
        {
            var index = MainStack.PopInt32();
            var data  = MainStack.Pop();

            if (data.Length == 0 || index == data.Length)
            {
                MainStack.Push(new byte[0]);
            }
            else if (index < 0)
            {
                throw new ScriptIndexOutOfRangeException(op.Code, "upper boundary less than zero");
            }
            else if (index > data.Length)
            {
                throw new ScriptIndexOutOfRangeException(op.Code, "upper boundary greater than array length");
            }
            else
            {
                MainStack.Push(data.Skip(index).ToArray());
            }
        }
Ejemplo n.º 18
0
        private void OpAbs(ParsedOpCode obj)
        {
            var value = MainStack.PopInt32();

            MainStack.Push(Math.Abs(value));
        }
Ejemplo n.º 19
0
        private void OpInvert(ParsedOpCode op)
        {
            var value = MainStack.PopInt32();

            MainStack.Push(~value);
        }
Ejemplo n.º 20
0
 private void Op1Add(ParsedOpCode op)
 {
     MainStack.Push(MainStack.PopInt32() + 1);
 }
Ejemplo n.º 21
0
 private void Op1Sub(ParsedOpCode op)
 {
     MainStack.Push(MainStack.PopInt32() - 1);
 }
Ejemplo n.º 22
0
 private void OpNegate(ParsedOpCode obj)
 {
     MainStack.Push(-MainStack.PopInt32());
 }
Ejemplo n.º 23
0
        private void Op0NotEqual(ParsedOpCode obj)
        {
            var value = MainStack.PopInt32();

            MainStack.Push(value == 0 ? 0 : 1);
        }
Ejemplo n.º 24
0
        private void OpNot(ParsedOpCode obj)
        {
            var value = MainStack.PopInt32();

            MainStack.Push(value == 0 ? 1 : 0);
        }
Ejemplo n.º 25
0
        private void OpPick()
        {
            var n = MainStack.PopInt32();

            MainStack.Push(MainStack.Peek(n));
        }