5858import soot .jimple .infoflow .entryPointCreators .BaseEntryPointCreator ;
5959import soot .jimple .infoflow .entryPointCreators .IEntryPointCreator ;
6060import soot .jimple .infoflow .entryPointCreators .SimulatedCodeElementTag ;
61+ import soot .jimple .infoflow .solver .cfg .IInfoflowCFG ;
6162import soot .jimple .infoflow .sourcesSinks .manager .ISourceSinkManager ;
6263import soot .jimple .infoflow .taintWrappers .ITaintPropagationWrapper ;
6364import soot .jimple .infoflow .util .SystemClassHandler ;
6869import soot .jimple .toolkits .scalar .UnconditionalBranchFolder ;
6970import soot .jimple .toolkits .scalar .UnreachableCodeEliminator ;
7071import soot .options .Options ;
72+ import soot .tagkit .SyntheticTag ;
7173import soot .toolkits .exceptions .ThrowAnalysis ;
7274import soot .toolkits .exceptions .ThrowableSet ;
7375import soot .toolkits .exceptions .UnitThrowAnalysis ;
@@ -127,7 +129,7 @@ public InterproceduralConstantValuePropagator(InfoflowManager manager) {
127129 public InterproceduralConstantValuePropagator (InfoflowManager manager , Collection <SootMethod > excludedMethods ,
128130 ISourceSinkManager sourceSinkManager , ITaintPropagationWrapper taintWrapper ) {
129131 this .manager = manager ;
130- this .excludedMethods = new HashSet <SootMethod >(excludedMethods );
132+ this .excludedMethods = new HashSet <>(excludedMethods );
131133 this .sourceSinkManager = sourceSinkManager ;
132134 this .taintWrapper = taintWrapper ;
133135 }
@@ -256,7 +258,7 @@ protected void internalTransform(String phaseName, Map<String, String> options)
256258 continue ;
257259
258260 boolean allCalleesRemoved = true ;
259- Set <SootClass > exceptions = new HashSet <SootClass >();
261+ Set <SootClass > exceptions = new HashSet <>();
260262 for (Iterator <Edge > edgeIt = Scene .v ().getCallGraph ().edgesOutOf (s ); edgeIt .hasNext ();) {
261263 Edge edge = edgeIt .next ();
262264 SootMethod callee = edge .tgt ();
@@ -392,10 +394,11 @@ private boolean typeSupportsConstants(Type returnType) {
392394 * @param sm The method whose value to propagate
393395 */
394396 private void propagateReturnValueIntoCallers (SootMethod sm ) {
397+ final IInfoflowCFG icfg = manager .getICFG ();
395398 // We need to make sure that all exit nodes agree on the same
396399 // constant value
397400 Constant value = null ;
398- for (Unit retSite : manager . getICFG () .getEndPointsOf (sm )) {
401+ for (Unit retSite : icfg .getEndPointsOf (sm )) {
399402 // Skip exceptional exits
400403 if (!(retSite instanceof ReturnStmt ))
401404 continue ;
@@ -411,7 +414,7 @@ private void propagateReturnValueIntoCallers(SootMethod sm) {
411414
412415 // Propagate the return value into the callers
413416 if (value != null )
414- for (Unit callSite : manager . getICFG () .getCallersOf (sm ))
417+ for (Unit callSite : icfg .getCallersOf (sm ))
415418 if (callSite instanceof AssignStmt ) {
416419 AssignStmt assign = (AssignStmt ) callSite ;
417420
@@ -427,13 +430,13 @@ private void propagateReturnValueIntoCallers(SootMethod sm) {
427430
428431 // Make sure that we don't access anything we have already
429432 // removed
430- SootMethod caller = manager . getICFG () .getMethodOf (assign );
433+ SootMethod caller = icfg .getMethodOf (assign );
431434 if (caller == null || !caller .getActiveBody ().getUnits ().contains (assign ))
432435 continue ;
433436
434437 // If the call site has multiple callees, we cannot
435438 // propagate a single constant
436- Collection <SootMethod > callees = manager . getICFG () .getCalleesOfCallAt (callSite );
439+ Collection <SootMethod > callees = icfg .getCalleesOfCallAt (callSite );
437440 if (callees != null && callees .size () > 1 )
438441 continue ;
439442
@@ -794,7 +797,11 @@ private boolean methodIsAndroidStub(SootMethod method) {
794797 * @param sm The method for which to look for call sites.
795798 */
796799 private void propagateConstantsIntoCallee (SootMethod sm ) {
797- Collection <Unit > callSites = manager .getICFG ().getCallersOf (sm );
800+
801+ // icfg field is final in InfoflowManager, hence it can't change
802+ // and we can cache it here so we don't have to retrieve it again and again.
803+ final IInfoflowCFG icfg = manager .getICFG ();
804+ Collection <Unit > callSites = icfg .getCallersOf (sm );
798805 if (callSites .isEmpty ())
799806 return ;
800807
@@ -807,9 +814,13 @@ private void propagateConstantsIntoCallee(SootMethod sm) {
807814 boolean hasCallSites = false ;
808815 for (Unit callSite : callSites ) {
809816 // If this call site is in an excluded method, we ignore it
810- if (excludedMethods != null && manager .getICFG ().isReachable (callSite )
811- && excludedMethods .contains (manager .getICFG ().getMethodOf (callSite )))
812- continue ;
817+ if (excludedMethods != null && icfg .isReachable (callSite )) {
818+ SootMethod caller = icfg .getMethodOf (callSite );
819+ // synthetic methods e.g. created by FlowDroid are excluded by default
820+ if (excludedMethods .contains (caller ) || caller .hasTag (SyntheticTag .NAME )) {
821+ continue ;
822+ }
823+ }
813824
814825 // We do not support special edges that do not provide a 1:1 argument mapping
815826 InvokeExpr iiExpr = ((Stmt ) callSite ).getInvokeExpr ();
@@ -821,7 +832,7 @@ private void propagateConstantsIntoCallee(SootMethod sm) {
821832 // If we have a reflective call site, we never have constant
822833 // arguments, because
823834 // they are always passed in using an array
824- if (manager . getICFG () .isReflectiveCallSite (callSite )) {
835+ if (icfg .isReflectiveCallSite (callSite )) {
825836 for (int i = 0 ; i < isConstant .length ; i ++)
826837 isConstant [i ] = false ;
827838 } else {
@@ -837,8 +848,9 @@ private void propagateConstantsIntoCallee(SootMethod sm) {
837848 isConstant [i ] = false ;
838849 else
839850 values [i ] = (Constant ) argVal ;
840- } else
851+ } else {
841852 isConstant [i ] = false ;
853+ }
842854 }
843855 }
844856 }
@@ -856,7 +868,7 @@ private void propagateConstantsIntoCallee(SootMethod sm) {
856868 sm .getActiveBody ().getUnits ().insertBefore (assignConst , point );
857869
858870 if (inserted == null )
859- inserted = new ArrayList <Unit >();
871+ inserted = new ArrayList <>();
860872 inserted .add (assignConst );
861873 }
862874 }
@@ -869,7 +881,7 @@ private void propagateConstantsIntoCallee(SootMethod sm) {
869881
870882 // This might lead to more opportunities of constant propagation
871883 for (Unit u : sm .getActiveBody ().getUnits ())
872- for (SootMethod callee : manager . getICFG () .getCalleesOfCallAt (u ))
884+ for (SootMethod callee : icfg .getCalleesOfCallAt (u ))
873885 checkAndAddMethod (callee );
874886 }
875887 }
0 commit comments