private Local getLocalUnsafe(Body b, String name) { for (Local local : b.getLocals()) { if (local.getName().equals(name)) { return local; } } return null; }
private void retrieveAllArrayLocals(Body body, Set<Local> container) { for (Local local : body.getLocals()) { Type type = local.getType(); if (type instanceof IntType || type instanceof ArrayType) { container.add(local); } } }
/** * Gets all variables that are not used in this body * * @return The list of variables declared, but not used in this body */ public Set<Local> getUnusedVariables() { Set<Local> res = new HashSet<Local>(body.getLocals()); res.retainAll(getUsedVariables()); return res; }
private void initLocalNames() { localNames = new HashSet<String>(); for (Local l : body.getLocals()) { localNames.add(l.getName()); } }
private void retrieveMultiArrayLocals(Body body, Set<Local> container) { for (Local local : body.getLocals()) { Type type = local.getType(); if (type instanceof ArrayType) { if (((ArrayType) type).numDimensions > 1) { this.multiarraylocals.add(local); } } } }
protected void internalTransform(Body body, String phaseName, Map<String, String> options) { soot.jbco.Main.methods2JLocals.put(body.getMethod(), new ArrayList<Local>(body.getLocals())); } }
public SimpleLocalDefs(UnitGraph graph, FlowAnalysisMode mode) { this(graph, graph.getBody().getLocals(), mode); }
private boolean hasArrayLocals(Body body) { Iterator localIt = body.getLocals().iterator(); while (localIt.hasNext()) { Local local = (Local) localIt.next(); if (local.getType() instanceof ArrayType) { return true; } } return false; }
public String toString() { StringBuffer tmp = new StringBuffer(); Body b = cfg.getBody(); Iterator localsIt = b.getLocals().iterator(); while (localsIt.hasNext()) { Local local = (Local) localsIt.next(); tmp.append(local + "\t" + getGlobalValueNumber(local) + "\n"); } /* * Iterator partitionsIt = partitions.iterator(); while(partitionsIt.hasNext()){ Partition partition = (Partition) * partitionsIt.next(); int partitionNumber = partition.getPartitionNumber(); * * Iterator partitionIt = partition.iterator(); while(partitionIt.hasNext()){ Local local = * vg.getLocal((Node)partitionIt.next()); if(local == null) continue; tmp.append(local + "\t" + partitionNumber + "\n"); * } } */ return tmp.toString(); }
@Override public void validate(Body body, List<ValidationException> exception) { for (Local l : body.getLocals()) { if (l.getType() instanceof VoidType) { exception.add(new ValidationException(l, "Local " + l + " in " + body.getMethod() + " defined with void type")); } } }
public SCPFAnalysis(UnitGraph graph) { super(graph); emptySet = new ArraySparseSet(); stmtToReplacement = new HashMap<Stmt, GotoStmt>(); deadStmts = new ArrayList<IfStmt>(); // initialise localToConstant map -- assume all scalars are // constant (Top) { Collection<Local> locals = graph.getBody().getLocals(); Iterator<Local> localsIt = locals.iterator(); localToConstant = new HashMap<Local, Constant>(graph.size() * 2 + 1, 0.7f); while (localsIt.hasNext()) { Local local = (Local) localsIt.next(); localToConstant.put(local, TopConstant.v()); } } doAnalysis(); }
protected soot.Local createLocal(String name, soot.Type sootType) { soot.Local sootLocal = soot.jimple.Jimple.v().newLocal(name, sootType); body.getLocals().add(sootLocal); return sootLocal; } }
private void validateLocal(Body body, ValueBox vb, List<ValidationException> exception) { Value value; if ((value = vb.getValue()) instanceof Local) { if (!body.getLocals().contains(value)) { exception.add(new ValidationException(value, "Local not in chain : " + value + " in " + body.getMethod())); } } }
/** * 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++); } }
public InitAnalysis(UnitGraph g) { super(g); allLocals = new ArraySparseSet<Local>(); for (Local loc : g.getBody().getLocals()) { allLocals.add(loc); } doAnalysis(); }
@Override protected void internalTransform(Body b, String phaseName, Map<String, String> options) { LocalCreation lc = new LocalCreation(b.getLocals(), "ex"); for (Iterator<Unit> unitIt = b.getUnits().snapshotIterator(); unitIt.hasNext();) { Unit u = unitIt.next(); // Check for a null exception if (u instanceof ThrowStmt) { ThrowStmt throwStmt = (ThrowStmt) u; if (throwStmt.getOp() == NullConstant.v() || throwStmt.getOp().equals(IntConstant.v(0)) || throwStmt.getOp().equals(LongConstant.v(0))) { createThrowStmt(b, throwStmt, lc); } } } }
@Override protected Map<Value, Parity> newInitialFlow() { Map<Value, Parity> initMap = new HashMap<Value, Parity>(); for (Local l : g.getBody().getLocals()) { Type t = l.getType(); // System.out.println("next local: "+next); if ((t instanceof IntegerType) || (t instanceof LongType)) { initMap.put(l, BOTTOM); } } for (ValueBox vb : g.getBody().getUseAndDefBoxes()) { Value val = vb.getValue(); if (val instanceof ArithmeticConstant) { initMap.put(val, getParity(initMap, val)); } } if (Options.v().interactive_mode()) { updateBeforeFilterMap(); } return initMap; }
@Override public void validate(Body body, List<ValidationException> exceptions) { SootMethod method = body.getMethod(); if (method != null) { if (!method.getReturnType().isAllowedInFinalCode()) { exceptions.add(new ValidationException(method, "Return type not allowed in final code: " + method.getReturnType(), "return type not allowed in final code:" + method.getReturnType() + "\n method: " + method)); } for (Type t : method.getParameterTypes()) { if (!t.isAllowedInFinalCode()) { exceptions.add(new ValidationException(method, "Parameter type not allowed in final code: " + t, "parameter type not allowed in final code:" + t + "\n method: " + method)); } } } for (Local l : body.getLocals()) { Type t = l.getType(); if (!t.isAllowedInFinalCode()) { exceptions.add(new ValidationException(l, "Local type not allowed in final code: " + t, "(" + method + ") local type not allowed in final code: " + t + " local: " + l)); } } }
/** * 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); }