-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.php
64 lines (52 loc) · 1.67 KB
/
main.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
use PhpParser\NodeDumper;
require __DIR__.'/vendor/autoload.php';
require "ASTParser.php";
require "IRGenerator.php";
require "ScopeExtractor.php";
require "CFGGenerator.php";
require "SSAConstructor.php";
require "TaintAnalyzer.php";
$proj_path = ""; // Path to project
// Parse AST
$ast_parser = new ASTParser($proj_path);
$asts = $ast_parser->getASTs();
// IR
$tacs = [];
foreach ($asts as $ast)
{
echo "Converting ".$ast["filename"]." to IRs\n";
$ir_gen = new IRGenerator($ast);
array_push($tacs, ["filename" => $ast["filename"], "lines" => $ir_gen->getTacs()]);
}
// Scope Tree
$scope_trees = [];
foreach ($tacs as $tac)
{
echo "Extracting functions of ".$tac["filename"]."\n";
$scope_ext = new ScopeExtractor($tac);
array_push($scope_trees, ["filename" => $tac["filename"], "scope_tree" => $scope_ext->getTopTreeNode()]);
}
// CFG
for ($i=0; $i<count($scope_trees); ++$i)
{
echo "Generating CFGs for ".$scope_trees[$i]["filename"]."\n";
$cfg_gen = new CFGGenerator($scope_trees[$i]["scope_tree"]);
$scope_trees[$i]["scope_tree"] = $cfg_gen->getScopeNode();
}
// SSA
for ($i=0; $i<count($scope_trees); ++$i)
{
echo "Converting IRs of ".$scope_trees[$i]["filename"]." to SSA form.\n";
$ssa_con = new SSAConstructor($scope_trees[$i]["scope_tree"]);
$scope_trees[$i]["scope_tree"] = $ssa_con->getScopeNode();
}
// Taint Analysis
for ($i=0; $i<count($scope_trees); ++$i)
{
echo "Performing taint analysis for ".$scope_trees[$i]["filename"]."\n";
$taint_analyzer = new TaintAnalyzer([], $scope_trees[$i]["scope_tree"]);
$taint_analyzer->setCalleeName("{main}");
echo "Taint Result:\n";
$taint_analyzer->outputResult(0);
}