public void outAIdentityNoTypeStatement(AIdentityNoTypeStatement node) { mProductions.removeLast(); // get rid of @caughtexception string // presently on top of the stack Value local = mLocals.get(mProductions.removeLast()); // the local ref // from it's // identifier Unit u = Jimple.v().newIdentityStmt(local, Jimple.v().newCaughtExceptionRef()); mProductions.addLast(u); }
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 List<Local> buildParameterLocals(PatchingChain<Unit> units, Collection<Local> locals, List<Type> paramTypes) { List<Local> args = new ArrayList<Local>(); for (int k = 0; k < paramTypes.size(); k++) { Type type = paramTypes.get(k); Local loc = Jimple.v().newLocal("l" + k, type); locals.add(loc); units.add(Jimple.v().newIdentityStmt(loc, Jimple.v().newParameterRef(type, k))); args.add(loc); } return args; }
private void handleInlineExceptionHandler(LabelNode ln, ArrayDeque<Edge> worklist) { // Catch the exception CaughtExceptionRef ref = Jimple.v().newCaughtExceptionRef(); Local local = newStackLocal(); DefinitionStmt as = Jimple.v().newIdentityStmt(local, ref); Operand opr = new Operand(ln, ref); opr.stack = local; ArrayList<Operand> stack = new ArrayList<Operand>(); stack.add(opr); worklist.add(new Edge(ln, stack)); // Save the statements inlineExceptionHandlers.put(ln, as); }
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); } }
public soot.jimple.IdentityStmt newIdentityStmt(Value local, Value identityRef, ASTNode location) { soot.jimple.IdentityStmt stmt = Jimple.v().newIdentityStmt(local, identityRef); soot.tagkit.Tag left = getTag(local); if(left != null) stmt.getLeftOpBox().addTag(left); soot.tagkit.Tag right = getTag(identityRef); if(right != null) stmt.getRightOpBox().addTag(right); return stmt; }
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; }
private void convertLabel(LabelNode ln) { if (!trapHandlers.containsKey(ln)) { return; } // We create a nop statement as a placeholder so that we can jump // somewhere from the real exception handler in case this is inline // code if (inlineExceptionLabels.contains(ln)) { if (!units.containsKey(ln)) { NopStmt nop = Jimple.v().newNopStmt(); setUnit(ln, nop); } return; } StackFrame frame = getFrame(ln); Operand[] out = frame.out(); Operand opr; if (out == null) { CaughtExceptionRef ref = Jimple.v().newCaughtExceptionRef(); Local stack = newStackLocal(); DefinitionStmt as = Jimple.v().newIdentityStmt(stack, ref); opr = new Operand(ln, ref); opr.stack = stack; frame.out(opr); setUnit(ln, as); } else { opr = out[0]; } push(opr); }
Stmt s = jimple.newIdentityStmt(l, jimple.newThisRef((RefType) l.getType())); for (Type t : getMethod().getParameterTypes()) { Local l = jimple.newLocal("parameter" + i, t); Stmt s = jimple.newIdentityStmt(l, jimple.newParameterRef(l.getType(), i));
@Override public void jimplify(DexBody body) { int dest = ((OneRegisterInstruction) instruction).getRegisterA(); Local l = body.getRegisterLocal(dest); stmtToRetype = Jimple.v().newIdentityStmt(l, Jimple.v().newCaughtExceptionRef()); setUnit(stmtToRetype); addTags(stmtToRetype); body.add(stmtToRetype); if (IDalvikTyper.ENABLE_DVKTYPER) { DalvikTyper.v().setType(stmtToRetype.getLeftOpBox(), RefType.v("java.lang.Throwable"), false); } }
private void getBootstrapBody(SootClass tclass, JimpleBody jb) { PatchingChain<Unit> us = jb.getUnits(); LocalGenerator lc = new LocalGenerator(jb); List<Value> capValues = new ArrayList<Value>(); List<Type> capTypes = new ArrayList<Type>(); int i = 0; for (SootField capField : capFields) { Type type = capField.getType(); capTypes.add(type); Local p = lc.generateLocal(type); ParameterRef pref = Jimple.v().newParameterRef(type, i); us.add(Jimple.v().newIdentityStmt(p, pref)); capValues.add(p); i++; } Local l = lc.generateLocal(tclass.getType()); Value val = Jimple.v().newNewExpr(tclass.getType()); us.add(Jimple.v().newAssignStmt(l, val)); us.add(Jimple.v() .newInvokeStmt(Jimple.v().newSpecialInvokeExpr(l, Scene.v().makeConstructorRef(tclass, capTypes), capValues))); us.add(Jimple.v().newReturnStmt(l)); }
/** * Formal creation - method parameters */ private void createFormal(polyglot.ast.Formal formal, int counter) { soot.Type sootType = Util.getSootType(formal.type().type()); soot.Local formalLocal = createLocal(formal.localInstance()); soot.jimple.ParameterRef paramRef = soot.jimple.Jimple.v().newParameterRef(sootType, counter); paramRefCount++; soot.jimple.Stmt stmt = soot.jimple.Jimple.v().newIdentityStmt(formalLocal, paramRef); body.getUnits().add(stmt); Util.addLnPosTags(((soot.jimple.IdentityStmt) stmt).getRightOpBox(), formal.position()); Util.addLnPosTags(stmt, formal.position()); }
soot.jimple.Stmt stmt = soot.jimple.Jimple.v().newIdentityStmt(paramLocal, paramRef); body.getUnits().add(stmt); fieldBase = paramLocal;
soot.jimple.Stmt stmt = soot.jimple.Jimple.v().newIdentityStmt(paramLocal, paramRef); body.getUnits().add(stmt);
us.add(Jimple.v().newIdentityStmt(l, Jimple.v().newThisRef(tclass.getType()))); for (SootField f : capFields) { Local l2 = lc.generateLocal(f.getType()); us.add(Jimple.v().newIdentityStmt(l2, Jimple.v().newParameterRef(f.getType(), i))); capLocals.add(l2); i++;
Local eRef = Jimple.v().newLocal("__exception", RefType.v("java.lang.Throwable")); b.getLocals().add(eRef); Stmt handlerStmt = Jimple.v().newIdentityStmt(eRef, Jimple.v().newCaughtExceptionRef()); l.add(handlerStmt); l.add((Stmt) exitMon.clone());
@Override protected void internalTransform(Body b, String phaseName, Map<String, String> options) { for (Trap t : b.getTraps()) { // If the first statement already catches the exception, we're fine if (isCaughtExceptionRef(t.getHandlerUnit())) { continue; } // Add the exception reference Local l = new LocalGenerator(b).generateLocal(t.getException().getType()); Stmt caughtStmt = Jimple.v().newIdentityStmt(l, Jimple.v().newCaughtExceptionRef()); b.getUnits().add(caughtStmt); b.getUnits().add(Jimple.v().newGotoStmt(t.getHandlerUnit())); t.setHandlerUnit(caughtStmt); } }
/** * Catch Formal creation - method parameters */ private soot.Local createCatchFormal(polyglot.ast.Formal formal) { soot.Type sootType = Util.getSootType(formal.type().type()); soot.Local formalLocal = createLocal(formal.localInstance()); soot.jimple.CaughtExceptionRef exceptRef = soot.jimple.Jimple.v().newCaughtExceptionRef(); soot.jimple.Stmt stmt = soot.jimple.Jimple.v().newIdentityStmt(formalLocal, exceptRef); body.getUnits().add(stmt); Util.addLnPosTags(stmt, formal.position()); Util.addLnPosTags(((soot.jimple.IdentityStmt) stmt).getRightOpBox(), formal.position()); String[] names = new String[] { formal.name() }; stmt.addTag(new soot.tagkit.ParamNamesTag(names)); return formalLocal; }
if (ref instanceof InstanceFieldRef) { parameterTypes.add(target.getType()); accStmts.addFirst(Jimple.v().newIdentityStmt(thisLocal, Jimple.v().newParameterRef(target.getType(), 0)));