[Soot-list] Help!!How to get into the inner class and analysis it
hxj
hxj163 at gmail.com
Sat Mar 10 16:17:17 EST 2012
Hi Developers:
I have a file CallGraphsTest.java and I want to analyse the method a();
so I created CallGraphEx.java to analyse the CallGraphsTest.java:
public class CallGraphsTest
{
public static void main(String[] args){
new CallGraphsTest().a();
}
public void a(){
final C cc = new C();
class D extends C{
@Override
public void foo(){
}
public void ta(){cc.bar();}
}
C b =new D();
doStuff(b);
}
public static void doStuff(C a) {
}
class C
{
public void foo() {
bar();
}
public void bar() {
}
}
public class CallGraphEx
{
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();
SootMethod scr =
Scene.v().getMainClass().getMethodByName("a");
CallGraph cg = Scene.v().getCallGraph();
Iterator<MethodOrMethodContext> targets = new
Targets(cg.edgesOutOf(scr));
while (targets.hasNext()) {
SootMethod tgt = (SootMethod)targets.next();
System.out.println(scr+ " may call " + tgt);
}
}}));
args = argsList.toArray(new String[0]);
soot.Main.main(args);
}
}
After running this CallGraphEx.java, I got the following results:
<testers.CallGraphsTest: void a()> may call <java.lang.Object: void
<clinit>()>
<testers.CallGraphsTest: void a()> may call <testers.CallGraphsTest$1D:
void <init>(testers.CallGraphsTest,testers.CallGraphsTest$C)>
<testers.CallGraphsTest: void a()> may call <testers.CallGraphsTest$C:
void <init>(testers.CallGraphsTest)>
<testers.CallGraphsTest: void a()> may call <java.lang.Object: void
<clinit>()>
<testers.CallGraphsTest: void a()> may call <java.lang.Object: void
<clinit>()>
<testers.CallGraphsTest: void a()> may call <testers.CallGraphsTest:
void doStuff(testers.CallGraphsTest$C)>
So we can find that in order to analyse a(), we still need to analyse
the inner class C and another inner class D inside the method a().
My problem is: how could we get the inner class C and D (not just get
their names) so that we could analyse these inner classes using
intraprocedural or interprocedural analysis?
Thanks very much!
Best regards,
Eve
More information about the Soot-list
mailing list