protected void assignColorsToLocals(Body body) { if (Options.v().verbose()) { logger.debug("[" + body.getMethod().getName() + "] Assigning colors to locals..."); localToGroup = new HashMap<Local, Object>(body.getLocalCount() * 2 + 1, 0.7f); groupToColorCount = new HashMap<Object, Integer>(body.getLocalCount() * 2 + 1, 0.7f); localToColor = new HashMap<Local, Integer>(body.getLocalCount() * 2 + 1, 0.7f); Iterator<Local> localIt = body.getLocals().iterator(); Iterator<Unit> codeIt = body.getUnits().iterator();
/** * Checks whether the given method can be made static, i.e., does not reference the "this" object * * @param target * The method to check * @return True if the given method can be made static, otherwise false */ private boolean canBeMadeStatic(SootMethod target) { if (target.hasActiveBody()) { Body body = target.getActiveBody(); Value thisLocal = body.getThisLocal(); for (Unit u : body.getUnits()) { for (ValueBox vb : u.getUseBoxes()) { if (vb.getValue() == thisLocal) { return false; } } } return true; } return false; }
/** * Prints out the method corresponding to b Body, (declaration and body), in the textual format corresponding to the IR * used to encode b body. * * @param out * a PrintWriter instance to print to. */ private void printTo(Body b, PrintWriter out) { b.validate(); String decl = b.getMethod().getDavaDeclaration(); { out.println(" " + decl); for (Iterator<Tag> tIt = b.getMethod().getTags().iterator(); tIt.hasNext();) { final Tag t = tIt.next(); if (Options.v().print_tags_in_output()) { out.println(t); } } out.println(" {"); /* * The locals are now printed out from within the toString method of ASTMethodNode Nomair A Naeem 10-MARCH-2005 */ // printLocalsInBody(b, out); } printStatementsInBody(b, out); out.println(" }"); }
@Override /** Verifies that the UnitBoxes of this Body all point to a Unit contained within this body. */ public void validate(Body body, List<ValidationException> exception) { for (UnitBox ub : body.getAllUnitBoxes()) { if (!body.getUnits().contains(ub.getUnit())) { throw new RuntimeException( "Unitbox points outside unitChain! to unit : " + ub.getUnit() + " in " + body.getMethod()); } } }
for (Unit original : b.getUnits()) { Unit copy = (Unit) original.clone(); for (Trap original : b.getTraps()) { Trap copy = (Trap) original.clone(); for (Local original : b.getLocals()) { Local copy = (Local) original.clone(); for (UnitBox box : getAllUnitBoxes()) { Unit newObject, oldObject = box.getUnit(); for (ValueBox vb : getUseBoxes()) { if (vb.getValue() instanceof Local) { vb.setValue((Value) bindings.get(vb.getValue())); for (ValueBox vb : getDefBoxes()) { if (vb.getValue() instanceof Local) { vb.setValue((Value) bindings.get(vb.getValue()));
protected void initialize() { int lastLocalNumber = 0; for (Local l : body.getLocals()) { localToNumber.put(l, lastLocalNumber++); localToDefsBits = new BitSet[body.getLocalCount()]; localToUsesBits = new BitSet[body.getLocalCount()]; unitList = new ArrayList<>(body.getUnits()); for (int i = 0; i < unitList.size(); i++) { Unit u = unitList.get(i);
b.getLocals().add(thisLocal); b.getUnits().add(Jimple.v().newIdentityStmt(thisLocal, Jimple.v().newThisRef(sc.getType()))); for (int i = 0; i < method.getParameterCount(); ++i) { Local paramLocal = Jimple.v().newLocal("param" + i, method.getParameterType(i)); b.getLocals().add(paramLocal); b.getUnits().add( Jimple.v().newIdentityStmt(paramLocal, Jimple.v().newParameterRef(method.getParameterType(i), i))); if (i == 0) b.getUnits() .add(Jimple.v().newInvokeStmt(Jimple.v().newVirtualInvokeExpr(thisLocal, Scene.v().makeMethodRef(sc, "handleMessage", b.getUnits().add(retStmt); b.validate();
protected void internalTransform(Body b, String phaseName, Map<String, String> options) { for (Unit u : b.getUnits()) { if (u instanceof TargetArgInst && !(u instanceof GotoInst) && !(u instanceof JSRInst)) { count++; } } } }
/** 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; }
@Override public void injectCode(Body body, Local messageLocal) { body.getUnits() .add(Jimple.v().newAssignStmt( Jimple.v().newInstanceFieldRef(messageLocal, fldWhat.makeRef()), body.getParameterLocal(1))); }
protected void internalTransform(Body b, String phaseName, Map<String, String> options) { if (!b.getMethod().isSynchronized() || b.getMethod().isStatic()) { return; } Iterator<Unit> it = b.getUnits().snapshotIterator(); while (it.hasNext()) { Unit u = it.next(); if (u instanceof IdentityStmt) { continue; } // This the first real statement. If it is not a MonitorEnter // instruction, we generate one if (!(u instanceof EnterMonitorStmt)) { b.getUnits().insertBeforeNoRedirect(Jimple.v().newEnterMonitorStmt(b.getThisLocal()), u); // We also need to leave the monitor when the method terminates UnitGraph graph = new ExceptionalUnitGraph(b); for (Unit tail : graph.getTails()) { b.getUnits().insertBefore(Jimple.v().newExitMonitorStmt(b.getThisLocal()), tail); } } break; } } }
@Override /** Verifies that the begin, end and handler units of each trap are in this body. */ public void validate(Body body, List<ValidationException> exception) { PatchingChain<Unit> units = body.getUnits(); for (Trap t : body.getTraps()) { if (!units.contains(t.getBeginUnit())) { exception.add(new ValidationException(t.getBeginUnit(), "begin not in chain" + " in " + body.getMethod())); } if (!units.contains(t.getEndUnit())) { exception.add(new ValidationException(t.getEndUnit(), "end not in chain" + " in " + body.getMethod())); } if (!units.contains(t.getHandlerUnit())) { exception.add(new ValidationException(t.getHandlerUnit(), "handler not in chain" + " in " + body.getMethod())); } } }
@Override public Local[] load(SootMethod method) throws Exception { if (!method.isConcrete() || !method.hasActiveBody()) return new Local[0]; List<Local> lcs = new ArrayList<Local>(method.getParameterCount() + (method.isStatic() ? 0 : 1)); for (Unit u : method.getActiveBody().getUnits()) useBox: for (ValueBox vb : u.getUseBoxes()) { // Check for parameters for (int i = 0; i < method.getParameterCount(); i++) { if (method.getActiveBody().getParameterLocal(i) == vb.getValue()) { lcs.add((Local) vb.getValue()); continue useBox; } } } // Add the "this" local if (!method.isStatic()) lcs.add(method.getActiveBody().getThisLocal()); return lcs.toArray(new Local[lcs.size()]); } });
/** * Reassigns the local numbers such that a dense bit set can be created over them */ public void pack() { int n = body.getLocalCount(); locals = new Local[n]; oldNumbers = new int[n]; n = 0; for (Local local : body.getLocals()) { locals[n] = local; oldNumbers[n] = local.getNumber(); local.setNumber(n++); } }
/** A constructor that doesn't run the analysis */ protected SimpleMethodInfoFlowAnalysis(UnitGraph g, InfoFlowAnalysis dfa, boolean ignoreNonRefTypeFlow, boolean dummyDontRunAnalysisYet) { super(g); this.sm = g.getBody().getMethod(); if (sm.isStatic()) { this.thisLocal = null; } else { this.thisLocal = g.getBody().getThisLocal(); } this.dfa = dfa; this.refOnly = ignoreNonRefTypeFlow; this.infoFlowGraph = new MemoryEfficientGraph<EquivalentValue>(); this.returnRef = new ParameterRef(g.getBody().getMethod().getReturnType(), -1); // it's a dummy parameter ref this.entrySet = new ArraySparseSet<Pair<EquivalentValue, EquivalentValue>>(); this.emptySet = new ArraySparseSet<Pair<EquivalentValue, EquivalentValue>>(); printMessages = false; }
if (sm.getActiveBody().getThisLocal() == l) { paramRegNum = 0; found = true; if (sm.getActiveBody().getParameterLocal(i) == l) {