Examples of IfInfo


Examples of jadx.core.dex.regions.conditions.IfInfo

  }

  static IfInfo makeIfInfo(BlockNode ifBlock) {
    IfNode ifNode = (IfNode) ifBlock.getInstructions().get(0);
    IfCondition condition = IfCondition.fromIfNode(ifNode);
    IfInfo info = new IfInfo(condition, ifNode.getThenBlock(), ifNode.getElseBlock());
    info.setIfBlock(ifBlock);
    info.getMergedBlocks().add(ifBlock);
    return info;
  }
View Full Code Here

Examples of jadx.core.dex.regions.conditions.IfInfo

    info.getMergedBlocks().add(ifBlock);
    return info;
  }

  static IfInfo searchNestedIf(IfInfo info) {
    IfInfo tmp = mergeNestedIfNodes(info);
    return tmp != null ? tmp : info;
  }
View Full Code Here

Examples of jadx.core.dex.regions.conditions.IfInfo

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

Examples of jadx.core.dex.regions.conditions.IfInfo

    BlockNode curElse = currentIf.getElseBlock();
    if (curThen == curElse) {
      return null;
    }
    boolean followThenBranch;
    IfInfo nextIf = getNextIf(currentIf, curThen);
    if (nextIf != null) {
      followThenBranch = true;
    } else {
      nextIf = getNextIf(currentIf, curElse);
      if (nextIf != null) {
        followThenBranch = false;
      } else {
        return null;
      }
    }
    if (isInversionNeeded(currentIf, nextIf)) {
      // invert current node for match pattern
      nextIf = IfInfo.invert(nextIf);
    }
    if (!RegionMaker.isEqualPaths(curElse, nextIf.getElseBlock())
        && !RegionMaker.isEqualPaths(curThen, nextIf.getThenBlock())) {
      // complex condition, run additional checks
      if (checkConditionBranches(curThen, curElse)
          || checkConditionBranches(curElse, curThen)) {
        return null;
      }
      BlockNode otherBranchBlock = followThenBranch ? curElse : curThen;
      if (!isPathExists(nextIf.getIfBlock(), otherBranchBlock)) {
        return checkForTernaryInCondition(currentIf);
      }
      if (isPathExists(nextIf.getThenBlock(), otherBranchBlock)
          && isPathExists(nextIf.getElseBlock(), otherBranchBlock)) {
        // both branches paths points to one block
        return null;
      }

      // this is nested conditions with different mode (i.e (a && b) || c),
      // search next condition for merge, get null if failed
      IfInfo tmpIf = mergeNestedIfNodes(nextIf);
      if (tmpIf != null) {
        nextIf = tmpIf;
        if (isInversionNeeded(currentIf, nextIf)) {
          nextIf = IfInfo.invert(nextIf);
        }
      } else {
        return currentIf;
      }
    }

    IfInfo result = mergeIfInfo(currentIf, nextIf, followThenBranch);
    // search next nested if block
    return searchNestedIf(result);
  }
View Full Code Here

Examples of jadx.core.dex.regions.conditions.IfInfo

    // search next nested if block
    return searchNestedIf(result);
  }

  private static IfInfo checkForTernaryInCondition(IfInfo currentIf) {
    IfInfo nextThen = getNextIf(currentIf, currentIf.getThenBlock());
    IfInfo nextElse = getNextIf(currentIf, currentIf.getElseBlock());
    if (nextThen == null || nextElse == null) {
      return null;
    }
    if (!nextThen.getIfBlock().getDomFrontier().equals(nextElse.getIfBlock().getDomFrontier())) {
      return null;
    }
    nextThen = searchNestedIf(nextThen);
    nextElse = searchNestedIf(nextElse);
    if (nextThen.getThenBlock() == nextElse.getThenBlock()
        && nextThen.getElseBlock() == nextElse.getElseBlock()) {
      return mergeTernaryConditions(currentIf, nextThen, nextElse);
    }
    if (nextThen.getThenBlock() == nextElse.getElseBlock()
        && nextThen.getElseBlock() == nextElse.getThenBlock()) {
      nextElse = IfInfo.invert(nextElse);
      return mergeTernaryConditions(currentIf, nextThen, nextElse);
    }
    return null;
  }
View Full Code Here

Examples of jadx.core.dex.regions.conditions.IfInfo

  }

  private static IfInfo mergeTernaryConditions(IfInfo currentIf, IfInfo nextThen, IfInfo nextElse) {
    IfCondition newCondition = IfCondition.ternary(currentIf.getCondition(),
        nextThen.getCondition(), nextElse.getCondition());
    IfInfo result = new IfInfo(newCondition, nextThen.getThenBlock(), nextThen.getElseBlock());
    result.setIfBlock(currentIf.getIfBlock());
    result.merge(currentIf, nextThen, nextElse);
    confirmMerge(result);
    return result;
  }
View Full Code Here

Examples of jadx.core.dex.regions.conditions.IfInfo

  private static IfInfo mergeIfInfo(IfInfo first, IfInfo second, boolean followThenBranch) {
    Mode mergeOperation = followThenBranch ? Mode.AND : Mode.OR;

    IfCondition condition = IfCondition.merge(mergeOperation, first.getCondition(), second.getCondition());
    IfInfo result = new IfInfo(condition, second);
    result.setIfBlock(first.getIfBlock());
    result.merge(first, second);

    BlockNode otherPathBlock = followThenBranch ? first.getElseBlock() : first.getThenBlock();
    skipSimplePath(otherPathBlock, result.getSkipBlocks());
    return result;
  }
View Full Code Here

Examples of jadx.core.dex.regions.conditions.IfInfo

    }
    curRegion.getSubBlocks().add(loopRegion);
    IRegion outerRegion = stack.peekRegion();
    stack.push(loopRegion);

    IfInfo condInfo = makeIfInfo(loopRegion.getHeader());
    condInfo = searchNestedIf(condInfo);
    confirmMerge(condInfo);
    if (!loop.getLoopBlocks().contains(condInfo.getThenBlock())) {
      // invert loop condition if 'then' points to exit
      condInfo = IfInfo.invert(condInfo);
    }
    loopRegion.setCondition(condInfo.getCondition());
    exitBlocks.removeAll(condInfo.getMergedBlocks());

    if (!exitBlocks.isEmpty()) {
      BlockNode loopExit = condInfo.getElseBlock();
      if (loopExit != null) {
        // add 'break' instruction before path cross between main loop exit and sub-exit
        for (Edge exitEdge : loop.getExitEdges()) {
          if (!exitBlocks.contains(exitEdge.getSource())) {
            continue;
          }
          insertBreak(stack, loopExit, exitEdge);
        }
      }
    }

    BlockNode out;
    if (loopRegion.isConditionAtEnd()) {
      BlockNode thenBlock = condInfo.getThenBlock();
      out = (thenBlock == loopStart ? condInfo.getElseBlock() : thenBlock);
      loopStart.remove(AType.LOOP);
      loop.getEnd().add(AFlag.SKIP);
      stack.addExit(loop.getEnd());
      loopRegion.setBody(makeRegion(loopStart, stack));
      loopStart.addAttr(AType.LOOP, loop);
      loop.getEnd().remove(AFlag.SKIP);
    } else {
      out = condInfo.getElseBlock();
      if (outerRegion != null
          && out.contains(AFlag.LOOP_START)
          && !out.getAll(AType.LOOP).contains(loop)
          && RegionUtils.isRegionContainsBlock(outerRegion, out)) {
        // exit to already processed outer loop
        out = null;
      }
      stack.addExit(out);
      BlockNode loopBody = condInfo.getThenBlock();
      Region body = makeRegion(loopBody, stack);
      // add blocks from loop start to first condition block
      BlockNode conditionBlock = condInfo.getIfBlock();
      if (loopStart != conditionBlock) {
        Set<BlockNode> blocks = BlockUtils.getAllPathsBlocks(loopStart, conditionBlock);
        blocks.remove(conditionBlock);
        for (BlockNode block : blocks) {
          if (block.getInstructions().isEmpty()
View Full Code Here

Examples of jadx.core.dex.regions.conditions.IfInfo

    if (block.contains(AFlag.SKIP)) {
      // block already included in other 'if' region
      return ifnode.getThenBlock();
    }

    IfInfo currentIf = makeIfInfo(block);
    IfInfo mergedIf = mergeNestedIfNodes(currentIf);
    if (mergedIf != null) {
      currentIf = mergedIf;
    } else {
      // invert simple condition (compiler often do it)
      currentIf = IfInfo.invert(currentIf);
    }
    IfInfo modifiedIf = IfMakerHelper.restructureIf(mth, block, currentIf);
    if (modifiedIf != null) {
      currentIf = modifiedIf;
    } else {
      if (currentIf.getMergedBlocks().size() <= 1) {
        return null;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.