/** * 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); }
/** * 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); }
localCreation = new LocalCreation(body.getLocals(), "ret"); Local newLocal = localCreation.newLocal(leftOp.getType()); assign.setLeftOp(newLocal); retStmt.setOp(newLocal);
helper = localCreation.newLocal(equiVal.getType()); expToHelper.put(equiVal, helper);
helper = localCreation.newLocal(equiVal.getType()); expToHelper.put(equiVal, helper);
/** * 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)); }
/** * 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)); } }
/** * 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); }
/** * 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); }
helper = localCreation.newLocal(equiVal.getType()); expToHelper.put(equiVal, helper);
helper = localCreation.newLocal(equiVal.getType()); expToHelper.put(equiVal, helper);
helper = localCreation.newLocal(equiVal.getType()); expToHelper.put(equiVal, helper);
helper = localCreation.newLocal(equiVal.getType()); expToHelper.put(equiVal, helper);