-
-
Notifications
You must be signed in to change notification settings - Fork 708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to generate a method call graph of a Jar file directly? #1346
Comments
Hi! Your code looks pretty good from a first glimpse. Soot generally needs some basic classes from the JDK to work (like Here is the place your error is emitted, caused by no basic class being loaded: https://github.com/Sable/soot/blob/master/src/main/java/soot/Scene.java#L1754 I think the issue might really be your classpath:
You are adding the jrt-fs.jar to the class path. But the basic jre classes are contained in jrt.jar. Please try to add this manually or use the |
@mbenz89 Thank you for your prompt reply. I switch to the JDK 8. And now it works. But there's another question: How can I set to read the jar file by Soot?
I think that it may be caused by the wrong .class files path. I extract all .classes files to a directory and remain the original package structure. Then I use the |
Does the class Also, you should load all classes first (especially the basic classes) before you force Soot to load a specific class. Set your main method afterward. Make sure the class containing the main method is on your classpath and then replace
by
Also, are you sure you want to run Soot in |
@mbenz89 Thank you for your kind reply to my question. Unfortunately, it didn't work. The class public static void main(String[] args) {
String mainclass = "com.ouc.Example";
//set classpath
String javapath = System.getProperty("java.class.path");
String jredir = System.getProperty("java.home") + "\\lib\\rt.jar";
String path = javapath + File.pathSeparator + jredir;
Scene.v().setSootClassPath(path);
//add an intra-procedural analysis phase to Soot
TestCallGraphSootJar_2 analysis = new TestCallGraphSootJar_2();
PackManager.v().getPack("wjtp").add(new Transform("wjtp.TestSootCallGraph", analysis));
excludeJDKLibrary();
Options.v().set_process_dir(Arrays.asList("C:\\Users\\username\\ll1\\src\\test\\java\\com\\demo\\dir"));
//whole program analysis
Options.v().set_whole_program(true);
//load and set main class
Scene.v().loadNecessaryClasses();
SootClass appclass = Scene.v().getSootClass(mainclass);
Scene.v().setMainClass(appclass);
enableSparkCallGraph();
//start working
PackManager.v().runPacks();
} |
You're welcome. I cannot see any problems with youe code. Could you send me the Example.class file and the code of |
@mbenz89 Thank you for your attention, and sorry for my late reply. |
Hello, I also want to know how to use soot to generate the call graph of the jar file, and I can use the same command to call the class in rt.jar, but for other jars it shows impossible't find class: android.content.Context ( is your soot-class-path set properly?) (command line) couldn't find class: com.baidu.location.LocationClient (is your soot-class-path set properly?) (in the program) Thank you for your help as soon as possible Solve my doubts @mbenz89 (error in command line) |
@sscui Without any setup, I cannot help. Generally speaking, Soot has a dedicated Android component: FlowDroid. I would suggest asking your question with a bit more information on FlowDroid's issue board. |
@liuyuanOUC What is |
@mbenz89 Thank you for your reply; my current purpose is just to analyze the jar packages in some SDKs that Android needs to use instand of apk. Should I use FlowDroid? If yes, I will try to learn the implementation of FlowDroid firstly; |
@mbenz89 Many thanks. The I found this statement doesn't load the |
MIght the app class be phantom? Could you show your exclude list? |
@mbenz89 Thanks for your prompt reply. private static LinkedList<String> excludeList() {
if (excludeList == null) {
excludeList = new LinkedList<String>();
excludeList.add("java.");
excludeList.add("javax.");
excludeList.add("sun.");
excludeList.add("sunw.");
excludeList.add("com.sun.");
excludeList.add("com.ibm.");
excludeList.add("com.apple.");
excludeList.add("apple.awt.");
}
return excludeList;
} The |
@sscui If you do not want to analyze an Android application, you probably do not need to use FlowDroid. It mainly assists with taint analysis and generation of a dummy entry point for call graph generation that will call certain lifecycle methods and system/ui handlers. You probably just don't have all the dependencies that are used by your target code on the classpath. So either add them (if you need to analyze them as well) or allow phantom classes so that soot just generates empty dummies for referenced classes that are not on the classpath. For further questions, please use another issue instead of hijacking this one! @liuyuanOUC Strang. Is the class phantom? This also seems to be a classpath issue from a first look. If the class is phantom, I would suggest to make sure that soot can actually find the class, i.e. it is on the classpath. |
@mbenz89 Thank you. That's really strange. I will review the classpath and record my future solution here. |
@mbenz89 Good afternoon, good news! public static void main(String[] args) {
//spotbugs -- testing
String classesDir = "D:\\wkspace\\seed8\\dir\\spotbugs";
String mainClass = "edu.umd.cs.findbugs.LaunchAppropriateUI";
//set classpath
String jreDir = System.getProperty("java.home") + "\\lib\\jce.jar";
String jceDir = System.getProperty("java.home") + "\\lib\\rt.jar";
String path = jreDir + File.pathSeparator + jceDir + File.pathSeparator + classesDir;
Scene.v().setSootClassPath(path);
//add an intra-procedural analysis phase to Soot
TestCallGraphSootJar_3 analysis = new TestCallGraphSootJar_3();
PackManager.v().getPack("wjtp").add(new Transform("wjtp.TestSootCallGraph", analysis));
excludeJDKLibrary();
Options.v().set_process_dir(Arrays.asList(classesDir));
Options.v().set_whole_program(true);
//Options.v().set_app(true);
SootClass appClass = Scene.v().loadClassAndSupport(mainClass);
Scene.v().setMainClass(appClass);
Scene.v().loadNecessaryClasses();
//enableCHACallGraph();
enableSparkCallGraph();
PackManager.v().runPacks();
} If I replace SootClass appclass = Scene.v().loadClassAndSupport(mainclass);
Scene.v().setMainClass(appclass);
Scene.v().loadNecessaryClasses(); by Scene.v().loadNecessaryClasses();
SootClass appclass = Scene.v().getSootClass(mainclass);
Scene.v().setMainClass(appclass); , the program also works. |
Sorry for bumping a closed issue, but this is the only way I could contact @liuyuanOUC. @liuyuanOUC |
I'm trying to generate a method call graph for a jar file using a programmatic way.
Here is the main code:
Note
Exception
The statement
Scene.v().loadNecessaryClasses();
throw the following exception:I have searched a lot, but didn't get useful information. So need your help. Thanks!
The text was updated successfully, but these errors were encountered: