Package jadx.core.dex.nodes

Examples of jadx.core.dex.nodes.InsnNode


        continue;
      }
      for (PhiInsn phi : phiList.getList()) {
        for (int i = 0; i < phi.getArgsCount(); i++) {
          RegisterArg arg = phi.getArg(i);
          InsnNode parentInsn = arg.getAssignInsn();
          if (parentInsn != null
              && parentInsn.getResult() != null
              && parentInsn.contains(AFlag.TRY_LEAVE)) {
            phi.removeArg(arg);
          }
        }
      }
    }
View Full Code Here


  private static boolean removeUselessPhi(MethodNode mth) {
    List<PhiInsn> insnToRemove = new ArrayList<PhiInsn>();
    for (SSAVar var : mth.getSVars()) {
      // phi result not used
      if (var.getUseCount() == 0) {
        InsnNode assignInsn = var.getAssign().getParentInsn();
        if (assignInsn != null && assignInsn.getType() == InsnType.PHI) {
          insnToRemove.add((PhiInsn) assignInsn);
        }
      }
    }
    for (BlockNode block : mth.getBasicBlocks()) {
View Full Code Here

      }
      if (!mth.getReturnType().equals(ArgType.VOID)
          && mth.getExitBlocks().size() > 1) {
        // fix debug for splitter 'return' instructions
        for (BlockNode exit : mth.getExitBlocks()) {
          InsnNode ret = exit.getInstructions().get(0);
          InsnNode oldRet = insnArr[ret.getOffset()];
          if (oldRet != ret) {
            RegisterArg oldArg = (RegisterArg) oldRet.getArg(0);
            RegisterArg newArg = (RegisterArg) ret.getArg(0);
            newArg.mergeDebugInfo(oldArg.getType(), oldArg.getName());
            ret.setSourceLine(oldRet.getSourceLine());
          }
        }
      }
    }
    mth.unloadInsnArr();
View Full Code Here

  }

  private static void removeInsn(MethodNode mth, BlockNode block, PhiInsn phiInsn) {
    Iterator<InsnNode> it = block.getInstructions().iterator();
    while (it.hasNext()) {
      InsnNode insn = it.next();
      if (insn == phiInsn) {
        it.remove();
        return;
      }
    }
View Full Code Here

    BlockProcessingHelper.visit(mth);
    mth.finishBasicBlocks();
  }

  private static void splitBasicBlocks(MethodNode mth) {
    InsnNode prevInsn = null;
    Map<Integer, BlockNode> blocksMap = new HashMap<Integer, BlockNode>();
    BlockNode curBlock = startNewBlock(mth, 0);
    mth.setEnterBlock(curBlock);

    // split into blocks
    for (InsnNode insn : mth.getInstructions()) {
      if (insn == null) {
        continue;
      }
      boolean startNew = false;
      if (prevInsn != null) {
        InsnType type = prevInsn.getType();
        if (type == InsnType.GOTO
            || type == InsnType.THROW
            || SEPARATE_INSNS.contains(type)) {

          if (type == InsnType.RETURN || type == InsnType.THROW) {
View Full Code Here

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

      }
    }
  }

  private static InsnNode duplicateReturnInsn(InsnNode returnInsn) {
    InsnNode insn = new InsnNode(returnInsn.getType(), returnInsn.getArgsCount());
    if (returnInsn.getArgsCount() == 1) {
      RegisterArg arg = (RegisterArg) returnInsn.getArg(0);
      insn.addArg(InsnArg.reg(arg.getRegNum(), arg.getType()));
    }
    insn.copyAttributesFrom(returnInsn);
    insn.setOffset(returnInsn.getOffset());
    insn.setSourceLine(returnInsn.getSourceLine());
    return insn;
  }
View Full Code Here

  private static void removeSynchronized(MethodNode mth) {
    Region startRegion = mth.getRegion();
    List<IContainer> subBlocks = startRegion.getSubBlocks();
    if (!subBlocks.isEmpty() && subBlocks.get(0) instanceof SynchronizedRegion) {
      SynchronizedRegion synchRegion = (SynchronizedRegion) subBlocks.get(0);
      InsnNode synchInsn = synchRegion.getEnterInsn();
      if (!synchInsn.getArg(0).isThis()) {
        LOG.warn("In synchronized method {}, top region not synchronized by 'this' {}", mth, synchInsn);
        return;
      }
      // replace synchronized block with inner region
      startRegion.getSubBlocks().set(0, synchRegion.getRegion());
View Full Code Here

    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) {
        IndexInsnNode fp = (IndexInsnNode) insn;
        FieldInfo f = (FieldInfo) fp.getIndex();
        if (f.getName().equals("$VALUES")) {
          if (i == size - 1) {
            cls.getMethods().remove(staticMethod);
          } else {
            list.subList(0, i + 1).clear();
          }
          break;
        }
      }
    }

    for (InsnNode insn : insns) {
      if (insn.getType() == InsnType.CONSTRUCTOR) {
        ConstructorInsn co = (ConstructorInsn) insn;
        if (insn.getArgsCount() < 2) {
          continue;
        }
        ClassInfo clsInfo = co.getClassType();
        ClassNode constrCls = cls.dex().resolveClass(clsInfo);
        if (constrCls == null) {
          continue;
        }
        if (!clsInfo.equals(cls.getClassInfo()) && !constrCls.getAccessFlags().isEnum()) {
          continue;
        }
        RegisterArg nameArg = (RegisterArg) insn.getArg(0);
        // InsnArg pos = insn.getArg(1);
        // TODO add check: pos == j
        String name = (String) nameArg.getConstValue(cls.dex());
        if (name == null) {
          throw new JadxException("Unknown enum field name: " + cls);
        }
        EnumField field = new EnumField(name, insn.getArgsCount() - 2);
        attr.getFields().add(field);
        for (int i = 2; i < insn.getArgsCount(); i++) {
          InsnArg constrArg;
          InsnArg iArg = insn.getArg(i);
          if (iArg.isLiteral()) {
            constrArg = iArg;
          } else {
            constrArg = CodeShrinker.inlineArgument(staticMethod, (RegisterArg) iArg);
            if (constrArg == null) {
View Full Code Here

        if (useList.size() != 1) {
          pass = false;
          break;
        }
        InsnArg arg = useList.get(0);
        InsnNode usePlace = arg.getParentInsn();
        if (!BlockUtils.blockContains(block, usePlace)
            && !BlockUtils.blockContains(next, usePlace)) {
          pass = false;
          break;
        }
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.