Java Code Examples for com.android.dx.rop.code.BasicBlockList#size()

The following examples show how to use com.android.dx.rop.code.BasicBlockList#size() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StdCatchBuilder.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public boolean hasAnyCatches() {
    BasicBlockList blocks = method.getBlocks();
    int size = blocks.size();

    for (int i = 0; i < size; i++) {
        BasicBlock block = blocks.get(i);
        TypeList catches = block.getLastInsn().getCatches();
        if (catches.size() != 0) {
            return true;
        }
    }

    return false;
}
 
Example 2
Source File: StdCatchBuilder.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public HashSet<Type> getCatchTypes() {
    HashSet<Type> result = new HashSet<Type>(20);
    BasicBlockList blocks = method.getBlocks();
    int size = blocks.size();

    for (int i = 0; i < size; i++) {
        BasicBlock block = blocks.get(i);
        TypeList catches = block.getLastInsn().getCatches();
        int catchSize = catches.size();

        for (int j = 0; j < catchSize; j++) {
            result.add(catches.getType(j));
        }
    }

    return result;
}
 
Example 3
Source File: BlockAddresses.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Sets up the address arrays.
 */
private void setupArrays(RopMethod method) {
    BasicBlockList blocks = method.getBlocks();
    int sz = blocks.size();

    for (int i = 0; i < sz; i++) {
        BasicBlock one = blocks.get(i);
        int label = one.getLabel();
        Insn insn = one.getInsns().get(0);

        starts[label] = new CodeAddress(insn.getPosition());

        SourcePosition pos = one.getLastInsn().getPosition();

        lasts[label] = new CodeAddress(pos);
        ends[label] = new CodeAddress(pos);
    }
}
 
Example 4
Source File: SsaMethod.java    From Box with Apache License 2.0 6 votes vote down vote up
private void convertRopToSsaBlocks(RopMethod rmeth) {
    BasicBlockList ropBlocks = rmeth.getBlocks();
    int sz = ropBlocks.size();

    blocks = new ArrayList<SsaBasicBlock>(sz + 2);

    for (int i = 0; i < sz; i++) {
        SsaBasicBlock sbb = SsaBasicBlock.newFromRop(rmeth, i, this);
        blocks.add(sbb);
    }

    // Add an no-op entry block.
    int origEntryBlockIndex = rmeth.getBlocks()
            .indexOfLabel(rmeth.getFirstLabel());

    SsaBasicBlock entryBlock
            = blocks.get(origEntryBlockIndex).insertNewPredecessor();

    entryBlockIndex = entryBlock.getIndex();
    exitBlockIndex = -1; // This gets made later.
}
 
Example 5
Source File: StdCatchBuilder.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
   @Override
public HashSet<Type> getCatchTypes() {
       HashSet<Type> result = new HashSet<Type>(20);
       BasicBlockList blocks = method.getBlocks();
       int size = blocks.size();

       for (int i = 0; i < size; i++) {
           BasicBlock block = blocks.get(i);
           TypeList catches = block.getLastInsn().getCatches();
           int catchSize = catches.size();

           for (int j = 0; j < catchSize; j++) {
               result.add(catches.getType(j));
           }
       }

       return result;
   }
 
Example 6
Source File: BlockAddresses.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Sets up the address arrays.
 */
private void setupArrays(RopMethod method) {
    BasicBlockList blocks = method.getBlocks();
    int sz = blocks.size();

    for (int i = 0; i < sz; i++) {
        BasicBlock one = blocks.get(i);
        int label = one.getLabel();
        Insn insn = one.getInsns().get(0);

        starts[label] = new CodeAddress(insn.getPosition());

        SourcePosition pos = one.getLastInsn().getPosition();

        lasts[label] = new CodeAddress(pos);
        ends[label] = new CodeAddress(pos);
    }
}
 
Example 7
Source File: StdCatchBuilder.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public boolean hasAnyCatches() {
    BasicBlockList blocks = method.getBlocks();
    int size = blocks.size();

    for (int i = 0; i < size; i++) {
        BasicBlock block = blocks.get(i);
        TypeList catches = block.getLastInsn().getCatches();
        if (catches.size() != 0) {
            return true;
        }
    }

    return false;
}
 
Example 8
Source File: StdCatchBuilder.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public HashSet<Type> getCatchTypes() {
    HashSet<Type> result = new HashSet<Type>(20);
    BasicBlockList blocks = method.getBlocks();
    int size = blocks.size();

    for (int i = 0; i < size; i++) {
        BasicBlock block = blocks.get(i);
        TypeList catches = block.getLastInsn().getCatches();
        int catchSize = catches.size();

        for (int j = 0; j < catchSize; j++) {
            result.add(catches.getType(j));
        }
    }

    return result;
}
 
Example 9
Source File: StdCatchBuilder.java    From buck with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
public HashSet<Type> getCatchTypes() {
    HashSet<Type> result = new HashSet<Type>(20);
    BasicBlockList blocks = method.getBlocks();
    int size = blocks.size();

    for (int i = 0; i < size; i++) {
        BasicBlock block = blocks.get(i);
        TypeList catches = block.getLastInsn().getCatches();
        int catchSize = catches.size();

        for (int j = 0; j < catchSize; j++) {
            result.add(catches.getType(j));
        }
    }

    return result;
}
 
Example 10
Source File: SsaMethod.java    From Box with Apache License 2.0 6 votes vote down vote up
private void convertRopToSsaBlocks(RopMethod rmeth) {
    BasicBlockList ropBlocks = rmeth.getBlocks();
    int sz = ropBlocks.size();

    blocks = new ArrayList<SsaBasicBlock>(sz + 2);

    for (int i = 0; i < sz; i++) {
        SsaBasicBlock sbb = SsaBasicBlock.newFromRop(rmeth, i, this);
        blocks.add(sbb);
    }

    // Add an no-op entry block.
    int origEntryBlockIndex = rmeth.getBlocks()
            .indexOfLabel(rmeth.getFirstLabel());

    SsaBasicBlock entryBlock
            = blocks.get(origEntryBlockIndex).insertNewPredecessor();

    entryBlockIndex = entryBlock.getIndex();
    exitBlockIndex = -1; // This gets made later.
}
 
Example 11
Source File: SsaMethod.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a BitSet of block indices from a basic block list and a list
 * of labels taken from Rop form.
 *
 * @param blocks Rop blocks
 * @param labelList list of rop block labels
 * @return BitSet of block indices
 */
static BitSet bitSetFromLabelList(BasicBlockList blocks,
        IntList labelList) {
    BitSet result = new BitSet(blocks.size());

    for (int i = 0, sz = labelList.size(); i < sz; i++) {
        result.set(blocks.indexOfLabel(labelList.get(i)));
    }

    return result;
}
 
Example 12
Source File: SsaMethod.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a BitSet of block indices from a basic block list and a list
 * of labels taken from Rop form.
 *
 * @param blocks Rop blocks
 * @param labelList list of rop block labels
 * @return BitSet of block indices
 */
static BitSet bitSetFromLabelList(BasicBlockList blocks,
        IntList labelList) {
    BitSet result = new BitSet(blocks.size());

    for (int i = 0, sz = labelList.size(); i < sz; i++) {
        result.set(blocks.indexOfLabel(labelList.get(i)));
    }

    return result;
}
 
Example 13
Source File: StdCatchBuilder.java    From buck with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
public boolean hasAnyCatches() {
    BasicBlockList blocks = method.getBlocks();
    int size = blocks.size();

    for (int i = 0; i < size; i++) {
        BasicBlock block = blocks.get(i);
        TypeList catches = block.getLastInsn().getCatches();
        if (catches.size() != 0) {
            return true;
        }
    }

    return false;
}
 
Example 14
Source File: SsaMethod.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a BitSet of block indices from a basic block list and a list
 * of labels taken from Rop form.
 *
 * @param blocks Rop blocks
 * @param labelList list of rop block labels
 * @return BitSet of block indices
 */
static BitSet bitSetFromLabelList(BasicBlockList blocks,
        IntList labelList) {
    BitSet result = new BitSet(blocks.size());

    for (int i = 0, sz = labelList.size(); i < sz; i++) {
        result.set(blocks.indexOfLabel(labelList.get(i)));
    }

    return result;
}
 
Example 15
Source File: DotDumper.java    From Box with Apache License 2.0 4 votes vote down vote up
@Override
public void endParsingMember(ByteArray bytes, int offset, String name,
                             String descriptor, Member member) {
    if (!(member instanceof Method)) {
        return;
    }

    if (!shouldDumpMethod(name)) {
        return;
    }

    ConcreteMethod meth = new ConcreteMethod((Method) member, classFile,
                                             true, true);

    TranslationAdvice advice = DexTranslationAdvice.THE_ONE;
    RopMethod rmeth =
        Ropper.convert(meth, advice, classFile.getMethods(), dexOptions);

    if (optimize) {
        boolean isStatic = AccessFlags.isStatic(meth.getAccessFlags());
        rmeth = Optimizer.optimize(rmeth,
                BaseDumper.computeParamWidth(meth, isStatic), isStatic,
                true, advice);
    }

    System.out.println("digraph "  + name + "{");

    System.out.println("\tfirst -> n"
            + Hex.u2(rmeth.getFirstLabel()) + ";");

    BasicBlockList blocks = rmeth.getBlocks();

    int sz = blocks.size();
    for (int i = 0; i < sz; i++) {
        BasicBlock bb = blocks.get(i);
        int label = bb.getLabel();
        IntList successors = bb.getSuccessors();

        if (successors.size() == 0) {
            System.out.println("\tn" + Hex.u2(label) + " -> returns;");
        } else if (successors.size() == 1) {
            System.out.println("\tn" + Hex.u2(label) + " -> n"
                    + Hex.u2(successors.get(0)) + ";");
        } else {
            System.out.print("\tn" + Hex.u2(label) + " -> {");
            for (int j = 0; j < successors.size(); j++ ) {
                int successor = successors.get(j);

                if (successor != bb.getPrimarySuccessor()) {
                    System.out.print(" n" + Hex.u2(successor) + " ");
                }

            }
            System.out.println("};");

            System.out.println("\tn" + Hex.u2(label) + " -> n"
                    + Hex.u2(bb.getPrimarySuccessor())
                    + " [label=\"primary\"];");


        }
    }

    System.out.println("}");
}
 
Example 16
Source File: DotDumper.java    From buck with Apache License 2.0 4 votes vote down vote up
public void endParsingMember(ByteArray bytes, int offset, String name,
                             String descriptor, Member member) {
    if (!(member instanceof Method)) {
        return;
    }

    if (!shouldDumpMethod(name)) {
        return;
    }

    ConcreteMethod meth = new ConcreteMethod((Method) member, classFile,
                                             true, true);

    TranslationAdvice advice = DexTranslationAdvice.THE_ONE;
    RopMethod rmeth =
        Ropper.convert(meth, advice, classFile.getMethods());

    if (optimize) {
        boolean isStatic = AccessFlags.isStatic(meth.getAccessFlags());
        rmeth = Optimizer.optimize(rmeth,
                BaseDumper.computeParamWidth(meth, isStatic), isStatic,
                true, advice);
    }

    System.out.println("digraph "  + name + "{");

    System.out.println("\tfirst -> n"
            + Hex.u2(rmeth.getFirstLabel()) + ";");

    BasicBlockList blocks = rmeth.getBlocks();

    int sz = blocks.size();
    for (int i = 0; i < sz; i++) {
        BasicBlock bb = blocks.get(i);
        int label = bb.getLabel();
        IntList successors = bb.getSuccessors();

        if (successors.size() == 0) {
            System.out.println("\tn" + Hex.u2(label) + " -> returns;");
        } else if (successors.size() == 1) {
            System.out.println("\tn" + Hex.u2(label) + " -> n"
                    + Hex.u2(successors.get(0)) + ";");
        } else {
            System.out.print("\tn" + Hex.u2(label) + " -> {");
            for (int j = 0; j < successors.size(); j++ ) {
                int successor = successors.get(j);

                if (successor != bb.getPrimarySuccessor()) {
                    System.out.print(" n" + Hex.u2(successor) + " ");
                }

            }
            System.out.println("};");

            System.out.println("\tn" + Hex.u2(label) + " -> n"
                    + Hex.u2(bb.getPrimarySuccessor())
                    + " [label=\"primary\"];");


        }
    }

    System.out.println("}");
}
 
Example 17
Source File: RopTranslator.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs an instance. This method is private. Use {@link #translate}.
 *
 * @param method {@code non-null;} the original method
 * @param positionInfo how much position info to preserve; one of the
 * static constants in {@link PositionList}
 * @param locals {@code null-ok;} local variable information to use
 * @param paramSize size, in register units, of all the parameters to
 * this method
 * @param dexOptions {@code non-null;} options for dex output
 */
private RopTranslator(RopMethod method, int positionInfo, LocalVariableInfo locals,
        int paramSize, DexOptions dexOptions) {
    this.dexOptions = dexOptions;
    this.method = method;
    this.positionInfo = positionInfo;
    this.locals = locals;
    this.addresses = new BlockAddresses(method);
    this.paramSize = paramSize;
    this.order = null;
    this.paramsAreInOrder = calculateParamsAreInOrder(method, paramSize);

    BasicBlockList blocks = method.getBlocks();
    int bsz = blocks.size();

    /*
     * Max possible instructions includes three code address
     * objects per basic block (to the first and last instruction,
     * and just past the end of the block), and the possibility of
     * an extra goto at the end of each basic block.
     */
    int maxInsns = (bsz * 3) + blocks.getInstructionCount();

    if (locals != null) {
        /*
         * If we're tracking locals, then there's could be another
         * extra instruction per block (for the locals state at the
         * start of the block) as well as one for each interblock
         * local introduction.
         */
        maxInsns += bsz + locals.getAssignmentCount();
    }

    /*
     * If params are not in order, we will need register space
     * for them before this is all over...
     */
    this.regCount = blocks.getRegCount()
            + (paramsAreInOrder ? 0 : this.paramSize);

    this.output = new OutputCollector(dexOptions, maxInsns, bsz * 3, regCount, paramSize);

    if (locals != null) {
        this.translationVisitor =
            new LocalVariableAwareTranslationVisitor(output, locals);
    } else {
        this.translationVisitor = new TranslationVisitor(output);
    }
}
 
Example 18
Source File: RopTranslator.java    From buck with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs an instance. This method is private. Use {@link #translate}.
 *
 * @param method {@code non-null;} the original method
 * @param positionInfo how much position info to preserve; one of the
 * static constants in {@link PositionList}
 * @param locals {@code null-ok;} local variable information to use
 * @param paramSize size, in register units, of all the parameters to
 * this method
 * @param dexOptions {@code non-null;} options for dex output
 */
private RopTranslator(RopMethod method, int positionInfo, LocalVariableInfo locals,
        int paramSize, DexOptions dexOptions) {
    this.dexOptions = dexOptions;
    this.method = method;
    this.positionInfo = positionInfo;
    this.locals = locals;
    this.addresses = new BlockAddresses(method);
    this.paramSize = paramSize;
    this.order = null;
    this.paramsAreInOrder = calculateParamsAreInOrder(method, paramSize);

    BasicBlockList blocks = method.getBlocks();
    int bsz = blocks.size();

    /*
     * Max possible instructions includes three code address
     * objects per basic block (to the first and last instruction,
     * and just past the end of the block), and the possibility of
     * an extra goto at the end of each basic block.
     */
    int maxInsns = (bsz * 3) + blocks.getInstructionCount();

    if (locals != null) {
        /*
         * If we're tracking locals, then there's could be another
         * extra instruction per block (for the locals state at the
         * start of the block) as well as one for each interblock
         * local introduction.
         */
        maxInsns += bsz + locals.getAssignmentCount();
    }

    /*
     * If params are not in order, we will need register space
     * for them before this is all over...
     */
    this.regCount = blocks.getRegCount()
            + (paramsAreInOrder ? 0 : this.paramSize);

    this.output = new OutputCollector(dexOptions, maxInsns, bsz * 3, regCount, paramSize);

    if (locals != null) {
        this.translationVisitor =
            new LocalVariableAwareTranslationVisitor(output, locals);
    } else {
        this.translationVisitor = new TranslationVisitor(output);
    }
}
 
Example 19
Source File: RopTranslator.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
/**
   * Constructs an instance. This method is private. Use {@link #translate}.
   *
   * @param method {@code non-null;} the original method
   * @param positionInfo how much position info to preserve; one of the
   * static constants in {@link PositionList}
   * @param locals {@code null-ok;} local variable information to use
   * @param paramSize size, in register units, of all the parameters to
   * this method
   * @param dexOptions {@code non-null;} options for dex output
   */
  private RopTranslator(RopMethod method, int positionInfo, LocalVariableInfo locals,
          int paramSize, DexOptions dexOptions) {
this.method = method;
      this.positionInfo = positionInfo;
      this.locals = locals;
      this.addresses = new BlockAddresses(method);
      this.paramSize = paramSize;
      this.order = null;
      this.paramsAreInOrder = calculateParamsAreInOrder(method, paramSize);

      BasicBlockList blocks = method.getBlocks();
      int bsz = blocks.size();

      /*
       * Max possible instructions includes three code address
       * objects per basic block (to the first and last instruction,
       * and just past the end of the block), and the possibility of
       * an extra goto at the end of each basic block.
       */
      int maxInsns = (bsz * 3) + blocks.getInstructionCount();

      if (locals != null) {
          /*
           * If we're tracking locals, then there's could be another
           * extra instruction per block (for the locals state at the
           * start of the block) as well as one for each interblock
           * local introduction.
           */
          maxInsns += bsz + locals.getAssignmentCount();
      }

      /*
       * If params are not in order, we will need register space
       * for them before this is all over...
       */
      this.regCount = blocks.getRegCount()
              + (paramsAreInOrder ? 0 : this.paramSize);

      this.output = new OutputCollector(dexOptions, maxInsns, bsz * 3, regCount, paramSize);

      if (locals != null) {
          this.translationVisitor =
              new LocalVariableAwareTranslationVisitor(output, locals);
      } else {
          this.translationVisitor = new TranslationVisitor(output);
      }
  }
 
Example 20
Source File: RopTranslator.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs an instance. This method is private. Use {@link #translate}.
 *
 * @param method {@code non-null;} the original method
 * @param positionInfo how much position info to preserve; one of the
 * static constants in {@link PositionList}
 * @param locals {@code null-ok;} local variable information to use
 * @param paramSize size, in register units, of all the parameters to
 * this method
 * @param dexOptions {@code non-null;} options for dex output
 */
private RopTranslator(RopMethod method, int positionInfo, LocalVariableInfo locals,
        int paramSize, DexOptions dexOptions) {
    this.dexOptions = dexOptions;
    this.method = method;
    this.positionInfo = positionInfo;
    this.locals = locals;
    this.addresses = new BlockAddresses(method);
    this.paramSize = paramSize;
    this.order = null;
    this.paramsAreInOrder = calculateParamsAreInOrder(method, paramSize);

    BasicBlockList blocks = method.getBlocks();
    int bsz = blocks.size();

    /*
     * Max possible instructions includes three code address
     * objects per basic block (to the first and last instruction,
     * and just past the end of the block), and the possibility of
     * an extra goto at the end of each basic block.
     */
    int maxInsns = (bsz * 3) + blocks.getInstructionCount();

    if (locals != null) {
        /*
         * If we're tracking locals, then there's could be another
         * extra instruction per block (for the locals state at the
         * start of the block) as well as one for each interblock
         * local introduction.
         */
        maxInsns += bsz + locals.getAssignmentCount();
    }

    /*
     * If params are not in order, we will need register space
     * for them before this is all over...
     */
    this.regCount = blocks.getRegCount()
            + (paramsAreInOrder ? 0 : this.paramSize);

    this.output = new OutputCollector(dexOptions, maxInsns, bsz * 3, regCount, paramSize);

    if (locals != null) {
        this.translationVisitor =
            new LocalVariableAwareTranslationVisitor(output, locals);
    } else {
        this.translationVisitor = new TranslationVisitor(output);
    }
}