[Soot-list] How to get a "this" reference?
Eric Bodden
bodden at st.informatik.tu-darmstadt.de
Tue Jun 8 03:19:55 EDT 2010
Hi Kanad.
> // Get the getClass() method
> SootClass pClass = thisMethod.getDeclaringClass();
> while(pClass.hasSuperclass())
> {
> pClass = pClass.getSuperclass();
> }
There's no need to walk the hierarchy. getClass() is declared on
java.lang.Object. Hence, you can just do this:
pClass = Scene.v().getSootClass("java.lang.Object");
> SootMethod gcCall = pClass.getMethod("java.lang.Class getClass()");
>
> // Assign "tmpClass = getClass();"
> Local tmpClass = Jimple.v().newLocal("temp",
> RefType.v("java.lang.Class"));
The above may break if your code already contains a local called
"temp". It is safer to use a soot.javaToJimple.LocalGenerator. This
class generates fresh locals.
> body.getLocals().add(tmpRef);
> AssignStmt toAssign = Jimple.v().newAssignStmt(#####, \\ What to use here,
> is what I haven't figured out
> Jimple.v().newVirtualInvokeExpr(tmpRef,
> gcCall.makeRef()));
First create a fresh Jimple local with the type of "this". Let's call
this local x.
Then assign to x an IdentityStmt containing a ThisRef. After the
assignment, x will hold a reference to "this".
Eric
More information about the Soot-list
mailing list