Package jadx.core.dex.trycatch

Examples of jadx.core.dex.trycatch.ExceptionHandler


  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;
            }
View Full Code Here


  private void makeTryCatch(TryCatchRegion region, CodeWriter code) throws CodegenException {
    TryCatchBlock tryCatchBlock = region.geTryCatchBlock();
    code.startLine("try {");
    makeRegionIndent(code, region.getTryRegion());
    // TODO: move search of 'allHandler' to 'TryCatchRegion'
    ExceptionHandler allHandler = null;
    for (ExceptionHandler handler : tryCatchBlock.getHandlers()) {
      if (!handler.isCatchAll()) {
        makeCatchBlock(code, handler);
      } else {
        if (allHandler != null) {
View Full Code Here

  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

    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();
    resArg = InsnArg.reg(resArg.getRegNum(), type);
    me.setResult(resArg);
    me.add(AFlag.DONT_INLINE);

    excHandler.setArg(resArg);
  }
View Full Code Here

  }

  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;
View Full Code Here

TOP

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

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.