[Soot-list] Help!!! interprocedural and intraprocedural analysis!!!
hxj
hxj163 at gmail.com
Sat Mar 10 11:13:32 EST 2012
Hi,
I have some questions about soot.
Now I have a java file like this:
package testers;
public class CallGraphsTest
{
public static void main(String[] args){
new CallGraphsTest().a();
}
public void a(){
class D extends C{
@Override
public void foo(){
int x =5;
}
public void ta(){}
}
D b =new D();
doStuff(b);
}
public static void doStuff(C a) {
}
}
class C
{
public void foo() {
bar();
}
public void bar() {
}
}
I want to analyze a(). So I developed the following program:
package dk.brics.soot.callgraphs;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import soot.Body;
import soot.MethodOrMethodContext;
import soot.PackManager;
import soot.Scene;
import soot.SceneTransformer;
import soot.SootClass;
import soot.SootMethod;
import soot.Transform;
import soot.Unit;
import soot.jimple.*;
import soot.jimple.Stmt;
import soot.jimple.toolkits.callgraph.CHATransformer;
import soot.jimple.toolkits.callgraph.CallGraph;
import soot.jimple.toolkits.callgraph.Targets;
import soot.toolkits.graph.ExceptionalUnitGraph;
import soot.toolkits.graph.UnitGraph;
public class CallGraphData
{
public static void main(String[] args) {
List<String> argsList = new ArrayList<String>(Arrays.asList(args));
argsList.addAll(Arrays.asList(new String[]{
"-w",
"-main-class",
"testers.CallGraphsTest",//main-class
"testers.CallGraphsTest",//argument classes
}));
PackManager.v().getPack("wjtp").add(new
Transform("wjtp.myTrans", new SceneTransformer() {
@Override
protected void internalTransform(String phaseName, Map options) {
CHATransformer.v().transform();
SootClass sClass =
Scene.v().loadClassAndSupport("testers.CallGraphsTest");
sClass.setApplicationClass();
Iterator methodIt = sClass.getMethods().iterator();
while (methodIt.hasNext()) {
SootMethod m = (SootMethod)methodIt.next();
Body b = m.retrieveActiveBody();
UnitGraph g = new ExceptionalUnitGraph(b);
Iterator unitIt = g.iterator();
while (unitIt.hasNext()) {
Unit s = (Unit) unitIt.next();
Stmt tmp = (Stmt) s;
System.out.println(tmp.toString());
}
}
}
}));
args = argsList.toArray(new String[0]);
soot.Main.main(args);
}
}
And I got the running result for the method a() is:
r0 := @this: testers.CallGraphsTest
$r1 = new testers.CallGraphsTest$1D
specialinvoke $r1.<testers.CallGraphsTest$1D: void
<init>(testers.CallGraphsTest)>(r0)
r2 = $r1
staticinvoke <testers.CallGraphsTest: void doStuff(testers.C)>(r2)
return
But actually, I want to analyse the inner class D in the method a(). So
how could I extract and then go into this inner class D to anlysis the
methods and statments in this inner class?
Looking forwards to your reply!
Best regards,
Eve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.cs.mcgill.ca/pipermail/soot-list/attachments/20120310/6a32fe67/attachment-0001.html
More information about the Soot-list
mailing list