Search in sources :

Example 1 with InstructionRemover

use of jadx.core.utils.InstructionRemover in project jadx by skylot.

the class ReSugarCode method visit.

@Override
public void visit(MethodNode mth) throws JadxException {
    if (mth.isNoCode()) {
        return;
    }
    InstructionRemover remover = new InstructionRemover(mth);
    for (BlockNode block : mth.getBasicBlocks()) {
        remover.setBlock(block);
        List<InsnNode> instructions = block.getInstructions();
        int size = instructions.size();
        for (int i = 0; i < size; i++) {
            InsnNode replacedInsn = process(mth, instructions, i, remover);
            if (replacedInsn != null) {
                instructions.set(i, replacedInsn);
            }
        }
        remover.perform();
    }
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode) IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode) InstructionRemover(jadx.core.utils.InstructionRemover)

Example 2 with InstructionRemover

use of jadx.core.utils.InstructionRemover in project jadx by skylot.

the class ModVisitor method visit.

@Override
public void visit(MethodNode mth) {
    if (mth.isNoCode()) {
        return;
    }
    InstructionRemover remover = new InstructionRemover(mth);
    replaceStep(mth, remover);
    removeStep(mth, remover);
    checkArgsNames(mth);
}
Also used : InstructionRemover(jadx.core.utils.InstructionRemover)

Example 3 with InstructionRemover

use of jadx.core.utils.InstructionRemover 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)

Aggregations

InstructionRemover (jadx.core.utils.InstructionRemover)3 BlockNode (jadx.core.dex.nodes.BlockNode)2 InsnNode (jadx.core.dex.nodes.InsnNode)2 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)1 CatchAttr (jadx.core.dex.trycatch.CatchAttr)1 ExcHandlerAttr (jadx.core.dex.trycatch.ExcHandlerAttr)1 ExceptionHandler (jadx.core.dex.trycatch.ExceptionHandler)1 TryCatchBlock (jadx.core.dex.trycatch.TryCatchBlock)1