Class OnFlyCallGraph

java.lang.Object
qilin.core.builder.callgraph.OnFlyCallGraph
All Implemented Interfaces:
Iterable<Edge>, CallGraph, MutableCallGraph

public class OnFlyCallGraph extends Object implements MutableCallGraph, Iterable<Edge>
Represents the edges in a call graph. This class is meant to act as only a container of edges; code for various call graph builders should be kept out of it, as well as most code for accessing the edges.
Author:
Ondrej Lhotak
  • Field Details

  • Constructor Details

    • OnFlyCallGraph

      public OnFlyCallGraph()
  • Method Details

    • addEdge

      public boolean addEdge(Edge e)
      Used to add an edge to the call graph. Returns true iff the edge was not already present.
    • removeAllEdgesOutOf

      public boolean removeAllEdgesOutOf(Stmt u)
      Removes all outgoing edges that start at the given unit
      Parameters:
      u - The unit from which to remove all outgoing edges
      Returns:
      True if at least one edge has been removed, otherwise false
    • swapEdgesOutOf

      public boolean swapEdgesOutOf(InvokableStmt out, InvokableStmt in)
      Swaps an invocation statement. All edges that previously went from the given statement to some callee now go from the new statement to the same callee. This method is intended to be used when a Jimple statement is replaced, but the replacement does not semantically affect the edges.
      Parameters:
      out - The old statement
      in - The new statement
      Returns:
      True if at least one edge was affected by this operation
    • removeEdge

      public boolean removeEdge(Edge e)
      Removes the edge e from the call graph. Returns true iff the edge was originally present in the call graph.
    • removeEdge

      public boolean removeEdge(Edge e, boolean removeInEdgeList)
      Removes the edge e from the call graph. Returns true iff the edge was originally present in the call graph.
      Parameters:
      e - the edge
      removeInEdgeList - when true (recommended), it is ensured that the edge reader is informed about the removal
      Returns:
      whether the removal was successful.
    • removeEdges

      public boolean removeEdges(Collection<Edge> edges)
      Removes the edges from the call graph. Returns true iff one edge was originally present in the call graph.
      Parameters:
      edges - the edges
      Returns:
      whether the removal was successful.
    • isEntryMethod

      public boolean isEntryMethod(SootMethod method)
      Does this method have no incoming edge?
      Parameters:
      method -
      Returns:
    • findEdge

      public Edge findEdge(Stmt u, SootMethod callee)
      Find the specific call edge that is going out from the callsite u and the call target is callee. Without advanced data structure, we can only sequentially search for the match. Fortunately, the number of outgoing edges for a unit is not too large.
      Parameters:
      u -
      callee -
      Returns:
    • sourceMethods

      public Iterator<ContextMethod> sourceMethods()
      Returns an iterator over all methods that are the sources of at least one edge.
    • edgesOutOf

      public Iterator<Edge> edgesOutOf(Stmt u)
      Returns an iterator over all edges that have u as their source unit.
    • edgesOutOf

      public Iterator<Edge> edgesOutOf(ContextMethod m)
      Returns an iterator over all edges that have m as their source method.
    • edgesInto

      public Iterator<Edge> edgesInto(ContextMethod m)
      Returns an iterator over all edges that have m as their target method.
    • listener

      public QueueReader<Edge> listener()
      Returns a QueueReader object containing all edges added so far, and which will be informed of any new edges that are later added to the graph.
    • newListener

      public QueueReader<Edge> newListener()
      Returns a QueueReader object which will contain ONLY NEW edges which will be added to the graph.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • size

      public int size()
      Returns the number of edges in the call graph.
    • iterator

      public Iterator<Edge> iterator()
      Specified by:
      iterator in interface Iterable<Edge>
    • addMethod

      public void addMethod(@Nonnull MethodSignature calledMethod)
      Description copied from interface: MutableCallGraph
      This method enables to add method that are nodes in the call graph.
      Specified by:
      addMethod in interface MutableCallGraph
      Parameters:
      calledMethod - the method that will be added to the call graph.
    • addCall

      public void addCall(@Nonnull MethodSignature sourceMethod, @Nonnull MethodSignature targetMethod, @Nonnull InvokableStmt stmt)
      Description copied from interface: MutableCallGraph
      This method enables to add calls that are edges in the call graph.
      Specified by:
      addCall in interface MutableCallGraph
      Parameters:
      sourceMethod - this parameter defines the source node of the edge in the call graph.
      targetMethod - this paramter defines the target node of the edge in the call graph.
      stmt - this paramter defines the invoke statement of the edge in the call graph.
    • addCall

      public void addCall(@Nonnull CallGraph.Call call)
      Description copied from interface: MutableCallGraph
      This method enables to add calls that are edges in the call graph.
      Specified by:
      addCall in interface MutableCallGraph
      Parameters:
      call - this parameter defines the call that is transformed to the edge in the call graph.
    • getMethodSignatures

      @Nonnull public Set<MethodSignature> getMethodSignatures()
      Description copied from interface: CallGraph
      This method returns method signatures in the call graph. A method signature is a node in the call graph.
      Specified by:
      getMethodSignatures in interface CallGraph
      Returns:
      a set containing all method signatures in the call graph.
    • copy

      @Nonnull public MutableCallGraph copy()
      Description copied from interface: CallGraph
      This method copies a call graph.
      Specified by:
      copy in interface CallGraph
      Returns:
      it returns a copied call graph.
    • diff

      Description copied from interface: CallGraph
      This method compares the difference between the current call graph and call graph passed into the argument.
      Specified by:
      diff in interface CallGraph
    • containsMethod

      public boolean containsMethod(@Nonnull MethodSignature method)
      Description copied from interface: CallGraph
      This method checks if a given method signature is a node in the call graph.
      Specified by:
      containsMethod in interface CallGraph
      Parameters:
      method - the method signature of the requested node
      Returns:
      it returns true if the node described by the method signature is included in the call graph, otherwise it will return false.
    • containsCall

      public boolean containsCall(@Nonnull MethodSignature sourceMethod, @Nonnull MethodSignature targetMethod, InvokableStmt stmt)
      Description copied from interface: CallGraph
      This method checks if an edge is contained in the call graph. The edge is defined by a source and target method signature which can be nodes in the call graph
      Specified by:
      containsCall in interface CallGraph
      Parameters:
      sourceMethod - it defines the source node in the call graph
      targetMethod - it defines the target node in the call graph
      stmt - it defines the invoke stmt of the call
      Returns:
      true if the edge is contained in the call graph, otherwise it will be false.
    • containsCall

      public boolean containsCall(@Nonnull CallGraph.Call call)
      Description copied from interface: CallGraph
      This method checks if an edge is contained in the call graph. The edge is defined by a source and target method signature which can be nodes in the call graph
      Specified by:
      containsCall in interface CallGraph
      Parameters:
      call - it defines the requested call in the call graph
      Returns:
      true if the edge is contained in the call graph, otherwise it will be false.
    • callCount

      public int callCount()
      Description copied from interface: CallGraph
      This method counts every edge in the call graph.
      Specified by:
      callCount in interface CallGraph
      Returns:
      it returns the number of all edges in the call graph.
    • exportAsDot

      public String exportAsDot()
      Description copied from interface: CallGraph
      This method converts the call graph object into dot format and write it to a string file.
      Specified by:
      exportAsDot in interface CallGraph
    • callsFrom

      @Nonnull public Set<CallGraph.Call> callsFrom(@Nonnull MethodSignature sourceMethod)
      Description copied from interface: CallGraph
      This method returns all method signatures that are called by a given method signature. It returns the targets of outgoing edges of the given node (method signature) in the call graph
      Specified by:
      callsFrom in interface CallGraph
      Parameters:
      sourceMethod - the method signature of the requested node in the call graph
      Returns:
      a set of method signatures that are reached by a direct outgoing edge in the call graph
    • callsTo

      @Nonnull public Set<CallGraph.Call> callsTo(@Nonnull MethodSignature targetMethod)
      Description copied from interface: CallGraph
      This method returns all method signatures that call a given method signature. It returns the sources of incoming edges of the given node (method signature) in the call graph
      Specified by:
      callsTo in interface CallGraph
      Parameters:
      targetMethod - the method signature of the requested node in the call graph
      Returns:
      a set of method signatures that reach the targetMethod by a direct edge in the call graph
    • callTargetsFrom

      @Nonnull public Set<MethodSignature> callTargetsFrom(@Nonnull MethodSignature sourceMethod)
      Description copied from interface: CallGraph
      This method returns all method signatures that are called by a given method signature. It returns the targets of outgoing edges of the given node (method signature) in the call graph
      Specified by:
      callTargetsFrom in interface CallGraph
      Parameters:
      sourceMethod - the method signature of the requested node in the call graph
      Returns:
      a set of method signatures that are reached by a direct outgoing edge in the call graph
    • callSourcesTo

      @Nonnull public Set<MethodSignature> callSourcesTo(@Nonnull MethodSignature targetMethod)
      Description copied from interface: CallGraph
      This method returns all method signatures that call a given method signature. It returns the sources of incoming edges of the given node (method signature) in the call graph
      Specified by:
      callSourcesTo in interface CallGraph
      Parameters:
      targetMethod - the method signature of the requested node in the call graph
      Returns:
      a set of method signatures that reach the targetMethod by a direct edge in the call graph
    • getEntryMethods

      public List<MethodSignature> getEntryMethods()
      Description copied from interface: CallGraph
      This method returns all entry methods of the call graph
      Specified by:
      getEntryMethods in interface CallGraph
      Returns:
      a list of method signatures of entry points of the call graph