Search in sources :

Example 6 with ByteArray

use of com.android.dx.util.ByteArray in project buck by facebook.

the class StdAttributeFactory method enclosingMethod.

/**
     * Parses an {@code EnclosingMethod} attribute.
     */
private Attribute enclosingMethod(DirectClassFile cf, int offset, int length, ParseObserver observer) {
    if (length != 4) {
        throwBadLength(4);
    }
    ByteArray bytes = cf.getBytes();
    ConstantPool pool = cf.getConstantPool();
    int idx = bytes.getUnsignedShort(offset);
    CstType type = (CstType) pool.get(idx);
    idx = bytes.getUnsignedShort(offset + 2);
    CstNat method = (CstNat) pool.get0Ok(idx);
    Attribute result = new AttEnclosingMethod(type, method);
    if (observer != null) {
        observer.parsed(bytes, offset, 2, "class: " + type);
        observer.parsed(bytes, offset + 2, 2, "method: " + DirectClassFile.stringOrNone(method));
    }
    return result;
}
Also used : CstNat(com.android.dx.rop.cst.CstNat) AttEnclosingMethod(com.android.dx.cf.attrib.AttEnclosingMethod) Attribute(com.android.dx.cf.iface.Attribute) ConstantPool(com.android.dx.rop.cst.ConstantPool) CstType(com.android.dx.rop.cst.CstType) ByteArray(com.android.dx.util.ByteArray)

Example 7 with ByteArray

use of com.android.dx.util.ByteArray in project buck by facebook.

the class StdAttributeFactory method signature.

/**
     * Parses a {@code Signature} attribute.
     */
private Attribute signature(DirectClassFile cf, int offset, int length, ParseObserver observer) {
    if (length != 2) {
        throwBadLength(2);
    }
    ByteArray bytes = cf.getBytes();
    ConstantPool pool = cf.getConstantPool();
    int idx = bytes.getUnsignedShort(offset);
    CstString cst = (CstString) pool.get(idx);
    Attribute result = new AttSignature(cst);
    if (observer != null) {
        observer.parsed(bytes, offset, 2, "signature: " + cst);
    }
    return result;
}
Also used : Attribute(com.android.dx.cf.iface.Attribute) AttSignature(com.android.dx.cf.attrib.AttSignature) ConstantPool(com.android.dx.rop.cst.ConstantPool) CstString(com.android.dx.rop.cst.CstString) ByteArray(com.android.dx.util.ByteArray)

Example 8 with ByteArray

use of com.android.dx.util.ByteArray 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 9 with ByteArray

use of com.android.dx.util.ByteArray in project buck by facebook.

the class StdAttributeFactory method lineNumberTable.

/**
     * Parses a {@code LineNumberTable} attribute.
     */
private Attribute lineNumberTable(DirectClassFile cf, int offset, int length, ParseObserver observer) {
    if (length < 2) {
        return throwSeverelyTruncated();
    }
    ByteArray bytes = cf.getBytes();
    // line_number_table_length
    int count = bytes.getUnsignedShort(offset);
    if (observer != null) {
        observer.parsed(bytes, offset, 2, "line_number_table_length: " + Hex.u2(count));
    }
    offset += 2;
    length -= 2;
    if (length != (count * 4)) {
        throwBadLength((count * 4) + 2);
    }
    LineNumberList list = new LineNumberList(count);
    for (int i = 0; i < count; i++) {
        int startPc = bytes.getUnsignedShort(offset);
        int lineNumber = bytes.getUnsignedShort(offset + 2);
        list.set(i, startPc, lineNumber);
        if (observer != null) {
            observer.parsed(bytes, offset, 4, Hex.u2(startPc) + " " + lineNumber);
        }
        offset += 4;
    }
    list.setImmutable();
    return new AttLineNumberTable(list);
}
Also used : LineNumberList(com.android.dx.cf.code.LineNumberList) ByteArray(com.android.dx.util.ByteArray) AttLineNumberTable(com.android.dx.cf.attrib.AttLineNumberTable)

Example 10 with ByteArray

use of com.android.dx.util.ByteArray in project buck by facebook.

the class AttributeListParser method parse.

/**
     * Does the actual parsing.
     */
private void parse() {
    int sz = list.size();
    // Skip the count.
    int at = offset + 2;
    ByteArray bytes = cf.getBytes();
    if (observer != null) {
        observer.parsed(bytes, offset, 2, "attributes_count: " + Hex.u2(sz));
    }
    for (int i = 0; i < sz; i++) {
        try {
            if (observer != null) {
                observer.parsed(bytes, at, 0, "\nattributes[" + i + "]:\n");
                observer.changeIndent(1);
            }
            Attribute attrib = attributeFactory.parse(cf, context, at, observer);
            at += attrib.byteLength();
            list.set(i, attrib);
            if (observer != null) {
                observer.changeIndent(-1);
                observer.parsed(bytes, at, 0, "end attributes[" + i + "]\n");
            }
        } catch (ParseException ex) {
            ex.addContext("...while parsing attributes[" + i + "]");
            throw ex;
        } catch (RuntimeException ex) {
            ParseException pe = new ParseException(ex);
            pe.addContext("...while parsing attributes[" + i + "]");
            throw pe;
        }
    }
    endOffset = at;
}
Also used : Attribute(com.android.dx.cf.iface.Attribute) ByteArray(com.android.dx.util.ByteArray) ParseException(com.android.dx.cf.iface.ParseException)

Aggregations

ByteArray (com.android.dx.util.ByteArray)24 ConstantPool (com.android.dx.rop.cst.ConstantPool)9 Attribute (com.android.dx.cf.iface.Attribute)7 CstString (com.android.dx.rop.cst.CstString)7 DirectClassFile (com.android.dx.cf.direct.DirectClassFile)5 ParseException (com.android.dx.cf.iface.ParseException)4 CstType (com.android.dx.rop.cst.CstType)4 BytecodeArray (com.android.dx.cf.code.BytecodeArray)3 LocalVariableList (com.android.dx.cf.code.LocalVariableList)3 ByteCatchList (com.android.dx.cf.code.ByteCatchList)2 StdAttributeList (com.android.dx.cf.iface.StdAttributeList)2 CstNat (com.android.dx.rop.cst.CstNat)2 IntList (com.android.dx.util.IntList)2 AttCode (com.android.dx.cf.attrib.AttCode)1 AttConstantValue (com.android.dx.cf.attrib.AttConstantValue)1 AttEnclosingMethod (com.android.dx.cf.attrib.AttEnclosingMethod)1 AttExceptions (com.android.dx.cf.attrib.AttExceptions)1 AttInnerClasses (com.android.dx.cf.attrib.AttInnerClasses)1 AttLineNumberTable (com.android.dx.cf.attrib.AttLineNumberTable)1 AttLocalVariableTable (com.android.dx.cf.attrib.AttLocalVariableTable)1