From 68659a78c64dd197e8279918bd1147ef343d80a4 Mon Sep 17 00:00:00 2001 From: Rodrigo Rato Date: Sat, 18 Nov 2017 21:53:57 +0000 Subject: [PATCH] Adds implementatio to all nodes that we're considering --- ast/conditionalnodes.py | 23 ++++++++++++++ ast/cyclenodes.py | 2 +- ast/expressionnodes.py | 66 +++++++++++++++++++++++++++++++++++++++++ ast/functionnodes.py | 8 +++++ ast/nodes.py | 5 +++- 5 files changed, 102 insertions(+), 2 deletions(-) diff --git a/ast/conditionalnodes.py b/ast/conditionalnodes.py index bcdb555..3fe267d 100644 --- a/ast/conditionalnodes.py +++ b/ast/conditionalnodes.py @@ -1 +1,24 @@ from ast.nodes import * + + +class IfThenElseNode(ChildfulNode): + def __init__(self, kind, test, body, alternate=None): + ChildfulNode.__init__(self, kind, body) + self.test = test # An expression + self.body = body # A list of Nodes + self.alternate = alternate # A IfThenElse node or None + + +# A SwitchNode's child are its CaseNodes +class SwitchNode(ChildfulNode): + def __init__(self, kind, test, body): + ChildfulNode.__init__(self, kind, body) + self.test = test + + +class CaseNode(ChildfulNode): + def __init__(self, kind, test, body): + ChildfulNode.__init__(self, kind, body) + self.test = test + + diff --git a/ast/cyclenodes.py b/ast/cyclenodes.py index 6d22d9b..dcbbe2b 100644 --- a/ast/cyclenodes.py +++ b/ast/cyclenodes.py @@ -4,7 +4,7 @@ class CycleNode(ChildfulNode): def __init__(self, kind, children, test): ChildfulNode.__init__(kind, children) - self.test = test + self.test = test # Its an ExpressionNode class WhileNode(CycleNode): diff --git a/ast/expressionnodes.py b/ast/expressionnodes.py index bcdb555..c1d10fc 100644 --- a/ast/expressionnodes.py +++ b/ast/expressionnodes.py @@ -1 +1,67 @@ from ast.nodes import * + + +class ExpressionNode(Node): + def __init__(self, kind): + Node.__init__(self, kind) + + +class AttributionNode(ExpressionNode): + def __init__(self, kind, left_expr, right_expr): + ExpressionNode.__init__(self, kind) + self.left_expr = left_expr + self.right_expr = right_expr + + +class UnaryExpression(ExpressionNode): + def __init__(self, kind, type, expr): + ExpressionNode.__init__(self, kind) + self.type = type # The Unary operator, like '!' and '++' + self.expr = expr # Every Unary expression has an expression associated with it + + +class BinaryExpression(ExpressionNode): + def __init__(self, kind, type, left_expr, right_expr): + ExpressionNode.__init__(self, kind) + self.type = type # The operator, like '+' or '*' + self.left_expr = left_expr # Every binary expression has a left expr and a.. + self.right_expr = right_expr # right expression! + + +class TernaryExpression(ExpressionNode): + def __init__(self, kind, test, true_expr, false_expr): + ExpressionNode.__init__(self, kind) + self.test = test + self.true_expr = true_expr + self.false_expr = false_expr + + +# FIXME assumption - an indexation is a variable +# so $a[1] is a variable node +class VariableNode(ExpressionNode): + def __init__(self, kind, name): + ExpressionNode.__init__(self, kind) + self.name = name + + +# FIXME assumption - we're not handling indexation calls +# so $a[1]("ha"); isn't handled +class FunctionCallNode(ExpressionNode): + def __init__(self, kind, name, arguments): + ExpressionNode.__init__(self, kind) + self.name = name + self.arguments = arguments # arguments is a list of VariableNodes + + +# Stuff like $_GET and $_POST +class EntryPointNode(VariableNode): + def __init__(self, kind, name): + VariableNode.__init__(self, kind, name) + self.tainted = True + self.visited = True + + +class ConstantNode(ExpressionNode): + def __init__(self, kind, value): + ExpressionNode.__init__(self, kind) + self.value = value \ No newline at end of file diff --git a/ast/functionnodes.py b/ast/functionnodes.py index bcdb555..38b84d2 100644 --- a/ast/functionnodes.py +++ b/ast/functionnodes.py @@ -1 +1,9 @@ from ast.nodes import * + + +# FIXME assumption, we're ignoring type hinting +class FunctionDefinitionNode(ChildfulNode): + def __init__(self, kind, name, arguments, children): + ChildfulNode.__init__(self, kind, children) + self.name = name + self.arguments = arguments # arguments is a list of VariableNodes diff --git a/ast/nodes.py b/ast/nodes.py index 6fad300..c2343c5 100644 --- a/ast/nodes.py +++ b/ast/nodes.py @@ -1,12 +1,15 @@ class Node: def __init__(self, kind): - self.kind = kind # This node's kind + self.kind = kind # This node's kind + self.tainted = True # FIXME assuming its good until an entry point is found + self.visited = False # has this node been visited already? def __repr__(self): return '' # This is just a fancy name for an abstraction of a node that has child nodes +# i.e. children somewhere, like inside a body class ChildfulNode(Node): def __init__(self, kind, children): Node.__init__(self, kind)