/** Inserts usual statements for handling this & parameters into body. */ public void insertIdentityStmts() { insertIdentityStmts(getMethod().getDeclaringClass()); }
body.insertIdentityStmts(declaringClass);
public SootMethod generateDummyMainMethod(List<String> entryPoints, String sootClassName) { SootClass compSootClass = Scene.v().getSootClass(sootClassName); List<SootClass> androidClasses = new ArrayList<>(); androidClasses.add(compSootClass); SootMethod mainMethod = new SootMethod(DUMMY_MAIN_METHOD, new ArrayList<Type>(), VoidType.v(), Modifier.PUBLIC);// | Modifier.STATIC); //no need be static JimpleBody body = Jimple.v().newBody(mainMethod); mainMethod.setActiveBody(body); compSootClass.addMethod(mainMethod); //this is mandatory, the default dummyMainMethod is static, so they //do not deal thisIdentity. since we don't need static dummyMainMethod, //we should define it explicit body.insertIdentityStmts(); MultiMap<SootClass, SootMethod> callbackFunctions = new HashMultiMap<>(); callbackFunctions.putAll(compSootClass, getCallbackFunctions(compSootClass)); AndroidEntryPointCreator androidEPCreator = new AndroidEntryPointCreator(androidClasses); androidEPCreator.setCallbackFunctions(callbackFunctions); return androidEPCreator.createDummyMain(mainMethod); }
body.insertIdentityStmts(); body.getUnits().add(Jimple.v().newReturnVoidStmt()); body = Jimple.v().newBody(staticInitializer); staticInitializer.setActiveBody(body); body.insertIdentityStmts(); body.getUnits().add(Jimple.v().newReturnVoidStmt()); sClass.addMethod(staticInitializer);
/** * Creates an implementation of setResult() that writes the given intent into * the correct field */ private void createSetResultMethod() { // We need to create an implementation of "getIntent". If there is already such // an implementation, we don't touch it. if (component.declaresMethod("void setResult(int,android.content.Intent)")) return; Type intentType = RefType.v("android.content.Intent"); List<Type> params = new ArrayList<>(); params.add(IntType.v()); params.add(intentType); SootMethod sm = Scene.v().makeSootMethod("setResult", params, VoidType.v(), Modifier.PUBLIC); component.addMethod(sm); sm.addTag(SimulatedCodeElementTag.TAG); JimpleBody b = Jimple.v().newBody(sm); sm.setActiveBody(b); b.insertIdentityStmts(); Local lcIntent = b.getParameterLocal(1); b.getUnits().add(Jimple.v().newAssignStmt( Jimple.v().newInstanceFieldRef(b.getThisLocal(), resultIntentField.makeRef()), lcIntent)); b.getUnits().add(Jimple.v().newReturnVoidStmt()); // Activity.setResult() is final. We need to change that SootMethod smSetResult = Scene.v() .grabMethod("<android.app.Activity: void setResult(int,android.content.Intent)>"); if (smSetResult != null && smSetResult.getDeclaringClass().isApplicationClass()) smSetResult.setModifiers(smSetResult.getModifiers() & ~Modifier.FINAL); }
/** * Creates an implementation of getIntent() that returns the intent from our ICC * model */ private void createGetIntentMethod() { // We need to create an implementation of "getIntent". If there is already such // an implementation, we don't touch it. if (component.declaresMethod("android.content.Intent getIntent()")) return; Type intentType = RefType.v("android.content.Intent"); SootMethod sm = Scene.v().makeSootMethod("getIntent", Collections.<Type>emptyList(), intentType, Modifier.PUBLIC); component.addMethod(sm); sm.addTag(SimulatedCodeElementTag.TAG); JimpleBody b = Jimple.v().newBody(sm); sm.setActiveBody(b); b.insertIdentityStmts(); LocalGenerator localGen = new LocalGenerator(b); Local lcIntent = localGen.generateLocal(intentType); b.getUnits().add(Jimple.v().newAssignStmt(lcIntent, Jimple.v().newInstanceFieldRef(b.getThisLocal(), intentField.makeRef()))); b.getUnits().add(Jimple.v().newReturnStmt(lcIntent)); }
/** * Creates an implementation of setIntent() that writes the given intent into * the correct field */ private void createSetIntentMethod() { // We need to create an implementation of "getIntent". If there is already such // an implementation, we don't touch it. if (component.declaresMethod("void setIntent(android.content.Intent)")) return; Type intentType = RefType.v("android.content.Intent"); SootMethod sm = Scene.v().makeSootMethod("setIntent", Collections.singletonList(intentType), VoidType.v(), Modifier.PUBLIC); component.addMethod(sm); sm.addTag(SimulatedCodeElementTag.TAG); JimpleBody b = Jimple.v().newBody(sm); sm.setActiveBody(b); b.insertIdentityStmts(); Local lcIntent = b.getParameterLocal(0); b.getUnits().add(Jimple.v() .newAssignStmt(Jimple.v().newInstanceFieldRef(b.getThisLocal(), intentField.makeRef()), lcIntent)); b.getUnits().add(Jimple.v().newReturnVoidStmt()); }
body.insertIdentityStmts(); arrayClass.addMethod(getElement); JimpleBody body = Jimple.v().newBody(getElement); body.insertIdentityStmts(); Local retLocal = Jimple.v().newLocal("retVal", elementType); body.getLocals().add(retLocal); arrayClass.addMethod(setElement); body = Jimple.v().newBody(setElement); body.insertIdentityStmts(); body = Jimple.v().newBody(constructor); body.insertIdentityStmts();
/** * 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)); }