Reputation: 66
Sorry if it's a basic question but even after searching a lot, I'm not able to figure this out.
I'm using SOOT to instrument my code. I'm able to check whether my statement accesses a field using stmt.containsFieldRef()
but I want to differentiate between a statement writing a value to the field and another which is just reading its value.
Is there a pre-defined method to do that or is parsing the statement the only option?
Upvotes: 2
Views: 222
Reputation: 3554
I also met this question and I finally figure it out by myself.
try{
if (stmt.getDefBoxes().get(0).getValue().getClass() == Class.forName("soot.jimple.StaticFieldRef") ||
stmt.getDefBoxes().get(0).getValue().getClass() == Class.forName("soot.jimple.internal.JInstanceFieldRef")){
isWrite = true;
}else{
isWrite = false;
}
}catch (Exception e){}
This can work because I found that stmt.getDefBoxes()
return a list related to the left-hand-side variable. If left-hand-side variable is of type soot.jimple.internal.JimpleLocal
, it is a read action; If it is of type class soot.jimple.internal.JInstanceFieldRef
or class soot.jimple.StaticFieldRef
, it is a write action.
Upvotes: 1