Search in sources :

Example 21 with CstString

use of com.taobao.android.dx.rop.cst.CstString in project atlas by alibaba.

the class TypeIdItem method writeTo.

/** {@inheritDoc} */
@Override
public void writeTo(DexFile file, AnnotatedOutput out) {
    CstType type = getDefiningClass();
    CstString descriptor = type.getDescriptor();
    int idx = file.getStringIds().indexOf(descriptor);
    if (out.annotates()) {
        out.annotate(0, indexString() + ' ' + descriptor.toHuman());
        out.annotate(4, "  descriptor_idx: " + Hex.u4(idx));
    }
    out.writeInt(idx);
}
Also used : CstType(com.taobao.android.dx.rop.cst.CstType) CstString(com.taobao.android.dx.rop.cst.CstString)

Example 22 with CstString

use of com.taobao.android.dx.rop.cst.CstString in project atlas by alibaba.

the class AnnotationItem method annotateTo.

/**
     * Write a (listing file) annotation for this instance to the given
     * output, that consumes no bytes of output. This is for annotating
     * a reference to this instance at the point of the reference.
     *
     * @param out {@code non-null;} where to output to
     * @param prefix {@code non-null;} prefix for each line of output
     */
public void annotateTo(AnnotatedOutput out, String prefix) {
    out.annotate(0, prefix + "visibility: " + annotation.getVisibility().toHuman());
    out.annotate(0, prefix + "type: " + annotation.getType().toHuman());
    for (NameValuePair pair : annotation.getNameValuePairs()) {
        CstString name = pair.getName();
        Constant value = pair.getValue();
        out.annotate(0, prefix + name.toHuman() + ": " + ValueEncoder.constantToHuman(value));
    }
}
Also used : NameValuePair(com.taobao.android.dx.rop.annotation.NameValuePair) Constant(com.taobao.android.dx.rop.cst.Constant) CstString(com.taobao.android.dx.rop.cst.CstString)

Example 23 with CstString

use of com.taobao.android.dx.rop.cst.CstString in project atlas by alibaba.

the class AnnotationUtils method makeSignature.

/**
     * Constructs a standard {@code Signature} annotation.
     *
     * @param signature {@code non-null;} the signature string
     * @return {@code non-null;} the annotation
     */
public static Annotation makeSignature(CstString signature) {
    Annotation result = new Annotation(SIGNATURE_TYPE, SYSTEM);
    /*
         * Split the string into pieces that are likely to be common
         * across many signatures and the rest of the file.
         */
    String raw = signature.getString();
    int rawLength = raw.length();
    ArrayList<String> pieces = new ArrayList<String>(20);
    for (int at = 0; at < rawLength; ) /*at*/
    {
        char c = raw.charAt(at);
        int endAt = at + 1;
        if (c == 'L') {
            // Scan to ';' or '<'. Consume ';' but not '<'.
            while (endAt < rawLength) {
                c = raw.charAt(endAt);
                if (c == ';') {
                    endAt++;
                    break;
                } else if (c == '<') {
                    break;
                }
                endAt++;
            }
        } else {
            // Scan to 'L' without consuming it.
            while (endAt < rawLength) {
                c = raw.charAt(endAt);
                if (c == 'L') {
                    break;
                }
                endAt++;
            }
        }
        pieces.add(raw.substring(at, endAt));
        at = endAt;
    }
    int size = pieces.size();
    CstArray.List list = new CstArray.List(size);
    for (int i = 0; i < size; i++) {
        list.set(i, new CstString(pieces.get(i)));
    }
    list.setImmutable();
    result.put(new NameValuePair(VALUE_STRING, new CstArray(list)));
    result.setImmutable();
    return result;
}
Also used : NameValuePair(com.taobao.android.dx.rop.annotation.NameValuePair) CstArray(com.taobao.android.dx.rop.cst.CstArray) ArrayList(java.util.ArrayList) CstString(com.taobao.android.dx.rop.cst.CstString) ArrayList(java.util.ArrayList) TypeList(com.taobao.android.dx.rop.type.TypeList) CstString(com.taobao.android.dx.rop.cst.CstString) Annotation(com.taobao.android.dx.rop.annotation.Annotation) CstAnnotation(com.taobao.android.dx.rop.cst.CstAnnotation)

Example 24 with CstString

use of com.taobao.android.dx.rop.cst.CstString in project atlas by alibaba.

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$")) {
            // We ignore the name of the containing class for simplicity.
            resourceNames.add(fieldName.getString());
        }
    }
}
Also used : Item(com.taobao.android.dx.dex.file.Item) ClassDefItem(com.taobao.android.dx.dex.file.ClassDefItem) FieldIdItem(com.taobao.android.dx.dex.file.FieldIdItem) FieldIdItem(com.taobao.android.dx.dex.file.FieldIdItem) CstType(com.taobao.android.dx.rop.cst.CstType) CstString(com.taobao.android.dx.rop.cst.CstString)

Example 25 with CstString

use of com.taobao.android.dx.rop.cst.CstString in project atlas by alibaba.

the class OutputFinisher method addConstants.

/**
     * Helper for {@link #getAllConstants} which adds all the info for
     * a single {@code RegisterSpec}.
     *
     * @param result {@code non-null;} result set to add to
     * @param spec {@code null-ok;} register spec to add
     */
private static void addConstants(HashSet<Constant> result, RegisterSpec spec) {
    if (spec == null) {
        return;
    }
    LocalItem local = spec.getLocalItem();
    CstString name = local.getName();
    CstString signature = local.getSignature();
    Type type = spec.getType();
    if (type != Type.KNOWN_NULL) {
        result.add(CstType.intern(type));
    }
    if (name != null) {
        result.add(name);
    }
    if (signature != null) {
        result.add(signature);
    }
}
Also used : CstType(com.taobao.android.dx.rop.cst.CstType) Type(com.taobao.android.dx.rop.type.Type) CstString(com.taobao.android.dx.rop.cst.CstString) LocalItem(com.taobao.android.dx.rop.code.LocalItem)

Aggregations

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