Jimple Values
An Immediate
has a given Type and consists of a Local ("a Variable", "Something that contains a Value") or a Constant ("Something that is a Value").
Local
A Local is a variable and its scope is inside its method i.e. no referencing from outside a method.
Values can be assigned to Locals via JIdentityStmt or JAssignStmt.
Constant
represents an actual value itself like 42
or "This is a String"
.
Constants are usually assigned to Local
s or Ref
s.
There exists a constant entity for every Primitive Type.
Expr
An expression is a language construct that calculates an operation and returns a value.
E.g. a binary operation AbstracBinopExpr
such as an addition a + b
, an AbstractInvokeExpr
such as virtualinvoke $stack2.<java.io.PrintStream: void println(int)>(1);
or an UnaryExpr
such as !valid
.
And a bunch more!
Ref
JArrayRef
| $arr[1] = 42;
$anotherLocal = arr[99];
|
referencing an array position.
JFieldRef
JFieldRef
s are referencing a SootField
via its FieldSignature
JStaticFieldRef
like <SomePackage.ExampleClass: fieldname>
JInstanceFieldRef
like r1.<SomePackage.ExampleClass: fieldname>
You can see the JInstanceFieldRef has the corresponding Local instance that points to the instance of the object which is holding the field.
IdentityRef
The IdentityRef makes those implicit special value assignments explicit.
JThisRef
| @this: package.fruit.Banana
|
represents the this pointer of the current class.
JCaughtExceptionRef
represents the value of the thrown exception (caught by this exceptionhandler).
JParameterRef
| i0 := @parameter0
i1 := @parameter1
|
represents a parameter of a method, identified by its index.
Good to know
A lot of the SootUp APIs return the Value
Interface. To determine and handle its subtypes you can make use of instanceof.
But this could escalate to a huge if-else-tree - almost a forest. To mitigate such scenario you can implement a subclass of AbstractValueVisitor
.
Just subclass the methods to the respective Value
s you need to handle. This is visitor acts like a switch-case, implemented via two dynamic calls.