[Soot-list] Getting jimple methods body
Marc-André Laverdière
marc-andre.laverdiere-papineau at polymtl.ca
Wed Oct 16 12:18:20 EDT 2013
Hello Mike,
When a statement is a method call, the Stmt object contains an
InvokeExpr statement, which will then have a SootMethodRef that
transparently gets resolved to a SootMethod. Since, by default, you have
a Unit object, you need to do something like this:
((Stmt)u).getInvokeExpr().getMethod()
As for getting the active body and the chain of units, the only caveat
is to check if there is an active body or not. Soot is fast-fail, so you
get an exception if you try to get a body when there isn't one.
I hope that helps!
Marc-André Laverdière-Papineau
Doctorant - PhD Candidate
On 10/16/2013 11:11 AM, Mike Shah wrote:
> Hello,
>
> I am analyzing a series of jimple statements, and if they are methods I
> would like to get the methods body.
>
> Here is a chunk of sample code of what I am trying to do.
>
> // If our statement is invoking then I claim we're calling some method
> if(stmt.containsInvokeExpr())
> // Check if the scene contains this method
> if(Scene.v().containsMethod(stmt.toString()))
> // I've tried to then get the method two different ways,
> settling for the uncomment code below
> //SootMethod method = ((InvokeExpr)stmt).getMethod();
> SootMethod method = Scene.v().getMethod(stmt.toString());
> // Load any supporting classes -- I'm not sure if I need
> this step at all, but I thought we may need the class.
> SootClass classWeNeedToLoad = method.getDeclaringClass();
>
> Scene.v().loadClassAndSupport(classWeNeedToLoad.toString());
> // Then I think I want to get the methods activeBody next so
> we can see the stmt's inside of it
> Body jimpleCodeBodyOfMethod = method.getActiveBody();
> // Then finally Iterate through a chain of units, producing
> a new series of jimple stmts
>
> Any help is sincerely appreciated.
>
> Thanks for your time,
> Mike
>
>
> _______________________________________________
> Soot-list mailing list
> Soot-list at sable.mcgill.ca
> http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list
>
More information about the Soot-list
mailing list