Search in sources :

Example 6 with ByteArrayAnnotatedOutput

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

the class DexFile method writeTo.

/**
     * Writes the contents of this instance as either a binary or a
     * human-readable form, or both.
     *
     * @param out {@code null-ok;} where to write to
     * @param humanOut {@code null-ok;} where to write human-oriented output to
     * @param verbose whether to be verbose when writing human-oriented output
     */
public void writeTo(OutputStream out, Writer humanOut, boolean verbose) throws IOException {
    boolean annotate = (humanOut != null);
    ByteArrayAnnotatedOutput result = toDex0(annotate, verbose);
    if (out != null) {
        out.write(result.getArray());
    }
    if (annotate) {
        result.writeAnnotationsTo(humanOut);
    }
}
Also used : ByteArrayAnnotatedOutput(com.taobao.android.dx.util.ByteArrayAnnotatedOutput)

Example 7 with ByteArrayAnnotatedOutput

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

the class EncodedArrayItem method place0.

/** {@inheritDoc} */
@Override
protected void place0(Section addedTo, int offset) {
    // Encode the data and note the size.
    ByteArrayAnnotatedOutput out = new ByteArrayAnnotatedOutput();
    ValueEncoder encoder = new ValueEncoder(addedTo.getFile(), out);
    encoder.writeArray(array, false);
    encodedForm = out.toByteArray();
    setWriteSize(encodedForm.length);
}
Also used : ByteArrayAnnotatedOutput(com.taobao.android.dx.util.ByteArrayAnnotatedOutput)

Example 8 with ByteArrayAnnotatedOutput

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

the class CatchStructs method encode.

/**
     * Encodes the handler lists.
     *
     * @param file {@code non-null;} file this instance is part of
     */
public void encode(DexFile file) {
    finishProcessingIfNecessary();
    TypeIdsSection typeIds = file.getTypeIds();
    int size = table.size();
    handlerOffsets = new TreeMap<CatchHandlerList, Integer>();
    /*
         * First add a map entry for each unique list. The tree structure
         * will ensure they are sorted when we reiterate later.
         */
    for (int i = 0; i < size; i++) {
        handlerOffsets.put(table.get(i).getHandlers(), null);
    }
    if (handlerOffsets.size() > 65535) {
        throw new UnsupportedOperationException("too many catch handlers");
    }
    ByteArrayAnnotatedOutput out = new ByteArrayAnnotatedOutput();
    // Write out the handlers "header" consisting of its size in entries.
    encodedHandlerHeaderSize = out.writeUleb128(handlerOffsets.size());
    // Now write the lists out in order, noting the offset of each.
    for (Map.Entry<CatchHandlerList, Integer> mapping : handlerOffsets.entrySet()) {
        CatchHandlerList list = mapping.getKey();
        int listSize = list.size();
        boolean catchesAll = list.catchesAll();
        // Set the offset before we do any writing.
        mapping.setValue(out.getCursor());
        if (catchesAll) {
            // A size <= 0 means that the list ends with a catch-all.
            out.writeSleb128(-(listSize - 1));
            listSize--;
        } else {
            out.writeSleb128(listSize);
        }
        for (int i = 0; i < listSize; i++) {
            CatchHandlerList.Entry entry = list.get(i);
            out.writeUleb128(typeIds.indexOf(entry.getExceptionType()));
            out.writeUleb128(entry.getHandler());
        }
        if (catchesAll) {
            out.writeUleb128(list.get(listSize).getHandler());
        }
    }
    encodedHandlers = out.toByteArray();
}
Also used : CatchHandlerList(com.taobao.android.dx.dex.code.CatchHandlerList) ByteArrayAnnotatedOutput(com.taobao.android.dx.util.ByteArrayAnnotatedOutput) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 9 with ByteArrayAnnotatedOutput

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

the class IndexMap method adjust.

public Annotation adjust(Annotation annotation) {
    ByteArrayAnnotatedOutput out = new ByteArrayAnnotatedOutput(32);
    new EncodedValueTransformer(out).transformAnnotation(annotation.getReader());
    return new Annotation(target, annotation.getVisibility(), new EncodedValue(out.toByteArray()));
}
Also used : EncodedValue(com.taobao.android.dex.EncodedValue) ByteArrayAnnotatedOutput(com.taobao.android.dx.util.ByteArrayAnnotatedOutput) Annotation(com.taobao.android.dex.Annotation)

Example 10 with ByteArrayAnnotatedOutput

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

the class IndexMap method adjustEncodedValue.

public EncodedValue adjustEncodedValue(EncodedValue encodedValue) {
    ByteArrayAnnotatedOutput out = new ByteArrayAnnotatedOutput(32);
    new EncodedValueTransformer(out).transform(new EncodedValueReader(encodedValue));
    return new EncodedValue(out.toByteArray());
}
Also used : EncodedValue(com.taobao.android.dex.EncodedValue) EncodedValueReader(com.taobao.android.dex.EncodedValueReader) ByteArrayAnnotatedOutput(com.taobao.android.dx.util.ByteArrayAnnotatedOutput)

Aggregations

ByteArrayAnnotatedOutput (com.taobao.android.dx.util.ByteArrayAnnotatedOutput)10 EncodedValue (com.taobao.android.dex.EncodedValue)3 EncodedValueReader (com.taobao.android.dex.EncodedValueReader)2 Annotation (com.taobao.android.dex.Annotation)1 ExceptionWithContext (com.taobao.android.dex.util.ExceptionWithContext)1 CatchHandlerList (com.taobao.android.dx.dex.code.CatchHandlerList)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1