1 19 20 package soot; 21 import soot.jimple.*; 22 import soot.util.*; 23 import java.util.*; 24 25 26 29 public class EntryPoints 30 { 31 public EntryPoints( Singletons.Global g ) {} 32 public static EntryPoints v() { return G.v().soot_EntryPoints(); } 33 34 final NumberedString sigMain = Scene.v().getSubSigNumberer(). 35 findOrAdd( "void main(java.lang.String[])" ); 36 final NumberedString sigFinalize = Scene.v().getSubSigNumberer(). 37 findOrAdd( "void finalize()" ); 38 final NumberedString sigExit = Scene.v().getSubSigNumberer(). 39 findOrAdd( "void exit()" ); 40 final NumberedString sigClinit = Scene.v().getSubSigNumberer(). 41 findOrAdd( "void <clinit>()" ); 42 final NumberedString sigInit = Scene.v().getSubSigNumberer(). 43 findOrAdd( "void <init>()" ); 44 final NumberedString sigStart = Scene.v().getSubSigNumberer(). 45 findOrAdd( "void start()" ); 46 final NumberedString sigRun = Scene.v().getSubSigNumberer(). 47 findOrAdd( "void run()" ); 48 final NumberedString sigObjRun = Scene.v().getSubSigNumberer(). 49 findOrAdd( "java.lang.Object run()" ); 50 final NumberedString sigForName = Scene.v().getSubSigNumberer(). 51 findOrAdd( "java.lang.Class forName(java.lang.String)" ); 52 private final void addMethod( List set, SootClass cls, NumberedString methodSubSig ) { 53 if( cls.declaresMethod( methodSubSig ) ) { 54 set.add( cls.getMethod( methodSubSig ) ); 55 } 56 } 57 private final void addMethod( List set, String methodSig ) { 58 if( Scene.v().containsMethod( methodSig ) ) { 59 set.add( Scene.v().getMethod( methodSig ) ); 60 } 61 } 62 64 public List application() { 65 List ret = new ArrayList(); 66 addMethod( ret, Scene.v().getMainClass(), sigMain ); 67 for( Iterator clinitIt = clinitsOf(Scene.v().getMainClass() ).iterator(); clinitIt.hasNext(); ) { 68 final SootMethod clinit = (SootMethod) clinitIt.next(); 69 ret.add(clinit); 70 } 71 return ret; 72 } 73 74 public List implicit() { 75 List ret = new ArrayList(); 76 addMethod( ret, "<java.lang.System: void initializeSystemClass()>" ); 77 addMethod( ret, "<java.lang.ThreadGroup: void <init>()>"); 78 addMethod( ret, "<java.lang.Thread: void exit()>"); 80 addMethod( ret, "<java.lang.ThreadGroup: void uncaughtException(java.lang.Thread,java.lang.Throwable)>"); 81 addMethod( ret, "<java.lang.ClassLoader: void <init>()>"); 83 addMethod( ret, "<java.lang.ClassLoader: java.lang.Class loadClassInternal(java.lang.String)>"); 84 addMethod( ret, "<java.lang.ClassLoader: void checkPackageAccess(java.lang.Class,java.security.ProtectionDomain)>"); 85 addMethod( ret, "<java.lang.ClassLoader: void addClass(java.lang.Class)>"); 86 addMethod( ret, "<java.lang.ClassLoader: long findNative(java.lang.ClassLoader,java.lang.String)>"); 87 addMethod( ret, "<java.security.PrivilegedActionException: void <init>(java.lang.Exception)>"); 88 addMethod( ret, "<java.lang.ref.Finalizer: void runFinalizer()>"); 90 addMethod( ret, "<java.lang.Thread: void <init>(java.lang.ThreadGroup,java.lang.Runnable)>"); 91 addMethod( ret, "<java.lang.Thread: void <init>(java.lang.ThreadGroup,java.lang.String)>"); 92 return ret; 93 } 94 95 public List all() { 96 List ret = new ArrayList(); 97 ret.addAll( application() ); 98 ret.addAll( implicit() ); 99 return ret; 100 } 101 102 public List clinits() { 103 List ret = new ArrayList(); 104 for( Iterator clIt = Scene.v().getClasses().iterator(); clIt.hasNext(); ) { 105 final SootClass cl = (SootClass) clIt.next(); 106 addMethod( ret, cl, sigClinit ); 107 } 108 return ret; 109 } 110 111 public List inits() { 112 List ret = new ArrayList(); 113 for( Iterator clIt = Scene.v().getClasses().iterator(); clIt.hasNext(); ) { 114 final SootClass cl = (SootClass) clIt.next(); 115 addMethod( ret, cl, sigInit ); 116 } 117 return ret; 118 } 119 120 121 public List methodsOfApplicationClasses() { 122 List ret = new ArrayList(); 123 for( Iterator clIt = Scene.v().getApplicationClasses().iterator(); clIt.hasNext(); ) { 124 final SootClass cl = (SootClass) clIt.next(); 125 for( Iterator mIt = cl.getMethods().iterator(); mIt.hasNext(); ) { 126 final SootMethod m = (SootMethod) mIt.next(); 127 if( m.isConcrete() ) ret.add( m ); 128 } 129 } 130 return ret; 131 } 132 133 135 public List mainsOfApplicationClasses() { 136 List ret = new ArrayList(); 137 for( Iterator clIt = Scene.v().getApplicationClasses().iterator(); clIt.hasNext(); ) { 138 final SootClass cl = (SootClass) clIt.next(); 139 if( cl.declaresMethod( "void main(java.lang.String[])" ) ) { 140 SootMethod m = cl.getMethod("void main(java.lang.String[])" ); 141 if( m.isConcrete() ) ret.add( m ); 142 } 143 } 144 return ret; 145 } 146 147 148 public List clinitsOf( SootClass cl ) { 149 List ret = new ArrayList(); 150 while(true) { 151 addMethod( ret, cl, sigClinit ); 152 if( !cl.hasSuperclass() ) break; 153 cl = cl.getSuperclass(); 154 } 155 return ret; 156 } 157 } 158 159 160 | Popular Tags |