/** Returns a list of all concrete methods of all application classes. */ public List<SootMethod> methodsOfApplicationClasses() { List<SootMethod> ret = new ArrayList<SootMethod>(); for (Iterator<SootClass> clIt = Scene.v().getApplicationClasses().iterator(); clIt.hasNext();) { final SootClass cl = clIt.next(); for (Iterator<SootMethod> mIt = cl.getMethods().iterator(); mIt.hasNext();) { final SootMethod m = mIt.next(); if (m.isConcrete()) { ret.add(m); } } } return ret; }
/** * Convenience method returning true if this class is an application class. * * @see Scene#getApplicationClasses() */ public boolean isApplicationClass() { return Scene.v().getApplicationClasses().contains(this); }
public void dump() { try { PrintWriter file = new PrintWriter(new FileOutputStream(new File(output_dir, "types"))); for (SootClass cls : Scene.v().getApplicationClasses()) { handleClass(file, cls); } for (SootClass cls : Scene.v().getLibraryClasses()) { handleClass(file, cls); } file.close(); } catch (IOException e) { throw new RuntimeException("Couldn't dump reaching types." + e); } }
private Iterator<SootClass> reachableClasses() { return Scene.v().getApplicationClasses().snapshotIterator(); }
/** * Returns a list of all concrete main(String[]) methods of all application classes. */ public List<SootMethod> mainsOfApplicationClasses() { List<SootMethod> ret = new ArrayList<SootMethod>(); for (Iterator<SootClass> clIt = Scene.v().getApplicationClasses().iterator(); clIt.hasNext();) { final SootClass cl = clIt.next(); SootMethod m = cl.getMethodUnsafe("void main(java.lang.String[])"); if (m != null) { if (m.isConcrete()) { ret.add(m); } } } return ret; }
public void internalTransform(String phaseName, Map<String, String> options) { Iterator<SootClass> it = Scene.v().getApplicationClasses().iterator(); while (it.hasNext()) { ArrayList<InnerClassTag> list = new ArrayList<InnerClassTag>(); SootClass nextSc = it.next(); for (Tag t : nextSc.getTags()) { if (t instanceof InnerClassTag) { list.add((InnerClassTag) t); } } if (!list.isEmpty()) { nextSc.addTag(new InnerClassAttribute(list)); } } } }
private static List<SootClass> getVisibleApplicationClasses(SootMethod visibleBy) { final List<SootClass> result = new ArrayList<>(); final Iterator<SootClass> applicationClassesIterator = Scene.v().getApplicationClasses().snapshotIterator(); while (applicationClassesIterator.hasNext()) { final SootClass applicationClass = applicationClassesIterator.next(); if (applicationClass.isConcrete() && !applicationClass.isInterface() && applicationClass.isPublic() && Scene.v().getActiveHierarchy().isVisible(applicationClass, visibleBy)) { result.add(applicationClass); } } return result; }
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 retrieveAllNames() { if (namesHaveBeenRetrieved) { return; } // iterate through application classes, rename fields with junk for (SootClass c : soot.Scene.v().getApplicationClasses()) { nameList.add(c.getName()); for (SootMethod m : c.getMethods()) { nameList.add(m.getName()); } for (SootField m : c.getFields()) { nameList.add(m.getName()); } } namesHaveBeenRetrieved = true; }
protected void internalTransform(String phaseName, Map<String, String> options) { lastClass = null; for (Iterator<SootClass> clIt = Scene.v().getApplicationClasses().iterator(); clIt.hasNext();) { final SootClass cl = clIt.next(); currentClass = cl; handleClass(cl); for (Iterator<SootMethod> it = cl.methodIterator(); it.hasNext();) { handleMethod(it.next()); } } Scene.v().setCallGraph(Scene.v().internalMakeCallGraph()); }
classIt = Scene.v().getApplicationClasses().iterator(); while (classIt.hasNext()) { add_ClassName(((SootClass) classIt.next()).getName(), appRoots);
protected void internalTransform(String phaseName, Map options) { // make list of all unreachable methods ArrayList<SootMethod> methodList = new ArrayList<SootMethod>(); Iterator getClassesIt = Scene.v().getApplicationClasses().iterator(); while (getClassesIt.hasNext()) { SootClass appClass = (SootClass) getClassesIt.next(); Iterator getMethodsIt = appClass.getMethods().iterator(); while (getMethodsIt.hasNext()) { SootMethod method = (SootMethod) getMethodsIt.next(); // System.out.println("adding method: "+method); if (!Scene.v().getReachableMethods().contains(method)) { methodList.add(method); } } } // tag unused methods Iterator<SootMethod> unusedIt = methodList.iterator(); while (unusedIt.hasNext()) { SootMethod unusedMethod = unusedIt.next(); unusedMethod.addTag(new StringTag("Method " + unusedMethod.getName() + " is not reachable!", "Unreachable Methods")); unusedMethod.addTag(new ColorTag(255, 0, 0, true, "Unreachable Methods")); // System.out.println("tagged method: "+unusedMethod); } }
startToContainingMethod = new HashMap<Stmt, SootMethod>(); Iterator runAnalysisClassesIt = Scene.v().getApplicationClasses().iterator(); while (runAnalysisClassesIt.hasNext()) { SootClass appClass = (SootClass) runAnalysisClassesIt.next();
Chain<SootClass> getContainingChain(SootClass c) { if (c.isApplicationClass()) { return getApplicationClasses(); } else if (c.isLibraryClass()) { return getLibraryClasses(); } else if (c.isPhantomClass()) { return getPhantomClasses(); } return null; }
/** Makes this class an application class. */ public void setApplicationClass() { if (isApplicationClass()) { return; } Chain<SootClass> c = Scene.v().getContainingChain(this); if (c != null) { c.remove(this); } Scene.v().getApplicationClasses().add(this); isPhantom = false; }
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; }
private void analyzeField(SootField sf) { Iterator classesIt = Scene.v().getApplicationClasses().iterator(); while (classesIt.hasNext()) { SootClass appClass = (SootClass) classesIt.next();
public void setMainClassFromOptions() { if (mainClass != null) { return; } if (Options.v().main_class() != null && Options.v().main_class().length() > 0) { setMainClass(getSootClass(Options.v().main_class())); } else { // try to infer a main class from the command line if none is given for (Iterator<String> classIter = Options.v().classes().iterator(); classIter.hasNext();) { SootClass c = getSootClass(classIter.next()); if (c.declaresMethod("main", Collections.<Type>singletonList(ArrayType.v(RefType.v("java.lang.String"), 1)), VoidType.v())) { logger.debug("No main class given. Inferred '" + c.getName() + "' as main class."); setMainClass(c); return; } } // try to infer a main class from the usual classpath if none is // given for (Iterator<SootClass> classIter = getApplicationClasses().iterator(); classIter.hasNext();) { SootClass c = classIter.next(); if (c.declaresMethod("main", Collections.<Type>singletonList(ArrayType.v(RefType.v("java.lang.String"), 1)), VoidType.v())) { logger.debug("No main class given. Inferred '" + c.getName() + "' as main class."); setMainClass(c); return; } } } }
boolean verbose = options.containsKey("verbose"); for (SootClass sootClass : Scene.v().getApplicationClasses()) {
for (SootClass sc : Scene.v().getApplicationClasses()) { if (Options.v().validate()) { sc.validate();