Search in sources :

Example 1 with MethodParametersAttr

use of jadx.api.plugins.input.data.attributes.types.MethodParametersAttr 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 MethodParametersAttr

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

the class DebugInfoApplyVisitor method processMethodParametersAttribute.

private void processMethodParametersAttribute(MethodNode mth) {
    MethodParametersAttr parametersAttr = mth.get(JadxAttrType.METHOD_PARAMETERS);
    if (parametersAttr == null) {
        return;
    }
    try {
        List<MethodParametersAttr.Info> params = parametersAttr.getList();
        if (params.size() != mth.getMethodInfo().getArgsCount()) {
            return;
        }
        int i = 0;
        for (RegisterArg mthArg : mth.getArgRegs()) {
            MethodParametersAttr.Info paramInfo = params.get(i++);
            String name = paramInfo.getName();
            if (NameMapper.isValidAndPrintable(name)) {
                CodeVar codeVar = mthArg.getSVar().getCodeVar();
                codeVar.setName(name);
                if (AccessFlags.hasFlag(paramInfo.getAccFlags(), AccessFlags.FINAL)) {
                    codeVar.setFinal(true);
                }
            }
        }
    } catch (Exception e) {
        mth.addWarnComment("Failed to process method parameters attribute: " + parametersAttr.getList(), e);
    }
}
Also used : CodeVar(jadx.core.dex.instructions.args.CodeVar) MethodParametersAttr(jadx.api.plugins.input.data.attributes.types.MethodParametersAttr) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) JadxException(jadx.core.utils.exceptions.JadxException)

Aggregations

MethodParametersAttr (jadx.api.plugins.input.data.attributes.types.MethodParametersAttr)2 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 IJadxAttribute (jadx.api.plugins.input.data.attributes.IJadxAttribute)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 SignatureAttr (jadx.api.plugins.input.data.attributes.types.SignatureAttr)1 Utils (jadx.api.plugins.utils.Utils)1 CodeVar (jadx.core.dex.instructions.args.CodeVar)1 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)1 JadxException (jadx.core.utils.exceptions.JadxException)1 AnnotationsUtils (jadx.plugins.input.dex.sections.annotations.AnnotationsUtils)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1