PatchingChain<Unit> units = b.getUnits(); GuaranteedDefs gd = new GuaranteedDefs(new soot.toolkits.graph.ExceptionalUnitGraph(b)); Iterator<Unit> unitIt = units.snapshotIterator(); Unit after = null; while (unitIt.hasNext()) { units.addFirst(after); units.insertAfter(store, after); units.insertBefore(tmp, store); store = tmp; units.insertBefore(pinit, store); units.remove(after);
final int unitsLeft = units.size() - precedingFirstNotIdentityIndex; if (unitsLeft < 8) { if (isVerbose()) { final Unit first = precedingFirstNotIdentity == null ? units.getFirst() : precedingFirstNotIdentity; final Unit firstReorderingUnit = units.getSuccOf(first); final Unit nextReorderingUnit = units.getSuccOf(reorderingUnit); units.remove(reorderingUnit); units.add(reorderingUnit); = first instanceof GotoStmt ? ((GotoStmt) first).getTargetBox().getUnit() : firstReorderingUnit; final GotoStmt gotoFirstReorderingNotGotoStmt = Jimple.v().newGotoStmt(firstReorderingNotGotoStmt); units.insertBeforeNoRedirect(gotoFirstReorderingNotGotoStmt, reorderingUnit); if (units.getLast().fallsThrough()) { final Stmt gotoStmt = (reorderingUnit instanceof GotoStmt) ? Jimple.v().newGotoStmt(((GotoStmt) reorderingUnit).getTargetBox().getUnit()) : Jimple.v().newGotoStmt(reorderingUnit); units.add(gotoStmt); Unit secondReorderedUnit = units.getSuccOf(firstReorderingNotGotoStmt); if (secondReorderedUnit == null || (secondReorderedUnit.equals(units.getLast()) && secondReorderedUnit instanceof IdentityStmt)) { units.add(caughtExceptionHandler); units.add(Jimple.v().newThrowStmt(caughtExceptionLocal));
public Body add(soot.jimple.Stmt stmt) { if(list != null) { list.add(stmt); list = null; } stmt.addTag(currentSourceRangeTag()); soot.PatchingChain<Unit> chain = (soot.PatchingChain<Unit>)chains.peek(); if(stmt instanceof IdentityStmt && chain.size() != 0) { IdentityStmt idstmt = (IdentityStmt) stmt; if(!(idstmt.getRightOp() instanceof CaughtExceptionRef)) { soot.Unit s = chain.getFirst(); while(s instanceof IdentityStmt) s = chain.getSuccOf((soot.jimple.Stmt)s); if(s != null) { chain.insertBefore(stmt, (soot.jimple.Stmt)s); return this; } } } chain.add(stmt); return this; }
/** Removes the given object from this Chain. */ @Override @SuppressWarnings("unchecked") public boolean remove(Object obj) { boolean res = false; if (contains(obj)) { Unit successor = getSuccOf((E) obj); if (successor == null) { successor = getPredOf((E) obj); } // Note that redirecting to the last unit in the method // like this is probably incorrect when dealing with a Trap. // I.e., let's say that the final unit in the method used to // be U10, preceded by U9, and that there was a Trap which // returned U10 as getEndUnit(). I.e., before the trap covered U9. // When we redirect the Trap's end unit to U9, the trap will no // longer cover U9. I know this is incorrect, but I'm not sure how // to fix it, so I'm leaving this comment in the hopes that some // future maintainer will see the right course to take. res = innerChain.remove(obj); ((E) obj).redirectJumpsToThisTo(successor); } return res; }
private Unit findNonTrappedUnit(PatchingChain<Unit> units, Chain<Trap> traps) { int intrap = 0; ArrayList<Unit> untrapped = new ArrayList<Unit>(); Iterator<Unit> it = units.snapshotIterator(); while (it.hasNext()) { Unit u = it.next(); count++; result = untrapped.get(Rand.getInt(999999) % untrapped.size()); if (!result.fallsThrough() || units.getSuccOf(result) == null || units.getSuccOf(result) instanceof ThrowInst) { result = null;
SootMethod thisMethod = b.getMethod(); PatchingChain<Unit> units = b.getUnits(); Iterator<Unit> unitIt = units.iterator(); Unit firstUnit = j.getFirstNonIdentityStmt(); Unit lastUnit = units.getLast(); clinitUnits.add(newStmt); } else { clinitUnits.insertBeforeNoRedirect(newStmt, firstStmt); .newInvokeStmt(Jimple.v().newSpecialInvokeExpr(lockObj[i], initMethod.makeRef(), Collections.EMPTY_LIST)); if (addingNewClinit) { clinitUnits.add(initStmt); } else { clinitUnits.insertBeforeNoRedirect(initStmt, firstStmt); clinitUnits.add(assignStmt); } else { clinitUnits.insertBeforeNoRedirect(assignStmt, firstStmt); clinitUnits.add(Jimple.v().newReturnVoidStmt()); units.insertBeforeNoRedirect(newPrep, firstUnit); } else { units.insertBefore(newPrep, tn.entermonitor); units.insertBefore(newPrep, tn.entermonitor); } else { units.insertBeforeNoRedirect(newPrep, tn.beginning);
Unit last = null; nonTrap = Baf.v().newNopInst(); for (Iterator<Unit> it = units.iterator(); it.hasNext();) { Unit u = (Unit) it.next(); if (u instanceof IdentityInst && ((IdentityInst) u).getLeftOp() instanceof Local) { } else { if (last != null) { units.insertAfter(nonTrap, last); } else { units.addFirst(nonTrap); Iterator<Unit> it = units.snapshotIterator(); while (it.hasNext()) { Unit u = (Unit) it.next(); TargetArgInst ifu = (TargetArgInst) u; Unit newTarg = Baf.v().newGotoInst(ifu.getTarget()); units.add(newTarg); ifu.setTarget(newTarg); addedUnits.add(newTarg); units.add(nop); toinsert.add(Baf.v().newStaticGetInst(field.makeRef())); if (field.getType() instanceof IntegerType) { toinsert.add(Baf.v().newIfGeInst((Unit) units.getSuccOf(nonTrap))); } else { SootMethod boolInit = ((RefType) field.getType()).getSootClass().getMethod("boolean booleanValue()");
Trap t = trapList.get(i); Unit nop = Baf.v().newNopInst(); units.insertBeforeNoRedirect(nop, headList.get(i)); headList.set(i, nop); t.setBeginUnit(nop); Iterator<Unit> uit = units.iterator(); while (uit.hasNext()) { Unit unit = (Unit) uit.next(); units.insertBefore(first, units.getFirst()); } else { first = (Unit) units.getSuccOf(first); units.insertBeforeNoRedirect((Unit) pushZero.clone(), first); units.insertBeforeNoRedirect((Unit) storZero.clone(), first); units.add(pushZero); units.add(storZero); locs.add(varLocal); varsToLoad.push(varLocal); units.add(Baf.v().newStoreInst(type, varLocal)); units.insertBeforeNoRedirect(FixUndefinedLocals.getPushInitializer(varLocal, type), first); units.insertBeforeNoRedirect(Baf.v().newStoreInst(type, varLocal), first); units.add(Baf.v().newPushInst(NullConstant.v())); units.add(Baf.v().newGotoInst(begUnit));
Iterator<Unit> it = units.snapshotIterator(); Unit prev = null; SpecialInvokeInst sii = null; Type t = ((Local) locals.get(bl)).getType(); if (t instanceof RefType && ((RefType) t).getSootClass().getName().equals(origClass.getName())) { units.insertBefore(Baf.v().newDup1Inst(RefType.v()), sii); Unit ifinst = Baf.v().newIfNullInst(sii); units.insertBeforeNoRedirect(ifinst, sii); units.insertAfter(Baf.v().newThrowInst(), ifinst); units.insertAfter(Baf.v().newPushInst(NullConstant.v()), ifinst); units.add(pop); units.add((Unit) prev.clone()); b.getTraps().add(Baf.v().newTrap(ThrowSet.getRandomThrowable(), ifinst, sii, pop)); if (Rand.getInt() % 2 == 0) { pop = (Unit) pop.clone(); units.insertBefore(pop, sii); units.insertBefore(Baf.v().newGotoInst(sii), pop); units.add(Baf.v().newJSRInst(pop)); } else { units.add(Baf.v().newGotoInst(sii)); if (!BodyBuilder.isExceptionCaughtAt(units, sii, b.getTraps().iterator())) { Unit handler = Baf.v().newThrowInst(); units.add(handler); b.getTraps().add(Baf.v().newTrap(ThrowSet.getRandomThrowable(), sii, (Unit) units.getSuccOf(sii), handler)); done = true; break;
boolean change = false; PatchingChain<Unit> units = b.getUnits(); Iterator<Unit> uit = units.snapshotIterator(); while (uit.hasNext()) { Unit u = uit.next(); Unit succ = units.getSuccOf(u); Unit pop = Baf.v().newPopInst(RefType.v()); Unit popClone = (Unit) pop.clone(); units.insertBefore(pop, targ); units.insertBefore(gotoTarg, pop); units.insertBefore(methCall, u); units.remove(u); units.insertAfter(popClone, methCall); } else { Unit throwu = Baf.v().newThrowInst(); units.insertBefore(throwu, u); units.remove(u); units.insertBefore(Baf.v().newPushInst(NullConstant.v()), throwu); Unit ifunit = Baf.v().newIfCmpNeInst(RefType.v(), succ); units.insertBefore(ifunit, throwu); units.insertBefore(Baf.v().newPushInst(NullConstant.v()), throwu); units.insertBefore(methCall, u);
HashMap<TargetArgInst, Unit> ignoreJumps = new HashMap<TargetArgInst, Unit>(); PatchingChain<Unit> u = b.getUnits(); Iterator<Unit> it = u.snapshotIterator(); while (it.hasNext()) { Unit unit = it.next(); it = u.snapshotIterator(); ArrayList<Unit> processedLabels = new ArrayList<Unit>(); HashMap<Unit, JSRInst> builtJsrs = new HashMap<Unit, JSRInst>(); JSRInst ji = Baf.v().newJSRInst(unit); builtJsrs.put(unit, ji); u.insertAfter(ji, prev); jsrcount++; u.insertBefore(pop, unit); processedLabels.add(unit); popsBuilt.put(pop, unit); it = u.snapshotIterator(); while (it.hasNext()) { Unit unit = (Unit) it.next(); } else { ji = Baf.v().newJSRInst(tu); u.insertAfter(ji, u.getPredOf(tu)); ti.setTarget(ji); it = u.snapshotIterator();
if (!body.getUnits().isEmpty()) { LinkedList<Unit> startPoints = new LinkedList<Unit>(); startPoints.addLast(body.getUnits().getFirst()); Iterator stmtIt = body.getUnits().snapshotIterator(); while (stmtIt.hasNext()) body.getUnits().remove(stmt); Set traps = handlerToTraps.get(stmt); if (traps != null) {
int longestSeq = (units.size() / 2) - 1; if (longestSeq > 20) { longestSeq = 20; Map<Unit, Stack<Type>> stackHeightsBefore = null; for (int count = longestSeq; count > 2; count--) { Unit uArry[] = units.toArray(new Unit[units.size()]); if (uArry.length <= 0) { return; units.insertBefore(store, first); units.insertBefore(pushUnit, store); Unit jump = units.getSuccOf(next.get(next.size() - 1)); units.insertBefore(storet, firstt); units.insertBefore(pushUnit, storet); units.insertAfter(goUnit, storet); jumps.add(jump); Unit swUnit = Baf.v().newTableSwitchInst(units.getSuccOf(insertAfter), 1, jumps.size(), jumps); units.insertAfter(swUnit, insertAfter); units.insertAfter(loadUnit, insertAfter);
Iterator<Unit> it = units.snapshotIterator(); while (it.hasNext()) { Unit unit = (Unit) it.next(); units.insertBefore(Jimple.v().newAssignStmt(b1, Jimple.v().newStaticFieldRef(ops[0].makeRef())), u); } else { RefType rt = (RefType) ops[0].getType(); Local B = Jimple.v().newLocal("addswitchesBOOL1", rt); locals.add(B); units.insertBefore(Jimple.v().newAssignStmt(B, Jimple.v().newStaticFieldRef(ops[0].makeRef())), u); units.insertBefore( Jimple.v().newAssignStmt(b1, Jimple.v().newVirtualInvokeExpr(B, m.makeRef(), Collections.<Value>emptyList())), u); units.insertBefore(Jimple.v().newAssignStmt(b2, Jimple.v().newStaticFieldRef(ops[1].makeRef())), u); } else { RefType rt = (RefType) ops[1].getType(); Local B = Jimple.v().newLocal("addswitchesBOOL2", rt); locals.add(B); units.insertBefore(Jimple.v().newAssignStmt(B, Jimple.v().newStaticFieldRef(ops[1].makeRef())), u); units.insertBefore( Jimple.v().newAssignStmt(b2, Jimple.v().newVirtualInvokeExpr(B, m.makeRef(), Collections.<Value>emptyList())), u); units.insertBefore(ifstmt, u); units.insertBeforeNoRedirect(Jimple.v().newAssignStmt(l, IntConstant.v(0)), first); units.insertAfter(Jimple.v().newTableSwitchStmt(l, 1, zeroheight.size(), targs, u), ifstmt);
private void split_new() { LocalDefs defs = LocalDefs.Factory.newLocalDefs(stmtBody); PatchingChain<Unit> units = stmtBody.getUnits(); Stmt[] stmts = new Stmt[units.size()]; units.toArray(stmts); units.insertAfter(Jimple.v().newAssignStmt(assign.getLeftOp(), newlocal), assign); assign.setLeftOp(newlocal);
/** Replaces <code>out</code> in the Chain by <code>in</code>. */ public void swapWith(E out, E in) { insertBefore(in, out); remove(out); }
protected void internalTransform(Body b, String phaseName, Map<String, String> options) { if (b.getMethod().getName().indexOf("<clinit>") >= 0) { return; } int weight = soot.jbco.Main.getWeight(phaseName, b.getMethod().getSignature()); if (weight == 0) { return; } PatchingChain<Unit> units = b.getUnits(); Iterator<Unit> iter = units.snapshotIterator(); while (iter.hasNext()) { Unit u = (Unit) iter.next(); if (u instanceof PushInst) { SootField f = CollectConstants.constantsToFields.get(((PushInst) u).getConstant()); if (f != null && Rand.getInt(10) <= weight) { Unit get = Baf.v().newStaticGetInst(f.makeRef()); units.insertBefore(get, u); BodyBuilder.updateTraps(get, u, b.getTraps()); units.remove(u); updated++; } } } } }
Iterator<Unit> it = units.snapshotIterator(); while (it.hasNext()) { Unit u = it.next(); IfStmt ifs = (IfStmt) s; JGotoStmt jgs = new JGotoStmt((Unit) units.getSuccOf(u)); units.insertAfter(jgs, u); units.insertAfter(jumper, jgs); ifs.setTarget((Unit) jumper); for (int i = 0; i < targetCount; i++) { JGotoStmt jgs = new JGotoStmt((Unit) tss.getTarget(i)); units.insertAfter(jgs, tss); tss.setTarget(i, (Unit) jgs); units.insertAfter(jgs, tss); tss.setDefaultTarget((Unit) jgs); units.insertAfter(jgs, lss); lss.setTarget(i, (Unit) jgs); units.insertAfter(jgs, lss); lss.setDefaultTarget((Unit) jgs); units.addLast(jgs); t.setHandlerUnit((Unit) jgs);
units.insertBefore(clone, u); units.insertBefore(Baf.v().newSwapInst(RefType.v(), clone.getOpType()), u); units.insertBefore(clone, u); Type t2 = clone.getOpType(); Unit dup; dup = Baf.v().newDup1_x2Inst(t2, t, t); units.insertBefore(dup, u); units.insertBefore(Baf.v().newPopInst(t2), u); units.insertBefore(clone, u); units.insertBefore(Baf.v().newSwapInst(IntType.v(), clone.getOpType()), u); ((TargetArgInst) u).setTarget((Unit) bug.getSuccsOf(suc).get(0)); } else { units.insertAfter(Baf.v().newGotoInst((Unit) bug.getSuccsOf(suc).get(0)), u); units.remove(suc);
public static List<Local> buildParameterLocals(PatchingChain<Unit> units, Collection<Local> locals, List<Type> paramTypes) { List<Local> args = new ArrayList<Local>(); for (int k = 0; k < paramTypes.size(); k++) { Type type = paramTypes.get(k); Local loc = Jimple.v().newLocal("l" + k, type); locals.add(loc); units.add(Jimple.v().newIdentityStmt(loc, Jimple.v().newParameterRef(type, k))); args.add(loc); } return args; }