/** * Constructs a NewSpecialInvokeExpr(Local base, SootMethodRef method, List of Immediate) grammar chunk. */ public SpecialInvokeExpr newSpecialInvokeExpr(Local base, SootMethodRef method, Value... args) { return newSpecialInvokeExpr(base, method, Arrays.asList(args)); }
public SpecialInvokeExpr newSpecialInvokeExpr(Local base, SootMethodRef method, Value arg) { return newSpecialInvokeExpr(base, method, Collections.<Value>singletonList(arg)); }
public SpecialInvokeExpr newSpecialInvokeExpr(Local base, SootMethodRef method) { return newSpecialInvokeExpr(base, method, Collections.<Value>emptyList()); }
/** Executes the "jimplify" operation for a special invocation */ protected void jimplifySpecial(DexBody body) { MethodReference item = (MethodReference) ((ReferenceInstruction) instruction).getReference(); List<Local> parameters = buildParameters(body, item.getParameterTypes(), false); invocation = Jimple.v().newSpecialInvokeExpr(parameters.get(0), getVirtualSootMethodRef(), parameters.subList(1, parameters.size())); body.setDanglingInstruction(this); }
public soot.jimple.SpecialInvokeExpr newSpecialInvokeExpr(Local base, SootMethodRef method, java.util.List args, ASTNode location) { soot.jimple.SpecialInvokeExpr expr = Jimple.v().newSpecialInvokeExpr(base, method, args); createTag(expr, location); for(int i = 0; i < args.size(); i++) { soot.tagkit.Tag tag = getTag((Value)args.get(i)); if(tag != null) expr.getArgBox(i).addTag(tag); } return expr; }
public void outANonstaticInvokeExpr(ANonstaticInvokeExpr node) { List args; if (node.getArgList() != null) { args = (List) mProductions.removeLast(); } else { args = new ArrayList(); } SootMethodRef method = (SootMethodRef) mProductions.removeLast(); String local = (String) mProductions.removeLast(); Local l = mLocals.get(local); if (l == null) { throw new RuntimeException("did not find local: " + local); } Node invokeType = node.getNonstaticInvoke(); Expr invokeExpr; if (invokeType instanceof ASpecialNonstaticInvoke) { invokeExpr = Jimple.v().newSpecialInvokeExpr(l, method, args); } else if (invokeType instanceof AVirtualNonstaticInvoke) { invokeExpr = Jimple.v().newVirtualInvokeExpr(l, method, args); } else { if (debug) { if (!(invokeType instanceof AInterfaceNonstaticInvoke)) { throw new RuntimeException("expected interface invoke."); } } invokeExpr = Jimple.v().newInterfaceInvokeExpr(l, method, args); } mProductions.addLast(invokeExpr); }
/** * 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); }
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; }
.getMethod("<init>", Collections.<Type>singletonList(RefType.v("java.lang.String"))).makeRef(); SpecialInvokeExpr constructorInvokeExpr = Jimple.v().newSpecialInvokeExpr(exceptionLocal, cref, StringConstant.v(guard.message)); InvokeStmt initStmt = Jimple.v().newInvokeStmt(constructorInvokeExpr); body.getUnits().insertAfter(initStmt, assignStmt);
/** * 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)); } }
= soot.jimple.Jimple.v().newSpecialInvokeExpr(base, methodToInvoke, sootParams);
return Jimple.v().newSpecialInvokeExpr(args.get(0), methodRef, rest(args)); } else { SootMethod m = implMethod.getMethodRef().resolve(); us.add(Jimple.v().newAssignStmt(newLocal, newRef)); SpecialInvokeExpr specialInvokeExpr = Jimple.v().newSpecialInvokeExpr(newLocal, methodRef, args); InvokeStmt invokeStmt = Jimple.v().newInvokeStmt(specialInvokeExpr); us.add(invokeStmt);
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; }
invoke = soot.jimple.Jimple.v().newStaticInvokeExpr(meth, methParams); } else { invoke = soot.jimple.Jimple.v().newSpecialInvokeExpr(base, meth, methParams);
.newInvokeStmt(Jimple.v().newSpecialInvokeExpr(l, Scene.v().makeConstructorRef(Scene.v().getObjectType().getSootClass(), Collections.<Type>emptyList()), Collections.<Value>emptyList())));
params = new ArrayList(); params.add(messageLocal); soot.jimple.Expr initInvoke = soot.jimple.Jimple.v().newSpecialInvokeExpr(throwLocal, initMethToInvoke, params); soot.jimple.Stmt initStmt = soot.jimple.Jimple.v().newInvokeStmt(initInvoke); classBody.getUnits().add(initStmt);
SpecialInvokeExpr constructorInvokeExpr = Jimple.v().newSpecialInvokeExpr(exceptionLocal, cref, StringConstant.v("Unresolved compilation error: Method " + getSignature() + " does not exist!")); InvokeStmt initStmt = Jimple.v().newInvokeStmt(constructorInvokeExpr);
units.addFirst(Jimple.v().newAssignStmt(Jimple.v().newStaticFieldRef(field.makeRef()), bool)); 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)));