Package sootup.callgraph
Class AbstractCallGraphAlgorithm
java.lang.Object
sootup.callgraph.AbstractCallGraphAlgorithm
- All Implemented Interfaces:
CallGraphAlgorithm
- Direct Known Subclasses:
ClassHierarchyAnalysisAlgorithm
,RapidTypeAnalysisAlgorithm
The AbstractCallGraphAlgorithm class is the super class of all call graph algorithm. It provides
basic methods used in all call graph algorithm. It is abstract since it has no implemented
functionality to resolve method calls because it is decided by the applied call graph algorithm
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
addCallToCG
(MethodSignature source, MethodSignature target, InvokableStmt invokeStmt, MutableCallGraph cg, Deque<MethodSignature> workList) Adds the defined call to the given call graph.Adds a class to the call graph.static Optional<SootMethod>
findConcreteMethod
(View view, MethodSignature sig) searches the method object in the given hierarchyfindMainMethod
(View view) The method iterates over all classes present in view, and finds method with name main and SourceType - Application.protected List<MethodSignature>
getClinitFromEntryPoints
(List<MethodSignature> entryPoints) This method returns a list of static initializers that should be considered by the given entry pointsprotected MutableCallGraph
initializeCallGraph
(List<MethodSignature> entryPoints, List<MethodSignature> clinits) This method creates the mutable call graph which is used in the call graph algorithm.protected abstract void
postProcessingMethod
(View view, MethodSignature sourceMethod, Deque<MethodSignature> workList, MutableCallGraph cg) This method enables optional post-processing of a method in the call graph algorithmprotected abstract void
preProcessingMethod
(View view, MethodSignature sourceMethod, Deque<MethodSignature> workList, MutableCallGraph cg) This method enables optional pre-processing of a method in the call graph algorithmprotected void
resolveAllCallsFromSourceMethod
(SootMethod sourceMethod, MutableCallGraph cg, Deque<MethodSignature> workList) This method resolves all calls from a given source method.protected void
resolveAllImplicitCallsFromSourceMethod
(SootMethod sourceMethod, MutableCallGraph cg, Deque<MethodSignature> workList) It resolves all implicit calls caused by the given source methodprotected void
resolveAllStaticInitializerCalls
(SootMethod sourceMethod, MutableCallGraph cg, Deque<MethodSignature> workList) It resolves all static initializer calls caused by the given source methodprotected abstract Stream<MethodSignature>
resolveCall
(SootMethod method, InvokableStmt invokableStmt) This method resolves the possible targets of a given invoke expression.static Optional<MethodSignature>
resolveConcreteDispatch
(View view, MethodSignature m) Searches for the signature of the method that is the concrete implementation ofm
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface sootup.callgraph.CallGraphAlgorithm
initialize, initialize
-
Field Details
-
view
-
-
Constructor Details
-
AbstractCallGraphAlgorithm
-
-
Method Details
-
initializeCallGraph
protected MutableCallGraph initializeCallGraph(List<MethodSignature> entryPoints, List<MethodSignature> clinits) This method creates the mutable call graph which is used in the call graph algorithm. Overwrite it to change the used mutable call graph- Returns:
- the initialized call graph used in the call graph algorithm
-
getClinitFromEntryPoints
This method returns a list of static initializers that should be considered by the given entry points- Parameters:
entryPoints
- the entry points of the call graph algorithm
-
addCallToCG
protected void addCallToCG(@Nonnull MethodSignature source, @Nonnull MethodSignature target, @Nonnull InvokableStmt invokeStmt, @Nonnull MutableCallGraph cg, @Nonnull Deque<MethodSignature> workList) Adds the defined call to the given call graph. If the source or target method was added as vertex to the call graph, they will be added to the worklist- Parameters:
source
- the method signature of the callertarget
- the method signature of the calleeinvokeStmt
- the stmt causing the callcg
- the call graph that will be updatedworkList
- the worklist in which the method signature of newly added vertexes will be added
-
resolveAllCallsFromSourceMethod
protected void resolveAllCallsFromSourceMethod(SootMethod sourceMethod, MutableCallGraph cg, Deque<MethodSignature> workList) This method resolves all calls from a given source method. resolveCall is called for each invokable statements in the body of the source method that is implemented in the corresponding call graph algorithm. If new methods will be added as vertexes in the call graph, the work list will be updated- Parameters:
sourceMethod
- this signature is used to access the statements contained method body of the specified methodcg
- the call graph that will receive the found callsworkList
- the work list that will be updated of found target methods
-
resolveAllImplicitCallsFromSourceMethod
protected void resolveAllImplicitCallsFromSourceMethod(SootMethod sourceMethod, MutableCallGraph cg, Deque<MethodSignature> workList) It resolves all implicit calls caused by the given source method- Parameters:
sourceMethod
- the inspected source methodcg
- new calls will be added to the call graphworkList
- new target methods will be added to the work list
-
resolveAllStaticInitializerCalls
protected void resolveAllStaticInitializerCalls(SootMethod sourceMethod, MutableCallGraph cg, Deque<MethodSignature> workList) It resolves all static initializer calls caused by the given source method- Parameters:
sourceMethod
- the inspected source methodcg
- clinit calls will be added to the call graphworkList
- found clinit methods will be added to the work list
-
preProcessingMethod
protected abstract void preProcessingMethod(View view, MethodSignature sourceMethod, @Nonnull Deque<MethodSignature> workList, @Nonnull MutableCallGraph cg) This method enables optional pre-processing of a method in the call graph algorithm- Parameters:
view
- viewsourceMethod
- the processed methodworkList
- the current work list that might be extendedcg
- the current cg that might be extended
-
postProcessingMethod
protected abstract void postProcessingMethod(View view, MethodSignature sourceMethod, @Nonnull Deque<MethodSignature> workList, @Nonnull MutableCallGraph cg) This method enables optional post-processing of a method in the call graph algorithm- Parameters:
view
- it contains classes and the type hierarchy.sourceMethod
- the processed methodworkList
- the current work list that might be extendedcg
- the current cg that might be extended
-
addClass
Description copied from interface:CallGraphAlgorithm
Adds a class to the call graph. All methods will be set as entry points in the call graph algorithm. Starts the call graph algorithm. The found edges will be added to the call graph.- Specified by:
addClass
in interfaceCallGraphAlgorithm
- Parameters:
oldCallGraph
- the call graph which will be modified.classType
- the type of the calls.- Returns:
- the modified call graph containing all methods of the given class
-
findMainMethod
The method iterates over all classes present in view, and finds method with name main and SourceType - Application. This method is used by initialize() method used for creating call graph and the call graph is created by considering the main method as an entry point.The method throws an exception if there is no main method in any of the classes or if there are more than one main method.
- Parameters:
view
- to get the view specific main method.- Returns:
- - MethodSignature of main method.
-
resolveCall
@Nonnull protected abstract Stream<MethodSignature> resolveCall(SootMethod method, InvokableStmt invokableStmt) This method resolves the possible targets of a given invoke expression. The results are dependable of the applied call graph algorithm. therefore, it is abstract.- Parameters:
method
- the method object that contains the given invoke expression in the body.invokableStmt
- it contains the call which is resolved.- Returns:
- a stream of all reachable method signatures defined by the applied call graph algorithm.
-
resolveConcreteDispatch
@Nonnull public static Optional<MethodSignature> resolveConcreteDispatch(View view, MethodSignature m) Searches for the signature of the method that is the concrete implementation ofm
. This is done by checking each superclass and the class itself for whether it contains the concrete implementation. -
findConcreteMethod
public static Optional<SootMethod> findConcreteMethod(@Nonnull View view, @Nonnull MethodSignature sig) searches the method object in the given hierarchy- Parameters:
view
- it contains all classessig
- the signature of the searched method- Returns:
- the found method object, or null if the method was not found.
-