Java Code Examples for com.android.dx.util.ByteArray#size()

The following examples show how to use com.android.dx.util.ByteArray#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: StdAttributeFactory.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Parse the table part of either a {@code LocalVariableTable}
 * or a {@code LocalVariableTypeTable}.
 *
 * @param bytes {@code non-null;} bytes to parse, which should <i>only</i>
 * contain the table data (no header)
 * @param pool {@code non-null;} constant pool to use
 * @param count {@code >= 0;} the number of entries
 * @param typeTable {@code true} iff this is for a type table
 * @return {@code non-null;} the constructed list
 */
private LocalVariableList parseLocalVariables(ByteArray bytes,
        ConstantPool pool, ParseObserver observer, int count,
        boolean typeTable) {
    if (bytes.size() != (count * 10)) {
        // "+ 2" is for the count.
        throwBadLength((count * 10) + 2);
    }

    ByteArray.MyDataInputStream in = bytes.makeDataInputStream();
    LocalVariableList list = new LocalVariableList(count);

    try {
        for (int i = 0; i < count; i++) {
            int startPc = in.readUnsignedShort();
            int length = in.readUnsignedShort();
            int nameIdx = in.readUnsignedShort();
            int typeIdx = in.readUnsignedShort();
            int index = in.readUnsignedShort();
            CstString name = (CstString) pool.get(nameIdx);
            CstString type = (CstString) pool.get(typeIdx);
            CstString descriptor = null;
            CstString signature = null;

            if (typeTable) {
                signature = type;
            } else {
                descriptor = type;
            }

            list.set(i, startPc, length, name,
                    descriptor, signature, index);

            if (observer != null) {
                observer.parsed(bytes, i * 10, 10, Hex.u2(startPc) +
                        ".." + Hex.u2(startPc + length) + " " +
                        Hex.u2(index) + " " + name.toHuman() + " " +
                        type.toHuman());
            }
        }
    } catch (IOException ex) {
        throw new RuntimeException("shouldn't happen", ex);
    }

    list.setImmutable();
    return list;
}
 
Example 2
Source File: StdAttributeFactory.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Parse the table part of either a {@code LocalVariableTable}
 * or a {@code LocalVariableTypeTable}.
 *
 * @param bytes {@code non-null;} bytes to parse, which should <i>only</i>
 * contain the table data (no header)
 * @param pool {@code non-null;} constant pool to use
 * @param count {@code >= 0;} the number of entries
 * @param typeTable {@code true} iff this is for a type table
 * @return {@code non-null;} the constructed list
 */
private LocalVariableList parseLocalVariables(ByteArray bytes,
        ConstantPool pool, ParseObserver observer, int count,
        boolean typeTable) {
    if (bytes.size() != (count * 10)) {
        // "+ 2" is for the count.
        throwBadLength((count * 10) + 2);
    }

    ByteArray.MyDataInputStream in = bytes.makeDataInputStream();
    LocalVariableList list = new LocalVariableList(count);

    try {
        for (int i = 0; i < count; i++) {
            int startPc = in.readUnsignedShort();
            int length = in.readUnsignedShort();
            int nameIdx = in.readUnsignedShort();
            int typeIdx = in.readUnsignedShort();
            int index = in.readUnsignedShort();
            CstString name = (CstString) pool.get(nameIdx);
            CstString type = (CstString) pool.get(typeIdx);
            CstString descriptor = null;
            CstString signature = null;

            if (typeTable) {
                signature = type;
            } else {
                descriptor = type;
            }

            list.set(i, startPc, length, name,
                    descriptor, signature, index);

            if (observer != null) {
                observer.parsed(bytes, i * 10, 10, Hex.u2(startPc) +
                        ".." + Hex.u2(startPc + length) + " " +
                        Hex.u2(index) + " " + name.toHuman() + " " +
                        type.toHuman());
            }
        }
    } catch (IOException ex) {
        throw new RuntimeException("shouldn't happen", ex);
    }

    list.setImmutable();
    return list;
}
 
Example 3
Source File: StdAttributeFactory.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
/**
 * Parse the table part of either a {@code LocalVariableTable}
 * or a {@code LocalVariableTypeTable}.
 *
 * @param bytes {@code non-null;} bytes to parse, which should <i>only</i>
 * contain the table data (no header)
 * @param pool {@code non-null;} constant pool to use
 * @param count {@code >= 0;} the number of entries
 * @param typeTable {@code true} iff this is for a type table
 * @return {@code non-null;} the constructed list
 */
private LocalVariableList parseLocalVariables(ByteArray bytes,
        ConstantPool pool, ParseObserver observer, int count,
        boolean typeTable) {
    if (bytes.size() != (count * 10)) {
        // "+ 2" is for the count.
        throwBadLength((count * 10) + 2);
    }

    ByteArray.MyDataInputStream in = bytes.makeDataInputStream();
    LocalVariableList list = new LocalVariableList(count);

    try {
        for (int i = 0; i < count; i++) {
            int startPc = in.readUnsignedShort();
            int length = in.readUnsignedShort();
            int nameIdx = in.readUnsignedShort();
            int typeIdx = in.readUnsignedShort();
            int index = in.readUnsignedShort();
            CstString name = (CstString) pool.get(nameIdx);
            CstString type = (CstString) pool.get(typeIdx);
            CstString descriptor = null;
            CstString signature = null;

            if (typeTable) {
                signature = type;
            } else {
                descriptor = type;
            }

            list.set(i, startPc, length, name,
                    descriptor, signature, index);

            if (observer != null) {
                observer.parsed(bytes, i * 10, 10, Hex.u2(startPc) +
                        ".." + Hex.u2(startPc + length) + " " +
                        Hex.u2(index) + " " + name.toHuman() + " " +
                        type.toHuman());
            }
        }
    } catch (IOException ex) {
        throw new RuntimeException("shouldn't happen", ex);
    }

    list.setImmutable();
    return list;
}
 
Example 4
Source File: StdAttributeFactory.java    From buck with Apache License 2.0 4 votes vote down vote up
/**
 * Parse the table part of either a {@code LocalVariableTable}
 * or a {@code LocalVariableTypeTable}.
 *
 * @param bytes {@code non-null;} bytes to parse, which should <i>only</i>
 * contain the table data (no header)
 * @param pool {@code non-null;} constant pool to use
 * @param count {@code >= 0;} the number of entries
 * @param typeTable {@code true} iff this is for a type table
 * @return {@code non-null;} the constructed list
 */
private LocalVariableList parseLocalVariables(ByteArray bytes,
        ConstantPool pool, ParseObserver observer, int count,
        boolean typeTable) {
    if (bytes.size() != (count * 10)) {
        // "+ 2" is for the count.
        throwBadLength((count * 10) + 2);
    }

    ByteArray.MyDataInputStream in = bytes.makeDataInputStream();
    LocalVariableList list = new LocalVariableList(count);

    try {
        for (int i = 0; i < count; i++) {
            int startPc = in.readUnsignedShort();
            int length = in.readUnsignedShort();
            int nameIdx = in.readUnsignedShort();
            int typeIdx = in.readUnsignedShort();
            int index = in.readUnsignedShort();
            CstString name = (CstString) pool.get(nameIdx);
            CstString type = (CstString) pool.get(typeIdx);
            CstString descriptor = null;
            CstString signature = null;

            if (typeTable) {
                signature = type;
            } else {
                descriptor = type;
            }

            list.set(i, startPc, length, name,
                    descriptor, signature, index);

            if (observer != null) {
                observer.parsed(bytes, i * 10, 10, Hex.u2(startPc) +
                        ".." + Hex.u2(startPc + length) + " " +
                        Hex.u2(index) + " " + name.toHuman() + " " +
                        type.toHuman());
            }
        }
    } catch (IOException ex) {
        throw new RuntimeException("shouldn't happen", ex);
    }

    list.setImmutable();
    return list;
}