Search in sources :

Example 6 with DecodeException

use of jadx.core.utils.exceptions.DecodeException in project jadx by skylot.

the class ReSugarCode method getEnumMap.

private static EnumMapAttr.KeyValueMap getEnumMap(MethodNode mth, FieldNode field) {
    ClassNode syntheticClass = field.getParentClass();
    EnumMapAttr mapAttr = syntheticClass.get(AType.ENUM_MAP);
    if (mapAttr != null) {
        return mapAttr.getMap(field);
    }
    mapAttr = new EnumMapAttr();
    syntheticClass.addAttr(mapAttr);
    MethodNode clsInitMth = syntheticClass.searchMethodByName("<clinit>()V");
    if (clsInitMth == null || clsInitMth.isNoCode()) {
        return null;
    }
    if (clsInitMth.getBasicBlocks() == null) {
        try {
            clsInitMth.load();
        } catch (DecodeException e) {
            LOG.error("Load failed", e);
            return null;
        }
        if (clsInitMth.getBasicBlocks() == null) {
            // TODO:
            return null;
        }
    }
    for (BlockNode block : clsInitMth.getBasicBlocks()) {
        for (InsnNode insn : block.getInstructions()) {
            if (insn.getType() == InsnType.APUT) {
                addToEnumMap(mth, mapAttr, insn);
            }
        }
    }
    return mapAttr.getMap(field);
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode) ClassNode(jadx.core.dex.nodes.ClassNode) IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode) MethodNode(jadx.core.dex.nodes.MethodNode) EnumMapAttr(jadx.core.dex.attributes.nodes.EnumMapAttr) DecodeException(jadx.core.utils.exceptions.DecodeException)

Example 7 with DecodeException

use of jadx.core.utils.exceptions.DecodeException in project jadx by skylot.

the class MethodNode method load.

@Override
public void load() throws DecodeException {
    try {
        if (noCode) {
            regsCount = 0;
            codeSize = 0;
            initMethodTypes();
            return;
        }
        DexNode dex = parentClass.dex();
        Code mthCode = dex.readCode(methodData);
        regsCount = mthCode.getRegistersSize();
        initMethodTypes();
        InsnDecoder decoder = new InsnDecoder(this);
        decoder.decodeInsns(mthCode);
        instructions = decoder.process();
        codeSize = instructions.length;
        initTryCatches(mthCode);
        initJumps();
        this.debugInfoOffset = mthCode.getDebugInfoOffset();
    } catch (Exception e) {
        if (!noCode) {
            noCode = true;
            // load without code
            load();
            noCode = false;
        }
        throw new DecodeException(this, "Load method exception", e);
    }
}
Also used : InsnDecoder(jadx.core.dex.instructions.InsnDecoder) Code(com.android.dex.Code) DecodeException(jadx.core.utils.exceptions.DecodeException) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) DecodeException(jadx.core.utils.exceptions.DecodeException)

Example 8 with DecodeException

use of jadx.core.utils.exceptions.DecodeException in project jadx by skylot.

the class RootNode method load.

public void load(List<InputFile> inputFiles) throws DecodeException {
    dexNodes = new ArrayList<DexNode>();
    for (InputFile input : inputFiles) {
        for (DexFile dexFile : input.getDexFiles()) {
            try {
                LOG.debug("Load: {}", dexFile);
                DexNode dexNode = new DexNode(this, dexFile);
                dexNodes.add(dexNode);
            } catch (Exception e) {
                throw new DecodeException("Error decode file: " + dexFile, e);
            }
        }
    }
    for (DexNode dexNode : dexNodes) {
        dexNode.loadClasses();
    }
    initInnerClasses();
}
Also used : DecodeException(jadx.core.utils.exceptions.DecodeException) DexFile(jadx.core.utils.files.DexFile) JadxException(jadx.core.utils.exceptions.JadxException) IOException(java.io.IOException) DecodeException(jadx.core.utils.exceptions.DecodeException) InputFile(jadx.core.utils.files.InputFile)

Example 9 with DecodeException

use of jadx.core.utils.exceptions.DecodeException in project jadx by skylot.

the class RootNode method initClassPath.

public void initClassPath() throws DecodeException {
    try {
        if (this.clsp == null) {
            ClspGraph clsp = new ClspGraph();
            clsp.load();
            List<ClassNode> classes = new ArrayList<ClassNode>();
            for (DexNode dexNode : dexNodes) {
                classes.addAll(dexNode.getClasses());
            }
            clsp.addApp(classes);
            this.clsp = clsp;
        }
    } catch (IOException e) {
        throw new DecodeException("Error loading classpath", e);
    }
}
Also used : ArrayList(java.util.ArrayList) ClspGraph(jadx.core.clsp.ClspGraph) IOException(java.io.IOException) DecodeException(jadx.core.utils.exceptions.DecodeException)

Example 10 with DecodeException

use of jadx.core.utils.exceptions.DecodeException in project jadx by skylot.

the class AnnotationsParser method readAnnotation.

public static Annotation readAnnotation(DexNode dex, Section s, boolean readVisibility) throws DecodeException {
    EncValueParser parser = new EncValueParser(dex, s);
    Visibility visibility = null;
    if (readVisibility) {
        byte v = s.readByte();
        visibility = VISIBILITIES[v];
    }
    int typeIndex = s.readUleb128();
    int size = s.readUleb128();
    Map<String, Object> values = new LinkedHashMap<String, Object>(size);
    for (int i = 0; i < size; i++) {
        String name = dex.getString(s.readUleb128());
        values.put(name, parser.parseValue());
    }
    ArgType type = dex.getType(typeIndex);
    Annotation annotation = new Annotation(visibility, type, values);
    if (!type.isObject()) {
        throw new DecodeException("Incorrect type for annotation: " + annotation);
    }
    return annotation;
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) Visibility(jadx.core.dex.attributes.annotations.Annotation.Visibility) DecodeException(jadx.core.utils.exceptions.DecodeException) Annotation(jadx.core.dex.attributes.annotations.Annotation) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

DecodeException (jadx.core.utils.exceptions.DecodeException)10 InsnNode (jadx.core.dex.nodes.InsnNode)2 JadxException (jadx.core.utils.exceptions.JadxException)2 IOException (java.io.IOException)2 Code (com.android.dex.Code)1 Dex (com.android.dex.Dex)1 DecodedInstruction (com.android.dx.io.instructions.DecodedInstruction)1 FillArrayDataPayloadDecodedInstruction (com.android.dx.io.instructions.FillArrayDataPayloadDecodedInstruction)1 PackedSwitchPayloadDecodedInstruction (com.android.dx.io.instructions.PackedSwitchPayloadDecodedInstruction)1 ShortArrayCodeInput (com.android.dx.io.instructions.ShortArrayCodeInput)1 SparseSwitchPayloadDecodedInstruction (com.android.dx.io.instructions.SparseSwitchPayloadDecodedInstruction)1 ClspGraph (jadx.core.clsp.ClspGraph)1 Annotation (jadx.core.dex.attributes.annotations.Annotation)1 Visibility (jadx.core.dex.attributes.annotations.Annotation.Visibility)1 EnumMapAttr (jadx.core.dex.attributes.nodes.EnumMapAttr)1 JadxErrorAttr (jadx.core.dex.attributes.nodes.JadxErrorAttr)1 SourceFileAttr (jadx.core.dex.attributes.nodes.SourceFileAttr)1 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)1 InsnDecoder (jadx.core.dex.instructions.InsnDecoder)1 ArgType (jadx.core.dex.instructions.args.ArgType)1