public static ComponentType getComponentType(SootClass currentClass) { ComponentType type = ComponentType.Plain; List<SootClass> extendedClasses = Scene.v().getActiveHierarchy().getSuperclassesOf(currentClass); for(SootClass sc : extendedClasses) { if(sc.getName().equals(AndroidEntryPointConstants.APPLICATIONCLASS)) type = ComponentType.Application; else if(sc.getName().equals(AndroidEntryPointConstants.ACTIVITYCLASS)) type = ComponentType.Activity; else if(sc.getName().equals(AndroidEntryPointConstants.SERVICECLASS)) type = ComponentType.Service; else if(sc.getName().equals(AndroidEntryPointConstants.BROADCASTRECEIVERCLASS)) type = ComponentType.BroadcastReceiver; else if(sc.getName().equals(AndroidEntryPointConstants.CONTENTPROVIDERCLASS)) type = ComponentType.ContentProvider; } return type; }
private boolean addLifecycleMethods(SootClass entryPointClass, List<MethodOrMethodContext> callbacks) { boolean result = true; Hierarchy hierarchy = Scene.v().getActiveHierarchy(); if (hierarchy.isClassSubclassOf(entryPointClass, activityClass)) { addLifecycleMethodsHelper(entryPointClass, AndroidEntryPointConstants.getActivityLifecycleMethods(), callbacks); } else if (hierarchy.isClassSubclassOf(entryPointClass, gcmBaseIntentServiceClass)) { addLifecycleMethodsHelper(entryPointClass, AndroidEntryPointConstants.getGCMIntentServiceMethods(), callbacks); } else if (hierarchy.isClassSubclassOf(entryPointClass, serviceClass)) { addLifecycleMethodsHelper(entryPointClass, AndroidEntryPointConstants.getServiceLifecycleMethods(), callbacks); } else if (hierarchy.isClassSubclassOf(entryPointClass, receiverClass)) { addLifecycleMethodsHelper(entryPointClass, AndroidEntryPointConstants.getBroadcastLifecycleMethods(), callbacks); } else if (hierarchy.isClassSubclassOf(entryPointClass, providerClass)) { addLifecycleMethodsHelper(entryPointClass, AndroidEntryPointConstants.getContentproviderLifecycleMethods(), callbacks); } else if (hierarchy.isClassSubclassOf(entryPointClass, applicationClass)) { addLifecycleMethodsHelper(entryPointClass, AndroidEntryPointConstants.getApplicationLifecycleMethods(), callbacks); } else { System.err.println("Unknown entry point type: " + entryPointClass); result = false; } return result; }
private List<String> getCallbackFunctions(SootClass sc) { List<String> callbacks = new ArrayList<String>(); for (SootMethod sm : sc.getMethods()) { //<init> and <cinit> if (sm.getName().contains("init>")) { continue; } ComponentType compType = Component.getComponentType(sc); switch (compType) { case Activity: if (AndroidEntryPointConstants.getActivityLifecycleMethods().contains(sm.getName())) { continue; } break; case Service: if (AndroidEntryPointConstants.getServiceLifecycleMethods().contains(sm.getName())) { continue; } break; case BroadcastReceiver: if (AndroidEntryPointConstants.getBroadcastLifecycleMethods().contains(sm.getName())) { continue; } break; case ContentProvider: if (AndroidEntryPointConstants.getContentproviderLifecycleMethods().contains(sm.getName())) { continue; } break; default: break; } if (! isPotentialCallbackMethod(sc, sm.getName())) { continue; } callbacks.add(sm.getSignature()); } callbacks.addAll(getAnonymousCallbacks(sc)); return callbacks; }