private void compareTypeAssigners(Body b, boolean useOlderTypeAssigner) { JimpleBody jb = (JimpleBody) b, oldJb, newJb; int size = jb.getUnits().size(); long oldTime, newTime; if (useOlderTypeAssigner) { newJb = (JimpleBody) jb.clone(); newTime = System.currentTimeMillis(); (new soot.jimple.toolkits.typing.fast.TypeResolver(newJb)).inferTypes(); } else { oldJb = (JimpleBody) jb.clone(); oldTime = System.currentTimeMillis(); TypeResolver.resolve(oldJb, Scene.v()); if (newJb.getLocals().size() < oldJb.getLocals().size()) { cmp = 2; } else if (newJb.getLocals().size() > oldJb.getLocals().size()) { cmp = -2; } else { logger.debug("cmp;" + jb.getMethod() + ";" + size + ";" + oldTime + ";" + newTime + ";" + cmp);
/** Inserts usual statements for handling this & parameters into body. */ public void insertIdentityStmts() { insertIdentityStmts(getMethod().getDeclaringClass()); }
/** * Make sure that the JimpleBody is well formed. If not, throw an exception. Right now, performs only a handful of checks. */ @Override public void validate() { final List<ValidationException> exceptionList = new ArrayList<ValidationException>(); validate(exceptionList); if (!exceptionList.isEmpty()) { throw exceptionList.get(0); } }
/** Clones the current body, making deep copies of the contents. */ @Override public Object clone() { Body b = new JimpleBody(getMethod()); b.importBodyContentsFrom(this); return b; }
public TypeResolver(JimpleBody jb) { this.jb = jb; this.assignments = new ArrayList<DefinitionStmt>(); this.depends = new HashMap<Local, BitSet>(jb.getLocalCount()); for (Local v : this.jb.getLocals()) { this.addLocal(v); } this.initAssignments(); }
b.insertIdentityStmts(); final Local thisLocal = b.getThisLocal(); final Local binderLocal = b.getParameterLocal(0); b.getUnits().add(Jimple.v().newAssignStmt(Jimple.v().newInstanceFieldRef(thisLocal, binderField.makeRef()), binderLocal)); b.getUnits().add(Jimple.v().newReturnStmt(binderLocal)); } else { Stmt firstNonIdentityStmt = b.getFirstNonIdentityStmt(); final Local thisLocal = b.getThisLocal(); final Local binderLocal = b.getParameterLocal(0); b.getUnits().insertAfter(Jimple.v() .newAssignStmt(Jimple.v().newInstanceFieldRef(thisLocal, binderField.makeRef()), binderLocal), firstNonIdentityStmt);
int size = node.getCatchClause().size(); for (int i = 0; i < size; i++) { jBody.getTraps().addFirst((Trap) mProductions.removeLast()); Object o = mProductions.removeLast(); if (o instanceof Unit) { jBody.getUnits().addFirst((Unit) o); lastStmt = (Unit) o; } else if (o instanceof String) { List<Local> localList = (List<Local>) mProductions.removeLast(); jBody.getLocals().addAll(localList);
private Local insertCast(Value oldvalue, Type oldtype, Type type, Stmt stmt) { Local newlocal1 = Jimple.v().newLocal("tmp", oldtype); Local newlocal2 = Jimple.v().newLocal("tmp", type); stmtBody.getLocals().add(newlocal1); stmtBody.getLocals().add(newlocal2); Unit u = Util.findFirstNonIdentityUnit(this.stmtBody, stmt); stmtBody.getUnits().insertBefore(Jimple.v().newAssignStmt(newlocal1, oldvalue), u); stmtBody.getUnits().insertBefore(Jimple.v().newAssignStmt(newlocal2, Jimple.v().newCastExpr(newlocal1, type)), u); return newlocal2; } }
public BafBody(JimpleBody body, Map<String, String> options) { super(body.getMethod()); JimpleToBafContext context = new JimpleToBafContext(jimpleBody.getLocalCount()); this.jimpleToBafContext = context; for (Local l : jimpleBody.getLocals()) { Type t = l.getType(); Local newLocal = Baf.v().newLocal(l.getName(), UnknownType.v()); for (Unit u : jimpleBody.getUnits()) { Stmt s = (Stmt) u; List<Unit> conversionList = new ArrayList<Unit>(); for (Trap trap : jimpleBody.getTraps()) { getTraps().add(Baf.v().newTrap(trap.getException(), stmtToFirstInstruction.get(trap.getBeginUnit()), stmtToFirstInstruction.get(trap.getEndUnit()), stmtToFirstInstruction.get(trap.getHandlerUnit())));
body.insertIdentityStmts(); SootClass objArrayClass = getArrayReplacementType(objAr).getSootClass(); SootMethod superConstructor = objArrayClass.getMethod(SootMethod.constructorName, argTypes); body.getUnits().add(Jimple.v().newInvokeStmt( Jimple.v().newSpecialInvokeExpr(body.getThisLocal(), superConstructor.makeRef(), body.getParameterLocals()))); String elementTypeName = ((RefType) elementType).getSootClass().getJavaStyleName(); elementTypeName = elementTypeName.replace('.', '/'); body.getUnits().add(Jimple.v().newAssignStmt( Jimple.v().newInstanceFieldRef(body.getThisLocal(), elemTypeField.makeRef()), ClassConstant.v(elementTypeName))); body.getUnits().add(retStmt); body.validate(); constructor.setActiveBody(body); arrayClass.addMethod(getElement); JimpleBody body = Jimple.v().newBody(getElement); body.insertIdentityStmts(); Local retLocal = Jimple.v().newLocal("retVal", elementType); body.getLocals().add(retLocal); List<Unit> retStmts = new LinkedList<Unit>(); Jimple.v().newInstanceFieldRef(body.getThisLocal(), arrFields[i].makeRef())); retStmts.add(ret); retStmts.add(Jimple.v().newReturnStmt(retLocal));
private void initAssignments() { for (Unit stmt : this.jb.getUnits()) { if (stmt instanceof DefinitionStmt) { this.initAssignment((DefinitionStmt) stmt); } } }
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); } }
clinitMethod = lockClass.getMethod("void <clinit>()"); clinitBody = (JimpleBody) clinitMethod.getActiveBody(); firstStmt = clinitBody.getFirstNonIdentityStmt(); PatchingChain<Unit> clinitUnits = clinitBody.getUnits(); clinitBody.getLocals().add(lockLocal); // TODO: add name conflict
for (Local local : body.getLocals()) { local.setType(arrayTypeToRefType(local.getType())); for (Unit u : new LinkedList<Unit>(body.getUnits())) { ParameterRef pr = (ParameterRef) ((IdentityStmt) u).getRightOp(); ((IdentityStmt) u).getRightOpBox().setValue(Jimple.v() .newParameterRef(body.getMethod().getParameterType(pr.getIndex()), pr.getIndex())); body.getUnits().insertAfter(ivk, u); body.getUnits().remove(u); } else { .newInvokeStmt(Jimple.v().newSpecialInvokeExpr(lhs, constructor.makeRef(), na.getSize())); ccall.addAllTagsOf(u); body.getUnits().insertAfter(ccall, u); } else if (u instanceof DefinitionStmt && ((DefinitionStmt) u).getRightOp() instanceof NewMultiArrayExpr) { .newInvokeStmt(Jimple.v().newSpecialInvokeExpr(lhs, constructor.makeRef(), args)); ccall.addAllTagsOf(u); body.getUnits().insertAfter(ccall, u); } else if (u instanceof DefinitionStmt && ((DefinitionStmt) u).getRightOp() instanceof LengthExpr) { LengthExpr le = (LengthExpr) ((DefinitionStmt) u).getRightOp(); body.validate(); } catch (soot.validation.ValidationException e) { throw e;
body.insertIdentityStmts(declaringClass); Local exceptionLocal = lg.generateLocal(runtimeExceptionType); AssignStmt assignStmt = Jimple.v().newAssignStmt(exceptionLocal, newExpr); body.getUnits().add(assignStmt); StringConstant.v("Unresolved compilation error: Method " + getSignature() + " does not exist!")); InvokeStmt initStmt = Jimple.v().newInvokeStmt(constructorInvokeExpr); body.getUnits().insertAfter(initStmt, assignStmt); body.getUnits().insertAfter(Jimple.v().newThrowStmt(exceptionLocal), initStmt);
JimpleBody body = (JimpleBody) m.retrieveActiveBody(); LocalGenerator localGen = new LocalGenerator(body); Unit firstStmt = body.getFirstNonIdentityStmt(); firstStmt = body.getUnits().getPredOf(firstStmt); InstanceFieldRef fieldRef = Jimple.v().newInstanceFieldRef(body.getParameterLocal(m.getParameterCount() - 1), Scene.v().makeFieldRef(c, ALREADY_CHECKED_FIELDNAME, BooleanType.v(), false)); Local alreadyCheckedLocal = localGen.generateLocal(BooleanType.v()); InstanceFieldRef fieldRef2 = Jimple.v().newInstanceFieldRef(body.getParameterLocal(m.getParameterCount() - 1), Scene.v().makeFieldRef(c, ALREADY_CHECKED_FIELDNAME, BooleanType.v(), false)); newUnits.add(Jimple.v().newAssignStmt(fieldRef2, IntConstant.v(1))); body.getUnits().insertAfter(newUnits, firstStmt); body.validate();
body.getLocals().add(counter); body.getUnits().add(Jimple.v().newAssignStmt(counter, IntConstant.v(0))); Stmt loopHead = Jimple.v().newIfStmt(Jimple.v().newGeExpr(counter, body.getParameterLocal(0)), returnStmt); body.getUnits().add(loopHead); body.getUnits().add(Jimple.v().newAssignStmt(newElement, Jimple.v().newNewExpr(elRefType))); List<Value> elConstructorArgs = new LinkedList<Value>(); for (int k=1; k<constructor.getParameterCount();k++) { elConstructorArgs.add(body.getParameterLocal(k)); body.getUnits().add( Jimple.v().newInvokeStmt( Jimple.v().newSpecialInvokeExpr(newElement, elConstructor.makeRef(), elConstructorArgs) args.add(newElement); body.getUnits().add(Jimple.v().newInvokeStmt(Jimple.v().newVirtualInvokeExpr(body.getThisLocal(), setElement.makeRef(), args))); body.getUnits().add(Jimple.v().newAssignStmt(counter, Jimple.v().newAddExpr(counter, IntConstant.v(1)))); body.getUnits().add(Jimple.v().newGotoStmt(loopHead));
private void handleFinalLocalInits() { ArrayList<SootField> finalsList = ((PolyglotMethodSource) body.getMethod().getSource()).getFinalsList(); if (finalsList == null) { return; } int paramCount = paramRefCount - finalsList.size(); Iterator<SootField> it = finalsList.iterator(); while (it.hasNext()) { soot.SootField sf = it.next(); soot.jimple.FieldRef fieldRef = soot.jimple.Jimple.v().newInstanceFieldRef(specialThisLocal, sf.makeRef()); soot.jimple.AssignStmt stmt = soot.jimple.Jimple.v().newAssignStmt(fieldRef, body.getParameterLocal(paramCount)); body.getUnits().add(stmt); paramCount++; } }
public Local newLocal(String name, soot.Type type) { Local local = Jimple.v().newLocal(name, type); body.getLocals().add(local); if(name.equals("this") && thisName == null) thisName = local; return local; }