Java Code Examples for com.android.dx.util.AnnotatedOutput#writeByte()

The following examples show how to use com.android.dx.util.AnnotatedOutput#writeByte() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StringDataItem.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo0(DexFile file, AnnotatedOutput out) {
    ByteArray bytes = value.getBytes();
    int utf16Size = value.getUtf16Size();

    if (out.annotates()) {
        out.annotate(Leb128.unsignedLeb128Size(utf16Size),
                "utf16_size: " + Hex.u4(utf16Size));
        out.annotate(bytes.size() + 1, value.toQuoted());
    }

    out.writeUleb128(utf16Size);
    out.write(bytes);
    out.writeByte(0);
}
 
Example 2
Source File: StringDataItem.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo0(DexFile file, AnnotatedOutput out) {
    ByteArray bytes = value.getBytes();
    int utf16Size = value.getUtf16Size();

    if (out.annotates()) {
        out.annotate(Leb128.unsignedLeb128Size(utf16Size),
                "utf16_size: " + Hex.u4(utf16Size));
        out.annotate(bytes.size() + 1, value.toQuoted());
    }

    out.writeUleb128(utf16Size);
    out.write(bytes);
    out.writeByte(0);
}
 
Example 3
Source File: StringDataItem.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo0(DexFile file, AnnotatedOutput out) {
    ByteArray bytes = value.getBytes();
    int utf16Size = value.getUtf16Size();

    if (out.annotates()) {
        out.annotate(Leb128.unsignedLeb128Size(utf16Size),
                "utf16_size: " + Hex.u4(utf16Size));
        out.annotate(bytes.size() + 1, value.toQuoted());
    }

    out.writeUleb128(utf16Size);
    out.write(bytes);
    out.writeByte(0);
}
 
Example 4
Source File: StringDataItem.java    From buck with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo0(DexFile file, AnnotatedOutput out) {
    ByteArray bytes = value.getBytes();
    int utf16Size = value.getUtf16Size();

    if (out.annotates()) {
        out.annotate(Leb128.unsignedLeb128Size(utf16Size),
                "utf16_size: " + Hex.u4(utf16Size));
        out.annotate(bytes.size() + 1, value.toQuoted());
    }

    out.writeUleb128(utf16Size);
    out.write(bytes);
    out.writeByte(0);
}
 
Example 5
Source File: AnnotationItem.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void writeTo0(DexFile file, AnnotatedOutput out) {
    boolean annotates = out.annotates();
    AnnotationVisibility visibility = annotation.getVisibility();

    if (annotates) {
        out.annotate(0, offsetString() + " annotation");
        out.annotate(1, "  visibility: VISBILITY_" + visibility);
    }

    switch (visibility) {
        case BUILD:   out.writeByte(VISIBILITY_BUILD); break;
        case RUNTIME: out.writeByte(VISIBILITY_RUNTIME); break;
        case SYSTEM:  out.writeByte(VISIBILITY_SYSTEM); break;
        default: {
            // EMBEDDED shouldn't appear at the top level.
            throw new RuntimeException("shouldn't happen");
        }
    }

    if (annotates) {
        /*
         * The output is to be annotated, so redo the work previously
         * done by place0(), except this time annotations will actually
         * get emitted.
         */
        ValueEncoder encoder = new ValueEncoder(file, out);
        encoder.writeAnnotation(annotation, true);
    } else {
        out.write(encodedForm);
    }
}
 
Example 6
Source File: AnnotationItem.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void writeTo0(DexFile file, AnnotatedOutput out) {
    boolean annotates = out.annotates();
    AnnotationVisibility visibility = annotation.getVisibility();

    if (annotates) {
        out.annotate(0, offsetString() + " annotation");
        out.annotate(1, "  visibility: VISBILITY_" + visibility);
    }

    switch (visibility) {
        case BUILD:   out.writeByte(VISIBILITY_BUILD); break;
        case RUNTIME: out.writeByte(VISIBILITY_RUNTIME); break;
        case SYSTEM:  out.writeByte(VISIBILITY_SYSTEM); break;
        default: {
            // EMBEDDED shouldn't appear at the top level.
            throw new RuntimeException("shouldn't happen");
        }
    }

    if (annotates) {
        /*
         * The output is to be annotated, so redo the work previously
         * done by place0(), except this time annotations will actually
         * get emitted.
         */
        ValueEncoder encoder = new ValueEncoder(file, out);
        encoder.writeAnnotation(annotation, true);
    } else {
        out.write(encodedForm);
    }
}
 
Example 7
Source File: AnnotationItem.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void writeTo0(DexFile file, AnnotatedOutput out) {
    boolean annotates = out.annotates();
    AnnotationVisibility visibility = annotation.getVisibility();

    if (annotates) {
        out.annotate(0, offsetString() + " annotation");
        out.annotate(1, "  visibility: VISBILITY_" + visibility);
    }

    switch (visibility) {
        case BUILD:   out.writeByte(VISIBILITY_BUILD); break;
        case RUNTIME: out.writeByte(VISIBILITY_RUNTIME); break;
        case SYSTEM:  out.writeByte(VISIBILITY_SYSTEM); break;
        default: {
            // EMBEDDED shouldn't appear at the top level.
            throw new RuntimeException("shouldn't happen");
        }
    }

    if (annotates) {
        /*
         * The output is to be annotated, so redo the work previously
         * done by place0(), except this time annotations will actually
         * get emitted.
         */
        ValueEncoder encoder = new ValueEncoder(file, out);
        encoder.writeAnnotation(annotation, true);
    } else {
        out.write(encodedForm);
    }
}
 
Example 8
Source File: AnnotationItem.java    From buck with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
protected void writeTo0(DexFile file, AnnotatedOutput out) {
    boolean annotates = out.annotates();
    AnnotationVisibility visibility = annotation.getVisibility();

    if (annotates) {
        out.annotate(0, offsetString() + " annotation");
        out.annotate(1, "  visibility: VISBILITY_" + visibility);
    }

    switch (visibility) {
        case BUILD:   out.writeByte(VISIBILITY_BUILD); break;
        case RUNTIME: out.writeByte(VISIBILITY_RUNTIME); break;
        case SYSTEM:  out.writeByte(VISIBILITY_SYSTEM); break;
        default: {
            // EMBEDDED shouldn't appear at the top level.
            throw new RuntimeException("shouldn't happen");
        }
    }

    if (annotates) {
        /*
         * The output is to be annotated, so redo the work previously
         * done by place0(), except this time annotations will actually
         * get emitted.
         */
        ValueEncoder encoder = new ValueEncoder(file, out);
        encoder.writeAnnotation(annotation, true);
    } else {
        out.write(encodedForm);
    }
}
 
Example 9
Source File: HeaderItem.java    From Box with Apache License 2.0 4 votes vote down vote up
/** {@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);
}
 
Example 10
Source File: HeaderItem.java    From Box with Apache License 2.0 4 votes vote down vote up
/** {@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);
}
 
Example 11
Source File: HeaderItem.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
/** {@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);
}
 
Example 12
Source File: HeaderItem.java    From buck with Apache License 2.0 4 votes vote down vote up
/** {@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);
}