Search in sources :

Example 1 with LocalVariableList

use of com.android.dx.cf.code.LocalVariableList in project buck by facebook.

the class StdAttributeFactory method localVariableTable.

/**
     * Parses a {@code LocalVariableTable} attribute.
     */
private Attribute localVariableTable(DirectClassFile cf, int offset, int length, ParseObserver observer) {
    if (length < 2) {
        return throwSeverelyTruncated();
    }
    ByteArray bytes = cf.getBytes();
    int count = bytes.getUnsignedShort(offset);
    if (observer != null) {
        observer.parsed(bytes, offset, 2, "local_variable_table_length: " + Hex.u2(count));
    }
    LocalVariableList list = parseLocalVariables(bytes.slice(offset + 2, offset + length), cf.getConstantPool(), observer, count, false);
    return new AttLocalVariableTable(list);
}
Also used : LocalVariableList(com.android.dx.cf.code.LocalVariableList) ByteArray(com.android.dx.util.ByteArray) AttLocalVariableTable(com.android.dx.cf.attrib.AttLocalVariableTable)

Example 2 with LocalVariableList

use of com.android.dx.cf.code.LocalVariableList in project J2ME-Loader by nikita36078.

the class StdAttributeFactory method parseLocalVariables.

/**
 * 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;
}
Also used : LocalVariableList(com.android.dx.cf.code.LocalVariableList) CstString(com.android.dx.rop.cst.CstString) ByteArray(com.android.dx.util.ByteArray) IOException(java.io.IOException)

Example 3 with LocalVariableList

use of com.android.dx.cf.code.LocalVariableList in project buck by facebook.

the class StdAttributeFactory method parseLocalVariables.

/**
     * 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;
}
Also used : LocalVariableList(com.android.dx.cf.code.LocalVariableList) CstString(com.android.dx.rop.cst.CstString) ByteArray(com.android.dx.util.ByteArray) IOException(java.io.IOException)

Example 4 with LocalVariableList

use of com.android.dx.cf.code.LocalVariableList in project buck by facebook.

the class StdAttributeFactory method localVariableTypeTable.

/**
     * Parses a {@code LocalVariableTypeTable} attribute.
     */
private Attribute localVariableTypeTable(DirectClassFile cf, int offset, int length, ParseObserver observer) {
    if (length < 2) {
        return throwSeverelyTruncated();
    }
    ByteArray bytes = cf.getBytes();
    int count = bytes.getUnsignedShort(offset);
    if (observer != null) {
        observer.parsed(bytes, offset, 2, "local_variable_type_table_length: " + Hex.u2(count));
    }
    LocalVariableList list = parseLocalVariables(bytes.slice(offset + 2, offset + length), cf.getConstantPool(), observer, count, true);
    return new AttLocalVariableTypeTable(list);
}
Also used : LocalVariableList(com.android.dx.cf.code.LocalVariableList) AttLocalVariableTypeTable(com.android.dx.cf.attrib.AttLocalVariableTypeTable) ByteArray(com.android.dx.util.ByteArray)

Example 5 with LocalVariableList

use of com.android.dx.cf.code.LocalVariableList in project J2ME-Loader by nikita36078.

the class StdAttributeFactory method localVariableTypeTable.

/**
 * Parses a {@code LocalVariableTypeTable} attribute.
 */
private Attribute localVariableTypeTable(DirectClassFile cf, int offset, int length, ParseObserver observer) {
    if (length < 2) {
        return throwSeverelyTruncated();
    }
    ByteArray bytes = cf.getBytes();
    int count = bytes.getUnsignedShort(offset);
    if (observer != null) {
        observer.parsed(bytes, offset, 2, "local_variable_type_table_length: " + Hex.u2(count));
    }
    LocalVariableList list = parseLocalVariables(bytes.slice(offset + 2, offset + length), cf.getConstantPool(), observer, count, true);
    return new AttLocalVariableTypeTable(list);
}
Also used : LocalVariableList(com.android.dx.cf.code.LocalVariableList) AttLocalVariableTypeTable(com.android.dx.cf.attrib.AttLocalVariableTypeTable) ByteArray(com.android.dx.util.ByteArray)

Aggregations

LocalVariableList (com.android.dx.cf.code.LocalVariableList)6 ByteArray (com.android.dx.util.ByteArray)6 AttLocalVariableTable (com.android.dx.cf.attrib.AttLocalVariableTable)2 AttLocalVariableTypeTable (com.android.dx.cf.attrib.AttLocalVariableTypeTable)2 CstString (com.android.dx.rop.cst.CstString)2 IOException (java.io.IOException)2