From 5ac1c7335d259037846002fe8960fa5522b7d20a Mon Sep 17 00:00:00 2001 From: sahilagichani Date: Sun, 15 Sep 2024 20:13:54 +0200 Subject: [PATCH 1/9] user can pass cg, or default as CHA --- .../icfg/JimpleBasedInterproceduralCFG.java | 69 ++++++++++++------- .../icfg/ICFGDotExporterTest.java | 15 ++-- .../ifds/IFDSTaintTestSetUp.java | 3 +- 3 files changed, 56 insertions(+), 31 deletions(-) diff --git a/sootup.analysis.interprocedural/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java b/sootup.analysis.interprocedural/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java index 141a4101e4a..056d36254d8 100644 --- a/sootup.analysis.interprocedural/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java +++ b/sootup.analysis.interprocedural/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java @@ -60,7 +60,7 @@ public class JimpleBasedInterproceduralCFG extends AbstractJimpleBasedICFG { protected static final Logger logger = LoggerFactory.getLogger(JimpleBasedInterproceduralCFG.class); - private final MethodSignature mainMethodSignature; + private List entryPoints; protected boolean includeReflectiveCalls; @@ -140,60 +140,79 @@ private Stmt filterEdgeAndGetCallerStmt(@Nonnull MethodSignature methodSignature public JimpleBasedInterproceduralCFG( View view, - MethodSignature mainMethodSignature, + List entryPoints, boolean enableExceptions, boolean includeReflectiveCalls) { super(enableExceptions); this.includeReflectiveCalls = includeReflectiveCalls; this.view = view; - this.mainMethodSignature = mainMethodSignature; + this.entryPoints = entryPoints; cg = initCallGraph(); initializeStmtToOwner(); } + public JimpleBasedInterproceduralCFG( + CallGraph cg, + View view, + List entryPoints, + boolean enableExceptions, + boolean includeReflectiveCalls) { + super(enableExceptions); + this.includeReflectiveCalls = includeReflectiveCalls; + this.view = view; + this.entryPoints = entryPoints; + this.cg = cg; + initializeStmtToOwner(); + } + public String buildICFGGraph(CallGraph callGraph) { Map> signatureToStmtGraph = new LinkedHashMap<>(); - computeAllCalls(mainMethodSignature, signatureToStmtGraph, callGraph); + computeAllCalls(entryPoints, signatureToStmtGraph, callGraph); return ICFGDotExporter.buildICFGGraph(signatureToStmtGraph, view, callGraph); } public void computeAllCalls( - MethodSignature methodSignature, + List entryPoints, Map> signatureToStmtGraph, CallGraph callGraph) { ArrayList visitedMethods = new ArrayList<>(); - computeAllCalls(methodSignature, signatureToStmtGraph, callGraph, visitedMethods); + computeAllCalls(entryPoints, signatureToStmtGraph, callGraph, visitedMethods); } private void computeAllCalls( - MethodSignature methodSignature, + List entryPoints, Map> signatureToStmtGraph, CallGraph callGraph, List visitedMethods) { - visitedMethods.add(methodSignature); - final Optional methodOpt = view.getMethod(methodSignature); - // return if the methodSignature is already added to the hashMap to avoid stackoverflow error. - if (signatureToStmtGraph.containsKey(methodSignature)) { - return; - } - if (methodOpt.isPresent()) { - SootMethod sootMethod = methodOpt.get(); - if (sootMethod.hasBody()) { - StmtGraph stmtGraph = sootMethod.getBody().getStmtGraph(); - signatureToStmtGraph.put(methodSignature, stmtGraph); + visitedMethods.addAll(entryPoints); + for (MethodSignature methodSignature : entryPoints) { + final Optional methodOpt = view.getMethod(methodSignature); + // return if the methodSignature is already added to the hashMap to avoid stackoverflow error. + if (signatureToStmtGraph.containsKey(methodSignature)) { + return; + } + if (methodOpt.isPresent()) { + SootMethod sootMethod = methodOpt.get(); + if (sootMethod.hasBody()) { + StmtGraph stmtGraph = sootMethod.getBody().getStmtGraph(); + signatureToStmtGraph.put(methodSignature, stmtGraph); + } } + callGraph.callTargetsFrom(methodSignature).stream() + .filter(methodSignature1 -> !visitedMethods.contains(methodSignature1)) + .forEach( + nextMethodSignature -> + computeAllCalls( + Collections.singletonList(nextMethodSignature), + signatureToStmtGraph, + callGraph, + visitedMethods)); } - callGraph.callTargetsFrom(methodSignature).stream() - .filter(methodSignature1 -> !visitedMethods.contains(methodSignature1)) - .forEach( - nextMethodSignature -> - computeAllCalls( - nextMethodSignature, signatureToStmtGraph, callGraph, visitedMethods)); } private CallGraph initCallGraph() { CallGraphAlgorithm cga = new ClassHierarchyAnalysisAlgorithm(view); - return cga.initialize(Collections.singletonList(mainMethodSignature)); + return cga.initialize(entryPoints); } protected void initializeStmtToOwner() { diff --git a/sootup.analysis.interprocedural/src/test/java/sootup/analysis/interprocedural/icfg/ICFGDotExporterTest.java b/sootup.analysis.interprocedural/src/test/java/sootup/analysis/interprocedural/icfg/ICFGDotExporterTest.java index 4ddfd325f5f..78a78a858eb 100644 --- a/sootup.analysis.interprocedural/src/test/java/sootup/analysis/interprocedural/icfg/ICFGDotExporterTest.java +++ b/sootup.analysis.interprocedural/src/test/java/sootup/analysis/interprocedural/icfg/ICFGDotExporterTest.java @@ -54,7 +54,8 @@ public void ICFGDotExportTest() { entryMethodSignature = entryMethod.getSignature(); JimpleBasedInterproceduralCFG icfg = - new JimpleBasedInterproceduralCFG(view, entryMethodSignature, false, false); + new JimpleBasedInterproceduralCFG( + view, Collections.singletonList(entryMethodSignature), false, false); CallGraph callGraph = loadCallGraph(view); String expectedCallGraph = icfg.buildICFGGraph(callGraph); Digraph digraph = parseDigraph(expectedCallGraph); @@ -89,7 +90,8 @@ public void ICFGDotExportTest2() { entryMethodSignature = entryMethod.getSignature(); JimpleBasedInterproceduralCFG icfg = - new JimpleBasedInterproceduralCFG(view, entryMethodSignature, false, false); + new JimpleBasedInterproceduralCFG( + view, Collections.singletonList(entryMethodSignature), false, false); CallGraph callGraph = loadCallGraph(view); String expectedCallGraph = icfg.buildICFGGraph(callGraph); Digraph digraph = parseDigraph(expectedCallGraph); @@ -124,7 +126,8 @@ public void ICFGArrayListDotExport() { entryMethodSignature = entryMethod.getSignature(); JimpleBasedInterproceduralCFG icfg = - new JimpleBasedInterproceduralCFG(view, entryMethodSignature, false, false); + new JimpleBasedInterproceduralCFG( + view, Collections.singletonList(entryMethodSignature), false, false); CallGraph callGraph = loadCallGraph(view); String expectedCallGraph = icfg.buildICFGGraph(callGraph); Digraph digraph = parseDigraph(expectedCallGraph); @@ -151,7 +154,8 @@ public void ICFGInterfaceDotExport() { entryMethodSignature = entryMethod.getSignature(); JimpleBasedInterproceduralCFG icfg = - new JimpleBasedInterproceduralCFG(view, entryMethodSignature, false, false); + new JimpleBasedInterproceduralCFG( + view, Collections.singletonList(entryMethodSignature), false, false); CallGraph callGraph = loadCallGraph(view); String expectedCallGraph = icfg.buildICFGGraph(callGraph); Digraph digraph = parseDigraph(expectedCallGraph); @@ -164,7 +168,8 @@ public void ICFGInterfaceDotExport() { public String edgesFromCallGraph( MethodSignature methodSignature, JimpleBasedInterproceduralCFG icfg, CallGraph callGraph) { Map> signatureToStmtGraph = new LinkedHashMap<>(); - icfg.computeAllCalls(methodSignature, signatureToStmtGraph, callGraph); + icfg.computeAllCalls( + Collections.singletonList(methodSignature), signatureToStmtGraph, callGraph); Map calls; calls = ICFGDotExporter.computeCalls(signatureToStmtGraph, view, callGraph); final Optional methodOpt = view.getMethod(methodSignature); diff --git a/sootup.analysis.interprocedural/src/test/java/sootup/analysis/interprocedural/ifds/IFDSTaintTestSetUp.java b/sootup.analysis.interprocedural/src/test/java/sootup/analysis/interprocedural/ifds/IFDSTaintTestSetUp.java index 6b3f30dc5d5..be5c4ebdbba 100644 --- a/sootup.analysis.interprocedural/src/test/java/sootup/analysis/interprocedural/ifds/IFDSTaintTestSetUp.java +++ b/sootup.analysis.interprocedural/src/test/java/sootup/analysis/interprocedural/ifds/IFDSTaintTestSetUp.java @@ -64,7 +64,8 @@ protected JimpleIFDSSolver> executeStati private void runAnalysis() { JimpleBasedInterproceduralCFG icfg = - new JimpleBasedInterproceduralCFG(view, entryMethodSignature, false, false); + new JimpleBasedInterproceduralCFG( + view, Collections.singletonList(entryMethodSignature), false, false); IFDSTaintAnalysisProblem problem = new IFDSTaintAnalysisProblem(icfg, entryMethod); JimpleIFDSSolver> solver = new JimpleIFDSSolver(problem); From dfb7d74937207f9207cebf2a71df315a0c1fe550 Mon Sep 17 00:00:00 2001 From: sahilagichani Date: Thu, 19 Sep 2024 11:07:04 +0200 Subject: [PATCH 2/9] implement reachable methods --- .../main/java/sootup/callgraph/CallGraph.java | 7 ++++ .../sootup/callgraph/GraphBasedCallGraph.java | 38 ++++++++++++++++--- .../builder/callgraph/OnFlyCallGraph.java | 5 +++ 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/sootup.callgraph/src/main/java/sootup/callgraph/CallGraph.java b/sootup.callgraph/src/main/java/sootup/callgraph/CallGraph.java index 0e222948acc..8441c024d10 100644 --- a/sootup.callgraph/src/main/java/sootup/callgraph/CallGraph.java +++ b/sootup.callgraph/src/main/java/sootup/callgraph/CallGraph.java @@ -209,4 +209,11 @@ boolean containsCall( */ @Nonnull CallGraphDifference diff(@Nonnull CallGraph callGraph); + + /** + * This method returns all reachable methods of the call graph + * + * @return a list of method signatures of reachable methods of the call graph + */ + Set getReachableMethods(); } diff --git a/sootup.callgraph/src/main/java/sootup/callgraph/GraphBasedCallGraph.java b/sootup.callgraph/src/main/java/sootup/callgraph/GraphBasedCallGraph.java index bae6cf9ce6c..fae25cd9c5d 100644 --- a/sootup.callgraph/src/main/java/sootup/callgraph/GraphBasedCallGraph.java +++ b/sootup.callgraph/src/main/java/sootup/callgraph/GraphBasedCallGraph.java @@ -23,12 +23,8 @@ */ import com.google.common.base.Preconditions; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; + +import java.util.*; import java.util.stream.Collectors; import javax.annotation.Nonnull; import org.jgrapht.graph.DirectedPseudograph; @@ -243,6 +239,36 @@ public CallGraphDifference diff(@Nonnull CallGraph callGraph) { return new CallGraphDifference(this, callGraph); } + @Override + @Nonnull + public Set getReachableMethods() { + Set reachableNodes = new HashSet<>(); + List entryMethods = getEntryMethods(); + + for (MethodSignature startingNode: entryMethods){ + Deque stack = new ArrayDeque<>(); + // add all entryMethods as reachableNodes + stack.push(startingNode); + // Traverse the call graph using DFS + while (!stack.isEmpty()) { + MethodSignature currentMethod = stack.pop(); + if (!reachableNodes.add(currentMethod)) { + continue; + } + // Get the successors (i.e., called methods) of the current method + Set successors = callsFrom(currentMethod); + + // Push the successors into the stack + for (CallGraph.Call successor : successors) { + if (!reachableNodes.contains(successor.getTargetMethodSignature())) { + stack.push(successor.getTargetMethodSignature()); + } + } + } + } + return reachableNodes; + } + /** * it returns the vertex of the graph that describes the given method signature in the call graph. * diff --git a/sootup.qilin/src/main/java/qilin/core/builder/callgraph/OnFlyCallGraph.java b/sootup.qilin/src/main/java/qilin/core/builder/callgraph/OnFlyCallGraph.java index 250c3a39891..7f3219a5335 100644 --- a/sootup.qilin/src/main/java/qilin/core/builder/callgraph/OnFlyCallGraph.java +++ b/sootup.qilin/src/main/java/qilin/core/builder/callgraph/OnFlyCallGraph.java @@ -462,6 +462,11 @@ public CallGraphDifference diff(@Nonnull CallGraph callGraph) { throw new UnsupportedOperationException(); } + @Override + public Set getReachableMethods() { + throw new UnsupportedOperationException(); + } + @Override public boolean containsMethod(@Nonnull MethodSignature method) { return this.methods.contains(method); From ca87d8d8b388604bd97258e10451e690ee68fe8c Mon Sep 17 00:00:00 2001 From: sahilagichani Date: Thu, 19 Sep 2024 14:50:42 +0200 Subject: [PATCH 3/9] initialize changes --- .../icfg/JimpleBasedInterproceduralCFG.java | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/sootup.analysis.interprocedural/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java b/sootup.analysis.interprocedural/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java index 056d36254d8..8b91c035c59 100644 --- a/sootup.analysis.interprocedural/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java +++ b/sootup.analysis.interprocedural/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java @@ -143,12 +143,7 @@ public JimpleBasedInterproceduralCFG( List entryPoints, boolean enableExceptions, boolean includeReflectiveCalls) { - super(enableExceptions); - this.includeReflectiveCalls = includeReflectiveCalls; - this.view = view; - this.entryPoints = entryPoints; - cg = initCallGraph(); - initializeStmtToOwner(); + this(new ClassHierarchyAnalysisAlgorithm(view).initialize(entryPoints), view, entryPoints, enableExceptions, includeReflectiveCalls); } public JimpleBasedInterproceduralCFG( @@ -210,11 +205,6 @@ private void computeAllCalls( } } - private CallGraph initCallGraph() { - CallGraphAlgorithm cga = new ClassHierarchyAnalysisAlgorithm(view); - return cga.initialize(entryPoints); - } - protected void initializeStmtToOwner() { for (MethodSignature methodSignature : cg.getMethodSignatures()) { final Optional methodOpt = view.getMethod(methodSignature); From 6e29d5805305ed5eb1d862c05ea3d225947a2dbf Mon Sep 17 00:00:00 2001 From: sahilagichani Date: Thu, 19 Sep 2024 19:35:59 +0200 Subject: [PATCH 4/9] fmt style --- .../icfg/JimpleBasedInterproceduralCFG.java | 8 ++++++-- .../main/java/sootup/callgraph/GraphBasedCallGraph.java | 6 ++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/sootup.analysis.interprocedural/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java b/sootup.analysis.interprocedural/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java index 8b91c035c59..d3218f7405b 100644 --- a/sootup.analysis.interprocedural/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java +++ b/sootup.analysis.interprocedural/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java @@ -37,7 +37,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import sootup.callgraph.CallGraph; -import sootup.callgraph.CallGraphAlgorithm; import sootup.callgraph.ClassHierarchyAnalysisAlgorithm; import sootup.core.graph.StmtGraph; import sootup.core.jimple.common.expr.AbstractInvokeExpr; @@ -143,7 +142,12 @@ public JimpleBasedInterproceduralCFG( List entryPoints, boolean enableExceptions, boolean includeReflectiveCalls) { - this(new ClassHierarchyAnalysisAlgorithm(view).initialize(entryPoints), view, entryPoints, enableExceptions, includeReflectiveCalls); + this( + new ClassHierarchyAnalysisAlgorithm(view).initialize(entryPoints), + view, + entryPoints, + enableExceptions, + includeReflectiveCalls); } public JimpleBasedInterproceduralCFG( diff --git a/sootup.callgraph/src/main/java/sootup/callgraph/GraphBasedCallGraph.java b/sootup.callgraph/src/main/java/sootup/callgraph/GraphBasedCallGraph.java index 539aec75bcb..61e7ae8ad35 100644 --- a/sootup.callgraph/src/main/java/sootup/callgraph/GraphBasedCallGraph.java +++ b/sootup.callgraph/src/main/java/sootup/callgraph/GraphBasedCallGraph.java @@ -22,15 +22,13 @@ * #L% */ +import java.util.*; import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; -import com.google.common.base.Preconditions; - -import java.util.*; import java.util.stream.Collectors; import javax.annotation.Nonnull; import org.jgrapht.graph.DirectedPseudograph; @@ -248,7 +246,7 @@ public Set getReachableMethods() { Set reachableNodes = new HashSet<>(); List entryMethods = getEntryMethods(); - for (MethodSignature startingNode: entryMethods){ + for (MethodSignature startingNode : entryMethods) { Deque stack = new ArrayDeque<>(); // add all entryMethods as reachableNodes stack.push(startingNode); From 95b4ec5acafb3da676cc715dbf223abbd4b33567 Mon Sep 17 00:00:00 2001 From: sahilagichani Date: Sat, 21 Sep 2024 14:32:04 +0200 Subject: [PATCH 5/9] fix constructor params --- .../interprocedural/icfg/JimpleBasedInterproceduralCFGTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sootup.analysis.interprocedural/src/test/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFGTest.java b/sootup.analysis.interprocedural/src/test/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFGTest.java index 6cbec7b7c6f..1dac2825184 100644 --- a/sootup.analysis.interprocedural/src/test/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFGTest.java +++ b/sootup.analysis.interprocedural/src/test/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFGTest.java @@ -42,7 +42,7 @@ void methodToCallerStmtTest() { entryMethodSignature = entryMethod.getSignature(); JimpleBasedInterproceduralCFG icfg = - new JimpleBasedInterproceduralCFG(view, entryMethodSignature, false, false); + new JimpleBasedInterproceduralCFG(view, Collections.singletonList(entryMethodSignature), false, false); MethodSignature sig = JavaIdentifierFactory.getInstance() From 07c72549b6ac601395436465aaaf7f56283bf0e8 Mon Sep 17 00:00:00 2001 From: sahilagichani Date: Sat, 21 Sep 2024 14:32:53 +0200 Subject: [PATCH 6/9] fix style --- .../icfg/JimpleBasedInterproceduralCFGTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sootup.analysis.interprocedural/src/test/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFGTest.java b/sootup.analysis.interprocedural/src/test/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFGTest.java index 1dac2825184..9d61efb8296 100644 --- a/sootup.analysis.interprocedural/src/test/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFGTest.java +++ b/sootup.analysis.interprocedural/src/test/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFGTest.java @@ -42,7 +42,8 @@ void methodToCallerStmtTest() { entryMethodSignature = entryMethod.getSignature(); JimpleBasedInterproceduralCFG icfg = - new JimpleBasedInterproceduralCFG(view, Collections.singletonList(entryMethodSignature), false, false); + new JimpleBasedInterproceduralCFG( + view, Collections.singletonList(entryMethodSignature), false, false); MethodSignature sig = JavaIdentifierFactory.getInstance() From 53270c2dcfddff4d7c96b465cafb846d7640c20d Mon Sep 17 00:00:00 2001 From: sahilagichani Date: Thu, 26 Sep 2024 16:03:04 +0200 Subject: [PATCH 7/9] use entry points from cg --- .../icfg/JimpleBasedInterproceduralCFG.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/sootup.analysis.interprocedural/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java b/sootup.analysis.interprocedural/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java index d4f4a8adba0..ae4d44822ad 100644 --- a/sootup.analysis.interprocedural/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java +++ b/sootup.analysis.interprocedural/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java @@ -108,27 +108,22 @@ public Collection load(SootMethod method) { public JimpleBasedInterproceduralCFG( View view, - List entryPoints, + List cgEntryPoints, boolean enableExceptions, boolean includeReflectiveCalls) { this( - new ClassHierarchyAnalysisAlgorithm(view).initialize(entryPoints), + new ClassHierarchyAnalysisAlgorithm(view).initialize(cgEntryPoints), view, - entryPoints, enableExceptions, includeReflectiveCalls); } public JimpleBasedInterproceduralCFG( - CallGraph cg, - View view, - List entryPoints, - boolean enableExceptions, - boolean includeReflectiveCalls) { + CallGraph cg, View view, boolean enableExceptions, boolean includeReflectiveCalls) { super(enableExceptions); this.includeReflectiveCalls = includeReflectiveCalls; this.view = view; - this.entryPoints = entryPoints; + this.entryPoints = cg.getEntryMethods(); this.cg = cg; initializeStmtToOwner(); } From d3f5c77118a1a4bc4d8bd5b61fd9a29e3fc516d7 Mon Sep 17 00:00:00 2001 From: sahilagichani Date: Fri, 27 Sep 2024 15:21:53 +0200 Subject: [PATCH 8/9] reachable methods in sootup same as getMethods --- .../main/java/sootup/callgraph/CallGraph.java | 7 ----- .../sootup/callgraph/GraphBasedCallGraph.java | 30 ------------------- .../builder/callgraph/OnFlyCallGraph.java | 5 ---- 3 files changed, 42 deletions(-) diff --git a/sootup.callgraph/src/main/java/sootup/callgraph/CallGraph.java b/sootup.callgraph/src/main/java/sootup/callgraph/CallGraph.java index 8441c024d10..0e222948acc 100644 --- a/sootup.callgraph/src/main/java/sootup/callgraph/CallGraph.java +++ b/sootup.callgraph/src/main/java/sootup/callgraph/CallGraph.java @@ -209,11 +209,4 @@ boolean containsCall( */ @Nonnull CallGraphDifference diff(@Nonnull CallGraph callGraph); - - /** - * This method returns all reachable methods of the call graph - * - * @return a list of method signatures of reachable methods of the call graph - */ - Set getReachableMethods(); } diff --git a/sootup.callgraph/src/main/java/sootup/callgraph/GraphBasedCallGraph.java b/sootup.callgraph/src/main/java/sootup/callgraph/GraphBasedCallGraph.java index 61e7ae8ad35..616c52cdfe6 100644 --- a/sootup.callgraph/src/main/java/sootup/callgraph/GraphBasedCallGraph.java +++ b/sootup.callgraph/src/main/java/sootup/callgraph/GraphBasedCallGraph.java @@ -240,36 +240,6 @@ public CallGraphDifference diff(@Nonnull CallGraph callGraph) { return new CallGraphDifference(this, callGraph); } - @Override - @Nonnull - public Set getReachableMethods() { - Set reachableNodes = new HashSet<>(); - List entryMethods = getEntryMethods(); - - for (MethodSignature startingNode : entryMethods) { - Deque stack = new ArrayDeque<>(); - // add all entryMethods as reachableNodes - stack.push(startingNode); - // Traverse the call graph using DFS - while (!stack.isEmpty()) { - MethodSignature currentMethod = stack.pop(); - if (!reachableNodes.add(currentMethod)) { - continue; - } - // Get the successors (i.e., called methods) of the current method - Set successors = callsFrom(currentMethod); - - // Push the successors into the stack - for (CallGraph.Call successor : successors) { - if (!reachableNodes.contains(successor.getTargetMethodSignature())) { - stack.push(successor.getTargetMethodSignature()); - } - } - } - } - return reachableNodes; - } - /** * it returns the vertex of the graph that describes the given method signature in the call graph. * It will throw an exception if the vertex is not found diff --git a/sootup.qilin/src/main/java/qilin/core/builder/callgraph/OnFlyCallGraph.java b/sootup.qilin/src/main/java/qilin/core/builder/callgraph/OnFlyCallGraph.java index c6e4a625147..cc2fca17469 100644 --- a/sootup.qilin/src/main/java/qilin/core/builder/callgraph/OnFlyCallGraph.java +++ b/sootup.qilin/src/main/java/qilin/core/builder/callgraph/OnFlyCallGraph.java @@ -468,11 +468,6 @@ public CallGraphDifference diff(@Nonnull CallGraph callGraph) { throw new UnsupportedOperationException(); } - @Override - public Set getReachableMethods() { - throw new UnsupportedOperationException(); - } - @Override public boolean containsMethod(@Nonnull MethodSignature method) { return this.methods.contains(method); From dc383ffbb607f617cdff25fa05bb0380a97c574e Mon Sep 17 00:00:00 2001 From: sahilagichani Date: Tue, 1 Oct 2024 11:07:10 +0200 Subject: [PATCH 9/9] removed entrypoints field from jimple cfg --- .../icfg/JimpleBasedInterproceduralCFG.java | 8 +++++--- .../icfg/BackwardsInterproceduralCFGTest.java | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/sootup.analysis.interprocedural/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java b/sootup.analysis.interprocedural/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java index ae4d44822ad..3dc36d344e7 100644 --- a/sootup.analysis.interprocedural/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java +++ b/sootup.analysis.interprocedural/src/main/java/sootup/analysis/interprocedural/icfg/JimpleBasedInterproceduralCFG.java @@ -55,7 +55,6 @@ public class JimpleBasedInterproceduralCFG extends AbstractJimpleBasedICFG { protected static final Logger logger = LoggerFactory.getLogger(JimpleBasedInterproceduralCFG.class); - private List entryPoints; protected boolean includeReflectiveCalls; @@ -123,14 +122,17 @@ public JimpleBasedInterproceduralCFG( super(enableExceptions); this.includeReflectiveCalls = includeReflectiveCalls; this.view = view; - this.entryPoints = cg.getEntryMethods(); this.cg = cg; initializeStmtToOwner(); } + public CallGraph getCg() { + return cg; + } + public String buildICFGGraph(CallGraph callGraph) { Map> signatureToStmtGraph = new LinkedHashMap<>(); - computeAllCalls(entryPoints, signatureToStmtGraph, callGraph); + computeAllCalls(callGraph.getEntryMethods(), signatureToStmtGraph, callGraph); return ICFGDotExporter.buildICFGGraph(signatureToStmtGraph, view, callGraph); } diff --git a/sootup.analysis.interprocedural/src/test/java/sootup/analysis/interprocedural/icfg/BackwardsInterproceduralCFGTest.java b/sootup.analysis.interprocedural/src/test/java/sootup/analysis/interprocedural/icfg/BackwardsInterproceduralCFGTest.java index 616c8c0fb8d..5d9ac4e36a4 100644 --- a/sootup.analysis.interprocedural/src/test/java/sootup/analysis/interprocedural/icfg/BackwardsInterproceduralCFGTest.java +++ b/sootup.analysis.interprocedural/src/test/java/sootup/analysis/interprocedural/icfg/BackwardsInterproceduralCFGTest.java @@ -42,7 +42,8 @@ public static void setup() { @Test void methodStartAndEndPointTest() { JimpleBasedInterproceduralCFG forwardICFG = - new JimpleBasedInterproceduralCFG(view, entryMethodSignature, false, false); + new JimpleBasedInterproceduralCFG( + view, Collections.singletonList(entryMethodSignature), false, false); BackwardsInterproceduralCFG backwardsInterproceduralCFG = new BackwardsInterproceduralCFG(forwardICFG); @@ -58,7 +59,8 @@ void methodStartAndEndPointTest() { @Test void methodToCallerStmtTest() { JimpleBasedInterproceduralCFG forwardICFG = - new JimpleBasedInterproceduralCFG(view, entryMethodSignature, false, false); + new JimpleBasedInterproceduralCFG( + view, Collections.singletonList(entryMethodSignature), false, false); BackwardsInterproceduralCFG backwardsInterproceduralCFG = new BackwardsInterproceduralCFG(forwardICFG);