Search in sources :

Example 11 with CstString

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

the class RegisterSpec method toString0.

/**
     * Helper for {@link #toString} and {@link #toHuman}.
     *
     * @param human whether to be human-oriented
     * @return {@code non-null;} the string form
     */
private String toString0(boolean human) {
    StringBuffer sb = new StringBuffer(40);
    sb.append(regString());
    sb.append(":");
    if (local != null) {
        sb.append(local.toString());
    }
    Type justType = type.getType();
    sb.append(justType);
    if (justType != type) {
        sb.append("=");
        if (human && (type instanceof CstString)) {
            sb.append(((CstString) type).toQuoted());
        } else if (human && (type instanceof Constant)) {
            sb.append(type.toHuman());
        } else {
            sb.append(type);
        }
    }
    return sb.toString();
}
Also used : Type(com.taobao.android.dx.rop.type.Type) Constant(com.taobao.android.dx.rop.cst.Constant) CstString(com.taobao.android.dx.rop.cst.CstString)

Example 12 with CstString

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

the class ThrowingCstInsn method getInlineString.

/** {@inheritDoc} */
@Override
public String getInlineString() {
    Constant cst = getConstant();
    String constantString = cst.toHuman();
    if (cst instanceof CstString) {
        constantString = ((CstString) cst).toQuoted();
    }
    return constantString + " " + ThrowingInsn.toCatchString(catches);
}
Also used : Constant(com.taobao.android.dx.rop.cst.Constant) CstString(com.taobao.android.dx.rop.cst.CstString) CstString(com.taobao.android.dx.rop.cst.CstString)

Example 13 with CstString

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

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.taobao.android.dx.rop.cst.CstString)

Example 14 with CstString

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

the class HeaderItem method writeTo.

/** {@inheritDoc} */
@Override
public void writeTo(DexFile file, AnnotatedOutput out) {
    int mapOff = file.getMap().getFileOffset();
    Section firstDataSection = file.getFirstDataSection();
    Section lastDataSection = file.getLastDataSection();
    int dataOff = firstDataSection.getFileOffset();
    int dataSize = lastDataSection.getFileOffset() + lastDataSection.writeSize() - dataOff;
    String magic = file.getDexOptions().getMagic();
    if (out.annotates()) {
        out.annotate(8, "magic: " + new CstString(magic).toQuoted());
        out.annotate(4, "checksum");
        out.annotate(20, "signature");
        out.annotate(4, "file_size:       " + Hex.u4(file.getFileSize()));
        out.annotate(4, "header_size:     " + Hex.u4(SizeOf.HEADER_ITEM));
        out.annotate(4, "endian_tag:      " + Hex.u4(DexFormat.ENDIAN_TAG));
        out.annotate(4, "link_size:       0");
        out.annotate(4, "link_off:        0");
        out.annotate(4, "map_off:         " + Hex.u4(mapOff));
    }
    // Write the magic number.
    for (int i = 0; i < 8; i++) {
        out.writeByte(magic.charAt(i));
    }
    // Leave space for the checksum and signature.
    out.writeZeroes(24);
    out.writeInt(file.getFileSize());
    out.writeInt(SizeOf.HEADER_ITEM);
    out.writeInt(DexFormat.ENDIAN_TAG);
    /*
         * Write zeroes for the link size and data, as the output
         * isn't a staticly linked file.
         */
    out.writeZeroes(8);
    out.writeInt(mapOff);
    // Write out each section's respective header part.
    file.getStringIds().writeHeaderPart(out);
    file.getTypeIds().writeHeaderPart(out);
    file.getProtoIds().writeHeaderPart(out);
    file.getFieldIds().writeHeaderPart(out);
    file.getMethodIds().writeHeaderPart(out);
    file.getClassDefs().writeHeaderPart(out);
    if (out.annotates()) {
        out.annotate(4, "data_size:       " + Hex.u4(dataSize));
        out.annotate(4, "data_off:        " + Hex.u4(dataOff));
    }
    out.writeInt(dataSize);
    out.writeInt(dataOff);
}
Also used : CstString(com.taobao.android.dx.rop.cst.CstString) CstString(com.taobao.android.dx.rop.cst.CstString)

Example 15 with CstString

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

the class ValueEncoder method writeAnnotation.

/**
     * Writes out the encoded form of the given annotation, that is,
     * as an {@code encoded_annotation} and not including a
     * {@code value_type} prefix. If the output stream keeps
     * (debugging) annotations and {@code topLevel} is
     * {@code true}, then this method will write (debugging)
     * annotations.
     *
     * @param annotation {@code non-null;} annotation instance to write
     * @param topLevel {@code true} iff the given annotation is the
     * top-level annotation or {@code false} if it is a sub-annotation
     * of some other annotation
     */
public void writeAnnotation(Annotation annotation, boolean topLevel) {
    boolean annotates = topLevel && out.annotates();
    StringIdsSection stringIds = file.getStringIds();
    TypeIdsSection typeIds = file.getTypeIds();
    CstType type = annotation.getType();
    int typeIdx = typeIds.indexOf(type);
    if (annotates) {
        out.annotate("  type_idx: " + Hex.u4(typeIdx) + " // " + type.toHuman());
    }
    out.writeUleb128(typeIds.indexOf(annotation.getType()));
    Collection<NameValuePair> pairs = annotation.getNameValuePairs();
    int size = pairs.size();
    if (annotates) {
        out.annotate("  size: " + Hex.u4(size));
    }
    out.writeUleb128(size);
    int at = 0;
    for (NameValuePair pair : pairs) {
        CstString name = pair.getName();
        int nameIdx = stringIds.indexOf(name);
        Constant value = pair.getValue();
        if (annotates) {
            out.annotate(0, "  elements[" + at + "]:");
            at++;
            out.annotate("    name_idx: " + Hex.u4(nameIdx) + " // " + name.toHuman());
        }
        out.writeUleb128(nameIdx);
        if (annotates) {
            out.annotate("    value: " + constantToHuman(value));
        }
        writeConstant(value);
    }
    if (annotates) {
        out.endAnnotation();
    }
}
Also used : NameValuePair(com.taobao.android.dx.rop.annotation.NameValuePair) Constant(com.taobao.android.dx.rop.cst.Constant) CstType(com.taobao.android.dx.rop.cst.CstType) CstString(com.taobao.android.dx.rop.cst.CstString)

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