Search in sources :

Example 11 with InsnWrapArg

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

the class EnumVisitor method getConstString.

private String getConstString(DexNode dex, InsnArg arg) {
    if (arg.isInsnWrap()) {
        InsnNode constInsn = ((InsnWrapArg) arg).getWrapInsn();
        Object constValue = InsnUtils.getConstValueByInsn(dex, constInsn);
        if (constValue instanceof String) {
            return (String) constValue;
        }
    }
    return null;
}
Also used : IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode) InsnWrapArg(jadx.core.dex.instructions.args.InsnWrapArg)

Example 12 with InsnWrapArg

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

the class TestDuplicateCast method test.

@Test
public void test() {
    dontUnloadClass();
    ClassNode cls = getClassNode(TestCls.class);
    MethodNode mth = getMethod(cls, "method");
    String code = cls.getCode().toString();
    assertThat(code, containsString("return (int[]) o;"));
    List<InsnNode> insns = mth.getBasicBlocks().get(1).getInstructions();
    assertEquals(insns.size(), 1);
    InsnNode insnNode = insns.get(0);
    assertEquals(InsnType.RETURN, insnNode.getType());
    assertTrue(insnNode.getArg(0).isInsnWrap());
    InsnNode wrapInsn = ((InsnWrapArg) insnNode.getArg(0)).getWrapInsn();
    assertEquals(InsnType.CHECK_CAST, wrapInsn.getType());
    assertFalse(wrapInsn.getArg(0).isInsnWrap());
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) InsnNode(jadx.core.dex.nodes.InsnNode) MethodNode(jadx.core.dex.nodes.MethodNode) InsnWrapArg(jadx.core.dex.instructions.args.InsnWrapArg) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test) IntegrationTest(jadx.tests.api.IntegrationTest)

Example 13 with InsnWrapArg

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

the class NameGen method makeNameFromInsn.

private String makeNameFromInsn(InsnNode insn) {
    switch(insn.getType()) {
        case INVOKE:
            InvokeNode inv = (InvokeNode) insn;
            return makeNameFromInvoke(inv.getCallMth());
        case CONSTRUCTOR:
            ConstructorInsn co = (ConstructorInsn) insn;
            return makeNameForObject(co.getClassType().getType());
        case ARRAY_LENGTH:
            return "length";
        case ARITH:
        case TERNARY:
        case CAST:
            for (InsnArg arg : insn.getArguments()) {
                if (arg.isInsnWrap()) {
                    InsnNode wrapInsn = ((InsnWrapArg) arg).getWrapInsn();
                    String wName = makeNameFromInsn(wrapInsn);
                    if (wName != null) {
                        return wName;
                    }
                }
            }
            break;
        default:
            break;
    }
    return null;
}
Also used : 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) ConstructorInsn(jadx.core.dex.instructions.mods.ConstructorInsn)

Example 14 with InsnWrapArg

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

the class InsnGen method processVarArg.

/**
	 * Expand varArgs from filled array.
	 */
private boolean processVarArg(CodeWriter code, MethodNode callMth, InsnArg lastArg) throws CodegenException {
    if (callMth == null || !callMth.getAccessFlags().isVarArgs()) {
        return false;
    }
    if (!lastArg.getType().isArray() || !lastArg.isInsnWrap()) {
        return false;
    }
    InsnNode insn = ((InsnWrapArg) lastArg).getWrapInsn();
    if (insn.getType() == InsnType.FILLED_NEW_ARRAY) {
        int count = insn.getArgsCount();
        for (int i = 0; i < count; i++) {
            InsnArg elemArg = insn.getArg(i);
            addArg(code, elemArg, false);
            if (i < count - 1) {
                code.add(", ");
            }
        }
        return true;
    }
    return false;
}
Also used : IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode) InsnArg(jadx.core.dex.instructions.args.InsnArg) InsnWrapArg(jadx.core.dex.instructions.args.InsnWrapArg)

Example 15 with InsnWrapArg

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

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