[Soot-list] How to access/dump the content of a object
reference from def box
Jimmy
myxlinux at hotmail.com
Wed Apr 9 16:31:12 EDT 2008
Thank you all.
If I really want to grab the value of a field in an object, what should I do?
For example, like the statement in the previous email:
$r0 = new MyTestClass
And the definition of MyTestClass is:
class MyTestClass{
int field1;
}
I want to get someting like $r0.field1 in the run-time, which means I have to
insert print statement with $r0.field1 as parameter.
My code is as follows,
public void dumpFieldValues(ValueBox vb, Stmt stmt, Chain units){
Value var = vb.getValue();
Type type = var.getType();
if(type.toString().equals("MyTestClass")){
SootClass sClass = soot.SootResolver.v().resolveClass(type.toString(), SootClass.SIGNATURES);
SootField sField = sClass.getField("field1");
SootFieldRef sFieldRef = sField.makeRef();
InstanceFieldRef ref = Jimple.v().newInstanceFieldRef(var, sFieldRef);
SootMethod toCall = Scene.v().getMethod("<instrument.MyInstrumentation: void printIntField(int)>");
InvokeStmt toAdd = Jimple.v().newInvokeStmt(Jimple.v().newStaticInvokeExpr(toCall.makeRef(), ref));
units.insertAfter(toAdd, stmt);
}
}
but it throws exception on the line:
"InvokeStmt toAdd = Jimple.v().newInvokeStmt(Jimple.v().newStaticInvokeExpr(toCall.makeRef(), ref));"
The exception is:
Exception in thread "main" java.lang.RuntimeException: Box VB(null) cannot contain value: $r0.<perturb.MyTestClass: int field1>(class soot.jimple.internal.JInstanceFieldRef)
at soot.AbstractValueBox.setValue(AbstractValueBox.java:42)
at soot.jimple.internal.ImmediateBox.<init>(ImmediateBox.java:40)
at soot.jimple.Jimple.newImmediateBox(Jimple.java:861)
at soot.jimple.internal.JStaticInvokeExpr.<init>(JStaticInvokeExpr.java:45)
at soot.jimple.Jimple.newStaticInvokeExpr(Jimple.java:514)
.....
Is it the reason that "ref" and "int" are not compatible? Can anyone help me out? Thanks.
Jimmy
> Date: Wed, 9 Apr 2008 22:00:35 +0200
> From: eric.bodden at mail.mcgill.ca
> To: soot-list at sable.mcgill.ca
> Subject: Re: [Soot-list] How to access/dump the content of a object reference from def box
>
> Hi all.
>
> > >From the type's fully qualified path name, you can create the SootClass
> > using the SootResolver method:
> >
> > public SootClass resolveClassAndSupportClasses(String className)
>
> IMHO actually the default way is to just consult the Scene to get the
> right class. This should be faster.
>
> Eric
>
> --
> Eric Bodden
> Sable Research Group
> McGill University, Montréal, Canada
> _______________________________________________
> Soot-list mailing list
> Soot-list at sable.mcgill.ca
> http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list
_________________________________________________________________
Going green? See the top 12 foods to eat organic.
http://green.msn.com/galleries/photos/photos.aspx?gid=164&ocid=T003MSN51N1653A
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.CS.McGill.CA/pipermail/soot-list/attachments/20080409/2d35c3a8/attachment.htm
More information about the Soot-list
mailing list