77import java .util .List ;
88import java .util .Set ;
99import java .util .concurrent .atomic .AtomicInteger ;
10- import java .util .function .Function ;
1110import java .util .regex .Matcher ;
1211import java .util .regex .Pattern ;
1312
1413import heros .solver .Pair ;
1514import heros .solver .PathEdge ;
16- import soot .*;
17- import soot .jimple .*;
15+ import soot .ArrayType ;
16+ import soot .FastHierarchy ;
17+ import soot .Hierarchy ;
18+ import soot .Local ;
19+ import soot .Modifier ;
20+ import soot .PrimType ;
21+ import soot .RefType ;
22+ import soot .Scene ;
23+ import soot .SootClass ;
24+ import soot .SootField ;
25+ import soot .SootFieldRef ;
26+ import soot .SootMethod ;
27+ import soot .Type ;
28+ import soot .Unit ;
29+ import soot .Value ;
30+ import soot .VoidType ;
31+ import soot .jimple .DefinitionStmt ;
32+ import soot .jimple .DynamicInvokeExpr ;
33+ import soot .jimple .InstanceInvokeExpr ;
34+ import soot .jimple .InvokeExpr ;
35+ import soot .jimple .ReturnStmt ;
36+ import soot .jimple .StaticInvokeExpr ;
37+ import soot .jimple .Stmt ;
1838import soot .jimple .infoflow .InfoflowConfiguration ;
1939import soot .jimple .infoflow .InfoflowManager ;
2040import soot .jimple .infoflow .data .Abstraction ;
2444import soot .jimple .infoflow .handlers .PreAnalysisHandler ;
2545import soot .jimple .infoflow .methodSummary .data .provider .IMethodSummaryProvider ;
2646import soot .jimple .infoflow .methodSummary .data .sourceSink .AbstractFlowSinkSource ;
47+ import soot .jimple .infoflow .methodSummary .data .sourceSink .FlowSource ;
2748import soot .jimple .infoflow .methodSummary .data .summary .ClassMethodSummaries ;
2849import soot .jimple .infoflow .methodSummary .data .summary .ClassSummaries ;
2950import soot .jimple .infoflow .methodSummary .data .summary .GapDefinition ;
@@ -507,8 +528,17 @@ public Set<Abstraction> getTaintsForMethod(Stmt stmt, Abstraction d1, Abstractio
507528 ByReferenceBoolean classSupported = new ByReferenceBoolean (false );
508529
509530 // Compute the wrapper taints for the current method
510- final SootMethod callee = stmt .getInvokeExpr ().getMethod ();
511- Set <AccessPath > res = computeTaintsForMethod (stmt , d1 , taintedAbs , callee , killIncomingTaint , classSupported );
531+ final InvokeExpr inv = stmt .getInvokeExpr ();
532+ SootMethod callee = inv .getMethod ();
533+ Set <AccessPath > res ;
534+ if (inv instanceof DynamicInvokeExpr ) {
535+ final DynamicInvokeExpr dyn = (DynamicInvokeExpr ) inv ;
536+ SootMethod m = dyn .getBootstrapMethodRef ().tryResolve ();
537+ if (m == null )
538+ return null ;
539+ callee = m ;
540+ }
541+ res = computeTaintsForMethod (stmt , d1 , taintedAbs , callee , killIncomingTaint , classSupported );
512542
513543 // Create abstractions from the access paths
514544 if (res != null && !res .isEmpty ()) {
@@ -522,7 +552,7 @@ public Set<Abstraction> getTaintsForMethod(Stmt stmt, Abstraction d1, Abstractio
522552 if (!killIncomingTaint .value && (resAbs == null || resAbs .isEmpty ())) {
523553 // Is this method explicitly excluded?
524554 if (!this .flows .isMethodExcluded (callee .getDeclaringClass ().getName (), callee .getSubSignature ())) {
525- // wrapperMisses.incrementAndGet();
555+ // wrapperMisses.incrementAndGet();
526556
527557 if (classSupported .value )
528558 return Collections .singleton (taintedAbs );
@@ -584,7 +614,7 @@ protected void reportMissingMethod(SootMethod method) {
584614 */
585615 private Set <AccessPath > computeTaintsForMethod (Stmt stmt , Abstraction d1 , Abstraction taintedAbs ,
586616 final SootMethod method , ByReferenceBoolean killIncomingTaint , ByReferenceBoolean classSupported ) {
587- // wrapperHits.incrementAndGet();
617+ // wrapperHits.incrementAndGet();
588618
589619 // Get the cached data flows
590620 ClassSummaries flowsInCallees = getFlowSummariesForMethod (stmt , method , taintedAbs , classSupported );
@@ -965,23 +995,28 @@ protected ClassSummaries getFlowSummariesForMethod(Stmt stmt, final SootMethod m
965995 */
966996 protected SootClass getSummaryDeclaringClass (Stmt stmt , AccessPath taintedAP ) {
967997 Type declaredType = null ;
968- if (stmt != null && stmt .getInvokeExpr () instanceof InstanceInvokeExpr ) {
969- // If the base object of the call is tainted, we may have a more precise type in
970- // the access path
971- InstanceInvokeExpr iinv = (InstanceInvokeExpr ) stmt .getInvokeExpr ();
972- if (taintedAP != null && iinv .getBase () == taintedAP .getPlainValue ()) {
973- declaredType = taintedAP .getBaseType ();
974- }
998+ if (stmt != null ) {
999+ if (stmt .getInvokeExpr () instanceof InstanceInvokeExpr ) {
1000+ // If the base object of the call is tainted, we may have a more precise type in
1001+ // the access path
1002+ InstanceInvokeExpr iinv = (InstanceInvokeExpr ) stmt .getInvokeExpr ();
1003+ if (taintedAP != null && iinv .getBase () == taintedAP .getPlainValue ()) {
1004+ declaredType = taintedAP .getBaseType ();
1005+ }
9751006
976- // We may have a call such as
977- // x = editable.toString();
978- // In that case, the callee is Object.toString(), since in the stub Android
979- // JAR, the class android.text.Editable does not override toString(). On a
980- // real device, it does. Consequently, we have a summary in the "Editable"
981- // class. To handle such weird cases, we walk the class hierarchy based on
982- // the declared type of the base object.
983- Type baseType = iinv .getBase ().getType ();
984- declaredType = manager .getTypeUtils ().getMorePreciseType (declaredType , baseType );
1007+ // We may have a call such as
1008+ // x = editable.toString();
1009+ // In that case, the callee is Object.toString(), since in the stub Android
1010+ // JAR, the class android.text.Editable does not override toString(). On a
1011+ // real device, it does. Consequently, we have a summary in the "Editable"
1012+ // class. To handle such weird cases, we walk the class hierarchy based on
1013+ // the declared type of the base object.
1014+ Type baseType = iinv .getBase ().getType ();
1015+ declaredType = manager .getTypeUtils ().getMorePreciseType (declaredType , baseType );
1016+ } else if (stmt .getInvokeExpr () instanceof DynamicInvokeExpr ) {
1017+ return ((DynamicInvokeExpr ) stmt .getInvokeExpr ()).getBootstrapMethodRef ().getDeclaringClass ();
1018+
1019+ }
9851020 }
9861021 return declaredType instanceof RefType ? ((RefType ) declaredType ).getSootClass () : null ;
9871022 }
@@ -1102,6 +1137,8 @@ private boolean flowMatchesTaint(final AbstractFlowSinkSource flowSource, final
11021137 if (compareFields (taint , flowSource ))
11031138 return true ;
11041139 }
1140+ if (flowSource .getParameterIndex () == FlowSource .ANY_PARAMETER )
1141+ return true ;
11051142 } else if (flowSource .isField ()) {
11061143 // Flows from a field can either be applied to the same field or
11071144 // the base object in total
0 commit comments