Package jadx.core.dex.instructions.args

Examples of jadx.core.dex.instructions.args.InsnArg


   * <b>Caution:</b> this method don't change usage information for replaced argument.
   */
  public boolean replaceArg(InsnArg from, InsnArg to) {
    int count = getArgsCount();
    for (int i = 0; i < count; i++) {
      InsnArg arg = arguments.get(i);
      if (arg == from) {
        setArg(i, to);
        return true;
      }
      if (arg.isInsnWrap() && ((InsnWrapArg) arg).getWrapInsn().replaceArg(from, to)) {
        return true;
      }
    }
    return false;
  }
View Full Code Here


  private static boolean checkInsn(MethodNode mth, InsnNode insn) {
    if (insn.getType() != InsnType.CONST) {
      return false;
    }
    InsnArg arg = insn.getArg(0);
    if (!arg.isLiteral()) {
      return false;
    }
    long lit = ((LiteralArg) arg).getLiteral();

    SSAVar sVar = insn.getResult().getSVar();
    if (lit == 0) {
      if (checkObjectInline(sVar)) {
        if (sVar.getUseCount() == 1) {
          insn.getResult().getAssignInsn().add(AFlag.DONT_INLINE);
        }
        return false;
      }

    }
    ArgType resType = insn.getResult().getType();
    // make sure arg has correct type
    if (!arg.getType().isTypeKnown()) {
      arg.merge(resType);
    }
    return replaceConst(mth, sVar, lit);
  }
View Full Code Here

        IndexInsnNode node = (IndexInsnNode) insn;
        insn.getArg(0).merge(((FieldInfo) node.getIndex()).getType());
        break;

      case IF: {
        InsnArg arg0 = insn.getArg(0);
        InsnArg arg1 = insn.getArg(1);
        if (arg0 == litArg) {
          arg0.merge(arg1);
        } else {
          arg1.merge(arg0);
        }
        break;
      }
      case CMP_G:
      case CMP_L:
        InsnArg arg0 = insn.getArg(0);
        InsnArg arg1 = insn.getArg(1);
        if (arg0 == litArg) {
          arg0.merge(arg1);
        } else {
          arg1.merge(arg0);
        }
        break;

      case RETURN:
        if (insn.getArgsCount() != 0) {
          insn.getArg(0).merge(mth.getReturnType());
        }
        break;

      case INVOKE:
        InvokeNode inv = (InvokeNode) insn;
        List<ArgType> types = inv.getCallMth().getArgumentsTypes();
        int count = insn.getArgsCount();
        int k = types.size() == count ? 0 : -1;
        for (int i = 0; i < count; i++) {
          InsnArg arg = insn.getArg(i);
          if (!arg.getType().isTypeKnown()) {
            ArgType type;
            if (k >= 0) {
              type = types.get(k);
            } else {
              type = mth.getParentClass().getClassInfo().getType();
            }
            arg.merge(type);
          }
          k++;
        }
        break;
View Full Code Here

    }
    ArithNode arithNode = (ArithNode) incrInsn;
    if (arithNode.getOp() != ArithOp.ADD) {
      return null;
    }
    InsnArg lit = incrInsn.getArg(1);
    if (!lit.isLiteral() || ((LiteralArg) lit).getLiteral() != 1) {
      return null;
    }
    if (initInsn.getType() != InsnType.CONST
        || !initInsn.getArg(0).isLiteral()
        || ((LiteralArg) initInsn.getArg(0)).getLiteral() != 0) {
      return null;
    }

    InsnArg condArg = incrInsn.getArg(0);
    if (!condArg.isRegister()) {
      return null;
    }
    SSAVar sVar = ((RegisterArg) condArg).getSVar();
    List<RegisterArg> args = sVar.getUseList();
    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

    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
            toSkip.add(parentInsn);
          }
        }
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) {
View Full Code Here

    }
    return filledArr;
  }

  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;
    }
    FieldNode enumMapField = enumMapInfo.getMapField();
    InsnArg invArg = enumMapInfo.getArg();

    EnumMapAttr.KeyValueMap valueMap = getEnumMap(mth, enumMapField);
    if (valueMap == null) {
      return null;
    }
View Full Code Here

    }
    return mapAttr.getMap(field);
  }

  private static void addToEnumMap(MethodNode mth, EnumMapAttr mapAttr, InsnNode aputInsn) {
    InsnArg litArg = aputInsn.getArg(2);
    if (!litArg.isLiteral()) {
      return;
    }
    EnumMapInfo mapInfo = checkEnumMapAccess(mth, aputInsn);
    if (mapInfo == null) {
      return;
    }
    InsnArg enumArg = mapInfo.getArg();
    FieldNode field = mapInfo.getMapField();
    if (field == null || !enumArg.isInsnWrap()) {
      return;
    }
    InsnNode sget = ((InsnWrapArg) enumArg).getWrapInsn();
    if (!(sget instanceof IndexInsnNode)) {
      return;
View Full Code Here

    int literal = (int) ((LiteralArg) litArg).getLiteral();
    mapAttr.add(field, literal, fieldNode);
  }

  public static EnumMapInfo checkEnumMapAccess(MethodNode mth, InsnNode checkInsn) {
    InsnArg sgetArg = checkInsn.getArg(0);
    InsnArg invArg = checkInsn.getArg(1);
    if (!sgetArg.isInsnWrap() || !invArg.isInsnWrap()) {
      return null;
    }
    InsnNode invInsn = ((InsnWrapArg) invArg).getWrapInsn();
    InsnNode sgetInsn = ((InsnWrapArg) sgetArg).getWrapInsn();
    if (invInsn.getType() != InsnType.INVOKE || sgetInsn.getType() != InsnType.SGET) {
View Full Code Here

  }

  @Test
  public void testNormalize() {
    // 'a != false' => 'a == true'
    InsnArg a = mockArg();
    IfCondition c = makeCondition(IfOp.NE, a, LiteralArg.FALSE);
    IfCondition simp = simplify(c);

    assertEquals(simp.getMode(), Mode.COMPARE);
    Compare compare = simp.getCompare();
View Full Code Here

TOP

Related Classes of jadx.core.dex.instructions.args.InsnArg

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.