public static void doAccept(DexAnnotationVisitor dexAnnotationVisitor, String k, Object value) { if (value instanceof ArrayList) { DexAnnotationVisitor a = dexAnnotationVisitor.visitArray(k); for (Object o : (ArrayList) value) { doAccept(a, null, o); } a.visitEnd(); } else if (value instanceof Ann) { Ann ann = (Ann) value; DexAnnotationVisitor a = dexAnnotationVisitor.visitAnnotation(k, ann.name); for (Map.Entry<String, Object> e : ann.elements) { doAccept(a, e.getKey(), e.getValue()); } a.visitEnd(); } else if (value instanceof Field) { Field f = (Field) value; dexAnnotationVisitor.visitEnum(k, f.getOwner(), f.getName()); } else { dexAnnotationVisitor.visit(k, value); } }
public void visit(String name, Object value) { if (value instanceof Object[]) { DexAnnotationVisitor s = visitArray(name); if (s != null) { for (Object v : (Object[]) value) { s.visit(null, v); } s.visitEnd(); } } else { AnnotationElement ae = newAnnotationElement(name); ae.value = EncodedValue.wrap(cp.wrapEncodedItem(value)); } }
@Test public void test3() { DexFileWriter w = new DexFileWriter(); DexClassVisitor cv = w.visit(0x1, "La/c;", null, new String[]{"Ljava/lang/Comparable;"}); cv.visitSource("c.java"); cv.visitAnnotation("LAnn;", Visibility.SYSTEM).visitEnd(); DexFieldVisitor fv = cv.visitField(ACC_PUBLIC | ACC_STATIC, new Field("La/c;", "a", "I"), 55); fv.visitAnnotation("LE;", Visibility.RUNTIME).visitEnd(); fv.visitEnd(); DexMethodVisitor mv = cv.visitMethod(ACC_STATIC, new Method("La/c;", "bb", new String[]{"I"}, "V")); mv.visitAnnotation("Laaa;", Visibility.RUNTIME).visitEnd(); DexAnnotationVisitor dav = mv.visitParameterAnnotation(0).visitAnnotation("Laaa;", Visibility.RUNTIME); dav.visit("abc", true); DexAnnotationVisitor dav2 = dav.visitArray("efg"); dav2.visit("", "123"); dav2.visit("", "456"); dav2.visitEnd(); dav.visitEnd(); DexCodeVisitor code = mv.visitCode(); code.visitRegister(2); code.visitStmt0R(Op.RETURN_VOID); code.visitEnd(); mv.visitEnd(); cv.visitEnd(); w.visitEnd(); w.toByteArray(); }
@Override public void visitEnd() { objs = null; super.visitEnd(); }
/** * Visits a primitive value of the annotation. * * @param name * the value name. * @param value * the actual value, whose type must be {@link Byte}, {@link Boolean}, {@link Character}, {@link Short}, * {@link Integer}, {@link Long}, {@link Float}, {@link Double}, {@link String} or {@link DexType}. */ public void visit(String name, Object value) { if (visitor != null) { visitor.visit(name, value); } }
public DexAnnotationVisitor visitArray(String name) { if (visitor != null) { return visitor.visitArray(name); } return null; }
/** * Visits an enumeration value of the annotation. * * @param name * the value name. * @param desc * the class descriptor of the enumeration class. * @param value * the actual enumeration value. */ public void visitEnum(String name, String desc, String value) { if (this.visitor != null) { visitor.visitEnum(name, desc, value); } }
/** * Visits a nested annotation value of the annotation. * * @param name * the value name. * @param desc * the class descriptor of the nested annotation class. * @return a visitor to visit the actual nested annotation value, or <tt>null</tt> if this visitor is not interested * in visiting this nested annotation. <i>The nested annotation value must be fully visited before calling * other methods on this annotation visitor</i>. */ public DexAnnotationVisitor visitAnnotation(String name, String desc) { if (this.visitor != null) { return this.visitor.visitAnnotation(name, desc); } return null; }
if (av00 != null) { DexAnnotationVisitor av01 = av00.visitArray("value"); if (av01 != null) { av01.visit(null, new DexType("Lorg/apache/commons/net/MalformedServerReplyException;")); av01.visitEnd(); av00.visitEnd();
/** * Visits the end of the annotation. */ public void visitEnd() { if (this.visitor != null) { visitor.visitEnd(); } } }
public void visit(String name, Object value) { if (value instanceof Object[]) { DexAnnotationVisitor s = visitArray(name); if (s != null) { for (Object v : (Object[]) value) { s.visit(null, v); } s.visitEnd(); } } else { AnnotationElement ae = newAnnotationElement(name); ae.value = EncodedValue.wrap(cp.wrapEncodedItem(value)); } }
/** * Visits a primitive value of the annotation. * * @param name * the value name. * @param value * the actual value, whose type must be {@link Byte}, {@link Boolean}, {@link Character}, {@link Short}, * {@link Integer}, {@link Long}, {@link Float}, {@link Double}, {@link String} or {@link DexType}. */ public void visit(String name, Object value) { if (visitor != null) { visitor.visit(name, value); } }
public DexAnnotationVisitor visitArray(String name) { if (visitor != null) { return visitor.visitArray(name); } return null; }
/** * Visits an enumeration value of the annotation. * * @param name * the value name. * @param desc * the class descriptor of the enumeration class. * @param value * the actual enumeration value. */ public void visitEnum(String name, String desc, String value) { if (this.visitor != null) { visitor.visitEnum(name, desc, value); } }
/** * Visits a nested annotation value of the annotation. * * @param name * the value name. * @param desc * the class descriptor of the nested annotation class. * @return a visitor to visit the actual nested annotation value, or <tt>null</tt> if this visitor is not interested * in visiting this nested annotation. <i>The nested annotation value must be fully visited before calling * other methods on this annotation visitor</i>. */ public DexAnnotationVisitor visitAnnotation(String name, String desc) { if (this.visitor != null) { return this.visitor.visitAnnotation(name, desc); } return null; }
public static void acceptAnnotationItem(DexAnnotationVisitor dav, String name, Object o) { if (o instanceof Object[]) { DexAnnotationVisitor arrayVisitor = dav.visitArray(name); if (arrayVisitor != null) { Object[] array = (Object[]) o; for (Object e : array) { acceptAnnotationItem(arrayVisitor, null, e); } arrayVisitor.visitEnd(); } } else if (o instanceof DexAnnotationNode) { DexAnnotationNode ann = (DexAnnotationNode) o; DexAnnotationVisitor av = dav.visitAnnotation(name, ann.type); if (av != null) { for (DexAnnotationNode.Item item : ann.items) { acceptAnnotationItem(av, item.name, item.value); } av.visitEnd(); } } else if (o instanceof Field) { Field f = (Field) o; dav.visitEnum(name, f.getType(), f.getName()); } else { dav.visit(name, o); } }
public void accept(DexAnnotationAble av) { DexAnnotationVisitor av1 = av.visitAnnotation(type, visibility); if (av1 != null) { for (Item item : items) { acceptAnnotationItem(av1, item.name, item.value); } av1.visitEnd(); } }
case SmaliParser.RULE_sSubannotation: { SmaliParser.SSubannotationContext subannotationContext = (SmaliParser.SSubannotationContext) t; DexAnnotationVisitor annotationVisitor = dexAnnotationVisitor.visitAnnotation(name, Utils .unEscapeId(subannotationContext.type.getText())); if (annotationVisitor != null) { annotationVisitor.visitEnd(); DexAnnotationVisitor annotationVisitor = dexAnnotationVisitor.visitArray(name); if (annotationVisitor != null) { for (SmaliParser.SAnnotationValueContext annotationValueContext : arrayValueContext acceptAnnotation(annotationVisitor, null, annotationValueContext); annotationVisitor.visitEnd(); SmaliParser.SBaseValueContext baseValueContext = (SmaliParser.SBaseValueContext) t; Object value = parseBaseValue(baseValueContext); dexAnnotationVisitor.visit(name, value); break;
private static void acceptAnnotations(List<SmaliParser.SAnnotationContext> sAnnotationContexts, DexAnnotationAble dexAnnotationAble) { if (dexAnnotationAble == null) { return; } if (sAnnotationContexts.size() > 0) { for (SmaliParser.SAnnotationContext ctx : sAnnotationContexts) { Visibility visibility = Utils.getAnnVisibility(ctx.visibility.getText()); String type = Utils.unEscapeId(ctx.type.getText()); DexAnnotationVisitor dexAnnotationVisitor = dexAnnotationAble.visitAnnotation(type, visibility); if (dexAnnotationVisitor != null) { List<SmaliParser.SAnnotationKeyNameContext> keys = ctx.sAnnotationKeyName(); if (keys.size() > 0) { List<SmaliParser.SAnnotationValueContext> values = ctx.sAnnotationValue(); for (int i = 0; i < keys.size(); i++) { acceptAnnotation(dexAnnotationVisitor, Utils.unEscapeId(keys.get(i).getText()), values.get(i)); } } dexAnnotationVisitor.visitEnd(); } } } }
public static void acceptAnnotationItem(DexAnnotationVisitor dav, String name, Object o) { if (o instanceof Object[]) { DexAnnotationVisitor arrayVisitor = dav.visitArray(name); if (arrayVisitor != null) { Object[] array = (Object[]) o; for (Object e : array) { acceptAnnotationItem(arrayVisitor, null, e); } arrayVisitor.visitEnd(); } } else if (o instanceof DexAnnotationNode) { DexAnnotationNode ann = (DexAnnotationNode) o; DexAnnotationVisitor av = dav.visitAnnotation(name, ann.type); if (av != null) { for (DexAnnotationNode.Item item : ann.items) { acceptAnnotationItem(av, item.name, item.value); } av.visitEnd(); } } else if (o instanceof Field) { Field f = (Field) o; dav.visitEnum(name, f.getType(), f.getName()); } else { dav.visit(name, o); } }