[Soot-list] How check for method calls such that the method call is defined in a particular class?

Quentin Sabah quentin.sabah at inria.fr
Sun May 26 07:16:41 EDT 2013


Hi John,

> I want to check all the statements in a method and for each statement, check whether it contains a method call that comes from the System class or the Math class (e.g., System.out.println or Math.abs). Or if you know how to determine whether the method comes from any class in the standard Java API, that's even better. I need to separate "safe" method calls (e.g., System.out.println) from method calls whose methods are not part of the standard Java API. I suppose if I can identify just method calls from System and Math, that's good enough.

The SootMethod objects have a very handy isJavaLibraryMethod() method doing just what you need.

> I tried checking each statement with instanceof JInvokeStmt, but oddly, that matches only Jimple-generated methods that have the name "<init>" (I don't understand the "<init>" method, but that's OK). 

<init> is the name for constructor methods, it is in the Java Specification.

> 1. How should I extract the expressions from the statement? I see there is a getInvokeExpr() method in the soot.jimple.Stmt interface, but the api doesn't say what happens if the statement can't find an invokeExpr. Does it return -1?

Yes, use getInvokeExpr(), I guess it will return null if the statement has no invoke expression (try and you'll see anyway). How could it return -1, the javadoc says it returns an InvokeExpr reference!

> 2. Once I have a JVirtualInvokeExpr, how can I retrieve the method's containing class? For example, if the invoking expression is System.out.println, how can I retrieve "System"? I tried using getName (for JInvokeStmt), and it returns just the method name without the class (e.g., println). If you know how to retrieve the entire System.out.println, that's good enough because I can use indexOf to search for "System". Should I use SootMethod's getSignature and search for "System" using indexOf?


Let say getInvokeExpr() returned you an object with the InvokeExpr interface. There is the getMethod() method that returns a SootMethod instance. From there, use isJavaLibraryMethod() or getDeclaringClass() or refer to the API.

Regards.

-- 
Quentin Sabah, CIFRE Ph.D. student
Grenoble University
INRIA-SARDES                   | STMicroelectronics/AST
Montbonnot, France             | Grenoble, France
mailto:quentin.sabah at inria.fr  | mailto:quentin.sabah at st.com
phone: +33 476 61 52 42        | phone: +33 476 58 44 14



More information about the Soot-list mailing list