Exemplo n.º 1
0
 public static function getInstance()
 {
     if (self::$instance === null) {
         self::$instance = new CFG();
     }
     return self::$instance;
 }
Exemplo n.º 2
0
<?php

include_once "PHP-Parser-master/lib/bootstrap.php";
include_once "TaintAnalysis/TaintAnalysis.php";
include_once "CFG/CFG.php";
$filename = $argv[1];
// Obtain the CFGs of the main function, auxiliary functions and function signatures.
$fileCFGInfo = CFG::construct_file_cfgs($filename);
fileTaintAnalysis($fileCFGInfo);
Exemplo n.º 3
0
 static function construct_file_cfgs($fileName)
 {
     print "Constructing CFGs for file " . $fileName . "\n";
     $file = fopen($fileName, "r");
     $parser = new PhpParser\Parser(new PhpParser\Lexer());
     $contents = fread($file, filesize($fileName));
     $stmts = array();
     try {
         $stmts = $parser->parse($contents);
     } catch (PhpParser\Error $e) {
         echo 'Parse Error: ', $e->getMessage();
     }
     echo "There are " . count($stmts) . " statements.\n";
     // Construct the CFGs for all the functions defined in
     // the file.
     echo "Constructing the CFG map of functions.\n";
     $className = "";
     // If there is only one statement and it's a class definition,
     // extract the inner class functions.
     if (count($stmts) == 1 && $stmts[0] instanceof PhpParser\Node\Stmt\Class_) {
         print "Constructing CFG for class\n";
         $className = $stmts[0]->name;
         $function_definitions = CFG::process_function_definitions($stmts[0]->stmts, $fileName, $className);
     } else {
         $function_definitions = CFG::process_function_definitions($stmts, $fileName, $className);
     }
     $function_cfgs = $function_definitions[0];
     $function_signatures = $function_definitions[1];
     echo "Finished construction of the CFG map of functions.\n";
     echo "Found " . count($function_signatures) . " inner functions.\n";
     echo "The function names are:\n";
     foreach ($function_signatures as $name => $signature) {
         print $name . "\n";
     }
     // Construct the CFG of the main procedure of the file.
     echo "Constructing the main CFG.\n";
     $main_cfg = CFG::construct_cfg($stmts);
     echo "Finished construction of the main CFG.\n";
     echo "The main in-order traversal of the CFG is:\n";
     $main_cfg->print_preorder_cfg();
     /*
     	echo "The CFGs of the inner functions are:\n";
     	     foreach($function_cfgs as $name => $inner_cfg) {
     		print "The CFG of ".$name." is :\n";
     		$inner_cfg->print_cfg();
     	 }
     */
     fclose($file);
     return new FileCFGInfo($main_cfg, $function_cfgs, $function_signatures, $className, $fileName);
 }