private static Body getActiveBodySafely(SootMethod method) { try { return method.getActiveBody(); } catch (Exception exception) { logger.warn("Getting Body from SootMethod {} caused exception that was suppressed.", exception); } return null; }
private static Body getBodySafely(SootMethod method) { try { return method.getActiveBody(); } catch (Exception exception) { logger.warn("Getting Body from SootMethod {} caused exception that was suppressed.", exception); return method.retrieveActiveBody(); } }
@Override public List<Value> load(SootMethod m) throws Exception { return m.getActiveBody().getParameterRefs(); } });
@Override public DirectedGraph<Unit> getOrCreateUnitGraph(SootMethod m) { return getOrCreateUnitGraph(m.getActiveBody()); }
protected Set<Unit> getCallsFromWithinMethod(SootMethod m) { Set<Unit> res = null; for (Unit u : m.getActiveBody().getUnits()) { if (isCallStmt(u)) { if (res == null) { res = new LinkedHashSet<Unit>(); } res.add(u); } } return res == null ? Collections.<Unit>emptySet() : res; }
/** Returns true if some method in this class has an active Baf body. */ public boolean containsBafBody() { Iterator<SootMethod> methodIt = methodIterator(); while (methodIt.hasNext()) { SootMethod m = methodIt.next(); if (m.hasActiveBody() && m.getActiveBody() instanceof soot.baf.BafBody) { return true; } } return false; }
public void initializeUnitToOwner(SootMethod m) { if (m.hasActiveBody()) { Body b = m.getActiveBody(); PatchingChain<Unit> units = b.getUnits(); for (Unit unit : units) { unitToOwner.put(unit, b); } } }
@Override public Collection<Unit> getEndPointsOf(SootMethod m) { if (m.hasActiveBody()) { Body body = m.getActiveBody(); DirectedGraph<Unit> unitGraph = getOrCreateUnitGraph(body); return unitGraph.getTails(); } return Collections.emptySet(); }
@Override public Collection<Unit> getStartPointsOf(SootMethod m) { if (m.hasActiveBody()) { Body body = m.getActiveBody(); DirectedGraph<Unit> unitGraph = getOrCreateUnitGraph(body); return unitGraph.getHeads(); } return Collections.emptySet(); }
private void byMCalledS0(PegCallGraph pcg) { Iterator it = pcg.iterator(); while (it.hasNext()) { SootMethod sm = (SootMethod) it.next(); UnitGraph graph = new CompleteUnitGraph(sm.getActiveBody()); CallGraph callGraph = Scene.v().getCallGraph(); MultiRunStatementsFinder finder = new MultiRunStatementsFinder(graph, sm, multiCalledMethods, callGraph); FlowSet fs = finder.getMultiRunStatements(); } }
private void dumpAllBodies(String baseName, boolean deleteGraphFiles) { List<SootClass> classes = Scene.v().getClasses(SootClass.BODIES); for (SootClass cls : classes) { for (Iterator m = cls.getMethods().iterator(); m.hasNext();) { SootMethod method = (SootMethod) m.next(); if (method.hasActiveBody()) { Body body = method.getActiveBody(); if (deleteGraphFiles) { deleteOldGraphFiles(body, baseName); } dumpBody(body, baseName); } } } }
public FlowFunction<Pair<Value, Type>> getCallFlowFunction(final Unit src, final SootMethod dest) { Stmt stmt = (Stmt) src; InvokeExpr ie = stmt.getInvokeExpr(); final List<Value> callArgs = ie.getArgs(); final List<Local> paramLocals = new ArrayList<Local>(); for (int i = 0; i < dest.getParameterCount(); i++) { paramLocals.add(dest.getActiveBody().getParameterLocal(i)); } return new FlowFunction<Pair<Value, Type>>() { public Set<Pair<Value, Type>> computeTargets(Pair<Value, Type> source) { if (!dest.getName().equals("<clinit>") && !dest.getSubSignature().equals("void run()")) { Value value = source.getO1(); int argIndex = callArgs.indexOf(value); if (argIndex > -1) { return Collections.singleton(new Pair<Value, Type>(paramLocals.get(argIndex), source.getO2())); } } return Collections.emptySet(); } }; }
@Override public FlowFunction<Value> getReturnFlowFunction(final Unit callSite, SootMethod calleeMethod, final Unit exitStmt, Unit returnSite) { Stmt s = (Stmt) callSite; InvokeExpr ie = s.getInvokeExpr(); final List<Value> callArgs = ie.getArgs(); final List<Local> paramLocals = new ArrayList<Local>(); for (int i = 0; i < calleeMethod.getParameterCount(); i++) { paramLocals.add(calleeMethod.getActiveBody().getParameterLocal(i)); } return new FlowFunction<Value>() { public Set<Value> computeTargets(Value source) { Set<Value> liveParamsAtCallee = new HashSet<Value>(); for (int i = 0; i < paramLocals.size(); i++) { if (paramLocals.get(i).equivTo(source)) { liveParamsAtCallee.add(callArgs.get(i)); } } return liveParamsAtCallee; } }; }
@Override public Map<Unit, Set<Local>> initialSeeds() { return DefaultSeeds.make(Collections.singleton(Scene.v().getMainMethod().getActiveBody().getUnits().getFirst()), zeroValue()); } }
public Map<Unit, Set<Local>> initialSeeds() { return DefaultSeeds.make(Collections.singleton(Scene.v().getMainMethod().getActiveBody().getUnits().getFirst()), zeroValue()); }
public Map<Unit, Set<Pair<Value, Type>>> initialSeeds() { return DefaultSeeds.make(Collections.singleton(Scene.v().getMainMethod().getActiveBody().getUnits().getFirst()), zeroValue()); }
public Map<Unit, Set<Pair<Value, Set<DefinitionStmt>>>> initialSeeds() { return DefaultSeeds.make(Collections.singleton(Scene.v().getMainMethod().getActiveBody().getUnits().getFirst()), zeroValue()); }
@Override public int getJavaSourceStartLineNumber() { super.getJavaSourceStartLineNumber(); // search statements for first line number if (line == -1 && hasActiveBody()) { PatchingChain<Unit> unit = getActiveBody().getUnits(); for (Unit u : unit) { int l = u.getJavaSourceStartLineNumber(); if (l > -1) { // store l-1, as method header is usually one line before // 1st statement line = l - 1; break; } } } return line; }
@Override public Body getBody(SootMethod m, String phaseName) { Body b = Jimple.v().newBody(m); try { // add the body of this code item DexBody dexBody = new DexBody(dexFile, method, declaringClass.getType()); dexBody.jimplify(b, m); } catch (InvalidDalvikBytecodeException e) { String msg = "Warning: Invalid bytecode in method " + m + ": " + e; logger.debug("" + msg); Util.emptyBody(b); Util.addExceptionAfterUnit(b, "java.lang.RuntimeException", b.getUnits().getLast(), "Soot has detected that this method contains invalid Dalvik bytecode," + " which would have throw an exception at runtime. [" + msg + "]"); TypeAssigner.v().transform(b); } m.setActiveBody(b); return m.getActiveBody(); } };
public BafBody convertJimpleBodyToBaf(SootMethod m) { JimpleBody body = (JimpleBody) m.getActiveBody().clone(); // Change // ConditionalBranchFolder.v().transform(body); // UnreachableCodeEliminator.v().transform(body); // DeadAssignmentEliminator.v().transform(body); // UnusedLocalEliminator.v().transform(body); BafBody bafBody = Baf.v().newBody(body); PackManager.v().getPack("bop").apply(bafBody); PackManager.v().getPack("tag").apply(bafBody); if (Options.v().validate()) { bafBody.validate(); } return bafBody; }