Search in sources :

Example 6 with InvokeNode

use of jadx.core.dex.instructions.InvokeNode in project jadx by skylot.

the class ReSugarCode method checkEnumMapAccess.

public static EnumMapInfo checkEnumMapAccess(MethodNode mth, InsnNode checkInsn) {
    InsnArg sgetArg = checkInsn.getArg(0);
    InsnArg invArg = checkInsn.getArg(1);
    if (!sgetArg.isInsnWrap() || !invArg.isInsnWrap()) {
        return null;
    }
    InsnNode invInsn = ((InsnWrapArg) invArg).getWrapInsn();
    InsnNode sgetInsn = ((InsnWrapArg) sgetArg).getWrapInsn();
    if (invInsn.getType() != InsnType.INVOKE || sgetInsn.getType() != InsnType.SGET) {
        return null;
    }
    InvokeNode inv = (InvokeNode) invInsn;
    if (!inv.getCallMth().getShortId().equals("ordinal()I")) {
        return null;
    }
    ClassNode enumCls = mth.dex().resolveClass(inv.getCallMth().getDeclClass());
    if (enumCls == null || !enumCls.isEnum()) {
        return null;
    }
    Object index = ((IndexInsnNode) sgetInsn).getIndex();
    if (!(index instanceof FieldInfo)) {
        return null;
    }
    FieldNode enumMapField = mth.dex().resolveField((FieldInfo) index);
    if (enumMapField == null || !enumMapField.getAccessFlags().isSynthetic()) {
        return null;
    }
    return new EnumMapInfo(inv.getArg(0), enumMapField);
}
Also used : IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode) ClassNode(jadx.core.dex.nodes.ClassNode) FieldNode(jadx.core.dex.nodes.FieldNode) InsnArg(jadx.core.dex.instructions.args.InsnArg) InvokeNode(jadx.core.dex.instructions.InvokeNode) InsnWrapArg(jadx.core.dex.instructions.args.InsnWrapArg) IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) FieldInfo(jadx.core.dex.info.FieldInfo)

Example 7 with InvokeNode

use of jadx.core.dex.instructions.InvokeNode 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)

Example 8 with InvokeNode

use of jadx.core.dex.instructions.InvokeNode in project jadx by skylot.

the class LoopRegionVisitor method checkInvoke.

/**
	 * Check if instruction is a interface invoke with corresponding parameters.
	 */
private static boolean checkInvoke(InsnNode insn, String declClsFullName, String mthId, int argsCount) {
    if (insn.getType() == InsnType.INVOKE) {
        InvokeNode inv = (InvokeNode) insn;
        MethodInfo callMth = inv.getCallMth();
        if (callMth.getArgsCount() == argsCount && callMth.getShortId().equals(mthId) && inv.getInvokeType() == InvokeType.INTERFACE) {
            return declClsFullName == null || callMth.getDeclClass().getFullName().equals(declClsFullName);
        }
    }
    return false;
}
Also used : InvokeNode(jadx.core.dex.instructions.InvokeNode) MethodInfo(jadx.core.dex.info.MethodInfo)

Aggregations

InvokeNode (jadx.core.dex.instructions.InvokeNode)8 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)6 InsnArg (jadx.core.dex.instructions.args.InsnArg)5 InsnNode (jadx.core.dex.nodes.InsnNode)5 MethodInfo (jadx.core.dex.info.MethodInfo)4 InsnWrapArg (jadx.core.dex.instructions.args.InsnWrapArg)4 ArgType (jadx.core.dex.instructions.args.ArgType)3 ConstructorInsn (jadx.core.dex.instructions.mods.ConstructorInsn)3 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)2 ClassNode (jadx.core.dex.nodes.ClassNode)2 DexNode (jadx.core.dex.nodes.DexNode)2 MethodNode (jadx.core.dex.nodes.MethodNode)2 FieldInfo (jadx.core.dex.info.FieldInfo)1 ConstClassNode (jadx.core.dex.instructions.ConstClassNode)1 ConstStringNode (jadx.core.dex.instructions.ConstStringNode)1 LiteralArg (jadx.core.dex.instructions.args.LiteralArg)1 FieldNode (jadx.core.dex.nodes.FieldNode)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1