public void outAInvokeStatement(AInvokeStatement node) { Value op = (Value) mProductions.removeLast(); Unit u = Jimple.v().newInvokeStmt(op); mProductions.addLast(u); }
public soot.jimple.InvokeStmt newInvokeStmt(Value op, ASTNode location) { soot.jimple.InvokeStmt stmt = Jimple.v().newInvokeStmt(op); soot.tagkit.Tag tag = getTag(op); if(tag != null) stmt.getInvokeExprBox().addTag(tag); return stmt; }
/** * 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); }
units.addFirst(Jimple.v().newInvokeStmt(Jimple.v().newStaticInvokeExpr(reset.makeRef()))); units.insertBefore(Jimple.v().newInvokeStmt(Jimple.v().newStaticInvokeExpr(report.makeRef())), stmt); units.insertBefore(Jimple.v().newInvokeStmt(Jimple.v().newStaticInvokeExpr(report.makeRef())), stmt);
SpecialInvokeExpr constructorInvokeExpr = Jimple.v().newSpecialInvokeExpr(exceptionLocal, cref, StringConstant.v(guard.message)); InvokeStmt initStmt = Jimple.v().newInvokeStmt(constructorInvokeExpr); body.getUnits().insertAfter(initStmt, assignStmt); InvokeStmt printStackTraceStmt = Jimple.v().newInvokeStmt(printStackTraceExpr); body.getUnits().insertAfter(printStackTraceStmt, initStmt); } else if (options.guards().equals("throw")) {
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)); }
static Stmt addThrowAfter(JimpleBody b, Stmt target) { Chain<Unit> units = b.getUnits(); Collection<Local> locals = b.getLocals(); int i = 0; // Bah! boolean canAddI = false; do { canAddI = true; Iterator<Local> localIt = locals.iterator(); while (localIt.hasNext()) { Local l = (Local) localIt.next(); if (l.getName().equals("__throwee" + i)) { canAddI = false; } } if (!canAddI) { i++; } } while (!canAddI); Local l = Jimple.v().newLocal("__throwee" + i, RefType.v("java.lang.NullPointerException")); b.getLocals().add(l); Stmt newStmt = Jimple.v().newAssignStmt(l, Jimple.v().newNewExpr(RefType.v("java.lang.NullPointerException"))); Stmt invStmt = Jimple.v().newInvokeStmt(Jimple.v().newSpecialInvokeExpr(l, Scene.v().getMethod("<java.lang.NullPointerException: void <init>()>").makeRef())); Stmt throwStmt = Jimple.v().newThrowStmt(l); units.insertAfter(newStmt, target); units.insertAfter(invStmt, newStmt); units.insertAfter(throwStmt, invStmt); return newStmt; }
list.add(Jimple.v().newInvokeStmt(Jimple.v().newStaticInvokeExpr(toCall.makeRef()))); list.add(Jimple.v().newInvokeStmt(Jimple.v().newVirtualInvokeExpr(tmpRef, toCall.makeRef(), StringConstant.v("Executing supposedly unreachable method:")))); list.add(Jimple.v().newInvokeStmt(Jimple.v().newVirtualInvokeExpr(tmpRef, toCall.makeRef(), StringConstant.v("\t" + method.getDeclaringClass().getName() + "." + method.getName())))); list.add(Jimple.v().newInvokeStmt(Jimple.v().newStaticInvokeExpr(toCall.makeRef(), IntConstant.v(1))));
private soot.Local getSpecialSuperQualifierLocal(polyglot.ast.Expr expr) { soot.SootClass classToInvoke; ArrayList methodParams = new ArrayList(); if (expr instanceof polyglot.ast.Call) { polyglot.ast.Special target = (polyglot.ast.Special) ((polyglot.ast.Call) expr).target(); classToInvoke = ((soot.RefType) Util.getSootType(target.qualifier().type())).getSootClass(); methodParams = getSootParams((polyglot.ast.Call) expr); } else if (expr instanceof polyglot.ast.Field) { polyglot.ast.Special target = (polyglot.ast.Special) ((polyglot.ast.Field) expr).target(); classToInvoke = ((soot.RefType) Util.getSootType(target.qualifier().type())).getSootClass(); } else { throw new RuntimeException("Trying to create special super qualifier for: " + expr + " which is not a field or call"); } // make an access method soot.SootMethod methToInvoke = makeSuperAccessMethod(classToInvoke, expr); // invoke it soot.Local classToInvokeLocal = Util.getThis(classToInvoke.getType(), body, getThisMap, lg); methodParams.add(0, classToInvokeLocal); soot.jimple.InvokeExpr invokeExpr = soot.jimple.Jimple.v().newStaticInvokeExpr(methToInvoke.makeRef(), methodParams); // return the local of return type if not void if (!methToInvoke.getReturnType().equals(soot.VoidType.v())) { soot.Local retLocal = lg.generateLocal(methToInvoke.getReturnType()); soot.jimple.AssignStmt stmt = soot.jimple.Jimple.v().newAssignStmt(retLocal, invokeExpr); body.getUnits().add(stmt); return retLocal; } else { body.getUnits().add(soot.jimple.Jimple.v().newInvokeStmt(invokeExpr)); return null; } }
/** * 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)); } }
/** * 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)); }
= soot.jimple.Jimple.v().newSpecialInvokeExpr(base, methodToInvoke, sootParams); soot.jimple.Stmt invokeStmt = soot.jimple.Jimple.v().newInvokeStmt(specialInvokeExpr);
private soot.Local createStringBuffer(polyglot.ast.Expr expr) { // create and add one string buffer soot.Local local = lg.generateLocal(soot.RefType.v("java.lang.StringBuffer")); soot.jimple.NewExpr newExpr = soot.jimple.Jimple.v().newNewExpr(soot.RefType.v("java.lang.StringBuffer")); soot.jimple.Stmt assign = soot.jimple.Jimple.v().newAssignStmt(local, newExpr); body.getUnits().add(assign); Util.addLnPosTags(assign, expr.position()); soot.SootClass classToInvoke1 = soot.Scene.v().getSootClass("java.lang.StringBuffer"); soot.SootMethodRef methodToInvoke1 = soot.Scene.v().makeMethodRef(classToInvoke1, "<init>", new ArrayList(), soot.VoidType.v(), false); soot.jimple.SpecialInvokeExpr invoke = soot.jimple.Jimple.v().newSpecialInvokeExpr(local, methodToInvoke1); soot.jimple.Stmt invokeStmt = soot.jimple.Jimple.v().newInvokeStmt(invoke); body.getUnits().add(invokeStmt); Util.addLnPosTags(invokeStmt, expr.position()); return local; }
InvokeStmt invoke = Jimple.v().newInvokeStmt(invocation); setUnit(invoke); addTags(invoke);
/** * Invocation of target implementation method. * * @param jb * @param us * @param args */ private void invokeImplMethod(JimpleBody jb, PatchingChain<Unit> us, LocalGenerator lc, List<Local> args) { Value value = _invokeImplMethod(jb, us, lc, args); if (value instanceof InvokeExpr && soot.VoidType.v().equals(implMethod.getMethodRef().returnType())) { // implementation method is void us.add(Jimple.v().newInvokeStmt(value)); us.add(Jimple.v().newReturnVoidStmt()); } else if (soot.VoidType.v().equals(implMethodType.getReturnType())) { // dispatch method is void us.add(Jimple.v().newInvokeStmt(value)); us.add(Jimple.v().newReturnVoidStmt()); } else { // neither is void, must pass through return value Local ret = lc.generateLocal(value.getType()); us.add(Jimple.v().newAssignStmt(ret, value)); // adapt return value Local retAdapted = adapt(ret, implMethodType.getReturnType(), jb, us, lc); us.add(Jimple.v().newReturnStmt(retAdapted)); } }
InvokeStmt invokeStmt = Jimple.v().newInvokeStmt(specialInvokeExpr); us.add(invokeStmt);
InvokeExpr newExpr = Jimple.v().newStaticInvokeExpr(accessor.makeRef(), args); Stmt newStmt = Jimple.v().newInvokeStmt(newExpr);
.newInvokeStmt(Jimple.v().newSpecialInvokeExpr(l, Scene.v().makeConstructorRef(Scene.v().getObjectType().getSootClass(), Collections.<Type>emptyList()), Collections.<Value>emptyList())));
SpecialInvokeExpr constructorInvokeExpr = Jimple.v().newSpecialInvokeExpr(exceptionLocal, cref, StringConstant.v("Unresolved compilation error: Method " + getSignature() + " does not exist!")); InvokeStmt initStmt = Jimple.v().newInvokeStmt(constructorInvokeExpr); body.getUnits().insertAfter(initStmt, assignStmt);
units.addFirst(Jimple.v().newInvokeStmt( Jimple.v().newSpecialInvokeExpr(bool, booleanWrapperConstructor.makeRef(), IntConstant.v(value ? 1 : 0)))); units.addFirst(Jimple.v().newAssignStmt(bool, Jimple.v().newNewExpr(booleanWrapperRefType)));