Package jadx.core.dex.nodes

Examples of jadx.core.dex.nodes.BlockNode


    boolean changed;
    int k = 0;
    do {
      changed = false;
      for (int i = 0; i < blocksSize; i++) {
        BlockNode block = blocks.get(i);
        int blockId = block.getId();
        BitSet prevIn = liveIn[blockId];
        BitSet newIn = new BitSet(regsCount);
        List<BlockNode> successors = block.getSuccessors();
        for (int s = 0, successorsSize = successors.size(); s < successorsSize; s++) {
          newIn.or(liveIn[successors.get(s).getId()]);
        }
        newIn.andNot(defs[blockId]);
        newIn.or(uses[blockId]);
View Full Code Here


          if (wrapInfo != null) {
            wrapList.add(wrapInfo);
          }
        } else {
          // another block
          BlockNode assignBlock = BlockUtils.getBlockByInsn(mth, assignInsn);
          if (assignBlock != null
              && assignInsn != arg.getParentInsn()
              && canMoveBetweenBlocks(assignInsn, assignBlock, block, argsInfo.getInsn())) {
            arg.wrapInstruction(assignInsn);
            InsnList.remove(assignBlock, assignInsn);
View Full Code Here

    for (int id = assignBlocks.nextSetBit(0); id >= 0; id = assignBlocks.nextSetBit(id + 1)) {
      processed.set(id);
      workList.add(blocks.get(id));
    }
    while (!workList.isEmpty()) {
      BlockNode block = workList.pop();
      BitSet domFrontier = block.getDomFrontier();
      for (int id = domFrontier.nextSetBit(0); id >= 0; id = domFrontier.nextSetBit(id + 1)) {
        if (!hasPhi.get(id) && la.isLive(id, regNum)) {
          BlockNode df = blocks.get(id);
          addPhi(df, regNum);
          hasPhi.set(id);
          if (!processed.get(id)) {
            processed.set(id);
            workList.add(df);
View Full Code Here

    }
    return splitReturn(mth);
  }

  private static BlockNode insertBlockBetween(MethodNode mth, BlockNode source, BlockNode target) {
    BlockNode newBlock = startNewBlock(mth, target.getStartOffset());
    newBlock.add(AFlag.SYNTHETIC);
    removeConnection(source, target);
    connect(source, newBlock);
    connect(newBlock, target);
    return newBlock;
  }
View Full Code Here

   */
  private static boolean splitReturn(MethodNode mth) {
    if (mth.getExitBlocks().size() != 1) {
      return false;
    }
    BlockNode exitBlock = mth.getExitBlocks().get(0);
    if (exitBlock.getPredecessors().size() > 1
        && exitBlock.getInstructions().size() == 1
        && !exitBlock.contains(AFlag.SYNTHETIC)) {
      InsnNode returnInsn = exitBlock.getInstructions().get(0);
      List<BlockNode> preds = new ArrayList<BlockNode>(exitBlock.getPredecessors());
      if (returnInsn.getArgsCount() != 0 && !isReturnArgAssignInPred(preds, returnInsn)) {
        return false;
      }
      boolean first = true;
      for (BlockNode pred : preds) {
        BlockNode newRetBlock = startNewBlock(mth, exitBlock.getStartOffset());
        newRetBlock.add(AFlag.SYNTHETIC);
        InsnNode newRetInsn;
        if (first) {
          newRetInsn = returnInsn;
          first = false;
        } else {
          newRetInsn = duplicateReturnInsn(returnInsn);
        }
        newRetBlock.getInstructions().add(newRetInsn);
        removeConnection(pred, exitBlock);
        connect(pred, newRetBlock);
      }
      cleanExitNodes(mth);
      return true;
View Full Code Here

    return false;
  }

  private static void cleanExitNodes(MethodNode mth) {
    for (Iterator<BlockNode> iterator = mth.getExitBlocks().iterator(); iterator.hasNext(); ) {
      BlockNode exitBlock = iterator.next();
      if (exitBlock.getPredecessors().isEmpty()) {
        mth.getBasicBlocks().remove(exitBlock);
        iterator.remove();
      }
    }
  }
View Full Code Here

        }

        for (Iterator<IContainer> it = region.getSubBlocks().iterator(); it.hasNext(); ) {
          IContainer container = it.next();
          if (container instanceof BlockNode) {
            BlockNode block = (BlockNode) container;
            if (block.getInstructions().isEmpty()) {
              try {
                it.remove();
              } catch (UnsupportedOperationException e) {
                LOG.warn("Can't remove block: {} from: {}, mth: {}", block, region, mth);
              }
View Full Code Here

      return false;
    }
    attr.setStaticMethod(staticMethod);

    // move enum specific instruction from static method to separate list
    BlockNode staticBlock = staticMethod.getBasicBlocks().get(0);
    List<InsnNode> insns = new ArrayList<InsnNode>();
    List<InsnNode> list = staticBlock.getInstructions();
    int size = list.size();
    for (int i = 0; i < size; i++) {
      InsnNode insn = list.get(i);
      insns.add(insn);
      if (insn.getType() == InsnType.SPUT) {
View Full Code Here

    IfInfo tmp = mergeNestedIfNodes(info);
    return tmp != null ? tmp : info;
  }

  static IfInfo restructureIf(MethodNode mth, BlockNode block, IfInfo info) {
    final BlockNode thenBlock = info.getThenBlock();
    final BlockNode elseBlock = info.getElseBlock();

    // select 'then', 'else' and 'exit' blocks
    if (thenBlock.contains(AFlag.RETURN) && elseBlock.contains(AFlag.RETURN)) {
      info.setOutBlock(null);
      return info;
    }
    boolean badThen = isBadBranchBlock(info, thenBlock);
    boolean badElse = isBadBranchBlock(info, elseBlock);
    if (badThen && badElse) {
      LOG.debug("Stop processing blocks after 'if': {}, method: {}", info.getIfBlock(), mth);
      return null;
    }
    if (badElse) {
      info = new IfInfo(info, thenBlock, null);
      info.setOutBlock(elseBlock);
    } else if (badThen) {
      info = IfInfo.invert(info);
      info = new IfInfo(info, elseBlock, null);
      info.setOutBlock(thenBlock);
    } else {
      List<BlockNode> thenSC = thenBlock.getCleanSuccessors();
      List<BlockNode> elseSC = elseBlock.getCleanSuccessors();
      if (thenSC.size() == 1 && sameElements(thenSC, elseSC)) {
        info.setOutBlock(thenSC.get(0));
      } else if (info.getMergedBlocks().size() == 1
          && block.getDominatesOn().size() == 2) {
        info.setOutBlock(BlockUtils.getPathCross(mth, thenBlock, elseBlock));
View Full Code Here

  }

  private static boolean isBadBranchBlock(IfInfo info, BlockNode block) {
    // check if block at end of loop edge
    if (block.contains(AFlag.LOOP_START) && block.getPredecessors().size() == 1) {
      BlockNode pred = block.getPredecessors().get(0);
      if (pred.contains(AFlag.LOOP_END)) {
        List<LoopInfo> startLoops = block.getAll(AType.LOOP);
        List<LoopInfo> endLoops = pred.getAll(AType.LOOP);
        // search for same loop
        for (LoopInfo startLoop : startLoops) {
          for (LoopInfo endLoop : endLoops) {
            if (startLoop == endLoop) {
              return true;
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.