/** * Returns a list of subinterfaces of sootClass, including itself. * * @param sootClass * the <strong>interface</strong> of which subinterfaces will be taken. Must not be {@code null} or class * @return list of subinterfaces, including passed one * @throws IllegalArgumentException * when passed class is a class * @throws NullPointerException * when passed argument is {@code null} */ public List<SootClass> getSubinterfacesOfIncluding(SootClass sootClass) { final List<SootClass> result = new ArrayList<>(getSubinterfacesOf(sootClass)); result.add(sootClass); return Collections.unmodifiableList(result); }
/** Returns true if child is a subinterface of possibleParent. */ public boolean isInterfaceSubinterfaceOf(SootClass child, SootClass possibleParent) { child.checkLevel(SootClass.HIERARCHY); possibleParent.checkLevel(SootClass.HIERARCHY); return getSubinterfacesOf(possibleParent).contains(child); }
/** Returns a list of subinterfaces of c, including itself. */ public List<SootClass> getSubinterfacesOfIncluding(SootClass c) { c.checkLevel(SootClass.HIERARCHY); if (!c.isInterface()) throw new RuntimeException("interface needed!"); List<SootClass> l = new ArrayList<SootClass>(); l.addAll(getSubinterfacesOf(c)); l.add(c); return Collections.unmodifiableList(l); }
/** Returns a list of subinterfaces of c, including itself. */ public List<SootClass> getSubinterfacesOfIncluding(SootClass c) { c.checkLevel(SootClass.HIERARCHY); if (!c.isInterface()) throw new RuntimeException("interface needed!"); List<SootClass> l = new ArrayList<SootClass>(); l.addAll(getSubinterfacesOf(c)); l.add(c); return Collections.unmodifiableList(l); }
/** Returns true if child is a subinterface of possibleParent. */ public boolean isInterfaceSubinterfaceOf(SootClass child, SootClass possibleParent) { child.checkLevel(SootClass.HIERARCHY); possibleParent.checkLevel(SootClass.HIERARCHY); return getSubinterfacesOf(possibleParent).contains(child); }
/** Returns true if child is a subinterface of possibleParent. */ public boolean isInterfaceSubinterfaceOf(SootClass child, SootClass possibleParent) { child.checkLevel(SootClass.HIERARCHY); possibleParent.checkLevel(SootClass.HIERARCHY); return getSubinterfacesOf(possibleParent).contains(child); }
/** * 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; }