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

Andreas Peter Dann adann at mail.uni-paderborn.de
Sun Mar 14 17:33:34 EDT 2021


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.




Von: Liu Yuan <liuyuan at fastmail.com>
Datum: Sonntag, 14. März 2021 um 13:59
An: Andreas Peter Dann <adann at mail.uni-paderborn.de>
Cc: soot-list <soot-list at CS.McGill.CA>
Betreff: Re: [Soot-list] JDK Support and Soot's Classpath Setting

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 <adann at mail.uni-paderborn.de<mailto:adann at 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-list-bounces at CS.McGill.CA im Auftrag von liuyuan at fastmail.com>:

   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-list at CS.McGill.CA
   https://mailman.CS.McGill.CA/mailman/listinfo/soot-list

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.CS.McGill.CA/pipermail/soot-list/attachments/20210314/fc3fba30/attachment-0001.html>


More information about the Soot-list mailing list