FileDocCategorySizeDatePackage
HeaderItem.javaAPI DocAndroid 5.1 API3695Thu Mar 12 22:18:30 GMT 2015com.android.dx.dex.file

HeaderItem

public final class HeaderItem extends IndexedItem
File header section of a {@code .dex} file.

Fields Summary
Constructors Summary
public HeaderItem()
Constructs an instance.

        // This space intentionally left blank.
    
Methods Summary
public voidaddContents(DexFile file)
{@inheritDoc}

        // Nothing to do here.
    
public ItemTypeitemType()
{@inheritDoc}

        return ItemType.TYPE_HEADER_ITEM;
    
public intwriteSize()
{@inheritDoc}

        return SizeOf.HEADER_ITEM;
    
public voidwriteTo(DexFile file, com.android.dx.util.AnnotatedOutput out)
{@inheritDoc}

        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);