/** * Adds the given class to the Scene. This method marks the given class as a library class and invalidates the class * hierarchy. * * @param c * The class to add */ public void addClass(SootClass c) { addClassSilent(c); c.setLibraryClass(); modifyHierarchy(); }
private void constantForName(String cls, SootMethod src, Stmt srcUnit) { if (cls.length() > 0 && cls.charAt(0) == '[') { if (cls.length() > 1 && cls.charAt(1) == 'L' && cls.charAt(cls.length() - 1) == ';') { cls = cls.substring(2, cls.length() - 1); constantForName(cls, src, srcUnit); } } else { if (!Scene.v().containsClass(cls)) { if (options.verbose()) { logger.warn("Class " + cls + " is" + " a dynamic class, and you did not specify" + " it as such; graph will be incomplete!"); } } else { SootClass sootcls = Scene.v().getSootClass(cls); if (!sootcls.isPhantomClass()) { if (!sootcls.isApplicationClass()) { sootcls.setLibraryClass(); } for (SootMethod clinit : EntryPoints.v().clinitsOf(sootcls)) { addEdge(src, srcUnit, clinit, Kind.CLINIT); } } } } }
SootClass sootcls = Scene.v().getSootClass(constant); if (!sootcls.isApplicationClass() && !sootcls.isPhantom()) { sootcls.setLibraryClass();
/** * @ast method * @aspect EmitJimple * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddExtensions/JimpleBackend/EmitJimple.jrag:32 */ private SootClass refined_EmitJimple_TypeDecl_getSootClassDecl() { if (compilationUnit().fromSource()) { return sootClass(); } else { if (options().verbose()) System.out.println("Loading .class file " + jvmName()); SootClass sc = Scene.v().loadClass(jvmName(), SootClass.SIGNATURES); sc.setLibraryClass(); return sc; } }
private void constantForName( String cls, SootMethod src, Stmt srcUnit ) { if( cls.length() > 0 && cls.charAt(0) == '[' ) { if( cls.length() > 1 && cls.charAt(1) == 'L' && cls.charAt(cls.length()-1) == ';' ) { cls = cls.substring(2,cls.length()-1); constantForName( cls, src, srcUnit ); } } else { if( !Scene.v().containsClass( cls ) ) { if( options.verbose() ) { G.v().out.println( "Warning: Class "+cls+" is"+ " a dynamic class, and you did not specify"+ " it as such; graph will be incomplete!" ); } } else { SootClass sootcls = Scene.v().getSootClass( cls ); if( !sootcls.isApplicationClass() ) { sootcls.setLibraryClass(); } for (SootMethod clinit : EntryPoints.v().clinitsOf(sootcls)) { addEdge( src, srcUnit, clinit, Kind.CLINIT ); } } } }
private void constantForName( String cls, SootMethod src, Stmt srcUnit ) { if( cls.length() > 0 && cls.charAt(0) == '[' ) { if( cls.length() > 1 && cls.charAt(1) == 'L' && cls.charAt(cls.length()-1) == ';' ) { cls = cls.substring(2,cls.length()-1); constantForName( cls, src, srcUnit ); } } else { if( !Scene.v().containsClass( cls ) ) { if( options.verbose() ) { G.v().out.println( "Warning: Class "+cls+" is"+ " a dynamic class, and you did not specify"+ " it as such; graph will be incomplete!" ); } } else { SootClass sootcls = Scene.v().getSootClass( cls ); if( !sootcls.isApplicationClass() ) { sootcls.setLibraryClass(); } for (SootMethod clinit : EntryPoints.v().clinitsOf(sootcls)) { addEdge( src, srcUnit, clinit, Kind.CLINIT ); } } } }
SootClass sootcls = Scene.v().getSootClass( constant ); if( !sootcls.isApplicationClass() ) { sootcls.setLibraryClass();
public void addClass(SootClass c) { if(c.isInScene()) throw new RuntimeException("already managed: "+c.getName()); if(containsClass(c.getName())) throw new RuntimeException("duplicate class: "+c.getName()); classes.add(c); c.setLibraryClass(); nameToClass.put(c.getName(), c.getType()); c.getType().setSootClass(c); c.setInScene(true); modifyHierarchy(); }
public void addClass(SootClass c) { if(c.isInScene()) throw new RuntimeException("already managed: "+c.getName()); if(containsClass(c.getName())) throw new RuntimeException("duplicate class: "+c.getName()); classes.add(c); c.setLibraryClass(); nameToClass.put(c.getName(), c.getType()); c.getType().setSootClass(c); c.setInScene(true); modifyHierarchy(); }
if (s.isApplicationClass() && (s.getPackageName()+".").startsWith(pkg)) { s.setLibraryClass();
if (s.isApplicationClass() && (s.getPackageName()+".").startsWith(pkg)) { s.setLibraryClass();
if (sc == null || sc.resolvingLevel() < SootClass.SIGNATURES) return; sc.setLibraryClass();
/** * Creates a new implementation for the given method * * @param sm * The method for which to generate a new implementation * @param injector * Callback to inject additional code into the new method */ private void generateMessageObtainMethod(SootMethod sm, IMessageObtainCodeInjector injector) { // Create the method RefType tpMessage = RefType.v("android.os.Message"); sm.getDeclaringClass().setLibraryClass(); sm.setPhantom(false); sm.addTag(new FlowDroidEssentialMethodTag()); // Create a body for the method JimpleBody body = Jimple.v().newBody(sm); sm.setActiveBody(body); body.insertIdentityStmts(); SootMethod smMessageConstructor = Scene.v().grabMethod("<android.os.Message: void <init>()>"); LocalGenerator lg = new LocalGenerator(body); Local messageLocal = lg.generateLocal(tpMessage); body.getUnits().add(Jimple.v().newAssignStmt(messageLocal, Jimple.v().newNewExpr(tpMessage))); body.getUnits().add(Jimple.v() .newInvokeStmt(Jimple.v().newSpecialInvokeExpr(messageLocal, smMessageConstructor.makeRef()))); if (injector != null) injector.injectCode(body, messageLocal); body.getUnits().add(Jimple.v().newReturnStmt(messageLocal)); }
sc.setLibraryClass(); method.setPhantom(false);
/** * Modifies Activity::getFragmentManager() to return new * MyFragmentManager(this); */ private void patchActivityGetFragmentManager() { SootClass sc = Scene.v().getSootClassUnsafe("android.app.Activity"); if (sc == null || sc.resolvingLevel() < SootClass.SIGNATURES) return; sc.setLibraryClass(); SootMethod smGetFM = sc.getMethodUnsafe("android.app.FragmentManager getFragmentManager()"); if (smGetFM == null || smGetFM.hasActiveBody()) return; Body b = Jimple.v().newBody(smGetFM); smGetFM.setActiveBody(b); Local thisLocal = Jimple.v().newLocal("this", sc.getType()); b.getLocals().add(thisLocal); b.getUnits().add(Jimple.v().newIdentityStmt(thisLocal, Jimple.v().newThisRef(sc.getType()))); SootClass scFragmentTransaction = Scene.v().forceResolve("android.app.FragmentManager", SootClass.SIGNATURES); Local retLocal = Jimple.v().newLocal("retFragMan", Scene.v().getSootClassUnsafe("android.app.FragmentManager").getType()); b.getLocals().add(retLocal); b.getUnits().add(Jimple.v().newAssignStmt(retLocal, Jimple.v().newNewExpr(scFragmentTransaction.getType()))); b.getUnits().add(Jimple.v().newReturnStmt(retLocal)); }
/** * Creates a synthetic "<init>(java.lang.Runnable)" method implementation that * stores the given runnable into a field for later use * * @param smCons * The <init>() method for which to create a synthetic implementation * @param runnable * The "java.lang.Runnable" interface * @param fldTarget * The field receiving the Runnable */ private void patchThreadConstructor(SootMethod smCons, SootClass runnable, SootField fldTarget) { SootClass sc = smCons.getDeclaringClass(); sc.setLibraryClass(); smCons.setPhantom(false); Body b = Jimple.v().newBody(smCons); smCons.setActiveBody(b); Local thisLocal = Jimple.v().newLocal("this", sc.getType()); b.getLocals().add(thisLocal); b.getUnits().add(Jimple.v().newIdentityStmt(thisLocal, Jimple.v().newThisRef(sc.getType()))); Local param0Local = Jimple.v().newLocal("p0", runnable.getType()); b.getLocals().add(param0Local); b.getUnits().add(Jimple.v().newIdentityStmt(param0Local, Jimple.v().newParameterRef(runnable.getType(), 0))); b.getUnits().add( Jimple.v().newAssignStmt(Jimple.v().newInstanceFieldRef(thisLocal, fldTarget.makeRef()), param0Local)); b.getUnits().add(Jimple.v().newReturnVoidStmt()); }
/** * Patch android.app.Activity getApplication method in order to return the * singleton Application instance created in the dummyMainMethod. */ private void patchActivityImplementation() { SootClass scApplicationHolder = createOrGetApplicationHolder(); SootClass sc = Scene.v().getSootClassUnsafe("android.app.Activity"); if (sc == null || sc.resolvingLevel() < SootClass.SIGNATURES || scApplicationHolder == null) return; sc.setLibraryClass(); SootMethod smRun = sc.getMethodUnsafe("android.app.Application getApplication()"); if (smRun == null || (smRun.hasActiveBody() && !isStubImplementation(smRun.getActiveBody()))) return; smRun.setPhantom(false); smRun.addTag(new FlowDroidEssentialMethodTag()); Body b = Jimple.v().newBody(smRun); smRun.setActiveBody(b); // add "this" local Local thisLocal = Jimple.v().newLocal("this", sc.getType()); b.getLocals().add(thisLocal); b.getUnits().add(Jimple.v().newIdentityStmt(thisLocal, Jimple.v().newThisRef(sc.getType()))); SootFieldRef appStaticFieldRef = scApplicationHolder.getFieldByName("application").makeRef(); // creating local to store the mApplication field Local targetLocal = Jimple.v().newLocal("retApplication", appStaticFieldRef.type()); b.getLocals().add(targetLocal); b.getUnits().add(Jimple.v().newAssignStmt(targetLocal, Jimple.v().newStaticFieldRef(appStaticFieldRef))); Unit retStmt = Jimple.v().newReturnStmt(targetLocal); b.getUnits().add(retStmt); b.validate(); }
sc.setLibraryClass(); method.setPhantom(false);
sc.setLibraryClass(); smRun.setPhantom(false);