java.lang.Object
proguard.analysis.datastructure.callgraph.CallGraph

public class CallGraph extends Object
Collection of all Calls in a program, optimized for retrieval of incoming and outgoing edges for any method in constant time.
  • Field Details

  • Constructor Details

  • Method Details

    • concurrentCallGraph

      public static CallGraph concurrentCallGraph()
      Provides concurrency ready CallGraph, backed by ConcurrentHashMaps and by ConcurrentSkipListSets. Not needed without multithreading.
    • addCall

      public void addCall(Call call)
      Add a Call to this call graph.
      Parameters:
      call - The call to be added.
    • clear

      public void clear()
      Clear the call graph references.
    • reconstructCallGraph

      public Node reconstructCallGraph(ClassPool programClassPool, MethodSignature start, Set<MethodSignature> stopMethods)
      Parameters:
      programClassPool - The current ClassPool of the program that can be used for mapping. class names to the actual Clazz.
      start - The MethodSignature of the method whose incoming call graph should be calculated.
      stopMethods - Set of MethodSignature to stop exploration at, if desired.
      Returns:
      A Node that represents the single call graph root, i.e. the start method.
    • reconstructCallGraph

      public Node reconstructCallGraph(ClassPool programClassPool, MethodSignature start, int maxDepth, int maxWidth, Set<MethodSignature> stopMethods)
      Calculate the incoming call graph for a method of interest, showing how it can be reached from a given Set of stop methods, which typically are Android lifecycle methods such as an Activity's onCreate() method:

      We have an inverted tree structure like the following example:

      
       onCreate() <-- predecessor -- proxy() <-- predecessor -- root()
                                  onResume() <-- predecessor ----|  |
                              unusedMethod() <-- predecessor -------|
      
       
      Here, root() is the method whose call graph is to be calculated, and the graph now shows that it can be reached from onCreate() via proxy(), and also directly from onResume() or unusedMethod().
      Parameters:
      programClassPool - The current ClassPool of the program that can be used for mapping. class names to the actual Clazz.
      start - The MethodSignature of the method whose incoming call graph should be calculated.
      maxDepth - maximal depth of reconstructed CallGraph similar to CallGraphWalker.MAX_DEPTH_DEFAULT.
      maxWidth - maximal width of reconstructed CallGraph similar to CallGraphWalker.MAX_WIDTH_DEFAULT.
      stopMethods - Set of method signatures to stop exploration, for example for entry points
      Returns:
      A Node that represents the single call graph root, i.e. the start method.
    • reconstructCallGraph

      public Node reconstructCallGraph(ClassPool programClassPool, MethodSignature start, Set<MethodSignature> stopMethods, Set<MethodSignature> reachedMethods)
      Extension of reconstructCallGraph(ClassPool, MethodSignature, Set) that also collects all reached stop methods.
      Parameters:
      programClassPool - The current ClassPool of the program that can be used for mapping.
      start - The MethodSignature of the method whose incoming call graph should be calculated.
      stopMethods - A set of MethodSignature to stop exploration, e.g. app entry points
      reachedMethods - A set that will be filled with all reached stop methods
      Returns:
      A Node that represents the single call graph root, i.e. the start method.
    • writeDot

      public void writeDot(Writer writer) throws IOException
      Writes a DOT graph representation of the given call graph.
      Throws:
      IOException
    • toDot

      public String toDot()
      Produces a DOT graph representation of the given call graph.