Search in sources :

Example 26 with InsnWrapArg

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

the class TestDuplicateCast method test.

@Test
public void test() {
    ClassNode cls = getClassNode(TestCls.class);
    MethodNode mth = getMethod(cls, "method");
    String code = cls.getCode().toString();
    assertThat(code, containsString("return (int[]) o;"));
    List<InsnNode> insns = BlockUtils.collectAllInsns(mth.getBasicBlocks());
    assertThat(insns, hasSize(1));
    InsnNode insnNode = insns.get(0);
    assertThat(insnNode.getType(), is(InsnType.RETURN));
    assertTrue(insnNode.getArg(0).isInsnWrap());
    InsnNode wrapInsn = ((InsnWrapArg) insnNode.getArg(0)).getWrapInsn();
    assertThat(wrapInsn.getType(), is(InsnType.CHECK_CAST));
    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.jupiter.api.Test) IntegrationTest(jadx.tests.api.IntegrationTest)

Example 27 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 28 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 29 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)

Example 30 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)

Aggregations

InsnWrapArg (jadx.core.dex.instructions.args.InsnWrapArg)50 InsnNode (jadx.core.dex.nodes.InsnNode)41 InsnArg (jadx.core.dex.instructions.args.InsnArg)38 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)32 FieldNode (jadx.core.dex.nodes.FieldNode)9 InvokeNode (jadx.core.dex.instructions.InvokeNode)8 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)8 FieldInfo (jadx.core.dex.info.FieldInfo)7 ArithNode (jadx.core.dex.instructions.ArithNode)7 ArgType (jadx.core.dex.instructions.args.ArgType)6 LiteralArg (jadx.core.dex.instructions.args.LiteralArg)5 ClassNode (jadx.core.dex.nodes.ClassNode)5 MethodNode (jadx.core.dex.nodes.MethodNode)5 ArrayList (java.util.ArrayList)5 InsnType (jadx.core.dex.instructions.InsnType)4 SSAVar (jadx.core.dex.instructions.args.SSAVar)4 Nullable (org.jetbrains.annotations.Nullable)4 ArithOp (jadx.core.dex.instructions.ArithOp)3 ConstStringNode (jadx.core.dex.instructions.ConstStringNode)3 ConstructorInsn (jadx.core.dex.instructions.mods.ConstructorInsn)3