public void collectMethodTags(SootMethod sm) { if (sm.hasActiveBody()) { collectHostTags(sm); } }
private void releaseBodies(SootClass cl) { Iterator<SootMethod> methodIt = cl.methodIterator(); while (methodIt.hasNext()) { SootMethod m = methodIt.next(); if (m.hasActiveBody()) { m.releaseActiveBody(); } } }
/** 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> getStartPointsOf(SootMethod m) { if (m.hasActiveBody()) { Body body = m.getActiveBody(); DirectedGraph<Unit> unitGraph = getOrCreateUnitGraph(body); return unitGraph.getHeads(); } return Collections.emptySet(); }
@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<SootMethod> load(Unit u) throws Exception { ArrayList<SootMethod> res = null; // only retain callers that are explicit call sites or // Thread.start() Iterator<Edge> edgeIter = new EdgeFilter().wrap(cg.edgesOutOf(u)); while (edgeIter.hasNext()) { Edge edge = edgeIter.next(); SootMethod m = edge.getTgt().method(); if (includePhantomCallees || m.hasActiveBody()) { if (res == null) { res = new ArrayList<SootMethod>(); } res.add(m); } else if (IDESolver.DEBUG) { logger.error(String.format("Method %s is referenced but has no body!", m.getSignature(), new Exception())); } } if (res != null) { res.trimToSize(); return res; } else { return Collections.emptySet(); } } };
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); } } } }
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); } } } }
public void preJimplify() { boolean change = true; while (change) { change = false; for (Iterator<SootClass> cIt = new ArrayList<>(Scene.v().getClasses()).iterator(); cIt.hasNext();) { final SootClass c = cIt.next(); for (final SootMethod m : c.getMethods()) { if (!m.isConcrete()) { continue; } if (m.isNative()) { continue; } if (m.isPhantom()) { continue; } if (!m.hasActiveBody()) { change = true; m.retrieveActiveBody(); } } } } }
@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; }
public static void retrieveAllBodies() { if (bodiesHaveBeenBuilt) { return; } // iterate through application classes, rename fields with junk for (SootClass c : soot.Scene.v().getApplicationClasses()) { for (SootMethod m : c.getMethods()) { if (!m.isConcrete()) { continue; } if (!m.hasActiveBody()) { m.retrieveActiveBody(); } } } bodiesHaveBeenBuilt = true; }
public void staticBlockInlining(SootClass sootClass) { this.sootClass = sootClass; // retrieve the clinit method if any for sootClass // the clinit method gets converted into the static block which could initialize the final variable if (!sootClass.declaresMethod("void <clinit>()")) { // System.out.println("no clinit"); return; } SootMethod clinit = sootClass.getMethod("void <clinit>()"); // System.out.println(clinit); // retireve the active body if (!clinit.hasActiveBody()) { throw new RuntimeException("method " + clinit.getName() + " has no active body!"); } Body clinitBody = clinit.getActiveBody(); Chain units = ((DavaBody) clinitBody).getUnits(); if (units.size() != 1) { throw new RuntimeException("DavaBody AST doesn't have single root."); } ASTNode AST = (ASTNode) units.getFirst(); if (!(AST instanceof ASTMethodNode)) { throw new RuntimeException("Starting node of DavaBody AST is not an ASTMethodNode"); } // running methodCallFinder on the Clinit method AST.apply(new MethodCallFinder(this)); }
/** * 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; }
private ArrayList<MethInfo> getTgtMethods(SootMethod method, boolean recurse) { if (!method.hasActiveBody()) { return new ArrayList<MethInfo>();
if (!maybeInline.hasActiveBody()) { throw new RuntimeException("method " + maybeInline.getName() + " has no active body!");
public void handleNextMethod() { if (!getNextMethod().hasActiveBody()) { return; } ArrayList<MethInfo> tgts = getTgtMethods(getNextMethod(), true); // System.out.println("for: "+getNextMethod().getName()+" tgts: "+tgts); ArrayList<MethInfo> srcs = getSrcMethods(getNextMethod(), true); // System.out.println("for: "+getNextMethod().getName()+" srcs: "+srcs); CallGraphInfo info = new CallGraphInfo(getNextMethod(), tgts, srcs); // System.out.println("sending next method"); InteractionHandler.v().handleCallGraphPart(info); // handleNextMethod(); }
/** * Collect tags from all fields and methods of <code>sc</code>. If <code>includeBodies</code> is true, then tags are also * collected from method bodies. * * @param sc * The class from which to collect the tags. */ public void collectTags(SootClass sc, boolean includeBodies) { // tag the class collectClassTags(sc); // tag fields for (SootField sf : sc.getFields()) { collectFieldTags(sf); } // tag methods for (SootMethod sm : sc.getMethods()) { collectMethodTags(sm); if (!includeBodies || !sm.hasActiveBody()) { continue; } Body b = sm.getActiveBody(); collectBodyTags(b); } }
protected void internalApply() { CGOptions options = new CGOptions(PhaseOptions.v().getPhaseOptions(this)); if (!Scene.v().hasCustomEntryPoints()) { if (!options.implicit_entry()) { Scene.v().setEntryPoints(EntryPoints.v().application()); } if (options.all_reachable()) { List<SootMethod> entryPoints = new ArrayList<SootMethod>(); entryPoints.addAll(EntryPoints.v().all()); entryPoints.addAll(EntryPoints.v().methodsOfApplicationClasses()); Scene.v().setEntryPoints(entryPoints); } } super.internalApply(); ClinitElimTransformer trimmer = new ClinitElimTransformer(); if (options.trim_clinit()) { for (SootClass cl : Scene.v().getClasses(SootClass.BODIES)) { for (SootMethod m : cl.getMethods()) { if (m.isConcrete() && m.hasActiveBody()) { trimmer.transform(m.getActiveBody()); } } } } } }
/** * @ast method * @aspect EmitJimpleRefinements * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddExtensions/SootJastAddJ/EmitJimpleRefinements.jrag:100 */ public void jimplify2() { if (!generate() || sootMethod().hasActiveBody() || (sootMethod().getSource() != null && (sootMethod().getSource() instanceof soot.coffi.CoffiMethodSource))) return; try { if (hasBlock() && !(hostType().isInterfaceDecl())) { JimpleBody body = Jimple.v().newBody(sootMethod()); sootMethod().setActiveBody(body); Body b = new Body(hostType(), body, this); b.setLine(this); for (int i = 0; i < getNumParameter(); i++) getParameter(i).jimplify2(b); getBlock().jimplify2(b); if (type() instanceof VoidType) b.add(Jimple.v().newReturnVoidStmt()); } } catch (RuntimeException e) { System.err.println("Error generating " + hostType().typeName() + ": " + this); throw e; } }