Search in sources :

Example 1 with EnumMapAttr

use of jadx.core.dex.attributes.nodes.EnumMapAttr 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)

Aggregations

EnumMapAttr (jadx.core.dex.attributes.nodes.EnumMapAttr)1 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)1 BlockNode (jadx.core.dex.nodes.BlockNode)1 ClassNode (jadx.core.dex.nodes.ClassNode)1 InsnNode (jadx.core.dex.nodes.InsnNode)1 MethodNode (jadx.core.dex.nodes.MethodNode)1 DecodeException (jadx.core.utils.exceptions.DecodeException)1