/** * Constructs a ThisRef(RefType) grammar chunk. */ public ThisRef newThisRef(RefType t) { return Jimple.v().newThisRef(t); }
public soot.jimple.ThisRef newThisRef(RefType t, ASTNode location) { soot.jimple.ThisRef ref = Jimple.v().newThisRef(t); createTag(ref, location); return ref; }
public void outAIdentityStatement(AIdentityStatement node) { Type identityRefType = (Type) mProductions.removeLast(); String atClause = (String) mProductions.removeLast(); Value local = mLocals.get(mProductions.removeLast()); // the local ref // from it's // identifier Value ref = null; if (atClause.startsWith("@this")) { ref = Jimple.v().newThisRef((RefType) identityRefType); } else if (atClause.startsWith("@parameter")) { int index = Integer.parseInt(atClause.substring(10, atClause.length() - 1)); ref = Jimple.v().newParameterRef(identityRefType, index); } else { throw new RuntimeException("shouldn't @caughtexception be handled by outAIdentityNoTypeStatement: got" + atClause); } Unit u = Jimple.v().newIdentityStmt(local, ref); mProductions.addLast(u); }
public static Local buildThisLocal(PatchingChain<Unit> units, ThisRef tr, Collection<Local> locals) { Local ths = Jimple.v().newLocal("ths", tr.getType()); locals.add(ths); units.add(Jimple.v().newIdentityStmt(ths, Jimple.v().newThisRef((RefType) tr.getType()))); return ths; }
private void emitLocals() { JimpleBody jb = body; SootMethod m = jb.getMethod(); Collection<Local> jbl = jb.getLocals(); Collection<Unit> jbu = jb.getUnits(); int iloc = 0; if (!m.isStatic()) { Local l = getLocal(iloc++); jbu.add(Jimple.v().newIdentityStmt(l, Jimple.v().newThisRef(m.getDeclaringClass().getType()))); } int nrp = 0; for (Object ot : m.getParameterTypes()) { Type t = (Type) ot; Local l = getLocal(iloc); jbu.add(Jimple.v().newIdentityStmt(l, Jimple.v().newParameterRef(t, nrp++))); if (AsmUtil.isDWord(t)) { iloc += 2; } else { iloc++; } } for (Local l : locals.values()) { jbl.add(l); } }
us.add(Jimple.v().newIdentityStmt(this_, Jimple.v().newThisRef(tclass.getType())));
currentLocalIndex++; units.add(Jimple.v().newIdentityStmt(local, Jimple.v().newThisRef(jmethod.getDeclaringClass().getType())));
public soot.Local emitThis(TypeDecl typeDecl) { if(thisName == null) { thisName = newLocal("this", typeDecl.getSootType()); if(body.getMethod().isStatic()) add(Jimple.v().newIdentityStmt(thisName, Jimple.v().newParameterRef(typeDecl.getSootType(), 0))); else add(Jimple.v().newIdentityStmt(thisName, Jimple.v().newThisRef(typeDecl.sootRef()))); } return thisName; }
body.getLocals().add(specialThisLocal); soot.jimple.ThisRef thisRef = soot.jimple.Jimple.v().newThisRef(type);
Stmt s = jimple.newIdentityStmt(l, jimple.newThisRef((RefType) l.getType()));
body.getLocals().add(specialThisLocal); soot.jimple.ThisRef thisRef = soot.jimple.Jimple.v().newThisRef(type);
us.add(Jimple.v().newIdentityStmt(l, Jimple.v().newThisRef(tclass.getType())));
JIdentityStmt idStmt = (JIdentityStmt) jimple.newIdentityStmt(thisLocal, jimple.newThisRef(declaringClassType)); add(idStmt); paramLocals.add(thisLocal);
/** Inserts usual statements for handling this & parameters into body. */ public void insertIdentityStmts() { int i = 0; Iterator parIt = getMethod().getParameterTypes().iterator(); while (parIt.hasNext()) { Type t = (Type)parIt.next(); Local l = Jimple.v().newLocal("parameter"+i, t); getLocals().add(l); getUnits().addFirst(Jimple.v().newIdentityStmt(l, Jimple.v().newParameterRef(l.getType(), i))); i++; } //add this-ref before everything else if (!getMethod().isStatic()) { Local l = Jimple.v().newLocal("this", RefType.v(getMethod().getDeclaringClass())); getLocals().add(l); getUnits().addFirst(Jimple.v().newIdentityStmt(l, Jimple.v().newThisRef((RefType)l.getType()))); } }
/** Inserts usual statements for handling this & parameters into body. */ public void insertIdentityStmts() { int i = 0; Iterator parIt = getMethod().getParameterTypes().iterator(); while (parIt.hasNext()) { Type t = (Type)parIt.next(); Local l = Jimple.v().newLocal("parameter"+i, t); getLocals().add(l); getUnits().addFirst(Jimple.v().newIdentityStmt(l, Jimple.v().newParameterRef(l.getType(), i))); i++; } //add this-ref before everything else if (!getMethod().isStatic()) { Local l = Jimple.v().newLocal("this", RefType.v(getMethod().getDeclaringClass())); getLocals().add(l); getUnits().addFirst(Jimple.v().newIdentityStmt(l, Jimple.v().newThisRef((RefType)l.getType()))); } }
b.getUnits().add(Jimple.v().newIdentityStmt(thisLocal, Jimple.v().newThisRef(sc.getType())));
/** * 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(); }
b.getUnits().add(Jimple.v().newIdentityStmt(thisLocal, Jimple.v().newThisRef(sc.getType())));