[Soot-list] Two interesting questions of Soot

Ye Henry Tian ytian8 at cs.mcgill.ca
Sun Feb 27 00:23:44 EST 2005


Hi all

I have detected two interesting questions in soot, which I cannot understand:

1. Questions of using the method: Scene.v().getMethod().
In the tutorial "Creating a class from scratch with Soot", it says we can
create a Jimple stmt like this:

 // insert "tmpRef.println("Hello world!")"
    {
        SootMethod toCall = Scene.v().getMethod
          ("<java.io.PrintStream: void println(java.lang.String)>");
        units.add(Jimple.v().newInvokeStmt
            (Jimple.v().newVirtualInvokeExpr
               (tmpRef, toCall.makeRef(), StringConstant.v("Hello
world!"))));
    }

However I have detected something, I donot understand, for example:
It seems stupid, but if I want to first get a method
"<java.lang.StringBuffer: void <init>(java.lang.String)>" and then change
its argument to "int" type (this is stupid, since I can directly get a int
type argument for this method), so I do something like this:

SootMethod toCall = Scene.v().getMethod("<java.lang.StringBuffer: void
<init>(java.lang.String)>");
arglist.add(IntType.v());
toCall.setParameterTypes(arglist);

this is ok, and works fine, but the problem is that if I want to get the
method "<java.lang.StringBuffer: void <init>(java.lang.String)>" again,
e.g

SootMethod toCall = Scene.v().getMethod("<java.lang.StringBuffer: void
<init>(java.lang.String)>");
arglist.add(IntType.v());
toCall.setParameterTypes(arglist);

SootMethod toCall = Scene.v().getMethod("<java.lang.StringBuffer: void
<init>(java.lang.String)>");

In run time it will raise exception says that the method is nonexistence.
I don't understand the reason. Is it because I change its argument type?
but I thought, I just copy the method in to a SootMethod variable and
modify it, how come it effect the Scene? Can someone explain this question
for me!?? Thanks a lot! I want to know how the method
Scene.v().getMethod() works.

2. I have detected something interesting of the Jimple code:
If we get the Jimple file of a class file like this:
java soot.Main -f J classfilename

The Jimple code of the method body in the file "classfilename.jimple" is a
bit different if we write a "BodyTransformer" and iterate the stmt
sequence of the Jimple body and print out the stmt:

Iterator it = body.getUnits().iterator();
        while (it.hasNext()) {
            Stmt s = (Stmt) it.next();
            System.out.println("stmt: "+s);
        }

for instance, I have notice for the stringbuffer initializing there is a
bit different, if you look at the Jimple code in a Jimple file, it may
look something like this:

$r2 = new java.lang.StringBuffer;
$r3 = staticinvoke <java.lang.String: java.lang.String
valueOf(java.lang.Object)>(r1);
specialinvoke $r2.<java.lang.StringBuffer: void
<init>(java.lang.String)>($r3);

but if you use a bodytransformer to iterate the body, you got something
like this:

$r2 = new java.lang.StringBuffer;
specialinvoke $r2.<java.lang.StringBuffer: void <init>()>();
$r3 = virtualinvoke $r2.<java.lang.StringBuffer: java.lang.StringBuffer
append(java.lang.String)>(r1);

Can anyone explain the reason for this!? Thanks a lot!

Best,

Henry
--
Ye Henry Tian
School of Computer Science
McGill University
Montreal, Quebec, Canada
Email: ye.tian at mail.mcgill.ca
or:    ytian8 at cs.mcgill.ca
       ye.henry.tian at gmail.com
       tianye_316 at hotmail.com





More information about the Soot-list mailing list