Beispiel #1
0
        /// <summary>
        /// Convert values to string representation and concatenate them.
        /// </summary>
        /// <param name="leftOperand">The left operand of concatenation.</param>
        /// <param name="rightOperand">The right operand of concatenation.</param>
        /// <returns>Concatenated string of both operands.</returns>
        public Value EvaluateConcatenation(Value leftOperand, Value rightOperand)
        {
            // Gets type of left operand and convert to string
            leftOperand.Accept(this);

            var leftString = result;

            // Gets type of right operand and convert to string
            rightOperand.Accept(this);

            // Get all flags from both operands if they are tainted
            var flags    = FlagsHandler.GetFlagsFromValues(leftOperand, rightOperand);
            var flagInfo = new Flags(flags);

            // Check whether it is concrete or abstract value
            Value taintedResult;

            if ((leftString != null) && (result != null))
            {
                taintedResult = OutSet.CreateString(string.Concat(leftString.Value, result.Value));
            }
            else
            {
                taintedResult = OutSet.AnyStringValue;
            }

            return(taintedResult.SetInfo(flagInfo));
        }
Beispiel #2
0
        /// <inheritdoc />
        public override void VisitUndefinedValue(UndefinedValue value)
        {
            // When comparing, both operands are converted to boolean
            switch (operation)
            {
            case Operations.Equal:
            case Operations.LessThanOrEqual:
                result = OutSet.CreateBool(!TypeConversion.ToBoolean(leftOperand.Value));
                break;

            case Operations.NotEqual:
            case Operations.GreaterThan:
            case Operations.Or:
            case Operations.Xor:
                result = TypeConversion.ToBoolean(OutSet, leftOperand);
                break;

            case Operations.BitOr:
            case Operations.BitXor:
            case Operations.ShiftLeft:
            case Operations.ShiftRight:
                result = leftOperand;
                break;

            case Operations.Mul:
                result = OutSet.CreateInt(0);
                break;

            default:
                base.VisitUndefinedValue(value);
                break;
            }
        }
Beispiel #3
0
        /// <inheritdoc />
        public override void VisitStringValue(StringValue value)
        {
            switch (operation)
            {
            case Operations.Identical:
                result = OutSet.CreateBool(false);
                break;

            case Operations.NotIdentical:
                result = OutSet.CreateBool(true);
                break;

            case Operations.Mod:
                result = ModuloOperation.AbstractModulo(flow, value.Value);
                break;

            default:
                result = LogicalOperation.AbstractLogical(OutSet, operation,
                                                          TypeConversion.ToBoolean(value.Value));
                if (result != null)
                {
                    break;
                }

                base.VisitStringValue(value);
                break;
            }
        }
Beispiel #4
0
        /// <inheritdoc />
        public override void VisitGenericIntervalValue <T>(IntervalValue <T> value)
        {
            switch (operation)
            {
            case Operations.Identical:
                result = OutSet.CreateBool(false);
                break;

            case Operations.NotIdentical:
                result = OutSet.CreateBool(true);
                break;

            default:
                result = Comparison.AbstractCompare(OutSet, operation);
                if (result != null)
                {
                    break;
                }

                result = ArithmeticOperation.AbstractFloatArithmetic(Snapshot, operation);
                if (result != null)
                {
                    break;
                }

                base.VisitGenericIntervalValue(value);
                break;
            }
        }
Beispiel #5
0
 /// <summary>
 /// Fetches variables of given name from global to local function scope when global keyword is used
 /// </summary>
 /// <param name="variables">Variables that are fetched from global scope</param>
 public virtual void GlobalStatement(IEnumerable <VariableIdentifier> variables)
 {
     foreach (var variable in variables)
     {
         OutSet.FetchFromGlobal(variable.PossibleNames);
     }
 }
Beispiel #6
0
 /// <inheritdoc />
 public override void VisitLongintValue(LongintValue value)
 {
     if (isIncrement)
     {
         if (value.Value < long.MaxValue)
         {
             result = OutSet.CreateLong(value.Value + 1);
         }
         else
         {
             result = OutSet.CreateDouble(TypeConversion.ToFloat(value.Value) + 1.0);
         }
     }
     else
     {
         if (value.Value > long.MinValue)
         {
             result = OutSet.CreateLong(value.Value - 1);
         }
         else
         {
             result = OutSet.CreateDouble(TypeConversion.ToFloat(value.Value) - 1.0);
         }
     }
 }
Beispiel #7
0
        /// <inheritdoc />
        public override void VisitGenericNumericValue <T>(NumericValue <T> value)
        {
            switch (operation)
            {
            case Operations.Identical:
                result = OutSet.CreateBool(false);
                break;

            case Operations.NotIdentical:
                result = OutSet.CreateBool(true);
                break;

            default:
                result = Comparison.AbstractCompare(OutSet, operation);
                if (result != null)
                {
                    break;
                }

                // If the left operand can not be recognized, result can be any integer value.
                result = BitwiseOperation.Bitwise(OutSet, operation);
                if (result != null)
                {
                    break;
                }

                base.VisitGenericNumericValue(value);
                break;
            }
        }
Beispiel #8
0
        /// <inheritdoc />
        public override void VisitBooleanValue(BooleanValue value)
        {
            switch (operation)
            {
            case Operations.Identical:
                result = OutSet.CreateBool(false);
                break;

            case Operations.NotIdentical:
                result = OutSet.CreateBool(true);
                break;

            case Operations.Mod:
                result = ModuloOperation.ModuloByBooleanValue(flow, value.Value);
                break;

            default:
                result = Comparison.IntervalCompare(OutSet, operation, leftOperand, value.Value);
                if (result != null)
                {
                    break;
                }

                result = LogicalOperation.Logical(OutSet, operation, leftOperand, value.Value);
                if (result != null)
                {
                    break;
                }

                base.VisitBooleanValue(value);
                break;
            }
        }
Beispiel #9
0
        /// <inheritdoc />
        public override void VisitIntervalFloatValue(FloatIntervalValue value)
        {
            switch (operation)
            {
            case Operations.Identical:
                result = OutSet.CreateBool(false);
                break;

            case Operations.NotIdentical:
                result = OutSet.CreateBool(true);
                break;

            case Operations.Mod:
                result = ModuloOperation.AbstractModulo(flow, value);
                break;

            default:
                result = ArithmeticOperation.LeftAbstractArithmetic(flow, operation, value);
                if (result != null)
                {
                    break;
                }

                base.VisitIntervalFloatValue(value);
                break;
            }
        }
Beispiel #10
0
        /// <inheritdoc />
        public override void VisitAnyBooleanValue(AnyBooleanValue value)
        {
            switch (operation)
            {
            case Operations.Identical:
                result = OutSet.CreateBool(false);
                break;

            case Operations.NotIdentical:
                result = OutSet.CreateBool(true);
                break;

            case Operations.Mod:
                result = ModuloOperation.ModuloByAnyBooleanValue(flow);
                break;

            default:
                result = Comparison.RightAbstractBooleanCompare(OutSet, operation, leftOperand);
                if (result != null)
                {
                    break;
                }

                base.VisitAnyBooleanValue(value);
                break;
            }
        }
Beispiel #11
0
        /// <inheritdoc />
        public override void VisitAnyStringValue(AnyStringValue value)
        {
            switch (operation)
            {
            case Operations.Identical:
                result = OutSet.CreateBool(false);
                break;

            case Operations.NotIdentical:
                result = OutSet.CreateBool(true);
                break;

            case Operations.Mod:
                result = ModuloOperation.AbstractModulo(flow);
                break;

            default:
                result = Comparison.AbstractCompare(OutSet, operation);
                if (result != null)
                {
                    break;
                }

                result = ArithmeticOperation.AbstractFloatArithmetic(Snapshot, operation);
                if (result != null)
                {
                    // A string can be converted into floating point number too.
                    break;
                }

                base.VisitAnyStringValue(value);
                break;
            }
        }
Beispiel #12
0
        /// <inheritdoc />
        public override void VisitUndefinedValue(UndefinedValue value)
        {
            // When comparing, both operands are converted to boolean
            switch (operation)
            {
            case Operations.BitOr:
            case Operations.BitXor:
            case Operations.ShiftLeft:
            case Operations.ShiftRight:
                IntervalValue <int> convertedValue;
                if (TypeConversion.TryConvertToIntegerInterval(OutSet, leftOperand, out convertedValue))
                {
                    result = convertedValue;
                }
                else
                {
                    result = OutSet.AnyIntegerValue;
                }
                break;

            case Operations.Mul:
                result = OutSet.CreateDouble(0.0);
                break;

            default:
                base.VisitUndefinedValue(value);
                break;
            }
        }
Beispiel #13
0
        public RuleEditorForm(ProjectItem item, ConfigControl oCon, ItemControl oItem)
        {
            InitializeComponent();
            configCon       = oCon;
            itemCon         = oItem;
            this.pageOutSet = new List <OutSet>();

            this.proItem              = item;
            this.ProName.Text         = item.ProName;
            this.UserAgent.Text       = item.UserAgent;
            this.InURL.Text           = item.InURL;
            this.WhenEnabled.Checked  = item.WhenEnabled != null && Boolean.Parse(item.WhenEnabled);
            this.WhenContents.Enabled = this.WhenEnabled.Checked;
            this.WhenContents.Text    = item.WhenContents;
            this.AttachedCookie.Text  = item.AttachedCookie;
            this.CookieHost.Text      = item.CookieHost;
            this.RequestCookies.Text  = item.RequestCookies;
            for (int i = 0, k = item.OutURLList.Count; i < k; i++)
            {
                OutSet set = new  OutSet();
                set.Enabled = item.OutURLList[i].Enabled;
                set.Order   = item.OutURLList[i].Order;
                set.OutURL  = item.OutURLList[i].OutURL;
                this.pageOutSet.Add(set);
            }
            //this.OutList.DroppedDown = true;
            bindOutList();
        }
Beispiel #14
0
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            string OutURL = this.OutList.Text.Trim();

            if (OutURL == null || "".Equals(OutURL))
            {
                MessageBox.Show("Please input 'ExportURL'");
                return;
            }
            OutSet tempSet = pageOutSet.Find(o => o.OutURL == OutURL);

            if (tempSet != null)
            {
                MessageBox.Show("Already exist");
                return;
            }
            OutSet temp = new OutSet();

            //temp.Enabled="false";
            temp.OutURL = this.OutList.Text.Trim();
            //temp.Order=Guid.NewGuid().ToString();
            pageOutSet.Add(temp);
            //this.OutList.Items.Add(temp);
            bindOutList();
        }
Beispiel #15
0
        /// <inheritdoc />
        public override void VisitAnyResourceValue(AnyResourceValue value)
        {
            switch (operation)
            {
            case Operations.Identical:
                result = OutSet.CreateBool(false);
                break;

            case Operations.NotIdentical:
                result = OutSet.CreateBool(true);
                break;

            case Operations.Mod:
                result = ModuloOperation.AbstractModulo(flow);
                break;

            default:
                result = BitwiseOperation.Bitwise(OutSet, operation);
                if (result != null)
                {
                    // Bitwise operation with resource can give any integer
                    break;
                }

                base.VisitAnyResourceValue(value);
                break;
            }
        }
Beispiel #16
0
        public override IEnumerable <Value> IssetEx(IEnumerable <ReadSnapshotEntryBase> entries)
        {
            Debug.Assert(entries.GetEnumerator().MoveNext(),
                         "isset expression must have at least one parameter");


            var canBeDefined   = false;
            var canBeUndefined = false;

            foreach (var snapshotEntry in entries)
            {
                if (snapshotEntry.IsDefined(OutSnapshot))
                {
                    canBeDefined = true;
                }
                else
                {
                    canBeUndefined = true;
                }
            }

            if (canBeDefined)
            {
                yield return(OutSet.CreateBool(true));
            }

            if (canBeUndefined)
            {
                yield return(OutSet.CreateBool(false));
            }
        }
Beispiel #17
0
 /// <inheritdoc />
 public override void VisitIntegerValue(IntegerValue value)
 {
     if (isIncrement)
     {
         if (value.Value < int.MaxValue)
         {
             result = OutSet.CreateInt(value.Value + 1);
         }
         else
         {
             result = OutSet.CreateDouble(TypeConversion.ToFloat(value.Value) + 1.0);
         }
     }
     else
     {
         if (value.Value > int.MinValue)
         {
             result = OutSet.CreateInt(value.Value - 1);
         }
         else
         {
             result = OutSet.CreateDouble(TypeConversion.ToFloat(value.Value) - 1.0);
         }
     }
 }
Beispiel #18
0
        public override MemoryEntry IndirectCreateObject(MemoryEntry possibleNames)
        {
            var declarations = new HashSet <TypeValue>();

            foreach (StringValue name in possibleNames.PossibleValues)
            {
                var qualifiedName = new QualifiedName(new Name(name.Value));
                var types         = OutSet.ResolveType(qualifiedName);
                if (!types.GetEnumerator().MoveNext())
                {
                    // TODO: If no type is resolved, exception should be thrown
                    Debug.Fail("No type resolved");
                }

                declarations.UnionWith(types);
            }

            var values = new List <ObjectValue>();

            foreach (var declaration in declarations)
            {
                var newObject = CreateInitializedObject(declaration);
                values.Add(newObject);
            }

            return(new MemoryEntry(values));
        }
Beispiel #19
0
 /// <inheritdoc />
 public override void VisitIntervalLongintValue(LongintIntervalValue value)
 {
     if (isIncrement)
     {
         if (value.End < long.MaxValue)
         {
             result = OutSet.CreateLongintInterval(value.Start + 1, value.End + 1);
         }
         else
         {
             result = OutSet.CreateFloatInterval(TypeConversion.ToFloat(value.Start) + 1.0,
                                                 TypeConversion.ToFloat(value.End) + 1.0);
         }
     }
     else
     {
         if (value.Start > long.MinValue)
         {
             result = OutSet.CreateLongintInterval(value.Start - 1, value.End - 1);
         }
         else
         {
             result = OutSet.CreateFloatInterval(TypeConversion.ToFloat(value.Start) - 1.0,
                                                 TypeConversion.ToFloat(value.End) - 1.0);
         }
     }
 }
Beispiel #20
0
        /// <inheritdoc />
        public override void VisitAnyScalarValue(AnyScalarValue value)
        {
            switch (operation)
            {
            case Operations.Identical:
                result = OutSet.CreateBool(false);
                break;

            case Operations.NotIdentical:
                result = OutSet.CreateBool(true);
                break;

            default:
                result = LogicalOperation.AbstractLogical(OutSet, operation,
                                                          TypeConversion.ToBoolean(leftOperand));
                if (result != null)
                {
                    break;
                }

                result = BitwiseOperation.Bitwise(OutSet, operation);
                if (result != null)
                {
                    SetWarning("Object cannot be converted to integer by bitwise operation",
                               AnalysisWarningCause.OBJECT_CONVERTED_TO_INTEGER);
                    break;
                }

                base.VisitAnyScalarValue(value);
                break;
            }
        }
Beispiel #21
0
        /// <inheritdoc />
        public override void VisitUndefinedValue(UndefinedValue value)
        {
            switch (operation)
            {
            case Operations.Add:
            case Operations.Sub:
                result = OutSet.AnyFloatValue;
                break;

            case Operations.Mul:
                result = OutSet.CreateDouble(0.0);
                break;

            case Operations.BitOr:
            case Operations.BitXor:
            case Operations.ShiftLeft:
            case Operations.ShiftRight:
                result = OutSet.AnyIntegerValue;
                break;

            default:
                base.VisitUndefinedValue(value);
                break;
            }
        }
Beispiel #22
0
        /// <inheritdoc />
        protected override void flowThrough()
        {
            ValuePoint firstPart, secondPart;

            switch (Assign.PublicOperation)
            {
            case Operations.AssignPrepend:
                firstPart  = ROperand;
                secondPart = LOperand;
                break;

            case Operations.AssignAppend:
                firstPart  = LOperand;
                secondPart = ROperand;
                break;

            default:
                throw new NotSupportedException("Given concat assign is not supported");
            }

            var concatedValue = Services.Evaluator.Concat(new MemoryEntry[] { firstPart.Value.ReadMemory(OutSnapshot), secondPart.Value.ReadMemory(OutSnapshot) });

            Value = OutSet.CreateSnapshotEntry(concatedValue);
            Services.Evaluator.Assign(AssignTarget.LValue, concatedValue);
        }
Beispiel #23
0
        /// <inheritdoc />
        protected override void flowThrough()
        {
            var value = Services.Evaluator.UnaryEx(
                Expression.PublicOperation, Operand.Value.ReadMemory(OutSnapshot));

            Value = OutSet.CreateSnapshotEntry(value);
        }
Beispiel #24
0
        /// <inheritdoc />
        public override void VisitGenericIntervalValue <T>(IntervalValue <T> value)
        {
            switch (operation)
            {
            case Operations.Identical:
                result = OutSet.CreateBool(false);
                break;

            case Operations.NotIdentical:
                result = OutSet.CreateBool(true);
                break;

            default:
                result = Comparison.LeftAlwaysGreater(OutSet, operation);
                if (result != null)
                {
                    break;
                }

                result = BitwiseOperation.Bitwise(OutSet, operation);
                if (result != null)
                {
                    break;
                }

                base.VisitGenericIntervalValue(value);
                break;
            }
        }
Beispiel #25
0
        /// <inheritdoc />
        protected override void flowThrough()
        {
            // Create the name of the variable in global controls
            // Should be unique for each function
            var varNameInGlobalStore = new VariableName("static_" + _variableName.Value + OwningPPGraph.FunctionName + OwningScript);

            // Get the variable from global store
            var variableInGlobalStore = OutSet.GetControlVariable(varNameInGlobalStore);

            // Initialize the variable with _initializer if it may be uninitialized and has an initializer
            var values = variableInGlobalStore.ReadMemory(OutSnapshot);

            if (_initializer != null && values.PossibleValues.Any(a => a is UndefinedValue))
            {
                var newValues = new List <Value> (values.PossibleValues.Where(a => !(a is UndefinedValue)));
                newValues.AddRange(_initializer.Values.PossibleValues);
                variableInGlobalStore.WriteMemory(OutSnapshot, new MemoryEntry(newValues), true);
            }
            else if (_initializer == null)
            {
                variableInGlobalStore.WriteMemory(OutSnapshot, new MemoryEntry(OutSnapshot.UndefinedValue), true);
            }

            // Static variable is an alias of the variable from global store (this respects the implementation in official PHP interpreter)
            _variable.LValue.SetAliases(OutSnapshot, variableInGlobalStore);
        }
Beispiel #26
0
        /// <inheritdoc />
        public override void VisitAnyScalarValue(AnyScalarValue value)
        {
            switch (operation)
            {
            case Operations.Identical:
                result = OutSet.CreateBool(false);
                break;

            case Operations.NotIdentical:
                result = OutSet.CreateBool(true);
                break;

            default:
                result = LogicalOperation.AbstractLogical(OutSet, operation);
                if (result != null)
                {
                    break;
                }

                result = BitwiseOperation.Bitwise(OutSet, operation);
                if (result != null)
                {
                    break;
                }

                base.VisitAnyScalarValue(value);
                break;
            }
        }
Beispiel #27
0
        /// <inheritdoc />
        public override void VisitIntervalFloatValue(FloatIntervalValue value)
        {
            switch (operation)
            {
            case Operations.Identical:
                result = OutSet.CreateBool(false);
                break;

            case Operations.NotIdentical:
                result = OutSet.CreateBool(true);
                break;

            case Operations.Mod:
                result = ModuloOperation.Modulo(flow, leftOperand, value);
                break;

            default:
                var floatInterval = TypeConversion.ToFloatInterval(OutSet, leftOperand);
                result = Comparison.IntervalCompare(OutSet, operation, floatInterval, value);
                if (result != null)
                {
                    break;
                }

                result = ArithmeticOperation.Arithmetic(flow, operation, leftOperand, value);
                if (result != null)
                {
                    break;
                }

                base.VisitIntervalFloatValue(value);
                break;
            }
        }
Beispiel #28
0
        /// <inheritdoc />
        public override void VisitUndefinedValue(UndefinedValue value)
        {
            switch (operation)
            {
            case Operations.Identical:
            case Operations.And:
                result = OutSet.CreateBool(false);
                break;

            case Operations.NotIdentical:
                result = OutSet.CreateBool(true);
                break;

            case Operations.BitAnd:
                result = OutSet.CreateInt(0);
                break;

            case Operations.Div:
                result = ArithmeticOperation.DivisionByNull(flow);
                break;

            case Operations.Mod:
                result = ModuloOperation.ModuloByNull(flow);
                break;

            default:
                base.VisitUndefinedValue(value);
                break;
            }
        }
Beispiel #29
0
        /// <inheritdoc />
        public override void VisitBooleanValue(BooleanValue value)
        {
            switch (operation)
            {
            case Operations.Identical:
                result = OutSet.CreateBool(false);
                break;

            case Operations.NotIdentical:
                result = OutSet.CreateBool(true);
                break;

            default:
                result = Comparison.LeftAbstractBooleanCompare(OutSet, operation, value.Value);
                if (result != null)
                {
                    break;
                }

                result = LogicalOperation.AbstractLogical(OutSet, operation, value.Value);
                if (result != null)
                {
                    break;
                }

                base.VisitBooleanValue(value);
                break;
            }
        }
Beispiel #30
0
        /// <inheritdoc />
        public override void VisitGenericIntervalValue <T>(IntervalValue <T> value)
        {
            switch (operation)
            {
            case Operations.Plus:
                result = value;
                break;

            case Operations.LogicNegation:
                bool nativeBooleanValue;
                if (TypeConversion.TryConvertToBoolean <T>(value, out nativeBooleanValue))
                {
                    result = OutSet.CreateBool(!nativeBooleanValue);
                }
                else
                {
                    result = OutSet.AnyBooleanValue;
                }
                break;

            default:
                if (PerformUsualOperation(value))
                {
                    break;
                }

                base.VisitGenericIntervalValue(value);
                break;
            }
        }