private boolean isCallClassSubClass(SootClass call, SootClass check) { if (!call.hasSuperclass()) { return false; } if (call.getSuperclass().equals(check)) { return true; } return false; }
TypeNode parent = hierarchy.typeNode(RefType.v(sClass.getSuperclass().getName())); plist.add(parent); parentClass = parent;
private boolean catches_Exception(IterableSet tryExceptionSet, SootClass c) { Iterator it = tryExceptionSet.iterator(); while (it.hasNext()) { SootClass thrownException = (SootClass) it.next(); while (true) { if (thrownException == c) { return true; } if (thrownException.hasSuperclass() == false) { break; } thrownException = thrownException.getSuperclass(); } } return false; }
private boolean handled_Exception(HashSet handledExceptions, SootClass c) { SootClass thrownException = c; if (is_HandledByRuntime(thrownException)) { return true; } if (handledExceptions == null) { return false; } while (true) { if (handledExceptions.contains(thrownException)) { return true; } if (thrownException.hasSuperclass() == false) { return false; } thrownException = thrownException.getSuperclass(); } }
public static List<SootField> getAllFields(SootClass sc) { // Get list of reachable methods declared in this class // Also get list of fields declared in this class List<SootField> allFields = new ArrayList<SootField>(); for (SootField field : sc.getFields()) { allFields.add(field); } // Add reachable methods and fields declared in superclasses SootClass superclass = sc; if (superclass.hasSuperclass()) { superclass = superclass.getSuperclass(); } while (superclass.hasSuperclass()) // we don't want to process Object { for (SootField scField : superclass.getFields()) { allFields.add(scField); } superclass = superclass.getSuperclass(); } return allFields; }
/** * Returns a list of <strong>direct</strong> superclasses of passed class in reverse order, starting with its parent. * * @param sootClass * the <strong>class</strong> of which superclasses will be taken. Must not be {@code null} or interface * @return list of superclasses * @throws IllegalArgumentException * when passed class is an interface * @throws NullPointerException * when passed argument is {@code null} */ public List<SootClass> getSuperclassesOf(SootClass sootClass) { sootClass.checkLevel(SootClass.HIERARCHY); if (sootClass.isInterface()) { throw new IllegalArgumentException(sootClass.getName() + " is an interface, but class is expected"); } checkState(); final List<SootClass> superclasses = new ArrayList<>(); SootClass current = sootClass; while (current.hasSuperclass()) { superclasses.add(current.getSuperclass()); current = current.getSuperclass(); } return Collections.unmodifiableList(superclasses); }
public static List<SootMethod> getAllReachableMethods(SootClass sc) { ReachableMethods rm = Scene.v().getReachableMethods(); // Get list of reachable methods declared in this class List<SootMethod> allMethods = new ArrayList<SootMethod>(); Iterator methodsIt = sc.methodIterator(); while (methodsIt.hasNext()) { SootMethod method = (SootMethod) methodsIt.next(); if (rm.contains(method)) { allMethods.add(method); } } // Add reachable methods declared in superclasses SootClass superclass = sc; if (superclass.hasSuperclass()) { superclass = superclass.getSuperclass(); } while (superclass.hasSuperclass()) // we don't want to process Object { Iterator scMethodsIt = superclass.methodIterator(); while (scMethodsIt.hasNext()) { SootMethod scMethod = (SootMethod) scMethodsIt.next(); if (rm.contains(scMethod)) { allMethods.add(scMethod); } } superclass = superclass.getSuperclass(); } return allMethods; }
private static Deque<RefType> superclassPath(RefType t, RefType anchor) { Deque<RefType> r = new ArrayDeque<RefType>(); r.addFirst(t); if (TypeResolver.typesEqual(t, anchor)) { return r; } SootClass sc = t.getSootClass(); while (sc.hasSuperclass()) { sc = sc.getSuperclass(); RefType cur = sc.getType(); r.addFirst(cur); if (TypeResolver.typesEqual(cur, anchor)) { break; } } if (!TypeResolver.typesEqual(r.getFirst(), anchor)) { r.addFirst(anchor); } return r; }
superclass = sootClass.getSuperclass(); superclass = superclass.getSuperclass();
SootClass superclass = sootClass; if (superclass.hasSuperclass()) { superclass = superclass.getSuperclass(); externalMethods.addAll(uf.getExtMethods(superclass)); superclass = superclass.getSuperclass(); superclass = sootClass; if (superclass.hasSuperclass()) { superclass = superclass.getSuperclass(); externalFields.addAll(uf.getExtFields(superclass)); superclass = superclass.getSuperclass();
private Optional<SootMethod> findAccessibleInSuperClassesBySubSig(SootClass base, String subSig) { Hierarchy hierarchy = Scene.v().getActiveHierarchy(); for (SootClass superClass : hierarchy.getSuperclassesOfIncluding(base.getSuperclass())) { if (superClass.isLibraryClass() && superClass.declaresMethod(subSig)) { SootMethod method = superClass.getMethod(subSig); if (hierarchy.isVisible(base, method)) { return Optional.of(method); } } } return Optional.empty(); } }
return; if (currClass.hasSuperclass() && !currClass.getSuperclass().isPhantom() && !currClass.getSuperclass().getName().equals("java.lang.Object")) { currClass = currClass.getSuperclass(); methodIterator = currClass.methodIterator(); continue;
private boolean isRewritable(Trap t) { // ignore traps that already catch their own begin unit if (t.getBeginUnit() == t.getHandlerUnit()) { return false; } // ignore runtime try blocks - these may have weird side-effects do to asynchronous exceptions SootClass exc = t.getException(); if (exc.getName().equals("java.lang.Throwable")) { return false; } do { if (exc.getName().equals("java.lang.RuntimeException")) { return false; } } while (exc.hasSuperclass() && (exc = exc.getSuperclass()) != null); return true; } }
private Set<SootClass> getParentsOfIncluding(Collection<SootClass> classes) { final Set<SootClass> parents = new HashSet<>(classes); for (SootClass clazz : classes) { // add implementing interfaces parents.addAll(clazz.getInterfaces()); // add extending class if any if (!clazz.isInterface() && clazz.hasSuperclass()) { parents.add(clazz.getSuperclass()); } // and superclasses (superinterfaces) of passed applicationClass parents.addAll(clazz.isInterface() ? Scene.v().getActiveHierarchy().getSuperinterfacesOfIncluding(clazz) : Scene.v().getActiveHierarchy().getSuperclassesOfIncluding(clazz)); } return parents; }
private static Collection<AncestryTreeNode> buildAncestryTree(RefType root) { if (root.getSootClass().isPhantom()) { return Collections.emptyList(); } LinkedList<AncestryTreeNode> leafs = new LinkedList<AncestryTreeNode>(); leafs.add(new AncestryTreeNode(null, root)); LinkedList<AncestryTreeNode> r = new LinkedList<AncestryTreeNode>(); final RefType objectType = RefType.v("java.lang.Object"); while (!leafs.isEmpty()) { AncestryTreeNode node = leafs.remove(); if (TypeResolver.typesEqual(node.type, objectType)) { r.add(node); } else { SootClass sc = node.type.getSootClass(); for (SootClass i : sc.getInterfaces()) { leafs.add(new AncestryTreeNode(node, (i).getType())); } // The superclass of all interfaces is Object // -- try to discard phantom interfaces. if ((!sc.isInterface() || sc.getInterfaceCount() == 0) && !sc.isPhantom()) { leafs.add(new AncestryTreeNode(node, sc.getSuperclass().getType())); } } } return r; }
private boolean is_HandledByRuntime(SootClass c) { SootClass thrownException = c, runtimeException = Scene.v().getSootClass("java.lang.RuntimeException"), error = Scene.v().getSootClass("java.lang.Error"); while (true) { if ((thrownException == runtimeException) || (thrownException == error)) { return true; } if (thrownException.hasSuperclass() == false) { return false; } thrownException = thrownException.getSuperclass(); } } }
private List<SootClass> getParentsOfIncluding(SootClass applicationClass) { // result contains of interfaces that implements passed applicationClass final List<SootClass> result = HierarchyUtils.getAllInterfacesOf(applicationClass); // add implementing interfaces result.addAll(applicationClass.getInterfaces()); // add extending class if any if (!applicationClass.isInterface() && applicationClass.hasSuperclass()) { result.add(applicationClass.getSuperclass()); } // and superclasses (superinterfaces) of passed applicationClass result.addAll( applicationClass.isInterface() ? Scene.v().getActiveHierarchy().getSuperinterfacesOfIncluding(applicationClass) : Scene.v().getActiveHierarchy().getSuperclassesOfIncluding(applicationClass)); return result; }
private boolean catches_RuntimeException(SootClass c) { if ((c == Scene.v().getSootClass("java.lang.Throwable")) || (c == Scene.v().getSootClass("java.lang.Exception"))) { return true; } SootClass caughtException = c, runtimeException = Scene.v().getSootClass("java.lang.RuntimeException"); while (true) { if (caughtException == runtimeException) { return true; } if (caughtException.hasSuperclass() == false) { return false; } caughtException = caughtException.getSuperclass(); } } }
public SootMethod resolveSpecial(SpecialInvokeExpr iie, NumberedString subSig, SootMethod container, boolean appOnly) { SootMethod target = iie.getMethod(); /* cf. JVM spec, invokespecial instruction */ if (Scene.v().getOrMakeFastHierarchy().canStoreType(container.getDeclaringClass().getType(), target.getDeclaringClass().getType()) && container.getDeclaringClass().getType() != target.getDeclaringClass().getType() && !target.getName().equals("<init>") && subSig != sigClinit) { return resolveNonSpecial(container.getDeclaringClass().getSuperclass().getType(), subSig, appOnly); } else { return target; } }
/** * needs accessors: when field or meth is private and in some other class when field or meth is protected and in */ protected boolean needsAccessor(polyglot.types.MemberInstance inst) { if (inst.flags().isPrivate()) { if (!Util.getSootType(inst.container()).equals(body.getMethod().getDeclaringClass().getType())) { return true; } } else if (inst.flags().isProtected()) { if (Util.getSootType(inst.container()).equals(body.getMethod().getDeclaringClass().getType())) { return false; } soot.SootClass currentClass = body.getMethod().getDeclaringClass(); if (currentClass.getSuperclass().getType().equals(Util.getSootType(inst.container()))) { return false; } while (currentClass.hasOuterClass()) { currentClass = currentClass.getOuterClass(); if (Util.getSootType(inst.container()).equals(currentClass.getType())) { return false; } else if (Util.getSootType(inst.container()).equals(currentClass.getSuperclass().getType())) { return true; } } return false; } return false; }