Class CallGraph
- java.lang.Object
-
- proguard.analysis.datastructure.callgraph.CallGraph
-
public class CallGraph extends java.lang.Object
Collection of allCall
s in a program, optimized for retrieval of incoming and outgoing edges for any method in constant time.
-
-
Field Summary
Fields Modifier and Type Field Description java.util.Map<MethodSignature,java.util.Set<Call>>
incoming
java.util.Map<MethodSignature,java.util.Set<Call>>
outgoing
-
Constructor Summary
Constructors Modifier Constructor Description CallGraph()
Create an empty call graph.protected
CallGraph(java.util.Map<MethodSignature,java.util.Set<Call>> incoming, java.util.Map<MethodSignature,java.util.Set<Call>> outgoing, boolean concurrent)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addCall(Call call)
Add aCall
to this call graph.void
clear()
Clear the call graph references.static CallGraph
concurrentCallGraph()
Node
reconstructCallGraph(ClassPool programClassPool, MethodSignature start, int maxDepth, int maxWidth, java.util.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:Node
reconstructCallGraph(ClassPool programClassPool, MethodSignature start, java.util.Set<MethodSignature> stopMethods)
Node
reconstructCallGraph(ClassPool programClassPool, MethodSignature start, java.util.Set<MethodSignature> stopMethods, java.util.Set<MethodSignature> reachedMethods)
Extension ofreconstructCallGraph(ClassPool, MethodSignature, Set)
that also collects all reached stop methods.
-
-
-
Field Detail
-
incoming
public final java.util.Map<MethodSignature,java.util.Set<Call>> incoming
-
outgoing
public final java.util.Map<MethodSignature,java.util.Set<Call>> outgoing
-
-
Constructor Detail
-
CallGraph
public CallGraph()
Create an empty call graph.
-
CallGraph
protected CallGraph(java.util.Map<MethodSignature,java.util.Set<Call>> incoming, java.util.Map<MethodSignature,java.util.Set<Call>> outgoing, boolean concurrent)
-
-
Method Detail
-
concurrentCallGraph
public static CallGraph concurrentCallGraph()
Provides concurrency readyCallGraph
, backed byConcurrentHashMap
s and bysynchronizedSet
s. Not needed without multithreading.
-
addCall
public void addCall(Call call)
Add aCall
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, java.util.Set<MethodSignature> stopMethods)
- Parameters:
programClassPool
- The currentClassPool
of the program that can be used for mapping. class names to the actualClazz
.start
- TheMethodSignature
of the method whose incoming call graph should be calculated.stopMethods
- Set ofMethodSignature
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, java.util.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:
Here,onCreate() <-- predecessor -- proxy() <-- predecessor -- root() onResume() <-- predecessor ----| | unusedMethod() <-- predecessor -------|
root()
is the method whose call graph is to be calculated, and the graph now shows that it can be reached fromonCreate()
viaproxy()
, and also directly fromonResume()
orunusedMethod()
.- Parameters:
programClassPool
- The currentClassPool
of the program that can be used for mapping. class names to the actualClazz
.start
- TheMethodSignature
of the method whose incoming call graph should be calculated.maxDepth
- maximal depth of reconstructedCallGraph
similar toCallGraphWalker.MAX_DEPTH_DEFAULT
.maxWidth
- maximal width of reconstructedCallGraph
similar toCallGraphWalker.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, java.util.Set<MethodSignature> stopMethods, java.util.Set<MethodSignature> reachedMethods)
Extension ofreconstructCallGraph(ClassPool, MethodSignature, Set)
that also collects all reached stop methods.- Parameters:
programClassPool
- The currentClassPool
of the program that can be used for mapping.start
- TheMethodSignature
of the method whose incoming call graph should be calculated.stopMethods
- A set ofMethodSignature
to stop exploration, e.g. app entry pointsreachedMethods
- 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.
-
-