[Soot-list] ***SPAM*** call graph!help!
水言子
1241635403 at qq.com
Sat Sep 22 03:45:28 EDT 2012
类:
public class MainDriver{
public static void main(String[] args){
List<String> argsList = new ArrayList<String>(Arrays.asList(args));
argsList.addAll(Arrays.asList(new String[]{
"-w",
"-main-class",
"Test",//main-class
"Test"}));
/* add a phase to transformer pack by call Pack.add */
Pack jtp = PackManager.v().getPack("wjtp");
jtp.add(new Transform("wjtp.myInter",new SceneTransformer() {
@Override
protected void internalTransform(String phaseName, Map options) {
CHATransformer.v().transform();
CallGraph cg = Scene.v().getCallGraph();
// SootClass c = Scene.v().getMainClass();
SootClass sClass =
Scene.v().loadClassAndSupport("Test");
sClass.setApplicationClass();
List<SootMethod> list1 = sClass.getMethods();
for(SootMethod m : list1)
{
Body body = m.getActiveBody();
Chain units = body.getUnits();
Iterator stmtIt = units.snapshotIterator();
while (stmtIt.hasNext()) {
Stmt stmt = (Stmt)stmtIt.next();
if (!stmt.containsInvokeExpr()) {
continue;
}
InvokeExpr expr = (InvokeExpr)stmt.getInvokeExpr();
List<Value> listArgs = (List<Value>)expr.getArgs();
SootMethod classTar = expr.getMethod();
}
String className = types.get(i).toString(); //Types是一个Type类型的list集合
System.out.println( className);
SootClass cl = new SootClass(className);
while(tars.hasNext()) //tars是一个Targets,装在SootMethod
{
SootMethod md = (SootMethod)tars.next();
String sig = md.getSubSignature();
System.out.println(sig); // 输出为 void fly()
System.out.println(cl.declaresMethod("void fly()")); //A 类有void fly() 方法
System.out.println(cl.declaresMethod(sig)); //为什么输出是 false? please help me with this!!!!
System.out.println();
if(cl.declaresMethod(sig))
{
System.out.println("function : " + sig + "is called" + "by the Class : " + t );
}
}//while
}//for
//in function
}));
/* Give control to Soot to process all options,
* InvokeStaticInstrumenter.internalTransform will get called.
*/
args = argsList.toArray(new String[0]);
soot.Main.main(args);
}
}
public class A
{
public void fly()
{
System.out.println("I believe A can fly!");
}
}
public class B extends A
{
public void fly()
{
System.out.println("I believe B can fly!");
}
}
public class C extends B
{
@Override
public void fly()
{
System.out.println("I believe c can fly!");
}
}
public class D extends B
{
@Override
public void fly()
{
System.out.println("I believe D can fly!");
}
}
public class Test
{
public static void main(String[] args)
{
B b1 = new B();
fun1(b1); // I believe B can fly!
fun2(b1); // I believe C can fly!
}
public static void fun1(A a1)
{
a1.fly();
}
public static void fun2(B b1)
{
B b2 = b1;
b2 = new C();
b2.fly();
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.cs.mcgill.ca/pipermail/soot-list/attachments/20120922/750d6c34/attachment-0001.html
More information about the Soot-list
mailing list