Search in sources :

Example 11 with Attribute

use of com.android.dx.cf.iface.Attribute in project J2ME-Loader by nikita36078.

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)

Example 12 with Attribute

use of com.android.dx.cf.iface.Attribute in project J2ME-Loader by nikita36078.

the class DirectClassFile method getSourceFile.

/**
 * {@inheritDoc}
 */
public CstString getSourceFile() {
    AttributeList attribs = getAttributes();
    Attribute attSf = attribs.findFirst(AttSourceFile.ATTRIBUTE_NAME);
    if (attSf instanceof AttSourceFile) {
        return ((AttSourceFile) attSf).getSourceFile();
    }
    return null;
}
Also used : Attribute(com.android.dx.cf.iface.Attribute) StdAttributeList(com.android.dx.cf.iface.StdAttributeList) AttributeList(com.android.dx.cf.iface.AttributeList) AttSourceFile(com.android.dx.cf.attrib.AttSourceFile)

Example 13 with Attribute

use of com.android.dx.cf.iface.Attribute in project J2ME-Loader by nikita36078.

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 14 with Attribute

use of com.android.dx.cf.iface.Attribute in project J2ME-Loader by nikita36078.

the class StdAttributeFactory method constantValue.

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

Example 15 with Attribute

use of com.android.dx.cf.iface.Attribute in project J2ME-Loader by nikita36078.

the class StdAttributeFactory method sourceDebugExtension.

/**
 * Parses a {@code SourceDebugExtesion} attribute.
 */
private Attribute sourceDebugExtension(DirectClassFile cf, int offset, int length, ParseObserver observer) {
    ByteArray bytes = cf.getBytes().slice(offset, offset + length);
    CstString smapString = new CstString(bytes);
    Attribute result = new AttSourceDebugExtension(smapString);
    if (observer != null) {
        String decoded = smapString.getString();
        observer.parsed(bytes, offset, length, "sourceDebugExtension: " + decoded);
    }
    return result;
}
Also used : Attribute(com.android.dx.cf.iface.Attribute) CstString(com.android.dx.rop.cst.CstString) ByteArray(com.android.dx.util.ByteArray) AttSourceDebugExtension(com.android.dx.cf.attrib.AttSourceDebugExtension) CstString(com.android.dx.rop.cst.CstString)

Aggregations

Attribute (com.android.dx.cf.iface.Attribute)16 ByteArray (com.android.dx.util.ByteArray)14 ConstantPool (com.android.dx.rop.cst.ConstantPool)10 CstString (com.android.dx.rop.cst.CstString)5 AttSourceFile (com.android.dx.cf.attrib.AttSourceFile)4 AttributeList (com.android.dx.cf.iface.AttributeList)3 AttConstantValue (com.android.dx.cf.attrib.AttConstantValue)2 AttEnclosingMethod (com.android.dx.cf.attrib.AttEnclosingMethod)2 AttSignature (com.android.dx.cf.attrib.AttSignature)2 RawAttribute (com.android.dx.cf.attrib.RawAttribute)2 ParseException (com.android.dx.cf.iface.ParseException)2 StdAttributeList (com.android.dx.cf.iface.StdAttributeList)2 CstNat (com.android.dx.rop.cst.CstNat)2 CstType (com.android.dx.rop.cst.CstType)2 TypedConstant (com.android.dx.rop.cst.TypedConstant)2 AttSourceDebugExtension (com.android.dx.cf.attrib.AttSourceDebugExtension)1 BaseAnnotations (com.android.dx.cf.attrib.BaseAnnotations)1 ClassPathOpener (com.android.dx.cf.direct.ClassPathOpener)1 DirectClassFile (com.android.dx.cf.direct.DirectClassFile)1 File (java.io.File)1