I'm using PHP-Parser to get the executed paths from AST. For example:
test code:
1 <?php
2 $var = $_POST['firstname'];
3 if($var === 'Admin')
4 {
5 echo 'Welcome';
6 }
7 echo "Done";
In the above code, It is clear that we have 2 executed paths. First one (1-2-3-4-5-6-7), and second one (1-2-3-4-6-7). This is what I want to find (2 executed paths in this source code). So I follow the next steps to find them.
First, I used PHP-Parser to build AST for the above code. The result of PHP-Parser to find the AST as following:
AST Result of PHP-Parser:
array( 0: Stmt_Expression( expr: Expr_Assign( var: Expr_Variable( name: var ) expr: Expr_ArrayDimFetch( var: Expr_Variable( name: _POST ) dim: Scalar_String( value: firstname ) ) ) ) 1: Stmt_If( cond: Expr_BinaryOp_Identical( left: Expr_Variable( name: var ) right: Scalar_String( value: Admin ) ) stmts: array( 0: Stmt_Echo( exprs: array( 0: Scalar_String( value: Welcome ) ) ) ) elseifs: array( ) else: null ) 2: Stmt_Echo( exprs: array( 0: Scalar_String( value: Done ) ) ) )
From the above tree, how I can find that there is 2 executable paths from the above tree. I mean how to traverse the above tree to find that there is 2 executed paths by using PHP-Parser commands too. Thanks
Aucun commentaire:
Enregistrer un commentaire