Package jadx.core.dex.nodes

Examples of jadx.core.dex.nodes.InsnNode


    BlockNode block = mth.getBasicBlocks().get(0);
    List<InsnNode> instructions = block.getInstructions();
    if (instructions.isEmpty()) {
      return false;
    }
    InsnNode insn = instructions.get(0);
    if (insn.getType() != InsnType.IPUT) {
      return false;
    }
    IndexInsnNode putInsn = (IndexInsnNode) insn;
    FieldInfo fieldInfo = (FieldInfo) putInsn.getIndex();
    if (!fieldInfo.equals(field.getFieldInfo()) || !putInsn.getArg(0).equals(arg)) {
      return false;
    }
    mth.removeFirstArgument();
    InstructionRemover.remove(mth, block, insn);
    // other arg usage -> wrap with IGET insn
    if (arg.getSVar().getUseCount() != 0) {
      InsnNode iget = new IndexInsnNode(InsnType.IGET, fieldInfo, 1);
      iget.addArg(insn.getArg(1));
      for (InsnArg insnArg : arg.getSVar().getUseList()) {
        insnArg.wrapInstruction(iget);
      }
    }
    return true;
View Full Code Here


    BlockNode eb = getTernaryInsnBlock(elseRegion);
    if (tb == null || eb == null) {
      return false;
    }
    BlockNode header = ifRegion.getHeader();
    InsnNode t = tb.getInstructions().get(0);
    InsnNode e = eb.getInstructions().get(0);

    if (t.getSourceLine() != e.getSourceLine()) {
      if (t.getSourceLine() != 0 && e.getSourceLine() != 0) {
        // sometimes source lines incorrect
        if (!checkLineStats(t, e)) {
          return false;
        }
      } else {
        // no debug info
        if (containsTernary(t) || containsTernary(e)) {
          // don't make nested ternary by default
          // TODO: add addition checks
          return false;
        }
      }
    }

    if (t.getResult() != null && e.getResult() != null) {
      PhiInsn phi = t.getResult().getSVar().getUsedInPhi();
      if (phi == null || !t.getResult().equalRegisterAndType(e.getResult())) {
        return false;
      }
      if (!ifRegion.getParent().replaceSubBlock(ifRegion, header)) {
        return false;
      }
      InsnList.remove(tb, t);
      InsnList.remove(eb, e);

      RegisterArg resArg;
      if (phi.getArgsCount() == 2) {
        resArg = phi.getResult();
      } else {
        resArg = t.getResult();
        phi.removeArg(e.getResult());
      }
      TernaryInsn ternInsn = new TernaryInsn(ifRegion.getCondition(),
          resArg, InsnArg.wrapArg(t), InsnArg.wrapArg(e));
      ternInsn.setSourceLine(t.getSourceLine());

      // remove 'if' instruction
      header.getInstructions().clear();
      header.getInstructions().add(ternInsn);

      // shrink method again
      CodeShrinker.shrinkMethod(mth);
      return true;
    }

    if (!mth.getReturnType().equals(ArgType.VOID)
        && t.getType() == InsnType.RETURN && e.getType() == InsnType.RETURN) {

      if (!ifRegion.getParent().replaceSubBlock(ifRegion, header)) {
        return false;
      }
      InsnList.remove(tb, t);
      InsnList.remove(eb, e);
      tb.remove(AFlag.RETURN);
      eb.remove(AFlag.RETURN);

      TernaryInsn ternInsn = new TernaryInsn(ifRegion.getCondition(), null, t.getArg(0), e.getArg(0));
      ternInsn.setSourceLine(t.getSourceLine());
      InsnNode retInsn = new InsnNode(InsnType.RETURN, 1);
      retInsn.addArg(InsnArg.wrapArg(ternInsn));

      header.getInstructions().clear();
      header.getInstructions().add(retInsn);
      header.add(AFlag.RETURN);
View Full Code Here

      return true;
    }
    for (int i = 0; i < insn.getArgsCount(); i++) {
      InsnArg arg = insn.getArg(i);
      if (arg.isInsnWrap()) {
        InsnNode wrapInsn = ((InsnWrapArg) arg).getWrapInsn();
        if (containsTernary(wrapInsn)) {
          return true;
        }
      }
    }
View Full Code Here

        umIt.remove();
        continue;
      }

      // variable declared at 'catch' clause
      InsnNode parentInsn = u.getArg().getParentInsn();
      if (parentInsn == null || parentInsn.getType() == InsnType.MOVE_EXCEPTION) {
        umIt.remove();
      }
    }
    if (usageMap.isEmpty()) {
      return;
View Full Code Here

    return usage;
  }

  private static boolean declareAtAssign(Usage u) {
    RegisterArg arg = u.getArg();
    InsnNode parentInsn = arg.getParentInsn();
    if (!arg.equals(parentInsn.getResult())) {
      return false;
    }
    parentInsn.add(AFlag.DECLARE_VAR);
    processVar(arg);
    return true;
  }
View Full Code Here

    @Override
    public void processBlockTraced(MethodNode mth, IBlock container, IRegion curRegion) {
      regionProcess(mth, curRegion);
      int len = container.getInstructions().size();
      for (int i = 0; i < len; i++) {
        InsnNode insn = container.getInstructions().get(i);
        if (insn.contains(AFlag.SKIP)) {
          continue;
        }
        args.clear();
        processInsn(insn, curRegion);
      }
View Full Code Here

   * Return constant value from register assign or null if not constant
   *
   * @return LiteralArg, String or ArgType
   */
  public Object getConstValue(DexNode dex) {
    InsnNode parInsn = getAssignInsn();
    if (parInsn == null) {
      return null;
    }
    InsnType insnType = parInsn.getType();
    switch (insnType) {
      case CONST:
        return parInsn.getArg(0);
      case CONST_STR:
        return ((ConstStringNode) parInsn).getString();
      case CONST_CLASS:
        return ((ConstClassNode) parInsn).getClsType();
      case SGET:
View Full Code Here

  public boolean isThis() {
    if ("this".equals(getName())) {
      return true;
    }
    // maybe it was moved from 'this' register
    InsnNode ai = getAssignInsn();
    if (ai != null && ai.getType() == InsnType.MOVE) {
      InsnArg arg = ai.getArg(0);
      if (arg != this) {
        return arg.isThis();
      }
    }
    return false;
View Full Code Here

  public InsnNode getPhiAssignInsn() {
    PhiInsn usePhi = sVar.getUsedInPhi();
    if (usePhi != null) {
      return usePhi;
    }
    InsnNode parent = sVar.getAssign().getParentInsn();
    if (parent != null && parent.getType() == InsnType.PHI) {
      return parent;
    }
    return null;
  }
View Full Code Here

  public void setParentInsn(InsnNode parentInsn) {
    this.parentInsn = parentInsn;
  }

  public InsnArg wrapInstruction(InsnNode insn) {
    InsnNode parent = parentInsn;
    if (parent == null) {
      return null;
    }
    if (parent == insn) {
      LOG.debug("Can't wrap instruction info itself: {}", insn);
      Thread.dumpStack();
      return null;
    }
    int i = getArgIndex(parent, this);
    if (i == -1) {
      return null;
    }
    insn.add(AFlag.WRAPPED);
    InsnArg arg = wrapArg(insn);
    parent.setArg(i, arg);
    return arg;
  }
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.