soot
soot copied to clipboard
How can I make call graph
I want to make call graph using Soot.
In this guideline (https://www.brics.dk/SootGuide/) there is call graph example. So I tried to add eclipse plugin and I figured it is not working (so, the link at the wiki is not working, and I adjusted the link a bit and downloaded Soot.zip, and I added it but still not working..)
My question is..
A. How can I compile using soot in two different java file... I checked wiki but I cannot understand... B. How can I generate call graph using Soot? I guess I need gui for soot...(but I never found it..)
Since I only used C or python for few years, I am not familiar to Java..
So the code for the call graph is as follows...
Main code name "CallGraphs.java". This is inside "src/testers/"
package testers;
public class CallGraphs
{
public static void main(String[] args) {
doStuff();
}
public static void doStuff() {
new A().foo();
}
}
class A
{
public void foo() {
bar();
}
public void bar() {
}
}
And the other code using Soot is as follows The code name is "CallGraphExample.java" and is located in "/src/dk/brics/soot/callgraphs/"
package dk.brics.soot.callgraphs;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import soot.MethodOrMethodContext;
import soot.PackManager;
import soot.Scene;
import soot.SceneTransformer;
import soot.SootClass;
import soot.SootMethod;
import soot.Transform;
import soot.jimple.toolkits.callgraph.CHATransformer;
import soot.jimple.toolkits.callgraph.CallGraph;
import soot.jimple.toolkits.callgraph.Targets;
public class CallGraphExample
{
public static void main(String[] args) {
List<String> argsList = new ArrayList<String>(Arrays.asList(args));
argsList.addAll(Arrays.asList(new String[]{
"-w",
"-main-class",
"testers.CallGraphs",//main-class
"testers.CallGraphs",//argument classes
"testers.A" //
}));
PackManager.v().getPack("wjtp").add(new Transform("wjtp.myTrans", new SceneTransformer() {
@Override
protected void internalTransform(String phaseName, Map options) {
CHATransformer.v().transform();
SootClass a = Scene.v().getSootClass("testers.A");
SootMethod src = Scene.v().getMainClass().getMethodByName("doStuff");
CallGraph cg = Scene.v().getCallGraph();
Iterator<MethodOrMethodContext> targets = new Targets(cg.edgesOutOf(src));
while (targets.hasNext()) {
SootMethod tgt = (SootMethod)targets.next();
System.out.println(src + " may call " + tgt);
}
}
}));
args = argsList.toArray(new String[0]);
soot.Main.main(args);
}
}
When I ran the source code using soot, it returned Illegal argument exception error
Soot started on Sun Jun 20 23:03:17 KST 2021
java.lang.IllegalArgumentException: Unsupported class file major version 60
at org.objectweb.asm.ClassReader.
This is the error message that I got...
The thrown exception implies that your input was compiled with Java16 (major version 60) which is not supported currently as Soot uses ASM 8.0 to read class files. ASM 8.0 supports up to java 14 (https://asm.ow2.io/versions.html).
Thanks, I'll try java 14..
hello, can u tell me how your code is working? Thanks! I use the same code but I only got information like this: " SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. Soot class path /Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home/jre/lib/rt.jar Soot started on Mon Aug 16 14:45:30 CST 2021 soot.SootResolver$SootClassNotFoundException: couldn't find class: javax.crypto.BadPaddingException (is your soot-class-path set properly?) at soot.SootResolver.bringToHierarchyUnchecked(SootResolver.java:232) at soot.SootResolver.bringToHierarchy(SootResolver.java:214) at soot.SootResolver.bringToSignatures(SootResolver.java:279) at soot.SootResolver.bringToBodies(SootResolver.java:319) at soot.SootResolver.processResolveWorklist(SootResolver.java:164) at soot.SootResolver.resolveClass(SootResolver.java:134) at soot.Scene.tryLoadClass(Scene.java:912) at soot.Scene.loadBasicClasses(Scene.java:1652) at soot.Scene.loadNecessaryClasses(Scene.java:1738) at soot.Main.run(Main.java:241) at soot.Main.main(Main.java:141) at demo.CallGraphExample.main(CallGraphExample.java:58) " @JayC1208
@XiaoQB I Think You Should check soot-class-path configuration.
@XiaoQB Hi, sorry for the late reply, and there's nothing special I did to run the code I mentioned.. I just installed Soot, and go to the example file and just "CallGraphExample.java"..