private Set<SootClass> getChildrenOfIncluding(Collection<SootClass> classes) { return Stream .concat(classes.stream().filter(c -> !c.getName().equals("java.lang.Object")) .map(c -> c.isInterface() ? Scene.v().getActiveHierarchy().getImplementersOf(c) : Scene.v().getActiveHierarchy().getSubclassesOf(c)) .flatMap(Collection::stream), classes.stream()) .collect(toSet()); }
/** * Given an abstract dispatch to an object of type c and a method m, gives a list of possible receiver methods. */ public List<SootMethod> resolveAbstractDispatch(SootClass c, SootMethod m) { c.checkLevel(SootClass.HIERARCHY); m.getDeclaringClass().checkLevel(SootClass.HIERARCHY); checkState(); Set<SootMethod> s = new ArraySet<SootMethod>(); Collection<SootClass> classesIt; if (c.isInterface()) { Set<SootClass> classes = new HashSet<SootClass>(); for (SootClass sootClass : getImplementersOf(c)) { classes.addAll(getSubclassesOfIncluding(sootClass)); } classesIt = classes; } else { classesIt = getSubclassesOfIncluding(c); } for (SootClass cl : classesIt) { if (!Modifier.isAbstract(cl.getModifiers())) { s.add(resolveConcreteDispatch(cl, m)); } } return Collections.unmodifiableList(new ArrayList<SootMethod>(s)); }
|| h.getSubinterfacesOfIncluding(classTwo).contains(classOne); } else { typeCompatible = h.getImplementersOf(classOne).contains(classTwo); typeCompatible = h.getImplementersOf(classTwo).contains(classOne); } else { typeCompatible = (classOne != null
/** * Gets all child classes of the given class. If the given class is an * interface, all implementors of this interface and its all of child- * interfaces are returned. * * @param sc The class or interface for which to get the children * @return The children of the given class or interface */ private Set<SootClass> getAllChildClasses(SootClass sc) { List<SootClass> workList = new ArrayList<SootClass>(); workList.add(sc); Set<SootClass> doneSet = new HashSet<SootClass>(); Set<SootClass> classes = new HashSet<>(); while (!workList.isEmpty()) { SootClass curClass = workList.remove(0); if (!doneSet.add(curClass)) continue; if (curClass.isInterface()) { workList.addAll(hierarchy.getImplementersOf(curClass)); workList.addAll(hierarchy.getSubinterfacesOf(curClass)); } else { workList.addAll(hierarchy.getSubclassesOf(curClass)); classes.add(curClass); } } return classes; }
/** * Gets all methods that implement the given abstract method. These are all * concrete methods with the same signature in all derived classes. * * @param method The method for which to find implementations * @return A set containing all implementations of the given method */ private Collection<SootMethod> getAllImplementors(SootMethod method) { final String subSig = method.getSubSignature(); Set<SootMethod> implementors = new HashSet<SootMethod>(); List<SootClass> workList = new ArrayList<SootClass>(); workList.add(method.getDeclaringClass()); Set<SootClass> doneSet = new HashSet<SootClass>(); while (!workList.isEmpty()) { SootClass curClass = workList.remove(0); if (!doneSet.add(curClass)) continue; if (curClass.isInterface()) { workList.addAll(hierarchy.getImplementersOf(curClass)); workList.addAll(hierarchy.getSubinterfacesOf(curClass)); } else workList.addAll(hierarchy.getSubclassesOf(curClass)); SootMethod ifm = curClass.getMethodUnsafe(subSig); if (ifm != null) implementors.add(ifm); } return implementors; }
/** Given an abstract dispatch to an object of type c and a method m, gives * a list of possible receiver methods. */ public List resolveAbstractDispatch(SootClass c, SootMethod m) { c.checkLevel(SootClass.HIERARCHY); m.getDeclaringClass().checkLevel(SootClass.HIERARCHY); checkState(); Iterator<SootClass> classesIt = null; if (c.isInterface()) { classesIt = getImplementersOf(c).iterator(); HashSet<SootClass> classes = new HashSet<SootClass>(); while (classesIt.hasNext()) classes.addAll(getSubclassesOfIncluding(classesIt.next())); classesIt = classes.iterator(); } else classesIt = getSubclassesOfIncluding(c).iterator(); ArraySet s = new ArraySet(); while (classesIt.hasNext()) { SootClass cl = classesIt.next(); if( Modifier.isAbstract( cl.getModifiers() ) ) continue; s.add(resolveConcreteDispatch(cl, m)); } List l = new ArrayList(); l.addAll(s); return Collections.unmodifiableList(l); }
/** Given an abstract dispatch to an object of type c and a method m, gives * a list of possible receiver methods. */ public List resolveAbstractDispatch(SootClass c, SootMethod m) { c.checkLevel(SootClass.HIERARCHY); m.getDeclaringClass().checkLevel(SootClass.HIERARCHY); checkState(); Iterator<SootClass> classesIt = null; if (c.isInterface()) { classesIt = getImplementersOf(c).iterator(); HashSet<SootClass> classes = new HashSet<SootClass>(); while (classesIt.hasNext()) classes.addAll(getSubclassesOfIncluding(classesIt.next())); classesIt = classes.iterator(); } else classesIt = getSubclassesOfIncluding(c).iterator(); ArraySet s = new ArraySet(); while (classesIt.hasNext()) { SootClass cl = classesIt.next(); if( Modifier.isAbstract( cl.getModifiers() ) ) continue; s.add(resolveConcreteDispatch(cl, m)); } List l = new ArrayList(); l.addAll(s); return Collections.unmodifiableList(l); }
/** * Gets all classes that are sub-classes of the given class / implementors of * the given interface * * @param sc The class or interface of which to get the implementors * @return The concrete implementors of the given interface / subclasses of the * given parent class */ private Collection<? extends String> getImplementorsOf(SootClass sc) { Set<String> classes = new HashSet<>(); Set<SootClass> doneSet = new HashSet<>(); List<SootClass> workList = new ArrayList<>(); workList.add(sc); while (!workList.isEmpty()) { SootClass curClass = workList.remove(0); if (!doneSet.add(curClass)) continue; if (curClass.isConcrete()) classes.add(curClass.getName()); if (sc.isInterface()) { workList.addAll(Scene.v().getActiveHierarchy().getImplementersOf(sc)); workList.addAll(Scene.v().getActiveHierarchy().getSubinterfacesOf(sc)); } else for (SootClass c : Scene.v().getActiveHierarchy().getSubclassesOf(sc)) classes.add(c.getName()); } return classes; }
List<SootClass> classes = null; if (sc.isInterface()) { classes = hierarchy.getImplementersOf(sc); } else { try {
classes = Scene.v().getActiveHierarchy().getImplementersOf(createdClass); else classes = Scene.v().getActiveHierarchy().getSubclassesOf(createdClass);