@@ -15,12 +15,16 @@ public static function getIncludeFilesDataFlows($fileSummary){
15
15
$ fileSummaryContext = FileSummaryContext::getInstance ();
16
16
$ ret = $ fileSummaryContext ->findSummaryByPath ($ absPath );
17
17
if ($ ret ){
18
+ //查看此文件是否有include文件
19
+ $ pRetFlows = self ::getIncludeFilesDataFlows ($ ret );
20
+ $ retFlows = array_merge ($ pRetFlows , $ retFlows );
21
+
18
22
$ dataFlows = $ ret ->getFlowsMap ();
19
23
$ retFlows = array_merge ($ dataFlows , $ retFlows );
20
24
}else {
21
- $ fileSummary = self ::getFileSummary ($ absPath );
22
- if ($ fileSummary )
23
- $ retFlows = array_merge ($ fileSummary ->getFlowsMap (), $ retFlows );
25
+ $ includeFileSummary = self ::getFileSummary ($ absPath );
26
+ if ($ includeFileSummary )
27
+ $ retFlows = array_merge ($ includeFileSummary ->getFlowsMap (), $ retFlows );
24
28
}
25
29
}
26
30
//return all files dataFlows
@@ -45,17 +49,33 @@ public static function getFileSummary($absPath){
45
49
46
50
$ fileSummary = new FileSummary ();
47
51
$ fileSummary ->setPath ($ absPath );
52
+
53
+ $ currBlock = new BasicBlock () ;
54
+ foreach ($ nodes as $ node ){
55
+ //搜集节点中的require include require_once include_once的PHP文件名称
56
+ $ fileSummary ->addIncludeToMap (NodeUtils::getNodeIncludeInfo ($ node )) ;
57
+
58
+ if (!is_object ($ node )) continue ;
59
+
60
+ //不分析函数定义
61
+ if ($ node ->getType () == "Stmt_Function " ){
62
+ continue ;
63
+ }
64
+ $ currBlock ->addNode ($ node );
65
+ }
66
+
67
+
48
68
$ fileSummaryGenerator = new FileSummaryGenerator ();
49
- $ fileSummaryGenerator ->simulate ($ nodes , $ fileSummary );
69
+ $ fileSummaryGenerator ->simulate ($ currBlock , $ fileSummary );
50
70
return $ fileSummary ;
51
71
}
52
72
53
73
/**
54
74
* 得到该文件的dataFlows
55
75
* @param Nodes $nodes
56
76
*/
57
- public function simulate ($ nodes , $ fileSummary ){
58
-
77
+ public function simulate ($ block , $ fileSummary ){
78
+ $ nodes = $ block -> getContainedNodes ();
59
79
//循环nodes集合,搜集信息加入到中
60
80
foreach ($ nodes as $ node ){
61
81
//搜集节点中的require include require_once include_once的PHP文件名称
@@ -65,20 +85,22 @@ public function simulate($nodes, $fileSummary){
65
85
//处理赋值语句
66
86
case 'Expr_Assign ' :
67
87
$ dataFlow = new DataFlow () ;
68
- $ this ->assignHandler ($ node , $ dataFlow , "left " ) ;
69
- $ this ->assignHandler ($ node , $ dataFlow , "right " ) ;
88
+ $ this ->assignHandler ($ node , $ dataFlow , "left " , $ block , $ fileSummary ) ;
89
+ $ this ->assignHandler ($ node , $ dataFlow , "right " , $ block , $ fileSummary ) ;
70
90
//处理完一条赋值语句,加入DataFlowMap
71
91
$ fileSummary ->addDataFlow ($ dataFlow );
92
+ $ block ->getBlockSummary ()->addDataFlowItem ($ dataFlow );
72
93
break ;
73
94
74
95
//处理字符串连接赋值
75
96
//$sql .= "from users where"生成sql => "from users where"
76
97
case 'Expr_AssignOp_Concat ' :
77
98
$ dataFlow = new DataFlow () ;
78
- $ this ->assignConcatHandler ($ node , $ dataFlow , "left " ) ;
79
- $ this ->assignConcatHandler ($ node , $ dataFlow , "right " ) ;
99
+ $ this ->assignConcatHandler ($ node , $ dataFlow , "left " , $ block , $ fileSummary ) ;
100
+ $ this ->assignConcatHandler ($ node , $ dataFlow , "right " , $ block , $ fileSummary ) ;
80
101
//处理完一条赋值语句,加入DataFlowMap
81
102
$ fileSummary ->addDataFlow ($ dataFlow );
103
+ $ block ->getBlockSummary ()->addDataFlowItem ($ dataFlow );
82
104
break ;
83
105
default :
84
106
break ;
@@ -92,7 +114,7 @@ public function simulate($nodes, $fileSummary){
92
114
* @param DataFlow $dataFlow
93
115
* @param string $type
94
116
*/
95
- public function assignHandler ($ node , $ dataFlow , $ type ){
117
+ public function assignHandler ($ node , $ dataFlow , $ type, $ block , $ fileSummary ){
96
118
$ part = null ;
97
119
if ($ type == "left " ){
98
120
$ part = $ node ->var ;
@@ -174,15 +196,22 @@ public function assignHandler($node, $dataFlow, $type){
174
196
}else if ($ type == "right " ){
175
197
$ dataFlow ->setValue ($ concat ) ;
176
198
}
177
- }else {
199
+ }elseif ($ part && $ part ->getType () == "Expr_Ternary " ){
200
+ //处理三元表达式
201
+ $ ter_symbol = new MutipleSymbol () ;
202
+ $ ter_symbol ->setItemByNode ($ part ) ;
203
+ if ($ type == 'right ' ){
204
+ $ dataFlow ->setValue ($ ter_symbol ) ;
205
+ }
206
+ }else {
178
207
//不属于已有的任何一个symbol类型,如函数调用
179
208
if ($ part && $ part ->getType () == "Expr_FuncCall " ){
180
209
if ($ type == "left " ){
181
210
$ dataFlow ->setLocation ($ arr ) ;
182
211
$ dataFlow ->setName (NodeUtils::getNodeStringName ($ part )) ;
183
212
}else if ($ type == "right " ){
184
213
//处理净化信息和编码信息
185
- // SanitizationHandler::setSanitiInfo($part, $dataFlow, $this-> fileSummary) ;
214
+ SanitizationHandler::setSanitiInfo ($ part , $ dataFlow , $ block , $ fileSummary ) ;
186
215
//EncodingHandler::setEncodeInfo($part, $dataFlow) ;
187
216
}
188
217
}
@@ -196,8 +225,8 @@ public function assignHandler($node, $dataFlow, $type){
196
225
* @param DataFlow $dataFlow
197
226
* @param string $type
198
227
*/
199
- private function assignConcatHandler ($ node , $ dataFlow , $ type ){
200
- $ this ->assignHandler ($ node , $ dataFlow , $ type ) ;
228
+ private function assignConcatHandler ($ node , $ dataFlow , $ type, $ block , $ fileSummary ){
229
+ $ this ->assignHandler ($ node , $ dataFlow , $ type, $ block , $ fileSummary ) ;
201
230
}
202
231
203
232
}
0 commit comments