@Override public ConstructorInfo[] getDeclaredConstructors() { Iterable<? extends Method> implConstructors = classDef.getMethods(); List<ConstructorInfo> result = new ArrayList<>(); for (Method constructor : implConstructors) { if (isConstructor(constructor)) { ConstructorInfo ci = new ConstructorInfo(); ci.parameterTypes = convertParameters(constructor.getParameters()); ci.annotations = convertAnnotations(constructor.getAnnotations()); ci.modifiers = constructor.getAccessFlags(); result.add(ci); } } ConstructorInfo[] array = new ConstructorInfo[result.size()]; return result.toArray(array); }
@Override public MethodInfo[] getDeclaredMethods() { Iterable<? extends Method> implMethods = classDef.getMethods(); List<MethodInfo> result = new ArrayList<>(); for (Method method : implMethods) { if (!isConstructor(method)) { MethodInfo mi = new MethodInfo(); mi.parameterTypes = convertParameters(method.getParameters()); mi.annotations = convertAnnotations(method.getAnnotations()); mi.modifiers = method.getAccessFlags(); mi.name = method.getName(); mi.exceptionTypes = new ExceptionInfo[0]; mi.returnType = DexlibAdapter.getTypeName(method.getReturnType()); result.add(mi); } } MethodInfo[] array = new MethodInfo[result.size()]; return result.toArray(array); }
/** * Converts method and method parameters annotations from Dexlib to Jimple * * @param h * @param method */ void handleMethodAnnotation(Host h, Method method) { Set<? extends Annotation> aSet = method.getAnnotations(); if (!(aSet == null || aSet.isEmpty())) { List<Tag> tags = handleAnnotation(aSet, null); if (tags != null) for (Tag t : tags) if (t != null) { h.addTag(t); Debug.printDbg("add method annotation: ", t); } } ArrayList<String> parameterNames = new ArrayList<String>(); boolean addParameterNames = false; for (MethodParameter p : method.getParameters()) { String name = p.getName(); parameterNames.add(name); if (name != null) addParameterNames = true; } if (addParameterNames) { h.addTag(new ParamNamesTag(parameterNames)); } // Is there any parameter annotation? boolean doParam = false; List<? extends MethodParameter> parameters = method.getParameters(); for (MethodParameter p : parameters) { Debug.printDbg("parameter ", p, " annotations: ", p.getAnnotations()); if (p.getAnnotations().size() > 0) { doParam = true; break; } } if (doParam) { VisibilityParameterAnnotationTag tag = new VisibilityParameterAnnotationTag( parameters.size(), AnnotationConstants.RUNTIME_VISIBLE); for (MethodParameter p : parameters) { List<Tag> tags = handleAnnotation(p.getAnnotations(), null); // If we have no tag for this parameter, add a placeholder // so that we keep the order intact. if (tags == null) { tag.addVisibilityAnnotation(null); continue; } VisibilityAnnotationTag paramVat = new VisibilityAnnotationTag(AnnotationConstants.RUNTIME_VISIBLE); tag.addVisibilityAnnotation(paramVat); for (Tag t : tags) { if (t == null) continue; AnnotationTag vat = null; if (!(t instanceof VisibilityAnnotationTag)) { if (t instanceof DeprecatedTag) { vat = new AnnotationTag("Ljava/lang/Deprecated;"); } else if (t instanceof SignatureTag) { SignatureTag sig = (SignatureTag) t; ArrayList<AnnotationElem> sigElements = new ArrayList<AnnotationElem>(); for (String s : SootToDexUtils.splitSignature(sig.getSignature())) sigElements.add(new AnnotationStringElem(s, 's', "value")); AnnotationElem elem = new AnnotationArrayElem(sigElements, 's', "value"); vat = new AnnotationTag("Ldalvik/annotation/Signature;", Collections.singleton(elem)); } else { throw new RuntimeException( "error: unhandled tag for parameter annotation in method " + h + " (" + t + ")."); } } else { vat = ((VisibilityAnnotationTag) t).getAnnotations().get(0); } Debug.printDbg("add parameter annotation: ", t); paramVat.addAnnotation(vat); } } if (tag.getVisibilityAnnotations().size() > 0) h.addTag(tag); } }