[Soot-list] JDK Support and Soot's Classpath Setting

383 views
Skip to first unread message

Liu Yuan

unread,
Mar 11, 2021, 7:20:03 PM3/11/21
to soot-list
Hi, I have JDK16 installed, and using the following to create a CFG.

But I get an exception Unsupported class file major version 60, for SootClass appclass = Scene.v().loadClassAndSupport(mainClass);

I think soot can run in JDK 16, so the reason is that the class files to be analyzed is compied at a high JDK version.

So is there any method to solve it? If not, what is the supported scope of the JDK compiled version for the class files?

Besides, JDK 9+ remove the rt.jar and ice.jar. After searching, I learned that I only need to set prepend_classpat to load the necessary classes for soot to run. I don't know if it is correct.

Any suggestion is appreciated, thank you.

public static void main(String[] args) {

String classesDir = "./input/dataset/tracker-server.jar";
String mainClass = "org.traccar.Main";
TypeReferenceSequencesSolver analysis = new TypeReferenceSequencesSolver();
Options.v().set_prepend_classpath(true);
PackManager.v().getPack("wjtp").add(new Transform("wjtp.TypeReferenceSequencesSolver", analysis));

Options.v().set_process_dir(Arrays.asList(classesDir));
Options.v().set_whole_program(false);
Options.v().setPhaseOption("jb", "preserve-source-annotations:true");
Options.v().setPhaseOption("jj", "use-original-names:true");
Options.v().set_keep_line_number(true);

SootClass appclass = Scene.v().loadClassAndSupport(mainClass);
Scene.v().setMainClass(appclass);
Scene.v().loadNecessaryClasses();

PackManager.v().runPacks();
}

Best,
Yuan
_______________________________________________
Soot-list mailing list
Soot...@CS.McGill.CA
https://mailman.CS.McGill.CA/mailman/listinfo/soot-list

Liu Yuan

unread,
Mar 14, 2021, 8:59:34 AM3/14/21
to Andreas Peter Dann, soot-list
Hi Andreas, thank you very much  for your reply!

I tried it again. Unfortunately, it doesn’t work. 

My case is following. Could you please give me an example at JDK >=9? thank you.

public static void main(String[] args) {

String classesDir = "/Users/liuyuan/Workspaces/testCFGbySoot/testCFGbySoot/target/classes/";
String mainClass = "org.yliu.test.soot.APP";
TypeReferenceSequencesSolver analysis = new TypeReferenceSequencesSolver();
//Options.v().set_prepend_classpath(true);
PackManager.v().getPack("wjtp").add(new Transform("wjtp.TypeReferenceSequencesSolver", analysis));
String jmodsPath = "/opt/homebrew/opt/openjdk/libexec/openjdk.jdk/Contents/Home/jmods";
Options.v().set_soot_classpath("VIRTUAL_FS_FOR_JDK" + File.pathSeparator + jmodsPath);

Options.v().set_process_dir(Arrays.asList(classesDir));
Options.v().set_whole_program(false);
Options.v().setPhaseOption("jb", "preserve-source-annotations:true");
Options.v().setPhaseOption("jj", "use-original-names:true");
Options.v().set_keep_line_number(true);

SootClass appclass = Scene.v().loadClassAndSupport(mainClass);
Scene.v().setMainClass(appclass);
Scene.v().loadNecessaryClasses();

PackManager.v().runPacks();
}

2021年3月14日 06:20,Andreas Peter Dann <ad...@mail.uni-paderborn.de> 写道:

Hi Yuan,

thanks for your question. Unfortunately, the current documentation is not very clear on that topic because only a few people used Soot to analyze ByteCode for Java Version >= 9.
At the end of the readme in the repo you'll find paragraph explaining how to run soot with Java >=9
https://github.com/soot-oss/soot

In a nutshell,
- please use the latest version from Maven Central https://soot-oss.github.io/soot/
- run soot with a JDK >= 8 (maybe it works with an older JDK but I've never tested it)
- if you want to run soot on JDK 8 but want to analyze the ByteCode of Java >=9  please run

java -cp soot-trunk.jar soot.Main -cp VIRTUAL_FS_FOR_JDK

the string VIRTUAL_FS_FOR_JDK tells Soot to look into the virtual file system of JDKs >=9 to find the base classes.

Please feel free to improve the current documentation by making a pull request.

Best,

Andreas
---------

Am 12.03.21, 01:20 schrieb "Soot-list im Auftrag von Liu Yuan" <soot-lis...@CS.McGill.CA im Auftrag von liu...@fastmail.com>:

Andreas Peter Dann

unread,
Mar 14, 2021, 5:33:51 PM3/14/21
to Liu Yuan, soot-list

Hi,

 

when you execute soot on JDK 8 and want to analyze bytecode >= JDK 9 using a classpath but not the modulepath feature

 

then configure soot as follows

 

Options.v().set_prepend_classpath(true);
Options.v().set_process_dir(Arrays.asList(applicationClassPath().split(File.pathSeparator)));
Options.v().set_claspath(sootClassPath());
 
 
Best,
 
Andreas
 
IF you get any errors than please open an issue in Soot and post the whole error log there.
Reply all
Reply to author
Forward
0 new messages