Reputation: 1
Currenlty I am using Sootup Framework - 1.3.0 (https://github.com/soot-oss/SootUp/tree/develop). Through the examples provided in documentation, I was able to create a complete Control Flow Graph (CFG) with its Intermediate Representation, Jimple
. However, it builds the entire program flow (Intra Procedural CFG) with all the relevant Jimple Statments.
However, I am trying to build a tool using SootUp’s library/API where it only captures the function calls - Call Graphs
indicating all the possible paths created due to loops and branching statments.
To summarize, How can I filter out just the flow of functions calls - Call Graph?
(Note: I have found similar quesitons but most of the questions were asked 5/6 years ago and were related to older vsersion of Soot. Sootup is the latest framework and am testing through it.
This is my implementation code, however this creates the full CFG
public class AnalyseCode {
public static void main(String[] args) {
generateProgramFlow('method-name');
}
public static void generateProgramFlow(String handler) {
// pointing towards the compiled classes
AnalysisInputLocation inputLocation =
new JavaClassPathAnalysisInputLocation("target/classes");
// creating (this will be stored in Cache, this can be changed how view is stored in cache)
JavaView view = new JavaView(inputLocation);
// Defining a class Type
JavaClassType classType =
view.getIdentifierFactory().getClassType("org.example.Experiment");
// Retrieving a SootClass
JavaSootClass sootClass = view.getClass(classType).get();
MethodSignature methodSignature = view.getIdentifierFactory().getMethodSignature(
classType,
handler,
"void",
Collections.singletonList("java.lang.String[]"));
//
SootMethod sootMethod = sootClass.getMethod(methodSignature.getSubSignature()).get();
// read jimple code of method
//System.out.println(sootMethod.getBody());
// ===== Retrieving the Control-Flow Graph of a Method
StmtGraph<?> graph = sootMethod.getBody().getStmtGraph();
//System.out.println(graph);
// Generate URL to visualize the CFG
String urlToWebeditor = DotExporter.createUrlToWebeditor(graph);
System.out.println(urlToWebeditor);
}
}
This was my result showing the full Control Flow Graph with the help of Sootup internal library. For reference only, this is what I got, FULL CFG.
Upvotes: 0
Views: 213