Search in sources :

Example 6 with ByteArray

use of com.taobao.android.dx.util.ByteArray in project atlas by alibaba.

the class ClassDumper method dump.

/**
     * Does the dumping.
     */
public void dump() {
    byte[] bytes = getBytes();
    ByteArray ba = new ByteArray(bytes);
    DirectClassFile cf = new DirectClassFile(ba, getFilePath(), getStrictParse());
    cf.setAttributeFactory(StdAttributeFactory.THE_ONE);
    cf.setObserver(this);
    // Force parsing to happen.
    cf.getMagic();
    int at = getAt();
    if (at != bytes.length) {
        parsed(ba, at, bytes.length - at, "<extra data at end of file>");
    }
}
Also used : DirectClassFile(com.taobao.android.dx.cf.direct.DirectClassFile) ByteArray(com.taobao.android.dx.util.ByteArray)

Example 7 with ByteArray

use of com.taobao.android.dx.util.ByteArray in project atlas by alibaba.

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.taobao.android.dx.rop.cst.TypedConstant) Attribute(com.taobao.android.dx.cf.iface.Attribute) ConstantPool(com.taobao.android.dx.rop.cst.ConstantPool) ByteArray(com.taobao.android.dx.util.ByteArray) AttConstantValue(com.taobao.android.dx.cf.attrib.AttConstantValue)

Example 8 with ByteArray

use of com.taobao.android.dx.util.ByteArray in project atlas by alibaba.

the class StdAttributeFactory method innerClasses.

/**
     * Parses an {@code InnerClasses} attribute.
     */
private Attribute innerClasses(DirectClassFile cf, int offset, int length, ParseObserver observer) {
    if (length < 2) {
        return throwSeverelyTruncated();
    }
    ByteArray bytes = cf.getBytes();
    ConstantPool pool = cf.getConstantPool();
    // number_of_classes
    int count = bytes.getUnsignedShort(offset);
    if (observer != null) {
        observer.parsed(bytes, offset, 2, "number_of_classes: " + Hex.u2(count));
    }
    offset += 2;
    length -= 2;
    if (length != (count * 8)) {
        throwBadLength((count * 8) + 2);
    }
    InnerClassList list = new InnerClassList(count);
    for (int i = 0; i < count; i++) {
        int innerClassIdx = bytes.getUnsignedShort(offset);
        int outerClassIdx = bytes.getUnsignedShort(offset + 2);
        int nameIdx = bytes.getUnsignedShort(offset + 4);
        int accessFlags = bytes.getUnsignedShort(offset + 6);
        CstType innerClass = (CstType) pool.get(innerClassIdx);
        CstType outerClass = (CstType) pool.get0Ok(outerClassIdx);
        CstString name = (CstString) pool.get0Ok(nameIdx);
        list.set(i, innerClass, outerClass, name, accessFlags);
        if (observer != null) {
            observer.parsed(bytes, offset, 2, "inner_class: " + DirectClassFile.stringOrNone(innerClass));
            observer.parsed(bytes, offset + 2, 2, "  outer_class: " + DirectClassFile.stringOrNone(outerClass));
            observer.parsed(bytes, offset + 4, 2, "  name: " + DirectClassFile.stringOrNone(name));
            observer.parsed(bytes, offset + 6, 2, "  access_flags: " + AccessFlags.innerClassString(accessFlags));
        }
        offset += 8;
    }
    list.setImmutable();
    return new AttInnerClasses(list);
}
Also used : ConstantPool(com.taobao.android.dx.rop.cst.ConstantPool) CstType(com.taobao.android.dx.rop.cst.CstType) CstString(com.taobao.android.dx.rop.cst.CstString) ByteArray(com.taobao.android.dx.util.ByteArray) InnerClassList(com.taobao.android.dx.cf.attrib.InnerClassList) AttInnerClasses(com.taobao.android.dx.cf.attrib.AttInnerClasses)

Example 9 with ByteArray

use of com.taobao.android.dx.util.ByteArray in project atlas by alibaba.

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.taobao.android.dx.rop.cst.CstNat) AttEnclosingMethod(com.taobao.android.dx.cf.attrib.AttEnclosingMethod) Attribute(com.taobao.android.dx.cf.iface.Attribute) ConstantPool(com.taobao.android.dx.rop.cst.ConstantPool) CstType(com.taobao.android.dx.rop.cst.CstType) ByteArray(com.taobao.android.dx.util.ByteArray)

Example 10 with ByteArray

use of com.taobao.android.dx.util.ByteArray in project atlas by alibaba.

the class StdAttributeFactory method exceptions.

/**
     * Parses an {@code Exceptions} attribute.
     */
private Attribute exceptions(DirectClassFile cf, int offset, int length, ParseObserver observer) {
    if (length < 2) {
        return throwSeverelyTruncated();
    }
    ByteArray bytes = cf.getBytes();
    // number_of_exceptions
    int count = bytes.getUnsignedShort(offset);
    if (observer != null) {
        observer.parsed(bytes, offset, 2, "number_of_exceptions: " + Hex.u2(count));
    }
    offset += 2;
    length -= 2;
    if (length != (count * 2)) {
        throwBadLength((count * 2) + 2);
    }
    TypeList list = cf.makeTypeList(offset, count);
    return new AttExceptions(list);
}
Also used : AttExceptions(com.taobao.android.dx.cf.attrib.AttExceptions) ByteArray(com.taobao.android.dx.util.ByteArray) TypeList(com.taobao.android.dx.rop.type.TypeList)

Aggregations

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