private Set<SootClass> getApplicationParents(SootClass applicationClass) { return getParents(applicationClass).stream().filter(parent -> !parent.isLibraryClass()).collect(toSet()); }
private void updateType(Type type) { if (type instanceof RefType) { RefType rt = (RefType) type; if (!rt.getSootClass().isLibraryClass() && oldToNewClassNames.containsKey(rt.getClassName())) { rt.setSootClass(newNameToClass.get(oldToNewClassNames.get(rt.getClassName()))); rt.setClassName(oldToNewClassNames.get(rt.getClassName())); } } else if (type instanceof ArrayType) { ArrayType at = (ArrayType) type; if (at.baseType instanceof RefType) { RefType rt = (RefType) at.baseType; if (!rt.getSootClass().isLibraryClass() && oldToNewClassNames.containsKey(rt.getClassName())) { rt.setSootClass(newNameToClass.get(oldToNewClassNames.get(rt.getClassName()))); } } } }
private void findMultiCalledMethodsIntra(Set<SootMethod> multiCalledMethods, CallGraph callGraph) { Iterator<Unit> it = multiRunStatements.iterator(); while (it.hasNext()) { Stmt stmt = (Stmt) it.next(); if (stmt.containsInvokeExpr()) { InvokeExpr invokeExpr = stmt.getInvokeExpr(); List<SootMethod> targetList = new ArrayList<SootMethod>(); SootMethod method = invokeExpr.getMethod(); if (invokeExpr instanceof StaticInvokeExpr) { targetList.add(method); } else if (invokeExpr instanceof InstanceInvokeExpr) { if (method.isConcrete() && !method.getDeclaringClass().isLibraryClass()) { TargetMethodsFinder tmd = new TargetMethodsFinder(); targetList = tmd.find(stmt, callGraph, true, true); } } if (targetList != null) { Iterator<SootMethod> iterator = targetList.iterator(); while (iterator.hasNext()) { SootMethod obj = iterator.next(); if (!obj.isNative()) { multiCalledMethods.add(obj); } } } } } }
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(); } }
} else { if (method.isConcrete() && !method.getDeclaringClass().isLibraryClass()) { Iterator it = cg.edgesOutOf(stmt); TargetMethodsFinder tmd = new TargetMethodsFinder();
private static SootMethod getMethodSafely(InvokeExpr invokeExpr) { try { final SootMethod invokedMethod = invokeExpr.getMethod(); if (invokedMethod == null) { return null; } if (SootMethod.constructorName.equals(invokedMethod.getName()) || SootMethod.staticInitializerName.equals(invokedMethod.getName())) { logger.debug("Skipping wrapping method {} as it is constructor/initializer.", invokedMethod); return null; } final SootClass invokedMethodClass = invokedMethod.getDeclaringClass(); if (!invokedMethodClass.isLibraryClass()) { logger.debug("Skipping wrapping method {} as it is not library one.", invokedMethod); return null; } if (invokeExpr.getMethodRef().declaringClass().isInterface() && !invokedMethodClass.isInterface()) { logger.debug( "Skipping wrapping method {} as original code suppose to execute it on interface {}" + " but resolved code trying to execute it on class {}", invokedMethod, invokeExpr.getMethodRef().declaringClass(), invokedMethodClass); return null; } return invokedMethod; } catch (RuntimeException exception) { logger.debug("Cannot resolve method of InvokeExpr: " + invokeExpr.toString(), exception); return null; } }
Chain<SootClass> getContainingChain(SootClass c) { if (c.isApplicationClass()) { return getApplicationClasses(); } else if (c.isLibraryClass()) { return getLibraryClasses(); } else if (c.isPhantomClass()) { return getPhantomClasses(); } return null; }
private ArrayList<MethInfo> getSrcMethods(SootMethod method, boolean recurse) { // logger.debug("meth for srcs: "+method); ArrayList<MethInfo> list = new ArrayList<MethInfo>(); for (Iterator momcIt = methodToContexts.get(method).iterator(); momcIt.hasNext();) { final MethodOrMethodContext momc = (MethodOrMethodContext) momcIt.next(); Iterator callerEdges = cg.edgesInto(momc); while (callerEdges.hasNext()) { Edge callEdge = (Edge) callerEdges.next(); SootMethod methodCaller = callEdge.src(); if (methodCaller.getDeclaringClass().isLibraryClass()) { if (isShowLibMeths()) { if (recurse) { list.add( new MethInfo(methodCaller, hasTgtMethods(methodCaller) | hasSrcMethods(methodCaller), callEdge.kind())); } else { list.add(new MethInfo(methodCaller, true, callEdge.kind())); } } } else { if (recurse) { list.add(new MethInfo(methodCaller, hasTgtMethods(methodCaller) | hasSrcMethods(methodCaller), callEdge.kind())); } else { list.add(new MethInfo(methodCaller, true, callEdge.kind())); } } } } return list; }
/** Makes this class a library class. */ public void setLibraryClass() { if (isLibraryClass()) { return; } Chain<SootClass> c = Scene.v().getContainingChain(this); if (c != null) { c.remove(this); } Scene.v().getLibraryClasses().add(this); isPhantom = false; }
if (sm.getDeclaringClass().isLibraryClass()) { if (isShowLibMeths()) { if (recurse) {
if (method.isConcrete() && !method.getDeclaringClass().isLibraryClass()) {
public void removeClass(SootClass c) { if (!c.isInScene()) { throw new RuntimeException(); } classes.remove(c); if (c.isLibraryClass()) { libraryClasses.remove(c); } else if (c.isPhantomClass()) { phantomClasses.remove(c); } else if (c.isApplicationClass()) { applicationClasses.remove(c); } c.getType().setSootClass(null); c.setInScene(false); modifyHierarchy(); }
for (SootMethod method : methods) { if (!method.isConcrete() || method.getDeclaringClass().isLibraryClass()) { continue;
final FieldRef fieldRef = (FieldRef) value; SootFieldRef sootFieldRef = fieldRef.getFieldRef(); if (sootFieldRef.declaringClass().isLibraryClass()) { continue;
public SootMethod resolveNonSpecial(RefType t, NumberedString subSig, boolean appOnly) { SmallNumberedMap<SootMethod> vtbl = typeToVtbl.get(t); if (vtbl == null) { typeToVtbl.put(t, vtbl = new SmallNumberedMap<SootMethod>()); } SootMethod ret = vtbl.get(subSig); if (ret != null) { return ret; } SootClass cls = t.getSootClass(); if (appOnly && cls.isLibraryClass()) { return null; } SootMethod m = cls.getMethodUnsafe(subSig); if (m != null) { if (!m.isAbstract()) { ret = m; } } else { SootClass c = cls.getSuperclassUnsafe(); if (c != null) { ret = resolveNonSpecial(c.getType(), subSig); } } vtbl.put(subSig, ret); return ret; }
Chain<Unit> containerUnits = containerB.getUnits(); if (!(inlinee.getDeclaringClass().isApplicationClass() || inlinee.getDeclaringClass().isLibraryClass())) { return null;
Chain<SootClass> getContainingChain(SootClass c) { if (c.isApplicationClass()) return getApplicationClasses(); else if (c.isLibraryClass()) return getLibraryClasses(); else if (c.isPhantomClass()) return getPhantomClasses(); return null; }
Chain<SootClass> getContainingChain(SootClass c) { if (c.isApplicationClass()) return getApplicationClasses(); else if (c.isLibraryClass()) return getLibraryClasses(); else if (c.isPhantomClass()) return getPhantomClasses(); return null; }
public void removeClass(SootClass c) { if(!c.isInScene()) throw new RuntimeException(); classes.remove(c); if(c.isLibraryClass()) { libraryClasses.remove(c); } else if(c.isPhantomClass()) { phantomClasses.remove(c); } else if(c.isApplicationClass()) { applicationClasses.remove(c); } c.getType().setSootClass(null); c.setInScene(false); modifyHierarchy(); }
public void removeClass(SootClass c) { if(!c.isInScene()) throw new RuntimeException(); classes.remove(c); if(c.isLibraryClass()) { libraryClasses.remove(c); } else if(c.isPhantomClass()) { phantomClasses.remove(c); } else if(c.isApplicationClass()) { applicationClasses.remove(c); } c.getType().setSootClass(null); c.setInScene(false); modifyHierarchy(); }