protected void addAnnotation(String classType, List<Tag> tags, VisibilityAnnotationTag[] vatg, Annotation a) { int v = getVisibility(a.getVisibility()); Type atype = DexType.toSoot(a.getType()); String atypes = atype.toString(); int eSize = a.getElements().size(); AnnotationElem anne = getElements(a.getElements()).get(0); AnnotationTag adt = new AnnotationTag(a.getType()); adt.addElem(anne); if (vatg[v] == null) { for (AnnotationElement elem : a.getElements()) { String outerClass = ((TypeEncodedValue) elem.getValue()).getValue(); outerClass = Util.dottedClassName(outerClass); AnnotationStringElem e = (AnnotationStringElem) getElements(a.getElements()).get(0); String[] split1 = e.getValue().split("\\ \\|"); String classString = split1[0]; for (AnnotationElem ele : getElements(a.getElements())) { if (ele instanceof AnnotationIntElem && ele.getName().equals("accessFlags")) { accessFlags = ((AnnotationIntElem) ele).getValue(); AnnotationArrayElem arre = (AnnotationArrayElem) getElements(a.getElements()).get(0); for (AnnotationElem ae : arre.getValues()) { AnnotationClassElem c = (AnnotationClassElem) ae; arre = (AnnotationArrayElem) getElements(a.getElements()).get(0); String sig = "";
private String buildASMSignature(ClassDef classDef) { String signature = null; outer: for (Annotation annotation : classDef.getAnnotations()) { if (!annotation.getType().equals("Ldalvik/annotation/Signature;")) { continue; } StringBuilder sb = new StringBuilder(); for (AnnotationElement e : annotation.getElements()) { BuilderEncodedValues.BuilderArrayEncodedValue ev = (BuilderEncodedValues.BuilderArrayEncodedValue) e .getValue(); for (EncodedValue v : ev.getValue()) { BuilderEncodedValues.BuilderStringEncodedValue value = (BuilderEncodedValues.BuilderStringEncodedValue) v; sb.append(value.getValue()); } } signature = sb.toString(); break; } return signature; }
@Nonnull @Override public Collection<? extends AnnotationElement> getElements(@Nonnull Annotation annotation) { return annotation.getElements(); }
@Override public int getVisibility() { return annotation.getVisibility(); }
private void visitClassAnnotations(Set<? extends Annotation> annotations, ClassWriter classWriter) { for (Annotation annotation : annotations) { switch (annotation.getType()) { case "Ldalvik/annotation/EnclosingMethod;": for (AnnotationElement e : annotation.getElements()) { BuilderEncodedValues.BuilderMethodEncodedValue v = (BuilderEncodedValues.BuilderMethodEncodedValue) e .getValue(); visitEnclosingMethod(v, classWriter); // There should only ever be one enclosing method. break; } break; case "Ldalvik/annotation/MemberClasses;": for (AnnotationElement e : annotation.getElements()) { BuilderEncodedValues.BuilderArrayEncodedValue ev = (BuilderEncodedValues.BuilderArrayEncodedValue) e .getValue(); for (EncodedValue v : ev.getValue()) { BuilderEncodedValues.BuilderTypeEncodedValue value = (BuilderEncodedValues.BuilderTypeEncodedValue) v; visitInnerClasses(value, classWriter); } } break; } } }
@Nonnull @Override public Collection<? extends AnnotationElement> getElements(@Nonnull Annotation annotation) { return annotation.getElements(); }
@Override public int getVisibility() { return annotation.getVisibility(); }
public static ImmutableAnnotation of(Annotation annotation) { if (annotation instanceof ImmutableAnnotation) { return (ImmutableAnnotation)annotation; } return new ImmutableAnnotation( annotation.getVisibility(), annotation.getType(), annotation.getElements()); }
/** * Processes a normal annotation and adds it to the proper visibility annotation tag in the given array * * @param vatg * the visibility annotation tags for different visibility levels * @param a * the annotation * @param v * the visibility */ protected void addNormalAnnotation(VisibilityAnnotationTag[] vatg, Annotation a, int v) { if (vatg[v] == null) { vatg[v] = new VisibilityAnnotationTag(v); } AnnotationTag tag = new AnnotationTag(a.getType()); for (AnnotationElem e : getElements(a.getElements())) { tag.addElem(e); } vatg[v].addAnnotation(tag); }
@Nonnull @Override public Collection<? extends AnnotationElement> getElements(@Nonnull Annotation annotation) { return annotation.getElements(); }
@Override public int getVisibility() { return annotation.getVisibility(); }
public static ImmutableAnnotation of(Annotation annotation) { if (annotation instanceof ImmutableAnnotation) { return (ImmutableAnnotation)annotation; } return new ImmutableAnnotation( annotation.getVisibility(), annotation.getType(), annotation.getElements()); }
protected List<SootClass> getThrownExceptions(final Method method) { // the following snippet retrieves all exceptions that this method // throws by analyzing its annotations List<SootClass> thrownExceptions = new ArrayList<SootClass>(); for (Annotation a : method.getAnnotations()) { Type atype = DexType.toSoot(a.getType()); String atypes = atype.toString(); if (!(atypes.equals("dalvik.annotation.Throws"))) { continue; } for (AnnotationElement ae : a.getElements()) { EncodedValue ev = ae.getValue(); if (ev instanceof ArrayEncodedValue) { for (EncodedValue evSub : ((ArrayEncodedValue) ev).getValue()) { if (evSub instanceof TypeEncodedValue) { TypeEncodedValue valueType = (TypeEncodedValue) evSub; String exceptionName = valueType.getValue(); String dottedName = Util.dottedClassName(exceptionName); thrownExceptions.add(SootResolver.v().makeClassRef(dottedName)); } } } } } return thrownExceptions; } }
@Override @Nonnull public Set<? extends AnnotationElement> getElements() { return RewriterUtils.rewriteSet(rewriters.getAnnotationElementRewriter(), annotation.getElements()); } }
@Override public int getVisibility(@Nonnull Annotation annotation) { return annotation.getVisibility(); }
public static ImmutableAnnotation of(Annotation annotation) { if (annotation instanceof ImmutableAnnotation) { return (ImmutableAnnotation)annotation; } return new ImmutableAnnotation( annotation.getVisibility(), annotation.getType(), annotation.getElements()); }