1515use progpilot \Representations \NodeCG ;
1616use progpilot \Inputs \MyCustomRule ;
1717use progpilot \Objects \MyDefinition ;
18- use progpilot \Objects \MyClass ;
19- use progpilot \Code \MyInstruction ;
2018use progpilot \Utils ;
2119use progpilot \Helpers \Analysis as HelpersAnalysis ;
2220
@@ -26,13 +24,15 @@ public static function disclosureOfInformation($context, $defs, $defassign)
2624 {
2725 $ customRules = $ context ->inputs ->getCustomRules ();
2826 foreach ($ customRules as $ customRule ) {
29- if ($ customRule ->getType () === MyCustomRule::TYPE_VARIABLE
30- && $ customRule ->getAction () === "ASSIGNMENT_DISCLOSE_HIGH_VALUE " ) {
27+ if (
28+ $ customRule ->getType () === MyCustomRule::TYPE_VARIABLE
29+ && $ customRule ->getAction () === "ASSIGNMENT_DISCLOSE_HIGH_VALUE "
30+ ) {
3131 $ result = HelpersAnalysis::checkIfDefEqualDefRule ($ context , $ defs , $ customRule , $ defassign );
32-
32+
3333 if ($ result ) {
3434 $ hashedValue = $ defassign ->getLine ();
35- $ hashedValue .= "- " . $ customRule ->getAction (). "- " . $ defassign ->getSourceMyFile ()->fileName ;
35+ $ hashedValue .= "- " . $ customRule ->getAction () . "- " . $ defassign ->getSourceMyFile ()->fileName ;
3636 $ idVuln = hash ("sha256 " , $ hashedValue );
3737
3838 if (is_null ($ context ->inputs ->getFalsePositiveById ($ idVuln ))) {
@@ -50,17 +50,19 @@ public static function disclosureOfInformation($context, $defs, $defassign)
5050 }
5151 }
5252 }
53-
53+
5454 return null ;
5555 }
56-
56+
5757 public static function defineObject ($ context , $ instruction , $ myFuncorDef , $ myClassFound , $ virtualReturnDef )
5858 {
5959 $ customRules = $ context ->inputs ->getCustomRules ();
6060 foreach ($ customRules as $ customRule ) {
61- if ($ customRule ->getType () === MyCustomRule::TYPE_VARIABLE
61+ if (
62+ $ customRule ->getType () === MyCustomRule::TYPE_VARIABLE
6263 && $ customRule ->getAction () === "DEFINE_OBJECT "
63- && !is_null ($ customRule ->getExtra ())) {
64+ && !is_null ($ customRule ->getExtra ())
65+ ) {
6466 $ result = HelpersAnalysis::checkIfDefEqualDefRule (
6567 $ context ,
6668 null ,
@@ -79,10 +81,10 @@ public static function defineObject($context, $instruction, $myFuncorDef, $myCla
7981 }
8082 }
8183 }
82-
84+
8385 return null ;
8486 }
85-
87+
8688 public static function returnObjectCreateObject ($ context , $ customRule , $ myFuncorDef , $ virtualReturnDef )
8789 {
8890 $ myFakeInstance = null ;
@@ -103,14 +105,16 @@ public static function returnObjectCreateObject($context, $customRule, $myFuncor
103105 return $ myFakeInstance ;
104106 }
105107 }
106-
108+
107109 public static function returnObject ($ context , $ myFuncorDef , $ myClass , $ instruction , $ virtualReturnDef )
108110 {
109111 $ customRules = $ context ->inputs ->getCustomRules ();
110112 foreach ($ customRules as $ customRule ) {
111- if ($ customRule ->getType () === MyCustomRule::TYPE_FUNCTION
112- && $ customRule ->getAction () === "DEFINE_OBJECT "
113- && !is_null ($ customRule ->getExtra ())) {
113+ if (
114+ $ customRule ->getType () === MyCustomRule::TYPE_FUNCTION
115+ && $ customRule ->getAction () === "DEFINE_OBJECT "
116+ && !is_null ($ customRule ->getExtra ())
117+ ) {
114118 $ result = HelpersAnalysis::checkIfDefEqualDefRule (
115119 $ context ,
116120 null ,
@@ -128,19 +132,21 @@ public static function returnObject($context, $myFuncorDef, $myClass, $instructi
128132 }
129133 }
130134 }
131-
135+
132136 return null ;
133137 }
134138
135139 public static function mustVerifyDefinition ($ context , $ instruction , $ myFunc , $ myClass = null )
136140 {
137141 $ customRules = $ context ->inputs ->getCustomRules ();
138142 foreach ($ customRules as $ customRule ) {
139- if ($ customRule ->getType () === MyCustomRule::TYPE_FUNCTION
143+ if (
144+ $ customRule ->getType () === MyCustomRule::TYPE_FUNCTION
140145 && ($ customRule ->getAction () === "MUST_VERIFY_DEFINITION "
141- || $ customRule ->getAction () === "MUST_NOT_VERIFY_DEFINITION " )) {
146+ || $ customRule ->getAction () === "MUST_NOT_VERIFY_DEFINITION " )
147+ ) {
142148 $ functionDefinition = $ customRule ->getDefinition ();
143-
149+
144150 if (!is_null ($ functionDefinition )) {
145151 $ result = HelpersAnalysis::checkIfFuncEqualMySpecify (
146152 $ context ,
@@ -149,13 +155,15 @@ public static function mustVerifyDefinition($context, $instruction, $myFunc, $my
149155 $ myClass
150156 );
151157 if ($ result ) {
152- if ($ myFunc ->getNbParams () < $ functionDefinition ->getMinNbArgs ()
153- || $ myFunc ->getNbParams () > $ functionDefinition ->getMaxNbArgs ()) {
158+ if (
159+ $ myFunc ->getNbParams () < $ functionDefinition ->getMinNbArgs ()
160+ || $ myFunc ->getNbParams () > $ functionDefinition ->getMaxNbArgs ()
161+ ) {
154162 $ isValid = true ;
155163 } else {
156164 $ isValid = false ;
157165 $ params = $ functionDefinition ->getParameters ();
158-
166+
159167 // if one parameter is not valid all the rule is not valid
160168 foreach ($ params as $ param ) {
161169 $ isValid = false ;
@@ -173,17 +181,19 @@ public static function mustVerifyDefinition($context, $instruction, $myFunc, $my
173181 $ isValid = $ validbydefault ;
174182 break ;
175183 }
176-
184+
177185 $ defArg = $ instruction ->getProperty ("argdef $ idParam " );
178-
186+
179187 foreach ($ valuesParameter as $ valueParameter ) {
180188 $ defLastKnownValues = [];
181189
182- if (isset ($ valueParameter ->is_array )
190+ if (
191+ isset ($ valueParameter ->is_array )
183192 && $ valueParameter ->is_array === true
184- && isset ($ valueParameter ->array_index )) {
193+ && isset ($ valueParameter ->array_index )
194+ ) {
185195 $ arrayfound = false ;
186-
196+
187197 if ($ defArg ->getCurrentState ()->isType (MyDefinition::TYPE_ARRAY )) {
188198 foreach ($ defArg ->getCurrentState ()->getArrayIndexes () as $ arrayIndex ) {
189199 if ($ arrayIndex ->index === $ valueParameter ->array_index ) {
@@ -195,15 +205,15 @@ public static function mustVerifyDefinition($context, $instruction, $myFunc, $my
195205 }
196206 }
197207 }
198-
208+
199209 if (!$ arrayfound ) {
200210 $ isValid = $ validbydefault ;
201211 break 2 ;
202212 }
203213 } else {
204214 $ defLastKnownValues = $ defArg ->getCurrentState ()->getLastKnownValues ();
205215 }
206-
216+
207217 if (count ($ defLastKnownValues ) === 0 ) {
208218 $ isValid = false ;
209219 }
@@ -213,9 +223,10 @@ public static function mustVerifyDefinition($context, $instruction, $myFunc, $my
213223 foreach ($ defLastKnownValues as $ lastKnownValue ) {
214224 // if it's valid we continue
215225 if (($ valueParameter ->value === $ lastKnownValue
216- && !$ isParameterNotEquals )
226+ && !$ isParameterNotEquals )
217227 || ($ valueParameter ->value !== $ lastKnownValue
218- && $ isParameterNotEquals )) {
228+ && $ isParameterNotEquals )
229+ ) {
219230 $ validForAllValues = true ;
220231 } else {
221232 // it's not valid we can break
@@ -253,8 +264,10 @@ public static function mustVerifyDefinition($context, $instruction, $myFunc, $my
253264 // * it can be enough (if sufficient) to valid the rule (no issue)
254265
255266 // one parameter is not valid and required
256- if (!$ isValid
257- && $ isParameterFixed ) {
267+ if (
268+ !$ isValid
269+ && $ isParameterFixed
270+ ) {
258271 $ isValid = true ;
259272 break ;
260273 }
@@ -264,15 +277,19 @@ public static function mustVerifyDefinition($context, $instruction, $myFunc, $my
264277 }
265278
266279 // one parameter is valid and enough
267- if ($ isValid
268- && $ isParameterSufficient ) {
280+ if (
281+ $ isValid
282+ && $ isParameterSufficient
283+ ) {
269284 $ isValid = true ;
270285 break ;
271286 }
272287
273288 // one parameter is not valid but should not fail and continue with other params
274- if (!$ isValid
275- && !$ isParameterFailIfNotVerifed ) {
289+ if (
290+ !$ isValid
291+ && !$ isParameterFailIfNotVerifed
292+ ) {
276293 $ isValid = true ;
277294 }
278295
@@ -283,12 +300,12 @@ public static function mustVerifyDefinition($context, $instruction, $myFunc, $my
283300 }
284301 }
285302 }
286-
303+
287304 if (!$ isValid ) {
288305 $ hashedValue = $ myFunc ->getLine ();
289- $ hashedValue .= "- " . $ customRule ->getAction (). "- " . $ myFunc ->getSourceMyFile ()->fileName ;
306+ $ hashedValue .= "- " . $ customRule ->getAction () . "- " . $ myFunc ->getSourceMyFile ()->fileName ;
290307 $ idVuln = hash ("sha256 " , $ hashedValue );
291-
308+
292309 if (is_null ($ context ->inputs ->getFalsePositiveById ($ idVuln ))) {
293310 $ temp ["vuln_rule " ] = Utils::encodeCharacters ($ customRule ->getAction ());
294311 $ temp ["vuln_name " ] = Utils::encodeCharacters ($ customRule ->getAttack ());
@@ -314,8 +331,10 @@ public static function mustVerifyCallFlow($context, $callgraph)
314331 $ rulesVerifyCallFlow = [];
315332 $ customRules = $ context ->inputs ->getCustomRules ();
316333 foreach ($ customRules as $ customRule ) {
317- if ($ customRule ->getType () === MyCustomRule::TYPE_SEQUENCE
318- && $ customRule ->getAction () === "MUST_VERIFY_CALL_FLOW " ) {
334+ if (
335+ $ customRule ->getType () === MyCustomRule::TYPE_SEQUENCE
336+ && $ customRule ->getAction () === "MUST_VERIFY_CALL_FLOW "
337+ ) {
319338 $ sequence = $ customRule ->getSequence ();
320339
321340 $ customRule ->setCurrentOrderNumber (0 );
0 commit comments