Search in sources :

Example 16 with InsnWrapArg

use of jadx.core.dex.instructions.args.InsnWrapArg in project jadx by skylot.

the class ReSugarCode method addToEnumMap.

private static void addToEnumMap(MethodNode mth, EnumMapAttr mapAttr, InsnNode aputInsn) {
    InsnArg litArg = aputInsn.getArg(2);
    if (!litArg.isLiteral()) {
        return;
    }
    EnumMapInfo mapInfo = checkEnumMapAccess(mth, aputInsn);
    if (mapInfo == null) {
        return;
    }
    InsnArg enumArg = mapInfo.getArg();
    FieldNode field = mapInfo.getMapField();
    if (field == null || !enumArg.isInsnWrap()) {
        return;
    }
    InsnNode sget = ((InsnWrapArg) enumArg).getWrapInsn();
    if (!(sget instanceof IndexInsnNode)) {
        return;
    }
    Object index = ((IndexInsnNode) sget).getIndex();
    if (!(index instanceof FieldInfo)) {
        return;
    }
    FieldNode fieldNode = mth.dex().resolveField((FieldInfo) index);
    if (fieldNode == null) {
        return;
    }
    int literal = (int) ((LiteralArg) litArg).getLiteral();
    mapAttr.add(field, literal, fieldNode);
}
Also used : IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode) FieldNode(jadx.core.dex.nodes.FieldNode) InsnArg(jadx.core.dex.instructions.args.InsnArg) InsnWrapArg(jadx.core.dex.instructions.args.InsnWrapArg) IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) FieldInfo(jadx.core.dex.info.FieldInfo)

Example 17 with InsnWrapArg

use of jadx.core.dex.instructions.args.InsnWrapArg in project jadx by skylot.

the class ReSugarCode method processEnumSwitch.

private static InsnNode processEnumSwitch(MethodNode mth, SwitchNode insn) {
    InsnArg arg = insn.getArg(0);
    if (!arg.isInsnWrap()) {
        return null;
    }
    InsnNode wrapInsn = ((InsnWrapArg) arg).getWrapInsn();
    if (wrapInsn.getType() != InsnType.AGET) {
        return null;
    }
    EnumMapInfo enumMapInfo = checkEnumMapAccess(mth, wrapInsn);
    if (enumMapInfo == null) {
        return null;
    }
    FieldNode enumMapField = enumMapInfo.getMapField();
    InsnArg invArg = enumMapInfo.getArg();
    EnumMapAttr.KeyValueMap valueMap = getEnumMap(mth, enumMapField);
    if (valueMap == null) {
        return null;
    }
    Object[] keys = insn.getKeys();
    for (Object key : keys) {
        Object newKey = valueMap.get(key);
        if (newKey == null) {
            return null;
        }
    }
    // replace confirmed
    if (!insn.replaceArg(arg, invArg)) {
        return null;
    }
    for (int i = 0; i < keys.length; i++) {
        keys[i] = valueMap.get(keys[i]);
    }
    enumMapField.add(AFlag.DONT_GENERATE);
    checkAndHideClass(enumMapField.getParentClass());
    return null;
}
Also used : IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode) FieldNode(jadx.core.dex.nodes.FieldNode) InsnArg(jadx.core.dex.instructions.args.InsnArg) EnumMapAttr(jadx.core.dex.attributes.nodes.EnumMapAttr) InsnWrapArg(jadx.core.dex.instructions.args.InsnWrapArg)

Example 18 with InsnWrapArg

use of jadx.core.dex.instructions.args.InsnWrapArg in project jadx by skylot.

the class ExtractFieldInit method checkInsn.

private static boolean checkInsn(InsnNode insn) {
    InsnArg arg = insn.getArg(0);
    if (arg.isInsnWrap()) {
        InsnNode wrapInsn = ((InsnWrapArg) arg).getWrapInsn();
        if (!wrapInsn.canReorderRecursive() && insn.contains(AType.CATCH_BLOCK)) {
            return false;
        }
    } else {
        return arg.isLiteral() || arg.isThis();
    }
    Set<RegisterArg> regs = new HashSet<RegisterArg>();
    insn.getRegisterArgs(regs);
    if (!regs.isEmpty()) {
        for (RegisterArg reg : regs) {
            if (!reg.isThis()) {
                return false;
            }
        }
    }
    return true;
}
Also used : IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) InsnArg(jadx.core.dex.instructions.args.InsnArg) InsnWrapArg(jadx.core.dex.instructions.args.InsnWrapArg) HashSet(java.util.HashSet)

Example 19 with InsnWrapArg

use of jadx.core.dex.instructions.args.InsnWrapArg in project jadx by skylot.

the class InsnNode method copyCommonParams.

protected <T extends InsnNode> T copyCommonParams(T copy) {
    copy.setResult(result);
    if (copy.getArgsCount() == 0) {
        for (InsnArg arg : this.getArguments()) {
            if (arg.isInsnWrap()) {
                InsnNode wrapInsn = ((InsnWrapArg) arg).getWrapInsn();
                copy.addArg(InsnArg.wrapArg(wrapInsn.copy()));
            } else {
                copy.addArg(arg);
            }
        }
    }
    copy.copyAttributesFrom(this);
    copy.copyLines(this);
    copy.setOffset(this.getOffset());
    return copy;
}
Also used : InsnArg(jadx.core.dex.instructions.args.InsnArg) InsnWrapArg(jadx.core.dex.instructions.args.InsnWrapArg)

Example 20 with InsnWrapArg

use of jadx.core.dex.instructions.args.InsnWrapArg in project jadx by skylot.

the class SimplifyVisitor method processCast.

private static InsnNode processCast(MethodNode mth, InsnNode insn) {
    InsnArg castArg = insn.getArg(0);
    ArgType argType = castArg.getType();
    // Don't removes CHECK_CAST for wrapped INVOKE if invoked method returns different type
    if (castArg.isInsnWrap()) {
        InsnNode wrapInsn = ((InsnWrapArg) castArg).getWrapInsn();
        if (wrapInsn.getType() == InsnType.INVOKE) {
            argType = ((InvokeNode) wrapInsn).getCallMth().getReturnType();
        }
    }
    ArgType castToType = (ArgType) ((IndexInsnNode) insn).getIndex();
    if (ArgType.isCastNeeded(mth.dex(), argType, castToType)) {
        return null;
    }
    InsnNode insnNode = new InsnNode(InsnType.MOVE, 1);
    insnNode.setOffset(insn.getOffset());
    insnNode.setResult(insn.getResult());
    insnNode.addArg(castArg);
    return insnNode;
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode) InsnArg(jadx.core.dex.instructions.args.InsnArg) InvokeNode(jadx.core.dex.instructions.InvokeNode) InsnWrapArg(jadx.core.dex.instructions.args.InsnWrapArg)

Aggregations

InsnWrapArg (jadx.core.dex.instructions.args.InsnWrapArg)22 InsnNode (jadx.core.dex.nodes.InsnNode)19 InsnArg (jadx.core.dex.instructions.args.InsnArg)15 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)11 ArithNode (jadx.core.dex.instructions.ArithNode)4 InvokeNode (jadx.core.dex.instructions.InvokeNode)4 FieldInfo (jadx.core.dex.info.FieldInfo)3 InsnType (jadx.core.dex.instructions.InsnType)3 FieldNode (jadx.core.dex.nodes.FieldNode)3 LiteralArg (jadx.core.dex.instructions.args.LiteralArg)2 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)2 ConstructorInsn (jadx.core.dex.instructions.mods.ConstructorInsn)2 ClassNode (jadx.core.dex.nodes.ClassNode)2 EnumMapAttr (jadx.core.dex.attributes.nodes.EnumMapAttr)1 MethodInfo (jadx.core.dex.info.MethodInfo)1 ArithOp (jadx.core.dex.instructions.ArithOp)1 ConstStringNode (jadx.core.dex.instructions.ConstStringNode)1 IfNode (jadx.core.dex.instructions.IfNode)1 ArgType (jadx.core.dex.instructions.args.ArgType)1 FieldArg (jadx.core.dex.instructions.args.FieldArg)1