[Soot-list] Is there a way to get the object whose method is being called?

Clarissa Grixti clarissa_14_4 at hotmail.com
Mon Mar 19 06:29:54 EDT 2012


Hey eric,
When you said  the call statement of the call edge, did you mean that you need the edge containing the statement in the source part?So for example I have the flow : 
doStuff -> label. setText 
and so the variable that I need is label. However setText does not point to any other methods, and so no edge will result from there. Now I tried the following code (this will be called after I call the CHATransformer):
 public static void method1() {        SootMethod src = Scene.v().getMainClass().getMethodByName("doStuff");        CallGraph cg = Scene.v().getCallGraph();
        Iterator<Edge> edges = cg.edgesOutOf(src);        while (edges.hasNext()) {            Edge e = edges.next();            Stmt stmt = e.srcStmt();
            InvokeExpr ie = stmt.getInvokeExpr();                        InstanceInvokeExpr iie = (InstanceInvokeExpr)ie;            Value v = iie.getBase();
            System.out.println("TYPE: " + v.getType().toString());        }            }
Stmt can only be retrieved from that method, and I'm assuming that in this case, since the egde will is from doStuff to some other method, than the statement in stmt will be that of doStuff. But if setText does not point to a method, how will I be able to get the srcStmt?
In addition when I tried to cast the invoke expression, im getting the following exception:  Exception in thread "main" java.lang.ClassCastException: soot.jimple.internal.JStaticInvokeExpr cannot be cast to soot.jimple.InstanceInvokeExpr. should it be casted in some other way?
Thanks for the help and regards


> From: eric.bodden at ec-spride.de
> Date: Sun, 18 Mar 2012 16:02:33 +0100
> Subject: Re: [Soot-list] Is there a way to get the object whose method is being called?
> To: clarissa_14_4 at hotmail.com
> CC: soot-list at sable.mcgill.ca
> 
> Hi Clarissa.
> 
> As Zheng wrote, you cannot determine the object. But possible what you
> actually mean is the variable holding that object at runtime. In this
> case you can get a handle to this variable as follows:
> 
> 1.) extract the call statement from the call edge
> 2.) on this stmt perform stmt.getInvokeExpr() to extract the invoke expression
> 3.) cast this invoke expression to an InstanceInvokeExpr on which you
> can then call getBase()
> 4.) getBase() returns a value, which you should be able to cast to a
> local variable
> 
> Cheers,
> Eric
> 
> On 18 March 2012 15:09, Clarissa Grixti <clarissa_14_4 at hotmail.com> wrote:
> > Hey all,
> >
> >  I am creating a call graph for my system in order to be able to get the
> > target nodes for a particular method. Is there a way to be able to identify
> > the object whose method is being called? I did manage to get the declaring
> > class for the method, but what I need is the actual object calling a
> > specific method.
> >
> > Thanks and regards
> >
> > _______________________________________________
> > Soot-list mailing list
> > Soot-list at sable.mcgill.ca
> > http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list
> >
> 
> 
> 
> -- 
> Eric Bodden, Ph.D., http://bodden.de/
> Head of Secure Software Engineering Group at EC SPRIDE
> Principal Investigator in Secure Services at CASED
> Tel: +49 6151 16-75422    Fax: +49 6151 16-72051
> Room 3.2.14, Mornewegstr. 30, 64293 Darmstadt
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.cs.mcgill.ca/pipermail/soot-list/attachments/20120319/499a75d0/attachment.html 


More information about the Soot-list mailing list