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

The following examples show how to use com.android.dx.util.Hex#u4() . 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: CatchStructs.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Writes this instance to the given stream.
 *
 * @param file {@code non-null;} file this instance is part of
 * @param out {@code non-null;} where to write to
 */
public void writeTo(DexFile file, AnnotatedOutput out) {
    finishProcessingIfNecessary();

    if (out.annotates()) {
        annotateEntries("  ", null, out);
    }

    int tableSize = table.size();
    for (int i = 0; i < tableSize; i++) {
        CatchTable.Entry one = table.get(i);
        int start = one.getStart();
        int end = one.getEnd();
        int insnCount = end - start;

        if (insnCount >= 65536) {
            throw new UnsupportedOperationException(
                    "bogus exception range: " + Hex.u4(start) + ".." +
                    Hex.u4(end));
        }

        out.writeInt(start);
        out.writeShort(insnCount);
        out.writeShort(handlerOffsets.get(one.getHandlers()));
    }

    out.write(encodedHandlers);
}
 
Example 2
Source File: CatchStructs.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Writes this instance to the given stream.
 *
 * @param file {@code non-null;} file this instance is part of
 * @param out {@code non-null;} where to write to
 */
public void writeTo(DexFile file, AnnotatedOutput out) {
    finishProcessingIfNecessary();

    if (out.annotates()) {
        annotateEntries("  ", null, out);
    }

    int tableSize = table.size();
    for (int i = 0; i < tableSize; i++) {
        CatchTable.Entry one = table.get(i);
        int start = one.getStart();
        int end = one.getEnd();
        int insnCount = end - start;

        if (insnCount >= 65536) {
            throw new UnsupportedOperationException(
                    "bogus exception range: " + Hex.u4(start) + ".." +
                    Hex.u4(end));
        }

        out.writeInt(start);
        out.writeShort(insnCount);
        out.writeShort(handlerOffsets.get(one.getHandlers()));
    }

    out.write(encodedHandlers);
}
 
Example 3
Source File: CodeObserver.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
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: 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 5
Source File: CstFloat.java    From buck with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public String toString() {
    int bits = getIntBits();
    return "float{0x" + Hex.u4(bits) + " / " +
        Float.intBitsToFloat(bits) + '}';
}
 
Example 6
Source File: CstFloat.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public String toString() {
    int bits = getIntBits();
    return "float{0x" + Hex.u4(bits) + " / " +
        Float.intBitsToFloat(bits) + '}';
}
 
Example 7
Source File: DalvInsn.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the short identifier for this instruction. This is its
 * address, if assigned, or its identity hashcode if not.
 *
 * @return {@code non-null;} the identifier
 */
public final String identifierString() {
    if (address != -1) {
        return String.format("%04x", address);
    }

    return Hex.u4(System.identityHashCode(this));
}
 
Example 8
Source File: CstFloat.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public String toString() {
    int bits = getIntBits();
    return "float{0x" + Hex.u4(bits) + " / " +
        Float.intBitsToFloat(bits) + '}';
}
 
Example 9
Source File: CatchStructs.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Writes this instance to the given stream.
 *
 * @param file {@code non-null;} file this instance is part of
 * @param out {@code non-null;} where to write to
 */
public void writeTo(DexFile file, AnnotatedOutput out) {
    finishProcessingIfNecessary();

    if (out.annotates()) {
        annotateEntries("  ", null, out);
    }

    int tableSize = table.size();
    for (int i = 0; i < tableSize; i++) {
        CatchTable.Entry one = table.get(i);
        int start = one.getStart();
        int end = one.getEnd();
        int insnCount = end - start;

        if (insnCount >= 65536) {
            throw new UnsupportedOperationException(
                    "bogus exception range: " + Hex.u4(start) + ".." +
                    Hex.u4(end));
        }

        out.writeInt(start);
        out.writeShort(insnCount);
        out.writeShort(handlerOffsets.get(one.getHandlers()));
    }

    out.write(encodedHandlers);
}
 
Example 10
Source File: CstInteger.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public String toString() {
    int value = getIntBits();
    return "int{0x" + Hex.u4(value) + " / " + value + '}';
}
 
Example 11
Source File: CstInteger.java    From Box with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public String toString() {
    int value = getIntBits();
    return "int{0x" + Hex.u4(value) + " / " + value + '}';
}
 
Example 12
Source File: CstInteger.java    From buck with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public String toString() {
    int value = getIntBits();
    return "int{0x" + Hex.u4(value) + " / " + value + '}';
}
 
Example 13
Source File: InsnFormat.java    From Box with Apache License 2.0 3 votes vote down vote up
/**
 * Helper method to return a branch address string.
 *
 * @param insn {@code non-null;} the instruction in question
 * @return {@code non-null;} the string form of the instruction's
 * branch target
 */
protected static String branchString(DalvInsn insn) {
    TargetInsn ti = (TargetInsn) insn;
    int address = ti.getTargetAddress();

    return (address == (char) address) ? Hex.u2(address) : Hex.u4(address);
}
 
Example 14
Source File: CodeObserver.java    From J2ME-Loader with Apache License 2.0 3 votes vote down vote up
/**
 * Helper for {@link #visitConstant} where the constant is a
 * {@code float}.
 *
 * @param opcode the opcode
 * @param offset offset to the instruction
 * @param length instruction length
 * @param bits constant value, as float-bits
 */
private void visitLiteralFloat(int opcode, int offset, int length,
        int bits) {
    String optArg = (length != 1) ? " #" + Hex.u4(bits) : "";

    observer.parsed(bytes, offset, length,
                    header(offset) + optArg + " // " +
                    Float.intBitsToFloat(bits));
}
 
Example 15
Source File: CodeObserver.java    From Box with Apache License 2.0 3 votes vote down vote up
/**
 * Helper for {@link #visitConstant} where the constant is a
 * {@code float}.
 *
 * @param opcode the opcode
 * @param offset offset to the instruction
 * @param length instruction length
 * @param bits constant value, as float-bits
 */
private void visitLiteralFloat(int opcode, int offset, int length,
        int bits) {
    String optArg = (length != 1) ? " #" + Hex.u4(bits) : "";

    observer.parsed(bytes, offset, length,
                    header(offset) + optArg + " // " +
                    Float.intBitsToFloat(bits));
}
 
Example 16
Source File: CodeObserver.java    From buck with Apache License 2.0 3 votes vote down vote up
/**
 * Helper for {@link #visitConstant} where the constant is a
 * {@code float}.
 *
 * @param opcode the opcode
 * @param offset offset to the instruction
 * @param length instruction length
 * @param bits constant value, as float-bits
 */
private void visitLiteralFloat(int opcode, int offset, int length,
        int bits) {
    String optArg = (length != 1) ? " #" + Hex.u4(bits) : "";

    observer.parsed(bytes, offset, length,
                    header(offset) + optArg + " // " +
                    Float.intBitsToFloat(bits));
}
 
Example 17
Source File: CodeObserver.java    From Box with Apache License 2.0 3 votes vote down vote up
/**
 * Helper for {@link #visitConstant} where the constant is a
 * {@code float}.
 *
 * @param opcode the opcode
 * @param offset offset to the instruction
 * @param length instruction length
 * @param bits constant value, as float-bits
 */
private void visitLiteralFloat(int opcode, int offset, int length,
        int bits) {
    String optArg = (length != 1) ? " #" + Hex.u4(bits) : "";

    observer.parsed(bytes, offset, length,
                    header(offset) + optArg + " // " +
                    Float.intBitsToFloat(bits));
}
 
Example 18
Source File: InsnFormat.java    From Box with Apache License 2.0 3 votes vote down vote up
/**
 * Helper method to return a branch address string.
 *
 * @param insn {@code non-null;} the instruction in question
 * @return {@code non-null;} the string form of the instruction's
 * branch target
 */
protected static String branchString(DalvInsn insn) {
    TargetInsn ti = (TargetInsn) insn;
    int address = ti.getTargetAddress();

    return (address == (char) address) ? Hex.u2(address) : Hex.u4(address);
}
 
Example 19
Source File: StdAttributeFactory.java    From Box with Apache License 2.0 2 votes vote down vote up
/**
 * Throws the right exception when an attribute has an unexpected length
 * (given its contents).
 *
 * @param expected expected length
 * @return never
 * @throws ParseException always thrown
 */
private static Attribute throwBadLength(int expected) {
    throw new ParseException("bad attribute length; expected length " +
                             Hex.u4(expected));
}
 
Example 20
Source File: CstString.java    From Box with Apache License 2.0 2 votes vote down vote up
/**
 * Helper for {@link #utf8BytesToString}, which throws the right
 * exception for a bogus utf-8 byte.
 *
 * @param value the byte value
 * @param offset the file offset
 * @return never
 * @throws IllegalArgumentException always thrown
 */
private static String throwBadUtf8(int value, int offset) {
    throw new IllegalArgumentException("bad utf-8 byte " + Hex.u1(value) +
                                       " at offset " + Hex.u4(offset));
}