[Soot-list] soot

Peng Li lipeng360 at gmail.com
Sat Sep 23 23:02:56 EDT 2006


Hi buddies
I am using soot to obtain the return value, I can do dynamic analysis by
inserting codes to class file(Thanks to Richard for your clear explanation
abt how to make my first soot program and Thanks to Eric abt how to set path
for soot class). However, I need to do the analysis statically. For example,
I have a simple program as following,

public class helloworld {
 public static void main(String[] args) {
  String y=foo();
  System.out.println(y);
 }
    public static String foo()
    {   String x="hello world";
  return x;
    }
}

I would like to get he return value of foo() statically. So I used soot to
find the return statement (ReturnStmt) and print out the operand. I found
the value is not "hello world " but a "r0". It looks like the program just
prints out the stack position. Could anyone give me some help? Any
suggestion is appreciated.

Cheers
Peng
I attached the source of my program and the generated jimple file for
helloworld.class.


import soot.*;
import soot.jimple.*;
import soot.util.*;
import java.util.*;

public class ReturnInstrumenter extends BodyTransformer{
    private static ReturnInstrumenter instance = new ReturnInstrumenter();
    private ReturnInstrumenter() {}

    public static ReturnInstrumenter v() { return instance; }

    public static void main(String[] args)
    {
     String[] a={"helloworld"};
     Scene.v
().setSootClassPath("C:/workspace/Hello;C:/j2sdk1.4.2_12/jre/lib/rt.jar");
     PackManager.v().getPack("jtp").add(new Transform("jtp.instrumenter",
ReturnInstrumenter.v()));
        Scene.v().addBasicClass("java.io.PrintStream",SootClass.SIGNATURES);
        soot.Main.main(a);
    }

 protected void internalTransform(Body body, String phase, Map options) {
  SootMethod method = body.getMethod();
  System.out.println("instrumenting method : " + method.getSignature());
  Chain units = body.getUnits();
  Iterator stmtIt = units.snapshotIterator();
  while(stmtIt.hasNext())
  {
   Stmt stmt = (Stmt) stmtIt.next();
   if(stmt instanceof ReturnStmt)
   {

    System.out.println(((ReturnStmt) stmt).getOp().toString());

   }}}}
Jimple for helloworld.class

public class helloworld extends java.lang.Object
{

    public static void main(java.lang.String[])
    {
        java.lang.String[] args;
        java.lang.String y;
        java.io.PrintStream $r0;

        args := @parameter0: java.lang.String[];
        y = staticinvoke <helloworld: java.lang.String foo()>();
        $r0 = <java.lang.System: java.io.PrintStream out>;
        virtualinvoke $r0.<java.io.PrintStream: void println(
java.lang.String)>(y);
        return;
    }

    public static java.lang.String foo()
    {
        java.lang.String x;

        x = "hello world";
        return x;
    }

    public void <init>()
    {
        helloworld this;

        this := @this: helloworld;
        specialinvoke this.<java.lang.Object: void <init>()>();
        return;
    }
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.CS.McGill.CA/pipermail/soot-list/attachments/20060924/cd2243e2/attachment.htm


More information about the Soot-list mailing list