public void Visit(AssignmentExpression statement) { switch (statement.AssignmentOperator) { case AssignmentOperator.Assign: statement.Right.Accept(this); break; case AssignmentOperator.Multiply: new BinaryExpression(BinaryExpressionType.Times, statement.Left, statement.Right).Accept(this); break; case AssignmentOperator.Divide: new BinaryExpression(BinaryExpressionType.Div, statement.Left, statement.Right).Accept(this); break; case AssignmentOperator.Modulo: new BinaryExpression(BinaryExpressionType.Modulo, statement.Left, statement.Right).Accept(this); break; case AssignmentOperator.Add: new BinaryExpression(BinaryExpressionType.Plus, statement.Left, statement.Right).Accept(this); break; case AssignmentOperator.Substract: new BinaryExpression(BinaryExpressionType.Minus, statement.Left, statement.Right).Accept(this); break; case AssignmentOperator.ShiftLeft: new BinaryExpression(BinaryExpressionType.LeftShift, statement.Left, statement.Right).Accept(this); break; case AssignmentOperator.ShiftRight: new BinaryExpression(BinaryExpressionType.RightShift, statement.Left, statement.Right).Accept(this); break; case AssignmentOperator.UnsignedRightShift: new BinaryExpression(BinaryExpressionType.UnsignedRightShift, statement.Left, statement.Right).Accept(this); break; case AssignmentOperator.And: new BinaryExpression(BinaryExpressionType.BitwiseAnd, statement.Left, statement.Right).Accept(this); break; case AssignmentOperator.Or: new BinaryExpression(BinaryExpressionType.BitwiseOr, statement.Left, statement.Right).Accept(this); break; case AssignmentOperator.XOr: new BinaryExpression(BinaryExpressionType.BitwiseXOr, statement.Left, statement.Right).Accept(this); break; default: throw new NotSupportedException(); } JsInstance right = Result; MemberExpression left = statement.Left as MemberExpression; if (left == null) { left = new MemberExpression(statement.Left, null); } Assign(left, right); Result = right; }
public void Visit(AssignmentExpression expression) { expression.Left.Accept(this); Builder.Append(" = "); expression.Right.Accept(this); }
void Analyze(AssignmentExpression Stmt) { SetCurrentLineAndCharNos(Stmt); List<JintItem> LeftItems = new List<JintItem>(); List<List<JintItem>> LeftItemParts = new List<List<JintItem>>(); List<List<JintItem>> SinkTaintedLeftItems = new List<List<JintItem>>(); ItemChecker TC = new ItemChecker(this); if (Stmt.Left != null) { int StatusIndex = AddToJintStack(Stmt.Left.Source, JintState.AssignmentExpressionLeft); Analyze(Stmt.Left); LeftItems = RemoveJintStackFrom(StatusIndex + 1); LeftItemParts = ItemChecker.GetItemParts(LeftItems); foreach (List<JintItem> LeftItemPart in LeftItemParts) { TaintResult LeftResult = TC.Check(LeftItemPart); if (LeftResult.SinkTaint) { SinkTaintedLeftItems.Add(LeftItemPart); if (LeftItemPart.Count > 0) AddSinkLine(LeftItemPart[0].LineNo, LeftResult.SinkReasons); else AddSinkLine(CurrentLineNo, LeftResult.SinkReasons); } } RemoveJintStackFrom(StatusIndex); } List<JintItem> RightItems = new List<JintItem>(); if (Stmt.Right != null) { int StatusIndex = AddToJintStack(Stmt.Left.Source, JintState.AssignmentExpressionRight); Analyze(Stmt.Right); RightItems = RemoveJintStackFrom(StatusIndex + 1); if (Stmt.Right.GetType().Name.Equals("AssignmentExpression")) { Analyze(((AssignmentExpression)Stmt.Right).Left); RightItems = RemoveJintStackFrom(StatusIndex + 1); } List<List<JintItem>> RightItemParts = ItemChecker.GetItemParts(RightItems); UpdateMappings(LeftItems, RightItemParts); foreach (List<JintItem> RightItemPart in RightItemParts) { TaintResult RightResult = TC.Check(RightItemPart); if (RightResult.SourceTaint) { foreach (JintItem Item in LeftItems) { Item.SourceReasons.AddRange(RightResult.SourceReasons); } AddToSourceObjects(LeftItems); if (RightItems.Count > 0) AddSourceLine(RightItemPart[0].LineNo, RightResult.SourceReasons); else AddSourceLine(CurrentLineNo, RightResult.SourceReasons); if (SinkTaintedLeftItems.Count > 0) if (LeftItems.Count > 0) AddSourceToSinkLine(LeftItems[0].LineNo); else AddSourceToSinkLine(CurrentLineNo); } else { foreach (List<JintItem> LeftItemPart in LeftItemParts) { RemoveFromSourceTaintedItems(LeftItemPart); } } if (RightResult.SinkTaint) { foreach (JintItem Item in LeftItems) { Item.SinkReasons.AddRange(RightResult.SinkReasons); } foreach (List<JintItem> LeftItemPart in LeftItemParts) { AddToSinkObjects(LeftItemPart); } if (RightItems.Count > 0) AddSinkLine(RightItemPart[0].LineNo, RightResult.SinkReasons); else AddSinkLine(CurrentLineNo, RightResult.SinkReasons); } else { foreach (List<JintItem> LeftItemPart in LeftItemParts) { RemoveFromSinkTaintedItems(LeftItemPart); } } } RemoveJintStackFrom(StatusIndex); } }