1 19 20 package soot.jimple.toolkits.callgraph; 21 22 import soot.*; 23 import soot.jimple.*; 24 import soot.jimple.internal.*; 25 import soot.util.*; 26 import java.util.*; 27 28 public class UnreachableMethodTransformer extends BodyTransformer 29 { 30 protected void internalTransform(Body b, String phaseName, Map options) { 31 ReachableMethods reachableMethods = Scene.v().getReachableMethods(); 33 SootMethod method = b.getMethod(); 34 if( reachableMethods.contains( method ) ) return; 36 37 JimpleBody body = (JimpleBody) method.getActiveBody(); 38 39 PatchingChain units = (PatchingChain) body.getUnits(); 40 List list = new Vector(); 41 42 Local tmpRef = Jimple.v().newLocal( "tmpRef", RefType.v( "java.io.PrintStream" ) ); 43 body.getLocals().add(tmpRef); 44 list.add( Jimple.v().newAssignStmt( tmpRef, Jimple.v().newStaticFieldRef( 45 Scene.v().getField( "<java.lang.System: java.io.PrintStream out>" ).makeRef() ) ) ); 46 47 SootMethod toCall = Scene.v().getMethod( "<java.lang.Thread: void dumpStack()>" ); 48 list.add( Jimple.v().newInvokeStmt( Jimple.v().newStaticInvokeExpr( toCall.makeRef() ) ) ); 49 50 toCall = Scene.v().getMethod( "<java.io.PrintStream: void println(java.lang.String)>" ); 51 list.add( Jimple.v().newInvokeStmt( Jimple.v().newVirtualInvokeExpr( 52 tmpRef, toCall.makeRef(), StringConstant.v( "Executing supposedly unreachable method:" ) ) ) ); 53 list.add( Jimple.v().newInvokeStmt( Jimple.v().newVirtualInvokeExpr( 54 tmpRef, toCall.makeRef(), StringConstant.v( "\t" + method.getDeclaringClass().getName() + "." + method.getName() ) ) ) ); 55 56 toCall = Scene.v().getMethod( "<java.lang.System: void exit(int)>" ); 57 list.add( Jimple.v().newInvokeStmt( Jimple.v().newStaticInvokeExpr( toCall.makeRef(), IntConstant.v( 1 ) ) ) ); 58 59 79 80 108 { 109 units.insertBefore( list, units.getFirst() ); 110 } 111 124 } 125 } 126 | Popular Tags |