soot-oss / SootUp

A new version of Soot with a completely overhauled architecture
https://soot-oss.github.io/SootUp/
GNU Lesser General Public License v2.1
586 stars 78 forks source link

Multiple jars cannot generate CallGraph #886

Closed qyi71 closed 8 months ago

qyi71 commented 8 months ago

My project has multiple modules, and these modules are built into multiple jars. When I analyze the interface of one of the modules, I cannot analyze it together with other modules. ` List inputLocations = new ArrayList<>();

inputLocations.add( new JavaClassPathAnalysisInputLocation(
                "/Users/zcy/java-code-ast/src/test/resources/Callgraph/source/rm-service-1.2.0-SNAPSHOT.jar"));
 inputLocations.add( new JavaClassPathAnalysisInputLocation(
                "/Users/zcy/java-code-ast/src/test/resources/Callgraph/source/rm-api-1.2.0-SNAPSHOT.jar"));
 inputLocations.add( new JavaClassPathAnalysisInputLocation(
                "/Users/zcy/java-code-ast/src/test/resources/Callgraph/source/rm-server-1.2.0-SNAPSHOT.jar"));

JavaView view = new JavaView(inputLocations);
ClassType classTypeB = view.getIdentifierFactory().getClassType("cn.gov.zcy.engr.service.BuildService");
MethodSignature entryMethodSignature =
    JavaIdentifierFactory.getInstance()
        .getMethodSignature(
                classTypeB,
                "find",
                "List<BaseZtBugDTO>",
                Lists.newArrayList("Long"));
CallGraphAlgorithm cha = new RapidTypeAnalysisAlgorithm(view);
CallGraph cg = cha.initialize(Collections.singletonList(entryMethodSignature));
cg.callsFrom(entryMethodSignature).forEach(System.out::println);` 

BuildService has multiple references in rm-server-1.2.0-SNAPSHOT.jar, but the output result is empty

JonasKlauke commented 8 months ago

Hi, The error is not caused by the multiple inputlocations. Your return value "List" is not correct. It should be "java.util.List". In bytecode lists dont have the <> in their type.
Your parameter is also wrong. If you wanted to use the primitive long it should be written "long" and if you wanted to use the class Long then you need to write "java.lang.Long". The call graph is empty because you are requesting a method signature which is not contained in the view.

  ClassType clazz = view.getIdentifierFactory().getClassType("cn.gov.zcy.engr.service.BuildService");
  view.getClass(clazz).ifPresent(javaSootClass -> javaSootClass.getMethods().forEach(
      System.out::println));

This will show all valid signatures of the requested class.

qyi71 commented 8 months ago

Hi, The error is not caused by the multiple inputlocations. Your return value "List" is not correct. It should be "java.util.List". In bytecode lists dont have the <> in their type. Your parameter is also wrong. If you wanted to use the primitive long it should be written "long" and if you wanted to use the class Long then you need to write "java.lang.Long". The call graph is empty because you are requesting a method signature which is not contained in the view.

  ClassType clazz = view.getIdentifierFactory().getClassType("cn.gov.zcy.engr.service.BuildService");
  view.getClass(clazz).ifPresent(javaSootClass -> javaSootClass.getMethods().forEach(
      System.out::println));

This will show all valid signatures of the requested class. Thanks But now I have a new problem. When I call cg.callsFrom, return an empty array. However, multiple method signatures should be returned

JonasKlauke commented 8 months ago

Can you call view.getMethod(signature) and check if the optional is present. Signature is your requested Methodsignature

JonasKlauke commented 8 months ago

Ah wait I might know the issue. You are using RTA. If RTA starts not at the main method or starting point of the application it will miss instantiated classes. These classes will be ignored as call targets. If your method does not contain any constructor call there won't be any call from the method. mmh maybe we should create a call to the actual method in the invoke, if the virtual invoke resolvers returns an empty list, since no class of a target method was instantiated before

JonasKlauke commented 8 months ago

could you test the same setup with cha instead of rta

qyi71 commented 8 months ago

First thank you for your answer. However, the reason for the question is that I used Spring Boot. After reviewing the source code of SoutUp, I found that it cannot generate Call Graph