Search in sources :

Example 16 with CstString

use of com.android.dx.rop.cst.CstString 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 17 with CstString

use of com.android.dx.rop.cst.CstString in project buck by facebook.

the class Main method computeReferencedResources.

private void computeReferencedResources() {
    for (Item genericItem : outputDex.getFieldIds().items()) {
        FieldIdItem item = (FieldIdItem) genericItem;
        CstType fieldClass = item.getDefiningClass();
        CstString fieldName = item.getRef().getNat().getName();
        if (fieldClass.getClassType().getDescriptor().contains("/R$")) {
            // Add the packageName of the class for better accuracy.
            resourceNames.add(fieldClass.getPackageName() + "." + fieldName.getString());
        }
    }
}
Also used : Item(com.android.dx.dex.file.Item) FieldIdItem(com.android.dx.dex.file.FieldIdItem) ClassDefItem(com.android.dx.dex.file.ClassDefItem) FieldIdItem(com.android.dx.dex.file.FieldIdItem) CstType(com.android.dx.rop.cst.CstType) CstString(com.android.dx.rop.cst.CstString)

Example 18 with CstString

use of com.android.dx.rop.cst.CstString in project buck by facebook.

the class MemberListParser method parse.

/**
     * Does the actual parsing.
     */
private void parse() {
    int attributeContext = getAttributeContext();
    int count = getCount();
    // Skip the count.
    int at = offset + 2;
    ByteArray bytes = cf.getBytes();
    ConstantPool pool = cf.getConstantPool();
    if (observer != null) {
        observer.parsed(bytes, offset, 2, humanName() + "s_count: " + Hex.u2(count));
    }
    for (int i = 0; i < count; i++) {
        try {
            int accessFlags = bytes.getUnsignedShort(at);
            int nameIdx = bytes.getUnsignedShort(at + 2);
            int descIdx = bytes.getUnsignedShort(at + 4);
            CstString name = (CstString) pool.get(nameIdx);
            CstString desc = (CstString) pool.get(descIdx);
            if (observer != null) {
                observer.startParsingMember(bytes, at, name.getString(), desc.getString());
                observer.parsed(bytes, at, 0, "\n" + humanName() + "s[" + i + "]:\n");
                observer.changeIndent(1);
                observer.parsed(bytes, at, 2, "access_flags: " + humanAccessFlags(accessFlags));
                observer.parsed(bytes, at + 2, 2, "name: " + name.toHuman());
                observer.parsed(bytes, at + 4, 2, "descriptor: " + desc.toHuman());
            }
            at += 6;
            AttributeListParser parser = new AttributeListParser(cf, attributeContext, at, attributeFactory);
            parser.setObserver(observer);
            at = parser.getEndOffset();
            StdAttributeList attributes = parser.getList();
            attributes.setImmutable();
            CstNat nat = new CstNat(name, desc);
            Member member = set(i, accessFlags, nat, attributes);
            if (observer != null) {
                observer.changeIndent(-1);
                observer.parsed(bytes, at, 0, "end " + humanName() + "s[" + i + "]\n");
                observer.endParsingMember(bytes, at, name.getString(), desc.getString(), member);
            }
        } catch (ParseException ex) {
            ex.addContext("...while parsing " + humanName() + "s[" + i + "]");
            throw ex;
        } catch (RuntimeException ex) {
            ParseException pe = new ParseException(ex);
            pe.addContext("...while parsing " + humanName() + "s[" + i + "]");
            throw pe;
        }
    }
    endOffset = at;
}
Also used : StdAttributeList(com.android.dx.cf.iface.StdAttributeList) CstNat(com.android.dx.rop.cst.CstNat) ConstantPool(com.android.dx.rop.cst.ConstantPool) CstString(com.android.dx.rop.cst.CstString) ByteArray(com.android.dx.util.ByteArray) ParseException(com.android.dx.cf.iface.ParseException) Member(com.android.dx.cf.iface.Member)

Example 19 with CstString

use of com.android.dx.rop.cst.CstString in project buck by facebook.

the class StdAttributeFactory method sourceFile.

/**
     * Parses a {@code SourceFile} attribute.
     */
private Attribute sourceFile(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 AttSourceFile(cst);
    if (observer != null) {
        observer.parsed(bytes, offset, 2, "source: " + cst);
    }
    return result;
}
Also used : Attribute(com.android.dx.cf.iface.Attribute) ConstantPool(com.android.dx.rop.cst.ConstantPool) CstString(com.android.dx.rop.cst.CstString) AttSourceFile(com.android.dx.cf.attrib.AttSourceFile) ByteArray(com.android.dx.util.ByteArray)

Example 20 with CstString

use of com.android.dx.rop.cst.CstString in project buck by facebook.

the class Annotation method add.

/**
     * Add an element to the set of (name, value) pairs for this instance.
     * It is an error to call this method if there is a preexisting element
     * with the same name.
     *
     * @param pair {@code non-null;} the (name, value) pair to add to this instance
     */
public void add(NameValuePair pair) {
    throwIfImmutable();
    if (pair == null) {
        throw new NullPointerException("pair == null");
    }
    CstString name = pair.getName();
    if (elements.get(name) != null) {
        throw new IllegalArgumentException("name already added: " + name);
    }
    elements.put(name, pair);
}
Also used : CstString(com.android.dx.rop.cst.CstString)

Aggregations

CstString (com.android.dx.rop.cst.CstString)35 CstType (com.android.dx.rop.cst.CstType)15 Constant (com.android.dx.rop.cst.Constant)13 ByteArray (com.android.dx.util.ByteArray)7 ConstantPool (com.android.dx.rop.cst.ConstantPool)6 ParseException (com.android.dx.cf.iface.ParseException)5 NameValuePair (com.android.dx.rop.annotation.NameValuePair)5 RegisterSpec (com.android.dx.rop.code.RegisterSpec)5 CstFieldRef (com.android.dx.rop.cst.CstFieldRef)5 CstNat (com.android.dx.rop.cst.CstNat)5 Annotation (com.android.dx.rop.annotation.Annotation)4 Type (com.android.dx.rop.type.Type)4 ClassDefItem (com.android.dx.dex.file.ClassDefItem)3 CstAnnotation (com.android.dx.rop.cst.CstAnnotation)3 CstMethodRef (com.android.dx.rop.cst.CstMethodRef)3 Attribute (com.android.dx.cf.iface.Attribute)2 CstInsn (com.android.dx.dex.code.CstInsn)2 Annotations (com.android.dx.rop.annotation.Annotations)2 AnnotationsList (com.android.dx.rop.annotation.AnnotationsList)2 LocalItem (com.android.dx.rop.code.LocalItem)2