Пример #1
0
        public void OperationResultEquality()
        {
            var same = new OperationResult(new AbstractValue(1), false);
            var same2 = new OperationResult(new AbstractValue(1), false);
            var different = new OperationResult(new AbstractValue(2), true);

            Assert.IsTrue(same.Equals(same2));
            Assert.IsFalse(same.Equals(different));

            Assert.IsTrue(same == same2);
            Assert.IsTrue(same != different);

            Assert.AreEqual(same.GetHashCode(), same2.GetHashCode());
            Assert.AreNotEqual(same.GetHashCode(), different.GetHashCode());
        }
Пример #2
0
        private static OperationResult DoOperation(AbstractValue lhs, OperatorEffect operatorEffect, AbstractValue rhs)
        {
            if (rhs.IsPointer &&
                operatorEffect != OperatorEffect.Assignment)
            {
                throw new ArgumentException("rhs pointer only supported for OperatorEffect.Assignment.");
            }

            var result = new OperationResult();
            AbstractValue totalValue;

            if (operatorEffect == OperatorEffect.Assignment)
            {
                var newValue = new AbstractValue(rhs);
                if (rhs.IsInitialized &&
                    rhs.IsOutOfBounds)
                {
                    newValue.IsOutOfBounds = true;
                }

                result.Value = newValue;

                return result;
            }

            if (operatorEffect == OperatorEffect.Cmp)
            {
                result.ZeroFlag = (lhs.Value - rhs.Value) == 0;

                totalValue = lhs;
                result.Value = totalValue;
                return result;
            }

            if (lhs.IsPointer)
            {
                var newBuffer = lhs.PointsTo.DoOperation(operatorEffect, rhs);
                result.Value = new AbstractValue(newBuffer);
                return result;
            }

            var total = CalculateValueFor(lhs.Value, operatorEffect, rhs.Value);
            totalValue = new AbstractValue(total);

            if (lhs.IsTainted ||
                rhs.IsTainted)
            {
                totalValue = totalValue.AddTaint();
            }

            result.Value = totalValue;
            return result;
        }