Search in sources :

Example 46 with BlockNode

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

the class BlockSplitter method setupConnectionsFromJumps.

private static void setupConnectionsFromJumps(MethodNode mth, Map<Integer, BlockNode> blocksMap) {
    for (BlockNode block : mth.getBasicBlocks()) {
        for (InsnNode insn : block.getInstructions()) {
            List<JumpInfo> jumps = insn.getAll(AType.JUMP);
            for (JumpInfo jump : jumps) {
                BlockNode srcBlock = getBlock(jump.getSrc(), blocksMap);
                BlockNode thisBlock = getBlock(jump.getDest(), blocksMap);
                connect(srcBlock, thisBlock);
            }
        }
    }
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode) TargetInsnNode(jadx.core.dex.instructions.TargetInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode) JumpInfo(jadx.core.dex.attributes.nodes.JumpInfo)

Example 47 with BlockNode

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

the class BlockSplitter method isDoWhile.

private static boolean isDoWhile(Map<Integer, BlockNode> blocksMap, BlockNode curBlock, InsnNode insn) {
    // split 'do-while' block (last instruction: 'if', target this block)
    if (insn.getType() != InsnType.IF) {
        return false;
    }
    IfNode ifs = (IfNode) insn;
    BlockNode targetBlock = blocksMap.get(ifs.getTarget());
    return targetBlock == curBlock;
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode) IfNode(jadx.core.dex.instructions.IfNode)

Example 48 with BlockNode

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

the class BlockSplitter method startNewBlock.

static BlockNode startNewBlock(MethodNode mth, int offset) {
    BlockNode block = new BlockNode(mth.getBasicBlocks().size(), offset);
    mth.getBasicBlocks().add(block);
    return block;
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode)

Example 49 with BlockNode

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

the class BlockSplitter method removeEmptyBlock.

static boolean removeEmptyBlock(BlockNode block) {
    if (canRemoveBlock(block)) {
        if (block.getSuccessors().size() == 1) {
            BlockNode successor = block.getSuccessors().get(0);
            block.getPredecessors().forEach(pred -> {
                pred.getSuccessors().remove(block);
                BlockSplitter.connect(pred, successor);
                BlockSplitter.replaceTarget(pred, block, successor);
                pred.updateCleanSuccessors();
            });
            BlockSplitter.removeConnection(block, successor);
        } else {
            block.getPredecessors().forEach(pred -> {
                pred.getSuccessors().remove(block);
                pred.updateCleanSuccessors();
            });
        }
        block.add(AFlag.REMOVE);
        block.getSuccessors().clear();
        block.getPredecessors().clear();
        return true;
    }
    return false;
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode)

Example 50 with BlockNode

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

the class BlockSplitter method expandMoveMulti.

private static void expandMoveMulti(MethodNode mth) {
    for (BlockNode block : mth.getBasicBlocks()) {
        List<InsnNode> insnsList = block.getInstructions();
        int len = insnsList.size();
        for (int i = 0; i < len; i++) {
            InsnNode insn = insnsList.get(i);
            if (insn.getType() == InsnType.MOVE_MULTI) {
                int mvCount = insn.getArgsCount() / 2;
                for (int j = 0; j < mvCount; j++) {
                    InsnNode mv = new InsnNode(InsnType.MOVE, 1);
                    int startArg = j * 2;
                    mv.setResult((RegisterArg) insn.getArg(startArg));
                    mv.addArg(insn.getArg(startArg + 1));
                    mv.copyAttributesFrom(insn);
                    if (j == 0) {
                        mv.setOffset(insn.getOffset());
                        insnsList.set(i, mv);
                    } else {
                        insnsList.add(i + j, mv);
                    }
                }
                i += mvCount - 1;
                len = insnsList.size();
            }
        }
    }
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode) TargetInsnNode(jadx.core.dex.instructions.TargetInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode)

Aggregations

BlockNode (jadx.core.dex.nodes.BlockNode)220 InsnNode (jadx.core.dex.nodes.InsnNode)91 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)43 ArrayList (java.util.ArrayList)41 BitSet (java.util.BitSet)31 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)29 InsnArg (jadx.core.dex.instructions.args.InsnArg)25 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)21 ExceptionHandler (jadx.core.dex.trycatch.ExceptionHandler)19 PhiInsn (jadx.core.dex.instructions.PhiInsn)14 SSAVar (jadx.core.dex.instructions.args.SSAVar)14 Nullable (org.jetbrains.annotations.Nullable)14 LoopInfo (jadx.core.dex.attributes.nodes.LoopInfo)13 IRegion (jadx.core.dex.nodes.IRegion)13 HashSet (java.util.HashSet)13 MethodNode (jadx.core.dex.nodes.MethodNode)12 Region (jadx.core.dex.regions.Region)12 LoopRegion (jadx.core.dex.regions.loops.LoopRegion)12 InsnType (jadx.core.dex.instructions.InsnType)11 SynchronizedRegion (jadx.core.dex.regions.SynchronizedRegion)11