Search in sources :

Example 31 with ByteArray

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

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 32 with ByteArray

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

the class DotDumper method run.

private void run() {
    ByteArray ba = new ByteArray(bytes);
    /*
         * First, parse the file completely, so we can safely refer to
         * attributes, etc.
         */
    classFile = new DirectClassFile(ba, filePath, strictParse);
    classFile.setAttributeFactory(StdAttributeFactory.THE_ONE);
    // Force parsing to happen.
    classFile.getMagic();
    // Next, reparse it and observe the process.
    DirectClassFile liveCf = new DirectClassFile(ba, filePath, strictParse);
    liveCf.setAttributeFactory(StdAttributeFactory.THE_ONE);
    liveCf.setObserver(this);
    // Force parsing to happen.
    liveCf.getMagic();
}
Also used : DirectClassFile(com.android.dx.cf.direct.DirectClassFile) ByteArray(com.android.dx.util.ByteArray)

Example 33 with ByteArray

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

the class ConstantPoolParser method parseUtf8.

/**
     * Parses a utf8 constant.
     *
     * @param at offset to the start of the constant (where the tag byte is)
     * @return {@code non-null;} the parsed value
     */
private CstString parseUtf8(int at) {
    int length = bytes.getUnsignedShort(at + 1);
    // Skip to the data.
    at += 3;
    ByteArray ubytes = bytes.slice(at, at + length);
    try {
        return new CstString(ubytes);
    } catch (IllegalArgumentException ex) {
        // Translate the exception
        throw new ParseException(ex);
    }
}
Also used : CstString(com.android.dx.rop.cst.CstString) ByteArray(com.android.dx.util.ByteArray) ParseException(com.android.dx.cf.iface.ParseException)

Example 34 with ByteArray

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

the class StringDataItem method writeTo0.

/** {@inheritDoc} */
@Override
public void writeTo0(DexFile file, AnnotatedOutput out) {
    ByteArray bytes = value.getBytes();
    int utf16Size = value.getUtf16Size();
    if (out.annotates()) {
        out.annotate(Leb128.unsignedLeb128Size(utf16Size), "utf16_size: " + Hex.u4(utf16Size));
        out.annotate(bytes.size() + 1, value.toQuoted());
    }
    out.writeUleb128(utf16Size);
    out.write(bytes);
    out.writeByte(0);
}
Also used : ByteArray(com.android.dx.util.ByteArray)

Example 35 with ByteArray

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

Aggregations

ByteArray (com.android.dx.util.ByteArray)42 ConstantPool (com.android.dx.rop.cst.ConstantPool)18 CstString (com.android.dx.rop.cst.CstString)15 Attribute (com.android.dx.cf.iface.Attribute)14 ParseException (com.android.dx.cf.iface.ParseException)8 CstType (com.android.dx.rop.cst.CstType)7 LocalVariableList (com.android.dx.cf.code.LocalVariableList)6 DirectClassFile (com.android.dx.cf.direct.DirectClassFile)5 BytecodeArray (com.android.dx.cf.code.BytecodeArray)4 StdAttributeList (com.android.dx.cf.iface.StdAttributeList)4 CstNat (com.android.dx.rop.cst.CstNat)4 ByteCatchList (com.android.dx.cf.code.ByteCatchList)3 AttCode (com.android.dx.cf.attrib.AttCode)2 AttConstantValue (com.android.dx.cf.attrib.AttConstantValue)2 AttEnclosingMethod (com.android.dx.cf.attrib.AttEnclosingMethod)2 AttExceptions (com.android.dx.cf.attrib.AttExceptions)2 AttInnerClasses (com.android.dx.cf.attrib.AttInnerClasses)2 AttLineNumberTable (com.android.dx.cf.attrib.AttLineNumberTable)2 AttLocalVariableTable (com.android.dx.cf.attrib.AttLocalVariableTable)2 AttLocalVariableTypeTable (com.android.dx.cf.attrib.AttLocalVariableTypeTable)2