[Soot-list] Getting jimple methods body

Mike Shah mshah.475 at gmail.com
Wed Oct 16 12:45:03 EDT 2013


Thank you for your help Marc-André. (Posting solution below)

It turns out the line:

 if(Scene.v().containsMethod(stmt.toString())) was throwing an exception
for some reason.

I removed this, and then just did as you suggested:
SootMethod method = ((Stmt)u).getInvokeExpr().getMethod();

if(method.hasActiveBody){
  // proceed with analysis
}

_______________________________
Mike Shah
Graduate Student
Tufts University
Halligan 107
http://www.eecs.tufts.edu/~mshah08/


On Wed, Oct 16, 2013 at 12:18 PM, Marc-André Laverdière <
marc-andre.laverdiere-papineau at polymtl.ca> wrote:

> 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
> >
> _______________________________________________
> Soot-list mailing list
> Soot-list at sable.mcgill.ca
> http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.cs.mcgill.ca/pipermail/soot-list/attachments/20131016/7b7ca834/attachment.html 


More information about the Soot-list mailing list