/** * Insert a runtime exception before unit u of body b. Useful to analyze broken code (which make reference to inexisting * class for instance) exceptionType: e.g., "java.lang.RuntimeException" */ public static void addExceptionAfterUnit(Body b, String exceptionType, Unit u, String m) { LocalCreation lc = new LocalCreation(b.getLocals()); Local l = lc.newLocal(RefType.v(exceptionType)); List<Unit> newUnits = new ArrayList<Unit>(); Unit u1 = Jimple.v().newAssignStmt(l, Jimple.v().newNewExpr(RefType.v(exceptionType))); Unit u2 = Jimple.v() .newInvokeStmt(Jimple.v().newSpecialInvokeExpr(l, Scene.v().makeMethodRef(Scene.v().getSootClass(exceptionType), "<init>", Collections.singletonList((Type) RefType.v("java.lang.String")), VoidType.v(), false), StringConstant.v(m))); Unit u3 = Jimple.v().newThrowStmt(l); newUnits.add(u1); newUnits.add(u2); newUnits.add(u3); b.getUnits().insertBefore(newUnits, u); }
/** * returns a new local with the prefix given to the constructor (or the default-prefix if none has been given) and the * given type.<br> * The returned local will automatically added to the locals-chain.<br> * The local will be of the form: <tt>prefix</tt><i>X</i> (where the last <i>X</i> is a number, so the localname is * unique). * * @param type * the Type of the new local. * @return a new local with a unique name and the given type. */ public Local newLocal(Type type) { return newLocal(prefix, type); }
@Override protected void internalTransform(Body b, String phaseName, Map<String, String> options) { LocalCreation lc = new LocalCreation(b.getLocals(), "ex"); for (Iterator<Unit> unitIt = b.getUnits().snapshotIterator(); unitIt.hasNext();) { Unit u = unitIt.next(); // Check for a null exception if (u instanceof ThrowStmt) { ThrowStmt throwStmt = (ThrowStmt) u; if (throwStmt.getOp() == NullConstant.v() || throwStmt.getOp().equals(IntConstant.v(0)) || throwStmt.getOp().equals(LongConstant.v(0))) { createThrowStmt(b, throwStmt, lc); } } } }
/** * Creates a new statement that throws a NullPointerException * * @param body * The body in which to create the statement * @param oldStmt * The old faulty statement that shall be replaced with the exception * @param lc * The object for creating new locals */ private void createThrowStmt(Body body, Unit oldStmt, LocalCreation lc) { RefType tp = RefType.v("java.lang.NullPointerException"); Local lcEx = lc.newLocal(tp); SootMethodRef constructorRef = Scene.v().makeConstructorRef(tp.getSootClass(), Collections.singletonList((Type) RefType.v("java.lang.String"))); // Create the exception instance Stmt newExStmt = Jimple.v().newAssignStmt(lcEx, Jimple.v().newNewExpr(tp)); body.getUnits().insertBefore(newExStmt, oldStmt); Stmt invConsStmt = Jimple.v().newInvokeStmt(Jimple.v().newSpecialInvokeExpr(lcEx, constructorRef, Collections.singletonList(StringConstant.v("Invalid array reference replaced by Soot")))); body.getUnits().insertBefore(invConsStmt, oldStmt); // Throw the exception body.getUnits().swapWith(oldStmt, Jimple.v().newThrowStmt(lcEx)); } }
protected void internalTransform(final Body body, String phaseName, Map<String, String> options) { final ExceptionalUnitGraph g = new ExceptionalUnitGraph(body, DalvikThrowAnalysis.v()); final LocalDefs defs = LocalDefs.Factory.newLocalDefs(g); final LocalCreation lc = new LocalCreation(body.getLocals(), "ex");
localCreation = new LocalCreation(body.getLocals(), "ret"); Local newLocal = localCreation.newLocal(leftOp.getType()); assign.setLeftOp(newLocal); retStmt.setOp(newLocal);
/** * Creates a new statement that throws a NullPointerException * * @param body * The body in which to create the statement * @param oldStmt * The old faulty statement that shall be replaced with the exception * @param lc * The object for creating new locals */ private void createThrowStmt(Body body, Unit oldStmt, LocalCreation lc) { RefType tp = RefType.v("java.lang.NullPointerException"); Local lcEx = lc.newLocal(tp); SootMethodRef constructorRef = Scene.v().makeConstructorRef(tp.getSootClass(), Collections.singletonList((Type) RefType.v("java.lang.String"))); // Create the exception instance Stmt newExStmt = Jimple.v().newAssignStmt(lcEx, Jimple.v().newNewExpr(tp)); body.getUnits().insertBefore(newExStmt, oldStmt); Stmt invConsStmt = Jimple.v().newInvokeStmt(Jimple.v().newSpecialInvokeExpr(lcEx, constructorRef, Collections.singletonList(StringConstant.v("Null throw statement replaced by Soot")))); body.getUnits().insertBefore(invConsStmt, oldStmt); // Throw the exception body.getUnits().swapWith(oldStmt, Jimple.v().newThrowStmt(lcEx)); }
EarliestnessComputation earliest = new EarliestnessComputation(graph, upSafe, downSafe, sideEffect); LocalCreation localCreation = new LocalCreation(b.getLocals(), PREFIX); helper = localCreation.newLocal(equiVal.getType()); expToHelper.put(equiVal, helper);
/** * returns a new local with the prefix given to the constructor (or the * default-prefix if none has been given) and the given type.<br> * The returned local will automaticly added to the locals-chain.<br> * The local will be of the form: <tt>prefix</tt><i>X</i> (where the last * <i>X</i> is a number, so the localname is unique). * * @param type the Type of the new local. * @return a new local with a unique name and the given type. */ public Local newLocal(Type type) { return newLocal(prefix, type); }
notIsolated = new NotIsolatedAnalysis(graph, latest, unitToEquivRhs, set); LocalCreation localCreation = new LocalCreation(b.getLocals(), PREFIX); helper = localCreation.newLocal(equiVal.getType()); expToHelper.put(equiVal, helper);
/** * returns a new local with the prefix given to the constructor (or the * default-prefix if none has been given) and the given type.<br> * The returned local will automaticly added to the locals-chain.<br> * The local will be of the form: <tt>prefix</tt><i>X</i> (where the last * <i>X</i> is a number, so the localname is unique). * * @param type the Type of the new local. * @return a new local with a unique name and the given type. */ public Local newLocal(Type type) { return newLocal(prefix, type); }
upSafe, downSafe, sideEffect ); LocalCreation localCreation = new LocalCreation(b.getLocals(), PREFIX); helper = localCreation.newLocal(equiVal.getType()); expToHelper.put(equiVal, helper);
upSafe, downSafe, sideEffect ); LocalCreation localCreation = new LocalCreation(b.getLocals(), PREFIX); helper = localCreation.newLocal(equiVal.getType()); expToHelper.put(equiVal, helper);
notIsolated = new NotIsolatedAnalysis(graph, latest, unitToEquivRhs, set); LocalCreation localCreation = new LocalCreation(b.getLocals(), PREFIX); helper = localCreation.newLocal(equiVal.getType()); expToHelper.put(equiVal, helper);
notIsolated = new NotIsolatedAnalysis(graph, latest, unitToEquivRhs, set); LocalCreation localCreation = new LocalCreation(b.getLocals(), PREFIX); helper = localCreation.newLocal(equiVal.getType()); expToHelper.put(equiVal, helper);