[Soot-list] Transform of call sites

Hal Hildebrand hal.hildebrand at gmail.com
Sun Jul 25 22:55:04 EDT 2010


Just to be sure I'm not completely mad, he's the essential code which I'm hoping will be correct:

        Iterator stmtIt = body.getUnits().snapshotIterator();
        while (stmtIt.hasNext()) {
            Stmt stmt = (Stmt) stmtIt.next();
	    if (stmt.containsInvokeExpr()) {
                ValueBox invocation = stmt.getInvokeExprBox();
                InvokeExpr expr = (InvokeExpr) invocation.getValue();
                Local synthesized = newLocal(UUID.randomUUID().toString(), expr.getType(), body);
                Unit invocationUnit = Jimple.v().newAssignStmt(synthesized, expr);
                units.insertBefore(stmt, invocationUnit);
                invocation.setValue(synthesized);
            }
        }

Assuming this transformation is correct and complete, I can then insert my pre-sequence and append my post-sequence around the new invocationUnit.

On Jul 25, 2010, at 12:06 PM, Hal Hildebrand wrote:

> D'oh!
> 
> Thanks a million.
> 
> On Jul 25, 2010, at 9:40 AM, Patrick Lam wrote:
> 
>> On 25/07/10 08:50 AM, Hal Hildebrand wrote:
>>> I need to make a transform of method bodies for call sites to specific methods.  Basically, I need to provide a pre and post sequence of instructions around each of these targeted method calls.  For InvokeStatement units, I know how to do this.  For the general case, my current theory is that I'd have to iterate over the units and look at the value boxes of the unit to see if the implement the InstanceInvokeExpr interface.  Then, I'd have to replace this value with a new local, and insert the pre sequence, a new assignment unit to this new local using the invocation statement as the assigned value, then the post sequence.  All before the original unit that contained the method I'm interested in.
>>> 
>>> Does this sound sane, or is there a better way, or perhaps some examples of doing something similar somewhere?
>> 
>> Stmt defines .containsInvokeExpr() as well as .getInvokeExpr(). That may be what you're looking for.
>> 
>> pat
>> 
> 



More information about the Soot-list mailing list