Package jadx.core.dex.nodes

Examples of jadx.core.dex.nodes.InsnNode


  private void setVar(LocalVar var) {
    int start = var.getStartAddr();
    int end = var.getEndAddr();

    for (int i = start; i <= end; i++) {
      InsnNode insn = insnByOffset[i];
      if (insn != null) {
        fillLocals(insn, var);
      }
    }
    merge(activeRegisters[var.getRegNum()], var);
View Full Code Here


  /**
   * Check for indexed loop.
   */
  private static boolean checkForIndexedLoop(MethodNode mth, LoopRegion loopRegion, IfCondition condition) {
    InsnNode incrInsn = RegionUtils.getLastInsn(loopRegion);
    if (incrInsn == null) {
      return false;
    }
    RegisterArg incrArg = incrInsn.getResult();
    if (incrArg == null
        || incrArg.getSVar() == null
        || !incrArg.getSVar().isUsedInPhi()) {
      return false;
    }
    PhiInsn phiInsn = incrArg.getSVar().getUsedInPhi();
    if (phiInsn == null
        || phiInsn.getArgsCount() != 2
        || !phiInsn.getArg(1).equals(incrArg)
        || incrArg.getSVar().getUseCount() != 1) {
      return false;
    }
    RegisterArg arg = phiInsn.getResult();
    List<RegisterArg> condArgs = condition.getRegisterArgs();
    if (!condArgs.contains(arg) || arg.getSVar().isUsedInPhi()) {
      return false;
    }
    RegisterArg initArg = phiInsn.getArg(0);
    InsnNode initInsn = initArg.getAssignInsn();
    if (initInsn == null || initArg.getSVar().getUseCount() != 1) {
      return false;
    }
    if (!usedOnlyInLoop(mth, loopRegion, arg)) {
      return false;
    }
    // can't make loop if argument from increment instruction is assign in loop
    List<RegisterArg> args = new LinkedList<RegisterArg>();
    incrInsn.getRegisterArgs(args);
    for (RegisterArg iArg : args) {
      if (assignOnlyInLoop(mth, loopRegion, iArg)) {
        return false;
      }
    }

    // all checks passed
    initInsn.add(AFlag.SKIP);
    incrInsn.add(AFlag.SKIP);
    LoopType arrForEach = checkArrayForEach(mth, initInsn, incrInsn, condition);
    if (arrForEach != null) {
      loopRegion.setType(arrForEach);
      return true;
View Full Code Here

    if (args.size() != 3 || args.get(2) != condArg) {
      return null;
    }
    condArg = args.get(0);
    RegisterArg arrIndex = args.get(1);
    InsnNode arrGetInsn = arrIndex.getParentInsn();
    if (arrGetInsn == null || arrGetInsn.getType() != InsnType.AGET) {
      return null;
    }
    if (!condition.isCompare()) {
      return null;
    }
    Compare compare = condition.getCompare();
    if (compare.getOp() != IfOp.LT || compare.getA() != condArg) {
      return null;
    }
    InsnNode len;
    InsnArg bCondArg = compare.getB();
    if (bCondArg.isInsnWrap()) {
      len = ((InsnWrapArg) bCondArg).getWrapInsn();
    } else if (bCondArg.isRegister()) {
      len = ((RegisterArg) bCondArg).getAssignInsn();
    } else {
      return null;
    }
    if (len == null || len.getType() != InsnType.ARRAY_LENGTH) {
      return null;
    }
    InsnArg arrayArg = len.getArg(0);
    if (!arrayArg.equals(arrGetInsn.getArg(0))) {
      return null;
    }
    RegisterArg iterVar = arrGetInsn.getResult();
    if (iterVar == null) {
      return null;
    }

    // array for each loop confirmed
    len.add(AFlag.SKIP);
    arrGetInsn.add(AFlag.SKIP);
    InstructionRemover.unbindInsn(mth, len);

    // inline array variable
    CodeShrinker.shrinkMethod(mth);
    if (arrGetInsn.contains(AFlag.WRAPPED)) {
      InsnArg wrapArg = BlockUtils.searchWrappedInsnParent(mth, arrGetInsn);
      if (wrapArg != null) {
        wrapArg.getParentInsn().replaceArg(wrapArg, iterVar);
      } else {
        LOG.debug(" checkArrayForEach: Wrapped insn not found: {}, mth: {}", arrGetInsn, mth);
      }
    }
    return new ForEachLoop(iterVar, len.getArg(0));
  }
View Full Code Here

    for (BlockNode block : mth.getBasicBlocks()) {
      remover.setBlock(block);
      List<InsnNode> instructions = block.getInstructions();
      int size = instructions.size();
      for (int i = 0; i < size; i++) {
        InsnNode replacedInsn = process(mth, instructions, i, remover);
        if (replacedInsn != null) {
          instructions.set(i, replacedInsn);
        }
      }
      remover.perform();
View Full Code Here

    SSAVar sVar = iteratorArg.getSVar();
    if (sVar == null || sVar.isUsedInPhi()) {
      return false;
    }
    List<RegisterArg> useList = sVar.getUseList();
    InsnNode assignInsn = iteratorArg.getAssignInsn();
    if (useList.size() != 2
        || assignInsn == null
        || !checkInvoke(assignInsn, null, "iterator()Ljava/util/Iterator;", 0)) {
      return false;
    }
    InsnArg iterableArg = assignInsn.getArg(0);
    InsnNode hasNextCall = useList.get(0).getParentInsn();
    InsnNode nextCall = useList.get(1).getParentInsn();
    if (!checkInvoke(hasNextCall, "java.util.Iterator", "hasNext()Z", 0)
        || !checkInvoke(nextCall, "java.util.Iterator", "next()Ljava/lang/Object;", 0)) {
      return false;
    }
    List<InsnNode> toSkip = new LinkedList<InsnNode>();
    RegisterArg iterVar = nextCall.getResult();
    if (nextCall.contains(AFlag.WRAPPED)) {
      InsnArg wrapArg = BlockUtils.searchWrappedInsnParent(mth, nextCall);
      if (wrapArg != null) {
        InsnNode parentInsn = wrapArg.getParentInsn();
        if (parentInsn.getType() != InsnType.CHECK_CAST) {
          parentInsn.replaceArg(wrapArg, iterVar);
        } else {
          iterVar = parentInsn.getResult();
          InsnArg castArg = BlockUtils.searchWrappedInsnParent(mth, parentInsn);
          if (castArg != null) {
            castArg.getParentInsn().replaceArg(castArg, iterVar);
          } else {
            // cast not inlined
View Full Code Here

      remover.perform();
    }
  }

  private static InsnNode process(MethodNode mth, List<InsnNode> instructions, int i, InstructionRemover remover) {
    InsnNode insn = instructions.get(i);
    switch (insn.getType()) {
      case NEW_ARRAY:
        return processNewArray(mth, instructions, i, remover);

      case SWITCH:
        return processEnumSwitch(mth, (SwitchNode) insn);
View Full Code Here

  /**
   * Replace new array and sequence of array-put to new filled-array instruction.
   */
  private static InsnNode processNewArray(MethodNode mth, List<InsnNode> instructions, int i, InstructionRemover remover) {
    InsnNode insn = instructions.get(i);
    InsnArg arg = insn.getArg(0);
    if (!arg.isLiteral()) {
      return null;
    }
    int len = (int) ((LiteralArg) arg).getLiteral();
    int size = instructions.size();
    if (len <= 0 || i + len >= size || instructions.get(i + len).getType() != InsnType.APUT) {
      return null;
    }
    InsnNode filledArr = new InsnNode(InsnType.FILLED_NEW_ARRAY, len);
    filledArr.setResult(insn.getResult());
    for (int j = 0; j < len; j++) {
      InsnNode put = instructions.get(i + 1 + j);
      if (put.getType() != InsnType.APUT) {
        LOG.debug("Not a APUT in expected new filled array: {}, method: {}", put, mth);
        return null;
      }
      filledArr.addArg(put.getArg(2));
      remover.add(put);
    }
    return filledArr;
  }
View Full Code Here

    }
    return false;
  }

  private static boolean assignOnlyInLoop(MethodNode mth, LoopRegion loopRegion, RegisterArg arg) {
    InsnNode assignInsn = arg.getAssignInsn();
    if (assignInsn == null) {
      return true;
    }
    if (!argInLoop(mth, loopRegion, assignInsn.getResult())) {
      return false;
    }
    if (assignInsn instanceof PhiInsn) {
      PhiInsn phiInsn = (PhiInsn) assignInsn;
      for (InsnArg phiArg : phiInsn.getArguments()) {
View Full Code Here

    }
    return true;
  }

  private static boolean argInLoop(MethodNode mth, LoopRegion loopRegion, RegisterArg arg) {
    InsnNode parentInsn = arg.getParentInsn();
    if (parentInsn == null) {
      return false;
    }
    BlockNode block = BlockUtils.getBlockByInsn(mth, parentInsn);
    if (block == null) {
View Full Code Here

  private static InsnNode processEnumSwitch(MethodNode mth, SwitchNode insn) {
    InsnArg arg = insn.getArg(0);
    if (!arg.isInsnWrap()) {
      return null;
    }
    InsnNode wrapInsn = ((InsnWrapArg) arg).getWrapInsn();
    if (wrapInsn.getType() != InsnType.AGET) {
      return null;
    }
    EnumMapInfo enumMapInfo = checkEnumMapAccess(mth, wrapInsn);
    if (enumMapInfo == null) {
      return null;
View Full Code Here

TOP

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

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.