libTriton  version 0.8 build 1439
AstNode

[python api] All information about the AstNode Python object.

Description


This object is used to represent each AST node of an expression.

>>> astCtxt = ctxt.getAstContext()
>>> node = astCtxt.bvadd(astCtxt.bv(1, 8), astCtxt.bvxor(astCtxt.bv(10, 8), astCtxt.bv(20, 8)))
>>> print(node)
(bvadd (_ bv1 8) (bvxor (_ bv10 8) (_ bv20 8)))
# Python's opertors overloaded
>>> a = astCtxt.bv(1, 8)
>>> b = astCtxt.bv(2, 8)
>>> c = (a & ~b) | (~a & b)
>>> print(c)
(bvor (bvand (_ bv1 8) (bvnot (_ bv2 8))) (bvand (bvnot (_ bv1 8)) (_ bv2 8)))

Python API - Methods of the AstNode class


  • bool equalTo(AstNode)
    Compares the current tree to another one.
  • integer evaluate(void)
    Evaluates the tree and returns its value.
  • integer getBitvectorMask(void)
    Returns the mask of the node vector according to its size.
    e.g: 0xffffffff
  • integer getBitvectorSize(void)
    Returns the node vector size.
  • [AstNode, ...] getChildren(void)
    Returns the list of child nodes.
  • integer getHash(void)
    Returns the hash (signature) of the AST.
  • integer getInteger(void)
    Returns the integer of the node. Only available on INTEGER_NODE, raises an exception otherwise.
  • [AstNode, ...] getParents(void)
    Returns the parents list nodes. The list is empty if there is no parent defined yet.
  • string getString(void)
    Returns the string of the node. Only available on STRING_NODE, raises an exception otherwise.
  • SymbolicExpression getSymbolicExpression(void)
    Returns the symbolic expression of the node. Only available on REFERENCE_NODE, raises an exception otherwise.
  • SymbolicVariable getSymbolicVariable(void)
    Returns the symbolic variable of the node. Only available on VARIABLE_NODE, raises an exception otherwise.
  • AST_NODE getType(void)
    Returns the type of the node.
    e.g: AST_NODE.BVADD
  • bool isLogical(void)
    Returns true if it's a logical node. e.g: AST_NODE.EQUAL, AST_NODE.LNOT, AST_NODE.LAND...
  • bool isSigned(void)
    According to the size of the expression, returns true if the MSB is 1.
  • bool isSymbolized(void)
    Returns true if the tree (and its sub-trees) contains a symbolic variable.
  • void setChild(integer index, AstNode node)
    Replaces a child node.

Python API - Operators


As we can not overload all AST operators only the following operators are overloaded:

Python's Operator e.g: SMT2-Lib format
a + b (bvadd a b)
a - b (bvsub a b)
a * b (bvmul a b)
a / b (bvudiv a b)
a | b (bvor a b)
a & b (bvand a b)
a ^ b (bvxor a b)
a % b (bvurem a b)
a << b (bvshl a b)
a >> b (bvlshr a b)
~a (bvnot a)
-a (bvneg a)
a == b (= a b)
a != b (not (= a b))
a <= b (bvule a b)
a >= b (bvuge a b)
a < b (bvult a b)
a > b (bvugt a b)