Skip to content

🏷️ Annotation

表示应用于类/字段/方法/参数的单个注解实例。

属性
包名org.jf.dexlib2.iface
类型interface extends BasicAnnotation, Comparable<Annotation>
源码Annotation.java
实现类DexBackedAnnotation

🎯 职责

描述 DEX annotation_item 的三要素:

  • 可见性getVisibility()):对应 AnnotationVisibility.BUILD / RUNTIME / SYSTEM
  • 类型getType()):注解类的类型描述符
  • 元素集合getElements()):name=value 键值对的 Set<AnnotationElement>

🧠 关键实现

java
public interface Annotation extends BasicAnnotation, Comparable<Annotation> {
    int getVisibility();         // AnnotationVisibility.BUILD/RUNTIME/SYSTEM
    @Nonnull String getType();   // 如 "Ljava/lang/Deprecated;"
    @Nonnull Set<? extends AnnotationElement> getElements();

    @Override int hashCode();    // visibility + type + elements 三者哈希
    @Override boolean equals(@Nullable Object o);
    @Override int compareTo(Annotation o);
}

抽象基类减少重复

BaseAnnotation(base/ 子包)提供了 hashCodeequalscompareTo 的标准实现,所有具体注解类(如 DexBackedAnnotation)只需继承基类,无需自行实现三个方法。

🔗 关系

📌 小结

注解在 DEX 中广泛用于框架元数据(如 @Override@Nullable)和 Dex 优化标记。脱壳时还原注解信息可以使 smali 文件在语义上更完整,便于后续逆向分析。

基于 MIT 协议发布 · 本文档仅用于安全研究与教学目的