Java Code Examples for com.android.dx.util.Hex#u2()

The following examples show how to use com.android.dx.util.Hex#u2() . 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: CodeObserver.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void visitLocal(int opcode, int offset, int length,
        int idx, Type type, int value) {
    String idxStr = (length <= 3) ? Hex.u1(idx) : Hex.u2(idx);
    boolean argComment = (length == 1);
    String valueStr = "";

    if (opcode == ByteOps.IINC) {
        valueStr = ", #" +
            ((length <= 3) ? Hex.s1(value) : Hex.s2(value));
    }

    String catStr = "";
    if (type.isCategory2()) {
        catStr = (argComment ? "," : " //") + " category-2";
    }

    observer.parsed(bytes, offset, length,
                    header(offset) + (argComment ? " // " : " ") +
                    idxStr + valueStr + catStr);
}
 
Example 2
Source File: Ropper.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Helper for {@link #addOrReplaceBlock} which recursively removes
 * the given block and all blocks that are (direct and indirect)
 * successors of it whose labels indicate that they are not in the
 * normally-translated range.
 *
 * @param idx {@code non-null;} block to remove (etc.)
 */
private void removeBlockAndSpecialSuccessors(int idx) {
    int minLabel = getMinimumUnreservedLabel();
    BasicBlock block = result.get(idx);
    IntList successors = block.getSuccessors();
    int sz = successors.size();

    result.remove(idx);
    resultSubroutines.remove(idx);

    for (int i = 0; i < sz; i++) {
        int label = successors.get(i);
        if (label >= minLabel) {
            idx = labelToResultIndex(label);
            if (idx < 0) {
                throw new RuntimeException("Invalid label "
                        + Hex.u2(label));
            }
            removeBlockAndSpecialSuccessors(idx);
        }
    }
}
 
Example 3
Source File: CodeObserver.java    From buck with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
public void visitBranch(int opcode, int offset, int length,
                        int target) {
    String targetStr = (length <= 3) ? Hex.u2(target) : Hex.u4(target);
    observer.parsed(bytes, offset, length,
                    header(offset) + " " + targetStr);
}
 
Example 4
Source File: RopMethod.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the predecessors associated with the given block. This throws
 * an exception if there is no block with the given label.
 *
 * @param label {@code >= 0;} the label of the block in question
 * @return {@code non-null;} the predecessors of that block
 */
public IntList labelToPredecessors(int label) {
    if (exitPredecessors == null) {
        calcPredecessors();
    }

    IntList result = predecessors[label];

    if (result == null) {
        throw new RuntimeException("no such block: " + Hex.u2(label));
    }

    return result;
}
 
Example 5
Source File: BasicBlockList.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the first block in the list with the given label, if any.
 *
 * @param label {@code label >= 0;} the label to look for
 * @return {@code non-null;} the so-labelled block
 * @throws IllegalArgumentException thrown if the label isn't found
 */
public BasicBlock labelToBlock(int label) {
    int idx = indexOfLabel(label);

    if (idx < 0) {
        throw new IllegalArgumentException("no such label: "
                + Hex.u2(label));
    }

    return get(idx);
}
 
Example 6
Source File: BasicBlockList.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the first block in the list with the given label, if any.
 *
 * @param label {@code label >= 0;} the label to look for
 * @return {@code non-null;} the so-labelled block
 * @throws IllegalArgumentException thrown if the label isn't found
 */
public BasicBlock labelToBlock(int label) {
    int idx = indexOfLabel(label);

    if (idx < 0) {
        throw new IllegalArgumentException("no such label: "
                + Hex.u2(label));
    }

    return get(idx);
}
 
Example 7
Source File: SsaToRop.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a single basic block to rop form.
 *
 * @param block SSA block to process
 * @return {@code non-null;} ROP block
 */
private BasicBlock convertBasicBlock(SsaBasicBlock block) {
    IntList successorList = block.getRopLabelSuccessorList();
    int primarySuccessorLabel = block.getPrimarySuccessorRopLabel();

    // Filter out any reference to the SSA form's exit block.

    // Exit block may be null.
    SsaBasicBlock exitBlock = ssaMeth.getExitBlock();
    int exitRopLabel = (exitBlock == null) ? -1 : exitBlock.getRopLabel();

    if (successorList.contains(exitRopLabel)) {
        if (successorList.size() > 1) {
            throw new RuntimeException(
                    "Exit predecessor must have no other successors"
                            + Hex.u2(block.getRopLabel()));
        } else {
            successorList = IntList.EMPTY;
            primarySuccessorLabel = -1;

            verifyValidExitPredecessor(block);
        }
    }

    successorList.setImmutable();

    BasicBlock result = new BasicBlock(
            block.getRopLabel(), convertInsns(block.getInsns()),
            successorList,
            primarySuccessorLabel);

    return result;
}
 
Example 8
Source File: SsaToRop.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a single basic block to rop form.
 *
 * @param block SSA block to process
 * @return {@code non-null;} ROP block
 */
private BasicBlock convertBasicBlock(SsaBasicBlock block) {
    IntList successorList = block.getRopLabelSuccessorList();
    int primarySuccessorLabel = block.getPrimarySuccessorRopLabel();

    // Filter out any reference to the SSA form's exit block.

    // Exit block may be null.
    SsaBasicBlock exitBlock = ssaMeth.getExitBlock();
    int exitRopLabel = (exitBlock == null) ? -1 : exitBlock.getRopLabel();

    if (successorList.contains(exitRopLabel)) {
        if (successorList.size() > 1) {
            throw new RuntimeException(
                    "Exit predecessor must have no other successors"
                            + Hex.u2(block.getRopLabel()));
        } else {
            successorList = IntList.EMPTY;
            primarySuccessorLabel = -1;

            verifyValidExitPredecessor(block);
        }
    }

    successorList.setImmutable();

    BasicBlock result = new BasicBlock(
            block.getRopLabel(), convertInsns(block.getInsns()),
            successorList,
            primarySuccessorLabel);

    return result;
}
 
Example 9
Source File: CstShort.java    From buck with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public String toString() {
    int value = getIntBits();
    return "short{0x" + Hex.u2(value) + " / " + value + '}';
}
 
Example 10
Source File: ReturnAddress.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public String toString() {
    return ("<addr:" + Hex.u2(subroutineAddress) + ">");
}
 
Example 11
Source File: CstShort.java    From Box with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public String toString() {
    int value = getIntBits();
    return "short{0x" + Hex.u2(value) + " / " + value + '}';
}
 
Example 12
Source File: SsaBasicBlock.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
/**
 * @return the label of this block in rop form as a hex string
 */
public String getRopLabelString() {
    return Hex.u2(ropLabel);
}
 
Example 13
Source File: BasicBlock.java    From Box with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return '{' + Hex.u2(label) + '}';
}
 
Example 14
Source File: CodeObserver.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
   @Override
public void visitConstant(int opcode, int offset, int length,
						  Constant cst, int value) {
       if (cst instanceof CstKnownNull) {
           // This is aconst_null.
           visitNoArgs(opcode, offset, length, null);
           return;
       }

       if (cst instanceof CstInteger) {
           visitLiteralInt(opcode, offset, length, value);
           return;
       }

       if (cst instanceof CstLong) {
           visitLiteralLong(opcode, offset, length,
                            ((CstLong) cst).getValue());
           return;
       }

       if (cst instanceof CstFloat) {
           visitLiteralFloat(opcode, offset, length,
                             ((CstFloat) cst).getIntBits());
           return;
       }

       if (cst instanceof CstDouble) {
           visitLiteralDouble(opcode, offset, length,
                            ((CstDouble) cst).getLongBits());
           return;
       }

       String valueStr = "";
       if (value != 0) {
           valueStr = ", ";
           if (opcode == ByteOps.MULTIANEWARRAY) {
               valueStr += Hex.u1(value);
           } else {
               valueStr += Hex.u2(value);
           }
       }

       observer.parsed(bytes, offset, length,
                       header(offset) + " " + cst + valueStr);
   }
 
Example 15
Source File: SsaBasicBlock.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * @return the label of this block in rop form as a hex string
 */
public String getRopLabelString() {
    return Hex.u2(ropLabel);
}
 
Example 16
Source File: CstShort.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public String toString() {
    int value = getIntBits();
    return "short{0x" + Hex.u2(value) + " / " + value + '}';
}
 
Example 17
Source File: SsaBasicBlock.java    From buck with Apache License 2.0 4 votes vote down vote up
/**
 * @return the label of this block in rop form as a hex string
 */
public String getRopLabelString() {
    return Hex.u2(ropLabel);
}
 
Example 18
Source File: StdConstantPool.java    From Box with Apache License 2.0 2 votes vote down vote up
/**
 * Throws the right exception for an invalid cpi.
 *
 * @param idx the bad cpi
 * @return never
 * @throws ExceptionWithContext always thrown
 */
private static Constant throwInvalid(int idx) {
    throw new ExceptionWithContext("invalid constant pool index " +
                                   Hex.u2(idx));
}
 
Example 19
Source File: OneLocalsArray.java    From Box with Apache License 2.0 2 votes vote down vote up
/**
 * Throws a properly-formatted exception.
 *
 * @param idx the salient local index
 * @param msg {@code non-null;} useful message
 * @return never (keeps compiler happy)
 */
private static TypeBearer throwSimException(int idx, String msg) {
    throw new SimException("local " + Hex.u2(idx) + ": " + msg);
}
 
Example 20
Source File: OneLocalsArray.java    From Box with Apache License 2.0 2 votes vote down vote up
/**
 * Throws a properly-formatted exception.
 *
 * @param idx the salient local index
 * @param msg {@code non-null;} useful message
 * @return never (keeps compiler happy)
 */
private static TypeBearer throwSimException(int idx, String msg) {
    throw new SimException("local " + Hex.u2(idx) + ": " + msg);
}