Package jadx.core.dex.trycatch

Examples of jadx.core.dex.trycatch.ExcHandlerAttr


    // attach EXC_HANDLER attributes to instructions
    addrs.clear();
    for (TryCatchBlock ct : catches) {
      for (ExceptionHandler eh : ct.getHandlers()) {
        int addr = eh.getHandleOffset();
        ExcHandlerAttr ehAttr = new ExcHandlerAttr(ct, eh);
        insnByOffset[addr].addAttr(ehAttr);
      }
    }

    // attach TRY_ENTER, TRY_LEAVE attributes to instructions
View Full Code Here


      stack.addExit(exit);
    }

    handler.setHandlerRegion(makeRegion(start, stack));

    ExcHandlerAttr excHandlerAttr = start.get(AType.EXC_HANDLER);
    handler.getHandlerRegion().addAttr(excHandlerAttr);
  }
View Full Code Here

public class TestContinueInLoop2 extends IntegrationTest {

  public static class TestCls {
    private static void test(MethodNode mth, BlockNode block) {
      ExcHandlerAttr handlerAttr = block.get(AType.EXC_HANDLER);
      if (handlerAttr != null) {
        ExceptionHandler excHandler = handlerAttr.getHandler();
        excHandler.addBlock(block);
        for (BlockNode node : BlockUtils.collectBlocksDominatedBy(block, block)) {
          excHandler.addBlock(node);
        }
        for (BlockNode excBlock : excHandler.getBlocks()) {
          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();

          for (InsnNode insn : excBlock.getInstructions()) {
            if (insn.getType() == InsnType.THROW) {
              CatchAttr catchAttr = insn.get(AType.CATCH_BLOCK);
              if (catchAttr != null) {
                TryCatchBlock handlerBlock = handlerAttr.getTryBlock();
                TryCatchBlock catchBlock = catchAttr.getTryBlock();
                if (handlerBlock != catchBlock) {
                  handlerBlock.merge(mth, catchBlock);
                  catchBlock.removeInsn(insn);
                }
View Full Code Here

      remover.perform();
    }
  }

  private static void processExceptionHandler(MethodNode mth, BlockNode block) {
    ExcHandlerAttr handlerAttr = block.get(AType.EXC_HANDLER);
    if (handlerAttr == null) {
      return;
    }
    ExceptionHandler excHandler = handlerAttr.getHandler();
    boolean noExitNode = true; // check if handler has exit edge to block not from this handler
    boolean reThrow = false;
    for (BlockNode excBlock : excHandler.getBlocks()) {
      if (noExitNode) {
        noExitNode = excHandler.getBlocks().containsAll(excBlock.getCleanSuccessors());
      }

      List<InsnNode> insns = excBlock.getInstructions();
      int size = insns.size();
      if (excHandler.isCatchAll()
          && size > 0
          && insns.get(size - 1).getType() == InsnType.THROW) {
        reThrow = true;
        InstructionRemover.remove(mth, excBlock, size - 1);

        // move not removed instructions to 'finally' block
        if (!insns.isEmpty()) {
          // TODO: support instructions from several blocks
          // tryBlock.setFinalBlockFromInsns(mth, insns);
          // TODO: because of incomplete realization don't extract final block,
          // just remove unnecessary instructions
          insns.clear();
        }
      }
    }

    List<InsnNode> blockInsns = block.getInstructions();
    if (!blockInsns.isEmpty()) {
      InsnNode insn = blockInsns.get(0);
      if (insn.getType() == InsnType.MOVE_EXCEPTION) {
        // result arg used both in this insn and exception handler,
        RegisterArg resArg = insn.getResult();
        ArgType type = excHandler.isCatchAll() ? ArgType.THROWABLE : excHandler.getCatchType().getType();
        String name = excHandler.isCatchAll() ? "th" : "e";
        if (resArg.getName() == null) {
          resArg.setName(name);
        }
        SSAVar sVar = insn.getResult().getSVar();
        if (sVar.getUseCount() == 0) {
          excHandler.setArg(new NamedArg(name, type));
          InstructionRemover.remove(mth, block, 0);
        } else if (sVar.isUsedInPhi()) {
          // exception var moved to external variable => replace with 'move' insn
          InsnNode moveInsn = new InsnNode(InsnType.MOVE, 1);
          moveInsn.setResult(insn.getResult());
          NamedArg namedArg = new NamedArg(name, type);
          moveInsn.addArg(namedArg);
          excHandler.setArg(namedArg);
          replaceInsn(block, 0, moveInsn);
        }
      }
    }
    int totalSize = 0;
    for (BlockNode excBlock : excHandler.getBlocks()) {
      totalSize += excBlock.getInstructions().size();
    }
    if (totalSize == 0 && noExitNode && reThrow) {
      handlerAttr.getTryBlock().removeHandler(mth, excHandler);
    }
  }
View Full Code Here

  private static void markExceptionHandlers(BlockNode block) {
    if (block.getInstructions().isEmpty()) {
      return;
    }
    InsnNode me = block.getInstructions().get(0);
    ExcHandlerAttr handlerAttr = me.get(AType.EXC_HANDLER);
    if (handlerAttr == null || me.getType() != InsnType.MOVE_EXCEPTION) {
      return;
    }
    ExceptionHandler excHandler = handlerAttr.getHandler();
    block.addAttr(handlerAttr);
    // set correct type for 'move-exception' operation
    ArgType type = excHandler.isCatchAll() ? ArgType.THROWABLE : excHandler.getCatchType().getType();

    RegisterArg resArg = me.getResult();
View Full Code Here

    excHandler.setArg(resArg);
  }

  private static void processExceptionHandlers(MethodNode mth, BlockNode block) {
    ExcHandlerAttr handlerAttr = block.get(AType.EXC_HANDLER);
    if (handlerAttr != null) {
      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()) {
          if (insn.getType() == InsnType.THROW) {
            CatchAttr catchAttr = insn.get(AType.CATCH_BLOCK);
            if (catchAttr != null) {
              TryCatchBlock handlerBlock = handlerAttr.getTryBlock();
              TryCatchBlock catchBlock = catchAttr.getTryBlock();
              if (handlerBlock != catchBlock) { // TODO: why it can be?
                handlerBlock.merge(mth, catchBlock);
                catchBlock.removeInsn(insn);
              }
View Full Code Here

  }

  private static void connectHandler(MethodNode mth, ExceptionHandler handler) {
    int addr = handler.getHandleOffset();
    for (BlockNode block : mth.getBasicBlocks()) {
      ExcHandlerAttr bh = block.get(AType.EXC_HANDLER);
      if (bh != null && bh.getHandler().getHandleOffset() == addr) {
        handler.setHandlerBlock(block);
        break;
      }
    }
  }
View Full Code Here

TOP

Related Classes of jadx.core.dex.trycatch.ExcHandlerAttr

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.