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

Dean, John John.Dean at park.edu
Sat May 25 19:32:32 EDT 2013


Hi all,

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.

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). In looking at my generated Jimple code, I see that my source code method calls (like println) are embedded in Jimple statements that contain "virtualinvoke." For example:

temp$5 = virtualinvoke temp$4.<java.lang.StringBuffer: java.lang.String toString()>()
virtualinvoke temp$3.<java.io.PrintStream: void println(java.lang.String)>(temp$5)

In perusing the soot api, I see that there is a JVirtualInvokeExpr class.

So should I check each statement by extracting the statement's expressions, for each expression use instanceof JVirtualInvokeExpr, and if there's a match, then somehow retrieve the method's containing class?

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?

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?

Thanks,
John

-----Original Message-----
From: soot-list-bounces at sable.mcgill.ca [mailto:soot-list-bounces at sable.mcgill.ca] On Behalf Of Rohan Padhye
Sent: Saturday, May 25, 2013 12:18 AM
To: Dean, John
Cc: soot-list at sable.mcgill.ca
Subject: Re: [Soot-list] How check for array argument?

Hello John,

1. You can look at the "type" of the "Value" being passed as the argument. Local variables of "ArrayType" will be what you would want to look for.

2,3,4. The calling convention is the same as that of Java. While arguments themselves are passed by value, these can include reference variables which refer to objects or arrays (See "RefLikeType"), and each of these type of arguments can be used in any way by the called method including changing the contents of the referenced heap memory.

Regards,
Rohan


On Saturday 25 May 2013 09:13 AM, Dean, John wrote:
> Hi all,
>
> 1. Can someone tell me how to detect an array being passed to a Jimple method (i.e., an array base argument in an InvoleExpr)?
> I know how to detect an array reference (instanceof ArrayRef), but that's not what I need; I need the array itself.
>
> 2. Here's why I'm asking the question above. I need to know whether a method is potentially "dangerous" in that it contains an argument that could potentially change something that affects my original calling module. Is it true that Jimple method calls use pass by value in which case I don't need to worry about most argument types?
>
> 3. I don't think pass-by-value will help to make the method call safe if an array is passed (because the array's contents could be changed within the method). Right?
>
> 4. Is it true that there's no way to pass an object to a method, so I don't need to worry about that situation? No objects in Jimple, right?
>   
> Thanks,
> John
> _______________________________________________
> Soot-list mailing list
> Soot-list at sable.mcgill.ca
> http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list

--
Regards,
Rohan Padhye

_______________________________________________
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