/** Returns the object immediately preceding <code>point</code>. */ @Override public E getPredOf(E point) { return innerChain.getPredOf(point); }
/** * Returns the Unit occurring immediately before some other Unit in the block. * * @param aItem * The Unit from which we wish to get it's predecessor. * @return The predecessor or null if <code>aItem</code> is the head for this Block. */ public Unit getPredOf(Unit aItem) { Chain<Unit> methodBody = mBody.getUnits(); if (aItem != mHead) { return methodBody.getPredOf(aItem); } else { return null; } }
public static boolean isExceptionCaughtAt(Chain<Unit> units, Unit u, Iterator<Trap> trapsIt) { while (trapsIt.hasNext()) { Trap t = trapsIt.next(); Iterator<Unit> it = units.iterator(t.getBeginUnit(), units.getPredOf(t.getEndUnit())); while (it.hasNext()) { if (u.equals(it.next())) { return true; } } } return false; }
/** Returns a set of units which lie inside the range of any trap. */ public static Set<Unit> getTrappedUnitsOf(Body b) { Set<Unit> trapsSet = new HashSet<Unit>(); Chain<Unit> units = b.getUnits(); for (Trap t : b.getTraps()) { Iterator<Unit> it = units.iterator(t.getBeginUnit(), units.getPredOf(t.getEndUnit())); while (it.hasNext()) { trapsSet.add(it.next()); } } return trapsSet; }
/** Returns the list of traps caught at Unit u in Body b. */ public static List<Trap> getTrapsAt(Unit unit, Body b) { List<Trap> trapsList = new ArrayList<Trap>(); Chain<Unit> units = b.getUnits(); for (Trap t : b.getTraps()) { Iterator<Unit> it = units.iterator(t.getBeginUnit(), units.getPredOf(t.getEndUnit())); while (it.hasNext()) { if (unit.equals(it.next())) { trapsList.add(t); } } } return trapsList; }
private static boolean isExceptionCaught(Unit unit, Chain<Unit> units, Chain<Trap> traps) { for (Trap trap : traps) { final Unit end = trap.getEndUnit(); if (end.equals(unit)) { return true; } final Iterator<Unit> unitsInTryIterator = units.iterator(trap.getBeginUnit(), units.getPredOf(end)); if (Iterators.contains(unitsInTryIterator, unit)) { return true; } } return false; }
private void register_AreasOfProtection(SootMethod m) { if (registeredMethods.contains(m)) { return; } registeredMethods.add(m); if (m.hasActiveBody() == false) { return; } Body b = m.getActiveBody(); Chain stmts = b.getUnits(); Iterator trapIt = b.getTraps().iterator(); while (trapIt.hasNext()) { Trap t = (Trap) trapIt.next(); SootClass exception = t.getException(); Iterator sit = stmts.iterator(t.getBeginUnit(), stmts.getPredOf(t.getEndUnit())); while (sit.hasNext()) { Stmt s = (Stmt) sit.next(); HashSet<SootClass> handled = null; if ((handled = protectionSet.get(s)) == null) { handled = new HashSet<SootClass>(); protectionSet.put(s, handled); } if (handled.contains(exception) == false) { handled.add(exception); } } } }
/** * Removes a Unit occurring before some other Unit in the Block. * * @param item * A Unit to be remove from the Block's Unit Chain. * @return True if the item could be found and removed. * */ public boolean remove(Unit item) { Chain<Unit> methodBody = mBody.getUnits(); if (item == mHead) { mHead = methodBody.getSuccOf(item); } else if (item == mTail) { mTail = methodBody.getPredOf(item); } return methodBody.remove(item); }
/** * Method to compute the edges corresponding to exceptional control flow. * * @param unitToSuccs * A <code>Map</code> from {@link Unit}s to {@link List}s of <code>Unit</code>s. This is an “out * parameter”; <code>buildExceptionalEdges</code> will add a mapping for every <code>Unit</code> within the * scope of one or more {@link Trap}s to a <code>List</code> of the handler units of those <code>Trap</code>s. * * @param unitToPreds * A <code>Map</code> from <code>Unit</code>s to <code>List</code>s of <code>Unit</code>s. This is an “out * parameter”; <code>buildExceptionalEdges</code> will add a mapping for every <code>Trap</code> handler to * all the <code>Unit</code>s within the scope of that <code>Trap</code>. */ protected void buildExceptionalEdges(Map<Unit, List<Unit>> unitToSuccs, Map<Unit, List<Unit>> unitToPreds) { for (Trap trap : body.getTraps()) { Unit first = trap.getBeginUnit(); Unit last = unitChain.getPredOf(trap.getEndUnit()); Unit catcher = trap.getHandlerUnit(); for (Iterator<Unit> unitIt = unitChain.iterator(first, last); unitIt.hasNext();) { Unit trapped = unitIt.next(); addEdge(unitToSuccs, unitToPreds, trapped, catcher); } } } }
/** * If exception e is caught at unit u in body b, return true; otherwise, return false. */ public static boolean isExceptionCaughtAt(SootClass e, Unit u, Body b) { /* * Look through the traps t of b, checking to see if: - caught exception is e; - and, unit lies between t.beginUnit and * t.endUnit */ Hierarchy h = Scene.v().getActiveHierarchy(); Chain<Unit> units = b.getUnits(); for (Trap t : b.getTraps()) { /* Ah ha, we might win. */ if (h.isClassSubclassOfIncluding(e, t.getException())) { Iterator<Unit> it = units.iterator(t.getBeginUnit(), units.getPredOf(t.getEndUnit())); while (it.hasNext()) { if (u.equals(it.next())) { return true; } } } } return false; }
current = (Unit) mUnits.getPredOf(current);
Unit prev = (Unit) units.getPredOf(newTarget); if (prev != null && prev.fallsThrough()) { units.insertAfter(Jimple.v().newGotoStmt(firstTargetStmt), prev); if (catchStart != units.getPredOf(afterEndStmt)) { throw new IllegalStateException("Assertion failure: catchStart != pred of afterEndStmt"); Tag tag = stmtstags.get(stmt); while (true) { pred = (Stmt) units.getPredOf(pred); if (pred == null) { break;
Set<Unit> trappedUnits = TrapManager.getTrappedUnitsOf(b); for (Stmt s = (Stmt) units.getLast(); s != units.getFirst(); s = (Stmt) units.getPredOf(s)) { if (trappedUnits.contains(s)) { continue; break; Stmt prosInvoke = (Stmt) units.getPredOf(s); break; Stmt prosNew = (Stmt) units.getPredOf(prosInvoke);
for (Iterator<Unit> unitIt = units.iterator(trap.getBeginUnit(), units.getPredOf(trap.getEndUnit())); unitIt .hasNext();) { Unit unit = unitIt.next();
Unit firstTrappedThrower = null; Unit firstUntrappedUnit = trap.getEndUnit(); Unit lastTrappedUnit = unitChain.getPredOf(firstUntrappedUnit); Unit lastTrappedThrower = null; for (Unit u = firstTrappedUnit; u != null && u != firstUntrappedUnit; u = unitChain.getSuccOf(u)) { for (Unit u = lastTrappedUnit; u != null; u = unitChain.getPredOf(u)) { if (mightThrowTo(graph, u, trap)) { lastTrappedThrower = u;
Iterator<Unit> it = containerUnits.iterator(containerUnits.getSuccOf(toInline), containerUnits.getPredOf(exitPoint)); Iterator<Unit> it = containerUnits.iterator(containerUnits.getSuccOf(toInline), containerUnits.getPredOf(exitPoint)); ArrayList<Unit> cuCopy = new ArrayList<Unit>(); = containerUnits.iterator(containerUnits.getSuccOf(toInline), containerUnits.getPredOf(exitPoint)); i.hasNext();) { newStmts.add(i.next());
/** Returns the object immediately preceding <code>point</code>. */ public E getPredOf(E point){return innerChain.getPredOf(point);}
/** * Returns the Unit occuring immediatly before some other Unit in the block. * * @param aItem The Unit from which we wish to get it's predecessor. * @return The predecessor or null if <code>aItem</code> is the head * for this Block. */ public Unit getPredOf(Unit aItem) { Chain<Unit> methodBody = mBody.getUnits(); if(aItem != mHead) return methodBody.getPredOf(aItem); else return null; }