Jimple
What is Jimple? Jimple is the intermediate representation IR of Soot, and thus SootUp.
Soot's intention is to provide a simplified way to analyze JVM bytecode. JVM bytecode is stack-based, which makes it difficult for program analysis.
Java source code, on the other hand, is also not quite suitable for program analysis, due to its nested structures.
Therefore, Jimple aims to bring the best of both worlds, a non-stack-based and flat (non-nested) representation.
For this purpose Jimple was designed as a representation of JVM bytecode which is human readable.
Info
To learn more about jimple, refer to the thesis by Raja Vallee-Rai.
Lets have a look at the following Jimple code representing Java code of a HelloWorld
class.
The Java Sourcecode is the easiest representation - So why all the fuzz and just use that?
Sometimes we have no access to the sourcecode but have a binary with the bytecode.
For most People reading bytecode is not that intuitive. So SootUp generates Jimple from the bytecode.
Jimple is very verbose, but makes everything explicit, that the JVM does implicitly and transforms the stack-machine strategy by a register-machine strategy i.e. Variable (Local
) handling .
Jimple Grammar Structure
Jimple mimics the JVMs class file structure.
Therefore it is object oriented.
A Single Class (or Interface) per file.
Three-Address-Code which means there are no nested expressions.
(nested expressions can be modeled via Locals that store intermediate calculation results.)
Signatures and ClassTypes
Signatures are used to identify Classes,Methods or Fields uniquely/globally.
Sidenote: Locals, do not have a signature, since they are referenced within method boundaries.
SootClass
A SootClass
consists of SootFields and SootMethods.
It is referenced by its global identifier the ClassType
like java.lang.String
.
SootField
A SootField is a piece of memory which can store a value that is accessible according to its visibility modifier.
It is referenced by its FieldSignature like <java.lang.String: int hash>
.
SootMethod and its Body
The interesting part is a method. A method is a "piece of code" that can be executed.
It is referenced by its MethodSignature like <java.lang.Object: java.lang.String toString()>
.
More about the Body of the SootMethod.