@Override public void run() { m.retrieveActiveBody(); }
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(); } }
private SmartMethodLocalObjectsAnalysis getMethodLocalObjectsAnalysis(SootMethod sm, boolean includePrimitiveDataFlowIfAvailable) { if (includePrimitiveDataFlowIfAvailable && primitiveDfa != null) { Body b = sm.retrieveActiveBody(); UnitGraph g = new ExceptionalUnitGraph(b); return new SmartMethodLocalObjectsAnalysis(g, primitiveDfa); } else if (!methodToMethodLocalObjectsAnalysis.containsKey(sm)) { // Analyze this method Body b = sm.retrieveActiveBody(); UnitGraph g = new ExceptionalUnitGraph(b); SmartMethodLocalObjectsAnalysis smloa = new SmartMethodLocalObjectsAnalysis(g, dfa); methodToMethodLocalObjectsAnalysis.put(sm, smloa); } return methodToMethodLocalObjectsAnalysis.get(sm); }
protected void buildNormal() { Body b = method.retrieveActiveBody(); for (Unit u : b.getUnits()) { nodeFactory.handleStmt((Stmt) u); } }
public SmartMethodInfoFlowAnalysis getMethodInfoFlowAnalysis(SootMethod method) { if (!methodToInfoFlowAnalysis.containsKey(method)) { methodCount++; // First do simple version that doesn't follow invoke expressions // The "smart" version will be computed later, but since it may // request its own DataFlowGraph, we need this simple version first. if (!methodToInfoFlowSummary.containsKey(method)) { HashMutableDirectedGraph<EquivalentValue> dataFlowGraph = simpleConservativeInfoFlowAnalysis(method); methodToInfoFlowSummary.put(method, dataFlowGraph); } // Then do smart version that does follow invoke expressions, if possible if (method.isConcrete()) { Body b = method.retrieveActiveBody(); UnitGraph g = new ExceptionalUnitGraph(b); SmartMethodInfoFlowAnalysis smdfa = new SmartMethodInfoFlowAnalysis(g, dfa); methodToInfoFlowAnalysis.put(method, smdfa); methodToInfoFlowSummary.remove(method); methodToInfoFlowSummary.put(method, smdfa.getMethodInfoFlowSummary()); return smdfa; // logger.debug(""+method + " has SMART infoFlowGraph: "); // printDataFlowGraph(mdfa.getMethodDataFlowGraph()); } } return methodToInfoFlowAnalysis.get(method); }
@Override protected void analyseMethod(SootMethod method, PurityGraphBox dst) { Body body = method.retrieveActiveBody(); ExceptionalUnitGraph graph = new ExceptionalUnitGraph(body); new PurityIntraproceduralAnalysis(graph, this).copyResult(dst); }
private void processNewMethod(SootMethod m) { if (!m.isConcrete()) { return; } Body b = m.retrieveActiveBody(); getImplicitTargets(m); findReceivers(m, b); }
public HashMutableDirectedGraph<EquivalentValue> getMethodInfoFlowSummary(SootMethod method, boolean doFullAnalysis) { if (!methodToInfoFlowSummary.containsKey(method)) { methodCount++; // First do simple version that doesn't follow invoke expressions // The "smart" version will be computed later, but since it may // request its own DataFlowGraph, we need this simple version first. HashMutableDirectedGraph<EquivalentValue> dataFlowGraph = simpleConservativeInfoFlowAnalysis(method); methodToInfoFlowSummary.put(method, dataFlowGraph); // Then do smart version that does follow invoke expressions, if possible if (method.isConcrete() && doFullAnalysis)// && method.getDeclaringClass().isApplicationClass()) { Body b = method.retrieveActiveBody(); UnitGraph g = new ExceptionalUnitGraph(b); SmartMethodInfoFlowAnalysis smdfa = new SmartMethodInfoFlowAnalysis(g, dfa); methodToInfoFlowAnalysis.put(method, smdfa); methodToInfoFlowSummary.remove(method); methodToInfoFlowSummary.put(method, smdfa.getMethodInfoFlowSummary()); // logger.debug(""+method + " has SMART infoFlowGraph: "); // printDataFlowGraph(mdfa.getMethodDataFlowGraph()); } } return methodToInfoFlowSummary.get(method); }
private void computeAverageMethodSizeAndSaveOriginalSizes() { long sum = 0, count = 0; Iterator classesIt = Scene.v().getApplicationClasses().iterator(); while (classesIt.hasNext()) { SootClass c = (SootClass) classesIt.next(); Iterator methodsIt = c.methodIterator(); while (methodsIt.hasNext()) { SootMethod m = (SootMethod) methodsIt.next(); if (m.isConcrete()) { int size = ((JimpleBody) m.retrieveActiveBody()).getUnits().size(); sum += size; methodToOriginalSize.put(m, new Integer(size)); count++; } } } if (count == 0) { return; } } }
public static void main(String[] args) { // assumes 2 args: Class + Method Scene.v().loadClassAndSupport(args[0]); SootClass sc = Scene.v().getSootClass(args[0]); SootMethod sm = sc.getMethod(args[1]); Body b = sm.retrieveActiveBody(); CompleteBlockGraph cfg = new CompleteBlockGraph(b); System.out.println(cfg); BlockGraphConverter.addStartStopNodesTo(cfg); System.out.println(cfg); BlockGraphConverter.reverse(cfg); System.out.println(cfg); }
public void findNTRWSets(SootMethod method) { if (methodToNTReadSet.containsKey(method) && methodToNTWriteSet.containsKey(method)) { return; } MethodRWSet read = null; MethodRWSet write = null; for (Iterator<Unit> sIt = method.retrieveActiveBody().getUnits().iterator(); sIt.hasNext();) { final Stmt s = (Stmt) sIt.next(); RWSet ntr = ntReadSet(method, s); if (ntr != null) { if (read == null) { read = new MethodRWSet(); } read.union(ntr); } RWSet ntw = ntWriteSet(method, s); if (ntw != null) { if (write == null) { write = new MethodRWSet(); } write.union(ntw); } } methodToNTReadSet.put(method, read); methodToNTWriteSet.put(method, write); }
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(); } } } } }
protected void handleClass(PrintWriter out, SootClass c) { for (SootMethod m : c.getMethods()) { if (!m.isConcrete()) { continue; } Body b = m.retrieveActiveBody(); Local[] sortedLocals = b.getLocals().toArray(new Local[b.getLocalCount()]); Arrays.sort(sortedLocals, new StringComparator<Local>()); for (Local l : sortedLocals) { out.println("V " + m + l); if (l.getType() instanceof RefLikeType) { Set<Type> types = pa.reachingObjects(l).possibleTypes(); Type[] sortedTypes = types.toArray(new Type[types.size()]); Arrays.sort(sortedTypes, new StringComparator<Type>()); for (Type type : sortedTypes) { out.println("T " + type); } } } } } }
protected void ensureProcessed(SootMethod m) { if (processedMethods.contains(m)) { return; } processedMethods.add(m); if (!m.isConcrete()) { return; } if (m.isPhantom()) { return; } for (Iterator sIt = m.retrieveActiveBody().getUnits().iterator(); sIt.hasNext();) { final Stmt s = (Stmt) sIt.next(); if (s instanceof AssignStmt) { AssignStmt as = (AssignStmt) s; Value l = as.getLeftOp(); if (l instanceof FieldRef) { methodToWrite.put(m, ((FieldRef) l).getField()); } Value r = as.getRightOp(); if (r instanceof FieldRef) { methodToRead.put(m, ((FieldRef) r).getField()); } } } }
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 static void main(String[] args) { // assumes 2 args: Class + Method Scene.v().loadClassAndSupport(args[0]); SootClass sc = Scene.v().getSootClass(args[0]); SootMethod sm = sc.getMethod(args[1]); Body b = sm.retrieveActiveBody(); ShimpleBody sb = Shimple.v().newBody(b); CompleteBlockGraph cfg = new CompleteBlockGraph(sb); SimpleGlobalValueNumberer sgvn = new SimpleGlobalValueNumberer(cfg); System.out.println(sgvn); }
public static void main(String[] args) { // assumes 2 args: Class + Method Scene.v().loadClassAndSupport(args[0]); SootClass sc = Scene.v().getSootClass(args[0]); SootMethod sm = sc.getMethod(args[1]); Body b = sm.retrieveActiveBody(); ShimpleBody sb = Shimple.v().newBody(b); CompleteBlockGraph cfg = new CompleteBlockGraph(sb); ValueGraph vg = new ValueGraph(cfg); System.out.println(vg); }
protected Body initForMethod(SootMethod m) { assert Scene.v().hasFastHierarchy(); Body b = null; if (m.isConcrete()) { SootClass declaringClass = m.getDeclaringClass(); ensureClassHasBodies(declaringClass); synchronized (Scene.v()) { b = m.retrieveActiveBody(); } if (b != null) { for (Unit u : b.getUnits()) { if (unitToOwner.put(u, b) != null) { // if the unit was registered already then so were all units; // simply skip the rest break; } } } } assert Scene.v().hasFastHierarchy(); return b; }
private SootMethod getOrCreateInitializer(SootClass sc, Set<SootField> alreadyInitialized) { SootMethod smInit; // Create a static initializer if we don't already have one smInit = sc.getMethodByNameUnsafe(SootMethod.staticInitializerName); if (smInit == null) { smInit = Scene.v().makeSootMethod(SootMethod.staticInitializerName, Collections.<Type>emptyList(), VoidType.v()); smInit.setActiveBody(Jimple.v().newBody(smInit)); sc.addMethod(smInit); smInit.setModifiers(Modifier.PUBLIC | Modifier.STATIC); } else if (smInit.isPhantom()) { return null; } else { smInit.retrieveActiveBody(); // We need to collect those variables that are already initialized // somewhere for (Unit u : smInit.getActiveBody().getUnits()) { Stmt s = (Stmt) u; for (ValueBox vb : s.getDefBoxes()) { if (vb.getValue() instanceof FieldRef) { alreadyInitialized.add(((FieldRef) vb.getValue()).getField()); } } } } return smInit; }
public static EquivalentValue getNodeForFieldRef(SootMethod sm, SootField sf, Local realLocal) { if (sf.isStatic()) { return new CachedEquivalentValue(Jimple.v().newStaticFieldRef(sf.makeRef())); } else { // Jimple.v().newThisRef(sf.getDeclaringClass().getType()) if (sm.isConcrete() && !sm.isStatic() && sm.getDeclaringClass() == sf.getDeclaringClass() && realLocal == null) { JimpleLocal fakethis = new FakeJimpleLocal("fakethis", sf.getDeclaringClass().getType(), sm.retrieveActiveBody().getThisLocal()); return new CachedEquivalentValue(Jimple.v().newInstanceFieldRef(fakethis, sf.makeRef())); // fake thisLocal } else { // Pretends to be a this.<somefield> ref for a method without a body, // for a static method, or for an inner field JimpleLocal fakethis = new FakeJimpleLocal("fakethis", sf.getDeclaringClass().getType(), realLocal); return new CachedEquivalentValue(Jimple.v().newInstanceFieldRef(fakethis, sf.makeRef())); // fake thisLocal } } }