Search in sources :

Example 6 with CatchAttr

use of jadx.core.dex.trycatch.CatchAttr in project jadx by skylot.

the class BlockExceptionHandler method processExceptionHandlers.

private static void processExceptionHandlers(MethodNode mth, BlockNode block) {
    ExcHandlerAttr handlerAttr = block.get(AType.EXC_HANDLER);
    if (handlerAttr == null) {
        return;
    }
    ExceptionHandler excHandler = handlerAttr.getHandler();
    excHandler.addBlock(block);
    for (BlockNode node : BlockUtils.collectBlocksDominatedBy(block, block)) {
        excHandler.addBlock(node);
    }
    for (BlockNode excBlock : excHandler.getBlocks()) {
        // remove 'monitor-exit' from exception handler blocks
        InstructionRemover remover = new InstructionRemover(mth, excBlock);
        for (InsnNode insn : excBlock.getInstructions()) {
            if (insn.getType() == InsnType.MONITOR_ENTER) {
                break;
            }
            if (insn.getType() == InsnType.MONITOR_EXIT) {
                remover.add(insn);
            }
        }
        remover.perform();
        // if 'throw' in exception handler block have 'catch' - merge these catch blocks
        for (InsnNode insn : excBlock.getInstructions()) {
            CatchAttr catchAttr = insn.get(AType.CATCH_BLOCK);
            if (catchAttr == null) {
                continue;
            }
            if (insn.getType() == InsnType.THROW || onlyAllHandler(catchAttr.getTryBlock())) {
                TryCatchBlock handlerBlock = handlerAttr.getTryBlock();
                TryCatchBlock catchBlock = catchAttr.getTryBlock();
                handlerBlock.merge(mth, catchBlock);
            }
        }
    }
}
Also used : ExceptionHandler(jadx.core.dex.trycatch.ExceptionHandler) BlockNode(jadx.core.dex.nodes.BlockNode) InsnNode(jadx.core.dex.nodes.InsnNode) ExcHandlerAttr(jadx.core.dex.trycatch.ExcHandlerAttr) CatchAttr(jadx.core.dex.trycatch.CatchAttr) TryCatchBlock(jadx.core.dex.trycatch.TryCatchBlock) InstructionRemover(jadx.core.utils.InstructionRemover)

Example 7 with CatchAttr

use of jadx.core.dex.trycatch.CatchAttr in project jadx by skylot.

the class BlockFinallyExtract method markForRemove.

/**
	 * Unbind block for removing.
	 */
private static void markForRemove(MethodNode mth, BlockNode block) {
    for (BlockNode p : block.getPredecessors()) {
        p.getSuccessors().remove(block);
        p.updateCleanSuccessors();
    }
    for (BlockNode s : block.getSuccessors()) {
        s.getPredecessors().remove(block);
    }
    block.getPredecessors().clear();
    block.getSuccessors().clear();
    block.add(AFlag.REMOVE);
    block.remove(AFlag.SKIP);
    CatchAttr catchAttr = block.get(AType.CATCH_BLOCK);
    if (catchAttr != null) {
        catchAttr.getTryBlock().removeBlock(mth, block);
        for (BlockNode skipBlock : mth.getBasicBlocks()) {
            if (skipBlock.contains(AFlag.SKIP)) {
                markForRemove(mth, skipBlock);
            }
        }
    }
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode) CatchAttr(jadx.core.dex.trycatch.CatchAttr)

Aggregations

CatchAttr (jadx.core.dex.trycatch.CatchAttr)7 BlockNode (jadx.core.dex.nodes.BlockNode)5 ExceptionHandler (jadx.core.dex.trycatch.ExceptionHandler)4 TryCatchBlock (jadx.core.dex.trycatch.TryCatchBlock)3 InsnNode (jadx.core.dex.nodes.InsnNode)2 SplitterBlockAttr (jadx.core.dex.trycatch.SplitterBlockAttr)2 IContainer (jadx.core.dex.nodes.IContainer)1 ExcHandlerAttr (jadx.core.dex.trycatch.ExcHandlerAttr)1 InstructionRemover (jadx.core.utils.InstructionRemover)1 CodegenException (jadx.core.utils.exceptions.CodegenException)1 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)1 ArrayList (java.util.ArrayList)1 BitSet (java.util.BitSet)1 HashSet (java.util.HashSet)1