Package jadx.core.dex.nodes

Examples of jadx.core.dex.nodes.BlockNode


    for (InsnNode exitInsn : synchRegion.getExitInsns()) {
      InstructionRemover.unbindInsn(mth, exitInsn);
    }

    BlockNode body = getNextBlock(block);
    if (body == null) {
      ErrorsCounter.methodError(mth, "Unexpected end of synchronized block");
      return null;
    }
    BlockNode exit;
    if (exits.size() == 1) {
      exit = getNextBlock(exits.iterator().next());
    } else {
      cacheSet.clear();
      exit = traverseMonitorExitsCross(body, exits, cacheSet);
View Full Code Here


      }
      if (cross) {
        return node;
      }
      if (!visited.contains(node)) {
        BlockNode res = traverseMonitorExitsCross(node, exits, visited);
        if (res != null) {
          return res;
        }
      }
    }
View Full Code Here

    stack.push(ifRegion);
    stack.addExit(currentIf.getOutBlock());

    ifRegion.setThenRegion(makeRegion(currentIf.getThenBlock(), stack));
    BlockNode elseBlock = currentIf.getElseBlock();
    if (elseBlock == null || stack.containsExit(elseBlock)) {
      ifRegion.setElseRegion(null);
    } else {
      ifRegion.setElseRegion(makeRegion(elseBlock, stack));
    }
View Full Code Here

      keys.add(key);
    }

    Map<BlockNode, List<Object>> blocksMap = new LinkedHashMap<BlockNode, List<Object>>(len);
    for (Map.Entry<Integer, List<Object>> entry : casesMap.entrySet()) {
      BlockNode c = getBlockByOffset(entry.getKey(), block.getSuccessors());
      assert c != null;
      blocksMap.put(c, entry.getValue());
    }

    BitSet succ = BlockUtils.blocksToBitSet(mth, block.getSuccessors());
    BitSet domsOn = BlockUtils.blocksToBitSet(mth, block.getDominatesOn());
    domsOn.xor(succ); // filter 'out' block

    BlockNode defCase = getBlockByOffset(insn.getDefaultCaseOffset(), block.getSuccessors());
    if (defCase != null) {
      blocksMap.remove(defCase);
    }

    int outCount = domsOn.cardinality();
    if (outCount > 1) {
      // remove exception handlers
      BlockUtils.cleanBitSet(mth, domsOn);
      outCount = domsOn.cardinality();
    }
    if (outCount > 1) {
      // filter successors of other blocks
      List<BlockNode> blocks = mth.getBasicBlocks();
      for (int i = domsOn.nextSetBit(0); i >= 0; i = domsOn.nextSetBit(i + 1)) {
        BlockNode b = blocks.get(i);
        for (BlockNode s : b.getCleanSuccessors()) {
          domsOn.clear(s.getId());
        }
      }
      outCount = domsOn.cardinality();
    }

    BlockNode out = null;
    if (outCount == 1) {
      out = mth.getBasicBlocks().get(domsOn.nextSetBit(0));
    } else if (outCount == 0) {
      // one or several case blocks are empty,
      // run expensive algorithm for find 'out' block
      for (BlockNode maybeOut : block.getSuccessors()) {
        boolean allReached = true;
        for (BlockNode s : block.getSuccessors()) {
          if (!isPathExists(s, maybeOut)) {
            allReached = false;
            break;
          }
        }
        if (allReached) {
          out = maybeOut;
          break;
        }
      }
    }

    stack.push(sw);
    if (out != null) {
      stack.addExit(out);
    }

    if (!stack.containsExit(defCase)) {
      sw.setDefaultCase(makeRegion(defCase, stack));
    }
    for (Entry<BlockNode, List<Object>> entry : blocksMap.entrySet()) {
      BlockNode c = entry.getKey();
      if (stack.containsExit(c)) {
        // empty case block
        sw.addCase(entry.getValue(), new Region(stack.peekRegion()));
      } else {
        sw.addCase(entry.getValue(), makeRegion(c, stack));
View Full Code Here

    }
    for (TryCatchBlock tc : tcs) {
      List<BlockNode> blocks = new ArrayList<BlockNode>(tc.getHandlersCount());
      Set<BlockNode> splitters = new HashSet<BlockNode>();
      for (ExceptionHandler handler : tc.getHandlers()) {
        BlockNode handlerBlock = handler.getHandlerBlock();
        if (handlerBlock != null) {
          blocks.add(handlerBlock);
          splitters.addAll(handlerBlock.getPredecessors());
        } else {
          LOG.debug(ErrorsCounter.formatErrorMsg(mth, "No exception handler block: " + handler));
        }
      }
      Set<BlockNode> exits = new HashSet<BlockNode>();
      for (BlockNode splitter : splitters) {
        for (BlockNode handler : blocks) {
          List<BlockNode> s = splitter.getSuccessors();
          if (s.isEmpty()) {
            LOG.debug(ErrorsCounter.formatErrorMsg(mth, "No successors for splitter: " + splitter));
            continue;
          }
          BlockNode ss = s.get(0);
          BlockNode cross = BlockUtils.getPathCross(mth, ss, handler);
          if (cross != null && cross != ss && cross != handler) {
            exits.add(cross);
          }
        }
      }
View Full Code Here

      }
    }
  }

  private void processExcHandler(ExceptionHandler handler, Set<BlockNode> exits) {
    BlockNode start = handler.getHandlerBlock();
    if (start == null) {
      return;
    }

    // TODO extract finally part which exists in all handlers from same try block
    // TODO add blocks common for several handlers to some region

    RegionStack stack = new RegionStack(mth);
    stack.addExits(exits);

    BlockNode exit = BlockUtils.traverseWhileDominates(start, start);
    if (exit != null && RegionUtils.isRegionContainsBlock(mth.getRegion(), exit)) {
      stack.addExit(exit);
    }

    handler.setHandlerRegion(makeRegion(start, stack));
View Full Code Here

  private static boolean isSyntheticPath(BlockNode b1, BlockNode b2) {
    if (!b1.isSynthetic() || !b2.isSynthetic()) {
      return false;
    }
    BlockNode n1 = getNextBlock(b1);
    BlockNode n2 = getNextBlock(b2);
    return isEqualPaths(n1, n2);
  }
View Full Code Here

      if (insns.length() != 0) {
        dot.add('|').add(insns);
      }
      dot.add("}\"];");

      BlockNode falsePath = null;
      List<InsnNode> list = block.getInstructions();
      if (!list.isEmpty() && list.get(0).getType() == InsnType.IF) {
        falsePath = ((IfNode) list.get(0)).getElseBlock();
      }
      for (BlockNode next : block.getSuccessors()) {
View Full Code Here

  public void visit(MethodNode mth) throws JadxException {
    AccessInfo accessFlags = mth.getAccessFlags();
    if (accessFlags.isSynthetic()
        && accessFlags.isStatic()
        && mth.getBasicBlocks().size() == 2) {
      BlockNode block = mth.getBasicBlocks().get(1);
      if (block.getInstructions().isEmpty()
          || block.contains(AFlag.RETURN)) {
        inlineMth(mth);
      }
    }
  }
View Full Code Here

      }
    }
  }

  private static void inlineMth(MethodNode mth) {
    BlockNode firstBlock = mth.getBasicBlocks().get(0);
    if (firstBlock.getInstructions().isEmpty()) {
      // synthetic field getter
      BlockNode block = mth.getBasicBlocks().get(1);
      InsnNode insn = block.getInstructions().get(0);
      // set arg from 'return' instruction
      addInlineAttr(mth, InsnNode.wrapArg(insn.getArg(0)));
    } else {
      // synthetic field setter or method invoke
      if (firstBlock.getInstructions().size() == 1) {
View Full Code Here

TOP

Related Classes of jadx.core.dex.nodes.BlockNode

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.