Search in sources :

Example 61 with InsnNode

use of jadx.core.dex.nodes.InsnNode in project jadx by skylot.

the class InstructionRemover method removeAll.

// Don't use 'instrList.removeAll(toRemove)' because it will remove instructions by content
// and here can be several instructions with same content
private static void removeAll(MethodNode mth, List<InsnNode> insns, List<InsnNode> toRemove) {
    for (InsnNode rem : toRemove) {
        unbindInsn(mth, rem);
        int insnsCount = insns.size();
        for (int i = 0; i < insnsCount; i++) {
            if (insns.get(i) == rem) {
                insns.remove(i);
                break;
            }
        }
    }
}
Also used : InsnNode(jadx.core.dex.nodes.InsnNode)

Example 62 with InsnNode

use of jadx.core.dex.nodes.InsnNode in project jadx by skylot.

the class RegionUtils method getLastInsn.

public static InsnNode getLastInsn(IContainer container) {
    if (container instanceof IBlock) {
        IBlock block = (IBlock) container;
        List<InsnNode> insnList = block.getInstructions();
        if (insnList.isEmpty()) {
            return null;
        }
        return insnList.get(insnList.size() - 1);
    } else if (container instanceof IBranchRegion) {
        return null;
    } else if (container instanceof IRegion) {
        IRegion region = (IRegion) container;
        List<IContainer> blocks = region.getSubBlocks();
        if (blocks.isEmpty()) {
            return null;
        }
        return getLastInsn(blocks.get(blocks.size() - 1));
    } else {
        throw new JadxRuntimeException(unknownContainerType(container));
    }
}
Also used : InsnNode(jadx.core.dex.nodes.InsnNode) IBlock(jadx.core.dex.nodes.IBlock) IBranchRegion(jadx.core.dex.nodes.IBranchRegion) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) IContainer(jadx.core.dex.nodes.IContainer) IRegion(jadx.core.dex.nodes.IRegion)

Example 63 with InsnNode

use of jadx.core.dex.nodes.InsnNode 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 64 with InsnNode

use of jadx.core.dex.nodes.InsnNode 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 65 with InsnNode

use of jadx.core.dex.nodes.InsnNode in project jadx by skylot.

the class NameGen method guessName.

private String guessName(RegisterArg arg) {
    SSAVar sVar = arg.getSVar();
    if (sVar != null && sVar.getName() == null) {
        RegisterArg assignArg = sVar.getAssign();
        InsnNode assignInsn = assignArg.getParentInsn();
        if (assignInsn != null) {
            String name = makeNameFromInsn(assignInsn);
            if (name != null && !NameMapper.isReserved(name)) {
                assignArg.setName(name);
                return name;
            }
        }
    }
    return makeNameForType(arg.getType());
}
Also used : InsnNode(jadx.core.dex.nodes.InsnNode) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) SSAVar(jadx.core.dex.instructions.args.SSAVar)

Aggregations

InsnNode (jadx.core.dex.nodes.InsnNode)123 BlockNode (jadx.core.dex.nodes.BlockNode)41 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)39 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)35 InsnArg (jadx.core.dex.instructions.args.InsnArg)32 InsnWrapArg (jadx.core.dex.instructions.args.InsnWrapArg)19 SSAVar (jadx.core.dex.instructions.args.SSAVar)16 ArrayList (java.util.ArrayList)14 ArgType (jadx.core.dex.instructions.args.ArgType)11 PhiInsn (jadx.core.dex.instructions.PhiInsn)10 FieldNode (jadx.core.dex.nodes.FieldNode)10 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)8 LiteralArg (jadx.core.dex.instructions.args.LiteralArg)7 ClassNode (jadx.core.dex.nodes.ClassNode)7 MethodNode (jadx.core.dex.nodes.MethodNode)7 FieldInfo (jadx.core.dex.info.FieldInfo)6 ArithNode (jadx.core.dex.instructions.ArithNode)6 ConstructorInsn (jadx.core.dex.instructions.mods.ConstructorInsn)6 InsnType (jadx.core.dex.instructions.InsnType)5 IContainer (jadx.core.dex.nodes.IContainer)5