Search in sources :

Example 1 with IJadxAttribute

use of jadx.api.plugins.input.data.attributes.IJadxAttribute in project jadx by skylot.

the class DexAnnotationsConvert method convertSystemAnnotations.

@SuppressWarnings("unchecked")
private static void convertSystemAnnotations(@Nullable String cls, List<IJadxAttribute> attributes, IAnnotation annotation) {
    switch(annotation.getAnnotationClass()) {
        case "Ldalvik/annotation/Signature;":
            attributes.add(new SignatureAttr(extractSignature(annotation)));
            break;
        case "Ldalvik/annotation/InnerClass;":
            try {
                String name = AnnotationsUtils.getValue(annotation, "name", EncodedType.ENCODED_STRING, null);
                int accFlags = AnnotationsUtils.getValue(annotation, "accessFlags", EncodedType.ENCODED_INT, 0);
                if (name != null || accFlags != 0) {
                    InnerClsInfo innerClsInfo = new InnerClsInfo(cls, null, name, accFlags);
                    attributes.add(new InnerClassesAttr(Collections.singletonMap(cls, innerClsInfo)));
                }
            } catch (Exception e) {
                LOG.warn("Failed to parse annotation: " + annotation, e);
            }
            break;
        case "Ldalvik/annotation/AnnotationDefault;":
            EncodedValue annValue = annotation.getDefaultValue();
            if (annValue != null && annValue.getType() == EncodedType.ENCODED_ANNOTATION) {
                IAnnotation defAnnotation = (IAnnotation) annValue.getValue();
                attributes.add(new AnnotationDefaultClassAttr(defAnnotation.getValues()));
            }
            break;
        case "Ldalvik/annotation/Throws;":
            try {
                EncodedValue defaultValue = annotation.getDefaultValue();
                if (defaultValue != null) {
                    List<String> excs = ((List<EncodedValue>) defaultValue.getValue()).stream().map(ev -> ((String) ev.getValue())).collect(Collectors.toList());
                    attributes.add(new ExceptionsAttr(excs));
                }
            } catch (Exception e) {
                LOG.warn("Failed to convert dalvik throws annotation", e);
            }
            break;
        case "Ldalvik/annotation/MethodParameters;":
            try {
                List<EncodedValue> names = AnnotationsUtils.getArray(annotation, "names");
                List<EncodedValue> accFlags = AnnotationsUtils.getArray(annotation, "accessFlags");
                if (!names.isEmpty() && names.size() == accFlags.size()) {
                    int size = names.size();
                    List<MethodParametersAttr.Info> list = new ArrayList<>(size);
                    for (int i = 0; i < size; i++) {
                        String name = (String) names.get(i).getValue();
                        int accFlag = (int) accFlags.get(i).getValue();
                        list.add(new MethodParametersAttr.Info(accFlag, name));
                    }
                    attributes.add(new MethodParametersAttr(list));
                }
            } catch (Exception e) {
                LOG.warn("Failed to parse annotation: " + annotation, e);
            }
            break;
    }
}
Also used : IAnnotation(jadx.api.plugins.input.data.annotations.IAnnotation) ExceptionsAttr(jadx.api.plugins.input.data.attributes.types.ExceptionsAttr) InnerClassesAttr(jadx.api.plugins.input.data.attributes.types.InnerClassesAttr) Logger(org.slf4j.Logger) AnnotationsAttr(jadx.api.plugins.input.data.attributes.types.AnnotationsAttr) SignatureAttr(jadx.api.plugins.input.data.attributes.types.SignatureAttr) LoggerFactory(org.slf4j.LoggerFactory) AnnotationsUtils(jadx.plugins.input.dex.sections.annotations.AnnotationsUtils) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Nullable(org.jetbrains.annotations.Nullable) EncodedType(jadx.api.plugins.input.data.annotations.EncodedType) InnerClsInfo(jadx.api.plugins.input.data.attributes.types.InnerClsInfo) List(java.util.List) AnnotationVisibility(jadx.api.plugins.input.data.annotations.AnnotationVisibility) IJadxAttribute(jadx.api.plugins.input.data.attributes.IJadxAttribute) MethodParametersAttr(jadx.api.plugins.input.data.attributes.types.MethodParametersAttr) Utils(jadx.api.plugins.utils.Utils) AnnotationDefaultClassAttr(jadx.api.plugins.input.data.attributes.types.AnnotationDefaultClassAttr) Collections(java.util.Collections) EncodedValue(jadx.api.plugins.input.data.annotations.EncodedValue) IAnnotation(jadx.api.plugins.input.data.annotations.IAnnotation) InnerClsInfo(jadx.api.plugins.input.data.attributes.types.InnerClsInfo) ArrayList(java.util.ArrayList) AnnotationDefaultClassAttr(jadx.api.plugins.input.data.attributes.types.AnnotationDefaultClassAttr) InnerClsInfo(jadx.api.plugins.input.data.attributes.types.InnerClsInfo) ExceptionsAttr(jadx.api.plugins.input.data.attributes.types.ExceptionsAttr) EncodedValue(jadx.api.plugins.input.data.annotations.EncodedValue) MethodParametersAttr(jadx.api.plugins.input.data.attributes.types.MethodParametersAttr) SignatureAttr(jadx.api.plugins.input.data.attributes.types.SignatureAttr) ArrayList(java.util.ArrayList) List(java.util.List) InnerClassesAttr(jadx.api.plugins.input.data.attributes.types.InnerClassesAttr)

Example 2 with IJadxAttribute

use of jadx.api.plugins.input.data.attributes.IJadxAttribute in project jadx by skylot.

the class DexClassData method getAttributes.

@Override
public List<IJadxAttribute> getAttributes() {
    List<IJadxAttribute> list = new ArrayList<>();
    String sourceFile = getSourceFile();
    if (sourceFile != null && !sourceFile.isEmpty()) {
        list.add(new SourceFileAttr(sourceFile));
    }
    DexAnnotationsConvert.forClass(getType(), list, getAnnotations());
    return list;
}
Also used : IJadxAttribute(jadx.api.plugins.input.data.attributes.IJadxAttribute) ArrayList(java.util.ArrayList) SourceFileAttr(jadx.api.plugins.input.data.attributes.types.SourceFileAttr)

Example 3 with IJadxAttribute

use of jadx.api.plugins.input.data.attributes.IJadxAttribute in project jadx by skylot.

the class JavaClassData method getAttributes.

@Override
public List<IJadxAttribute> getAttributes() {
    data.absPos(offsets.getAttributesOffset());
    JavaAttrStorage attributes = attributesReader.load(data);
    int size = attributes.size();
    if (size == 0) {
        return Collections.emptyList();
    }
    List<IJadxAttribute> list = new ArrayList<>(size);
    Utils.addToList(list, JavaAnnotationsAttr.merge(attributes));
    Utils.addToList(list, attributes.get(JavaAttrType.INNER_CLASSES));
    Utils.addToList(list, attributes.get(JavaAttrType.SOURCE_FILE));
    Utils.addToList(list, attributes.get(JavaAttrType.SIGNATURE));
    return list;
}
Also used : IJadxAttribute(jadx.api.plugins.input.data.attributes.IJadxAttribute) ArrayList(java.util.ArrayList) JavaAttrStorage(jadx.plugins.input.java.data.attributes.JavaAttrStorage)

Example 4 with IJadxAttribute

use of jadx.api.plugins.input.data.attributes.IJadxAttribute in project jadx by skylot.

the class AttributeStorage method getAttributeStrings.

public List<String> getAttributeStrings() {
    int size = flags.size() + attributes.size() + attributes.size();
    if (size == 0) {
        return Collections.emptyList();
    }
    List<String> list = new ArrayList<>(size);
    for (AFlag a : flags) {
        list.add(a.toString());
    }
    for (IJadxAttribute a : attributes.values()) {
        list.add(a.toAttrString());
    }
    return list;
}
Also used : IJadxAttribute(jadx.api.plugins.input.data.attributes.IJadxAttribute) ArrayList(java.util.ArrayList)

Example 5 with IJadxAttribute

use of jadx.api.plugins.input.data.attributes.IJadxAttribute in project jadx by skylot.

the class AttributeStorage method remove.

public void remove(IJadxAttribute attr) {
    if (!attributes.isEmpty()) {
        IJadxAttrType<? extends IJadxAttribute> type = attr.getAttrType();
        IJadxAttribute a = attributes.get(type);
        if (a == attr) {
            attributes.remove(type);
        }
    }
}
Also used : IJadxAttribute(jadx.api.plugins.input.data.attributes.IJadxAttribute)

Aggregations

IJadxAttribute (jadx.api.plugins.input.data.attributes.IJadxAttribute)5 ArrayList (java.util.ArrayList)4 AnnotationVisibility (jadx.api.plugins.input.data.annotations.AnnotationVisibility)1 EncodedType (jadx.api.plugins.input.data.annotations.EncodedType)1 EncodedValue (jadx.api.plugins.input.data.annotations.EncodedValue)1 IAnnotation (jadx.api.plugins.input.data.annotations.IAnnotation)1 AnnotationDefaultClassAttr (jadx.api.plugins.input.data.attributes.types.AnnotationDefaultClassAttr)1 AnnotationsAttr (jadx.api.plugins.input.data.attributes.types.AnnotationsAttr)1 ExceptionsAttr (jadx.api.plugins.input.data.attributes.types.ExceptionsAttr)1 InnerClassesAttr (jadx.api.plugins.input.data.attributes.types.InnerClassesAttr)1 InnerClsInfo (jadx.api.plugins.input.data.attributes.types.InnerClsInfo)1 MethodParametersAttr (jadx.api.plugins.input.data.attributes.types.MethodParametersAttr)1 SignatureAttr (jadx.api.plugins.input.data.attributes.types.SignatureAttr)1 SourceFileAttr (jadx.api.plugins.input.data.attributes.types.SourceFileAttr)1 Utils (jadx.api.plugins.utils.Utils)1 AnnotationsUtils (jadx.plugins.input.dex.sections.annotations.AnnotationsUtils)1 JavaAttrStorage (jadx.plugins.input.java.data.attributes.JavaAttrStorage)1 Collections (java.util.Collections)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1