1313import java .util .concurrent .ExecutionException ;
1414import java .util .stream .Collectors ;
1515
16+ import com .sun .istack .NotNull ;
1617import org .slf4j .Logger ;
1718import org .slf4j .LoggerFactory ;
1819
@@ -765,12 +766,13 @@ public void initialize() {
765766
766767 String subSignatureWithoutReturnType = (((MethodSourceSinkDefinition ) sourceSinkDef ).getMethod ()
767768 .getSubSignature ());
769+
768770 SootMethod sootMethod = grabMethodWithoutReturn (className , subSignatureWithoutReturnType );
769771
770772 if (sootMethod != null )
771773 sourceMethods .put (sootMethod , sourceSinkDef );
772774 } else {
773- SootMethod sm = Scene . v (). grabMethod (entry .getO1 ());
775+ SootMethod sm = grabMethod (entry .getO1 ());
774776 if (sm != null )
775777 sourceMethods .put (sm , sourceSinkDef );
776778 }
@@ -806,6 +808,7 @@ public void initialize() {
806808 SootMethodAndClass method = methodSourceSinkDef .getMethod ();
807809 String returnType = method .getReturnType ();
808810 boolean isMethodWithoutReturnType = returnType == null || returnType .isEmpty ();
811+
809812 if (isMethodWithoutReturnType ) {
810813 String className = method .getClassName ();
811814 String subSignatureWithoutReturnType = (((MethodSourceSinkDefinition ) sourceSinkDef )
@@ -814,7 +817,7 @@ public void initialize() {
814817 if (sootMethod != null )
815818 sinkMethods .put (sootMethod , sourceSinkDef );
816819 } else {
817- SootMethod sm = Scene . v (). grabMethod (entry .getO1 ());
820+ SootMethod sm = grabMethod (entry .getO1 ());
818821 if (sm != null )
819822 sinkMethods .put (sm , entry .getO2 ());
820823 }
@@ -833,6 +836,31 @@ public void initialize() {
833836 }
834837 }
835838
839+ /**
840+ * Get the method of a class without matching the return type.
841+ *
842+ * @param sootClass The class of the method
843+ * @param subSignature The sub signature of the method which is the method name
844+ * and its parameters
845+ * @return The soot method of the given class and sub signature or null
846+ */
847+ private SootMethod matchMethodWithoutReturn (@ NotNull SootClass sootClass , String subSignature ) {
848+ if (sootClass .resolvingLevel () == DANGLING ) {
849+ List <SootMethod > sootMethods = sootClass .getMethods ();
850+
851+ for (SootMethod s : sootMethods ) {
852+ String [] tempSignature = s .getSubSignature ().split (" " );
853+
854+ if (tempSignature .length == 2 ) {
855+ if (tempSignature [1 ].equals (subSignature ))
856+ return s ;
857+ }
858+ }
859+ }
860+
861+ return null ;
862+ }
863+
836864 /**
837865 * Gets a soot method defined by class name and its sub signature from the
838866 * loaded methods in the Scene object
@@ -847,19 +875,40 @@ private SootMethod grabMethodWithoutReturn(String sootClassName, String subSigna
847875 if (sootClass == null )
848876 return null ;
849877
850- List < SootMethod > sootMethods = null ;
851- if (sootClass . resolvingLevel () != DANGLING ) {
852- sootMethods = sootClass . getMethods () ;
878+ SootMethod sootMethod = matchMethodWithoutReturn ( sootClass , subSignature ) ;
879+ if (sootMethod != null )
880+ return sootMethod ;
853881
854- for (SootMethod s : sootMethods ) {
855- String [] tempSignature = s .getSubSignature ().split (" " );
882+ for (SootClass i : parentClassesAndInterfaces .getUnchecked (sootClass )) {
883+ sootMethod = matchMethodWithoutReturn (i , subSignature );
884+ if (sootMethod != null )
885+ return sootMethod ;
886+ }
856887
857- if (tempSignature .length == 2 ) {
858- if (tempSignature [1 ].equals (subSignature ))
859- return s ;
860- }
888+ return null ;
889+ }
861890
862- }
891+ /**
892+ * Gets a soot method defined by the class name or one of its superclasses.
893+ *
894+ * @param signature method signature
895+ * @return The soot method of the given class or above in the hierarchy. Null if the method doesn't exist.
896+ */
897+ private SootMethod grabMethod (String signature ) {
898+ String sootClassName = Scene .signatureToClass (signature );
899+ SootClass sootClass = Scene .v ().getSootClassUnsafe (sootClassName );
900+ if (sootClass == null )
901+ return null ;
902+
903+ String subSignature = Scene .signatureToSubsignature (signature );
904+ SootMethod sootMethod = sootClass .getMethodUnsafe (subSignature );
905+ if (sootMethod != null )
906+ return sootMethod ;
907+
908+ for (SootClass i : parentClassesAndInterfaces .getUnchecked (sootClass )) {
909+ sootMethod = i .getMethodUnsafe (subSignature );
910+ if (sootMethod != null )
911+ return sootMethod ;
863912 }
864913
865914 return null ;
0 commit comments