/** Returns a list of subclasses of c, including itself. */ public List<SootClass> getSubclassesOfIncluding(SootClass c) { c.checkLevel(SootClass.HIERARCHY); if (c.isInterface()) { throw new RuntimeException("class needed!"); } List<SootClass> l = new ArrayList<SootClass>(); l.addAll(getSubclassesOf(c)); l.add(c); return Collections.unmodifiableList(l); }
/** Returns true if child is a superclass of possibleParent. */ public boolean isClassSuperclassOf(SootClass parent, SootClass possibleChild) { parent.checkLevel(SootClass.HIERARCHY); possibleChild.checkLevel(SootClass.HIERARCHY); return getSubclassesOf(parent).contains(possibleChild); }
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()); }
/** Returns a list of subclasses of c, including itself. */ public List<SootClass> getSubclassesOfIncluding(SootClass c) { c.checkLevel(SootClass.HIERARCHY); if (c.isInterface()) throw new RuntimeException("class needed!"); List<SootClass> l = new ArrayList<SootClass>(); l.addAll(getSubclassesOf(c)); l.add(c); return Collections.unmodifiableList(l); }
/** Returns a list of subclasses of c, including itself. */ public List<SootClass> getSubclassesOfIncluding(SootClass c) { c.checkLevel(SootClass.HIERARCHY); if (c.isInterface()) throw new RuntimeException("class needed!"); List<SootClass> l = new ArrayList<SootClass>(); l.addAll(getSubclassesOf(c)); l.add(c); return Collections.unmodifiableList(l); }
/** Returns true if child is a superclass of possibleParent. */ public boolean isClassSuperclassOf(SootClass parent, SootClass possibleChild) { parent.checkLevel(SootClass.HIERARCHY); possibleChild.checkLevel(SootClass.HIERARCHY); return getSubclassesOf(parent).contains(possibleChild); }
/** Returns true if child is a superclass of possibleParent. */ public boolean isClassSuperclassOf(SootClass parent, SootClass possibleChild) { parent.checkLevel(SootClass.HIERARCHY); possibleChild.checkLevel(SootClass.HIERARCHY); return getSubclassesOf(parent).contains(possibleChild); }
/** * 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; }
/** * 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; }
classes = Scene.v().getActiveHierarchy().getImplementersOf(createdClass); else classes = Scene.v().getActiveHierarchy().getSubclassesOf(createdClass);