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 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(); } }
private boolean isSuitableClassToAddFieldConstant(SootClass sc, Constant constant) { if (sc.isInterface()) { return false; } if (constant instanceof ClassConstant) { ClassConstant classConstant = (ClassConstant) constant; RefType type = (RefType) classConstant.toSootType(); SootClass classFromConstant = type.getSootClass(); Hierarchy hierarchy = Scene.v().getActiveHierarchy(); return hierarchy.isVisible(sc, classFromConstant); } return true; }
/** * Given an object of actual type C (o = new C()), returns the method which will be called on an o.f() invocation. */ public SootMethod resolveConcreteDispatch(SootClass concreteType, SootMethod m) { concreteType.checkLevel(SootClass.HIERARCHY); m.getDeclaringClass().checkLevel(SootClass.HIERARCHY); checkState(); if (concreteType.isInterface()) { throw new RuntimeException("class needed!"); } String methodSig = m.getSubSignature(); for (SootClass c : getSuperclassesOfIncluding(concreteType)) { SootMethod sm = c.getMethodUnsafe(methodSig); if (sm != null && isVisible(c, m)) { return sm; } } throw new RuntimeException("could not resolve concrete dispatch!\nType: " + concreteType + "\nMethod: " + m); }
/** * Returns true if the classmember m is visible from code in the class from. */ public boolean isVisible(SootClass from, ClassMember m) { from.checkLevel(SootClass.HIERARCHY); m.getDeclaringClass().checkLevel(SootClass.HIERARCHY); if (!isVisible(from, m.getDeclaringClass())) { return false; } if (m.isPublic()) { return true; } if (m.isPrivate()) { return from.equals(m.getDeclaringClass()); } if (m.isProtected()) { return isClassSubclassOfIncluding(from, m.getDeclaringClass()) || from.getJavaPackageName().equals(m.getDeclaringClass().getJavaPackageName()); } // m is package return from.getJavaPackageName().equals(m.getDeclaringClass().getJavaPackageName()); }
/** Given an object of actual type C (o = new C()), returns the method which will be called on an o.f() invocation. */ public SootMethod resolveConcreteDispatch(SootClass concreteType, SootMethod m) { concreteType.checkLevel(SootClass.HIERARCHY); m.getDeclaringClass().checkLevel(SootClass.HIERARCHY); checkState(); if (concreteType.isInterface()) throw new RuntimeException("class needed!"); Iterator<SootClass> it = getSuperclassesOfIncluding(concreteType).iterator(); String methodSig = m.getSubSignature(); while (it.hasNext()) { SootClass c = it.next(); if (c.declaresMethod(methodSig) && isVisible( c, m ) ) { return c.getMethod(methodSig); } } throw new RuntimeException("could not resolve concrete dispatch!\nType: "+concreteType+"\nMethod: "+m); }
/** Given an object of actual type C (o = new C()), returns the method which will be called on an o.f() invocation. */ public SootMethod resolveConcreteDispatch(SootClass concreteType, SootMethod m) { concreteType.checkLevel(SootClass.HIERARCHY); m.getDeclaringClass().checkLevel(SootClass.HIERARCHY); checkState(); if (concreteType.isInterface()) throw new RuntimeException("class needed!"); Iterator<SootClass> it = getSuperclassesOfIncluding(concreteType).iterator(); String methodSig = m.getSubSignature(); while (it.hasNext()) { SootClass c = it.next(); if (c.declaresMethod(methodSig) && isVisible( c, m ) ) { return c.getMethod(methodSig); } } throw new RuntimeException("could not resolve concrete dispatch!\nType: "+concreteType+"\nMethod: "+m); }