Running Soot

Felix Dekker edited this page Apr 24, 2018 · 27 revisions

Contributed by Eric Bodden, GitHub account

Download Jar Files

The first step is to download the Soot .jar file. You can download the latest release version of Soot from the Soot download page. In case, if you wish to download Soot, Jasmin, Polyglot package separately there are also options available on the page. Please visit the following to download the files: Soot Downloads

For the people who wish to have the latest features, Secure Software Engineering Group at Technische Universität Darmstadt provides a nightly build that is directly drawn from our Github repository. Usually the latest nightly build is the most stable version of Soot because tend to test code before we commit it. However, this may not always be true. You can find:

  • Soot release 3.0.1 here
  • nightly builds here.

Now we are ready to give Soot a try!

Using Soot as Command Line

Once, the .jar file is downloaded. Please use the following command to run the Soot: Java –jar soot.jar

1. Processing single files
Soot in general processes a bunch of classes. These classes can come in one of three formats:

  • Java source code, i.e. .java files,
  • Java bytecode, i.e. .class files, and
  • Jimple source, i.e. .jimple files.

In case you don’t know yet, Jimple is Soot’s primary intermediate representation, a three-address code that is basically a sort of simplified version of Java that only requires around 15 different kinds of statements. You can instruct Soot to convert .java or .class files to .jimple files or the other way around. You can even generate .jimple file from .java, and modify the .jimple with a normal text editor and then convert your .jimple file to .class, virtually hand-optimizing your program. So it means you can simplify your task by Soot easily.

The principle way to have Soot process two classes A and B is just to add them to the command line, which makes them “application classes”:
java -jar soot.jar A B

2. Processing entire directories
You can also process entire directories or JAR files using Soot, using the –process-dir option:
java -jar soot.jar -process-dir

To process a JAR file, just use the same option but provide a path to a JAR instead of a directory. Nice, eh? Be careful, though: If you apply the very same command again to the very same folder you will run into a problem now:

What happened? Well, as I noted earlier, Soot places the generated .class files into the folder sootOutput, which resides in the current directory “.”. Therefore Soot now processed the previously generated files, at the same time complaining about the fact that a class of name “A” resides at location ./sootOutput/A and therefore should actually have the name sootOutput.A, i.e. be in the sootOutput package. Therefore, when using the –process-dir option also use the –d option to redirect Soot’s output:
java -jar soot.jar -process-dir /dirpath -d /sootOutputdir

3. Processing certain types of files (.class / .java / .jimple)
Assume you have a directory that contains both A.java and A.class and you invoke Soot as before. In this case Soot will load the definition of A from the file A.class. This may not always be what you want. The –src-prec option tells Soot which input type it should prefer over others. There are four options:

  • c or class (default): favour class files as Soot source,
  • only-class: use only class files as Soot source,
  • J or jimple: favour Jimple files as Soot source, and
  • java: favour Java files as Soot source.

So e.g. -src-prec java will load A.java in the above example.

6. Application classes vs. library classes
Classes that Soot actually processes are called “application classes”. This is opposed to “library classes”, which Soot does not process but only uses for type resolution. Application classes are usually those explicitly stated on the command line or those classes that reside in a directory referred to via –process-dir.

When you use the -app option, however, then Soot also processes all classes referenced by these classes. It will not, however, process any classes in the JDK, i.e. classes in one of the java.* and com.sun.*packages. If you wish to include those too you have to use the special –i option, e.g. -i java.. See the guide for this and other command line options.

7. Output of .jimple or .java files
Soot cannot only produce .class files, it can also produce .jimple and .java files and others. You can select the output format using the –f option. If you use –f dava to decompile to Java please make sure that the file /lib/jce.jar is on Soot’s classpath.

8. Phase options
Soot supports hundreds of very fine grained options that allow you to tune all the analyses and optimizations to your needs, directly from the command line.

The general format of these command line options is -p PHASE OPT:VAL. To find the complete document of all phase options please click on the following link below:
http://www.sable.mcgill.ca/soot/tutorial/phase/

For instance, let’s say that we want to preserve the names of local variables (if possible) when performing an analysis within Soot. Then we can add the command line option -p jb use-original-names:true. A shortcut is -p jb use-original-names, where the true is implicitly assumed.

The current full list of command-line options can be found at: http://www.sable.mcgill.ca/soot/tutorial/usage/index.html

Table of Contents

Also check out Soot's webpage NOTE: If you find any bugs in those tutorials (or other parts of Soot) please help us out by reporting them in our issue tracker.

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.