Java Code Examples for com.android.dex.Dex#getTableOfContents()

The following examples show how to use com.android.dex.Dex#getTableOfContents() . 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: DexMerger.java    From Box with Apache License 2.0 5 votes vote down vote up
private void transformAnnotationSets(Dex in, IndexMap indexMap) {
    TableOfContents.Section section = in.getTableOfContents().annotationSets;
    if (section.exists()) {
        Dex.Section setIn = in.open(section.off);
        for (int i = 0; i < section.size; i++) {
            transformAnnotationSet(indexMap, setIn);
        }
    }
}
 
Example 2
Source File: DexMerger.java    From Box with Apache License 2.0 5 votes vote down vote up
private void transformAnnotationSetRefLists(Dex in, IndexMap indexMap) {
    TableOfContents.Section section = in.getTableOfContents().annotationSetRefLists;
    if (section.exists()) {
        Dex.Section setIn = in.open(section.off);
        for (int i = 0; i < section.size; i++) {
            transformAnnotationSetRefList(indexMap, setIn);
        }
    }
}
 
Example 3
Source File: DexMerger.java    From Box with Apache License 2.0 5 votes vote down vote up
private void transformAnnotationDirectories(Dex in, IndexMap indexMap) {
    TableOfContents.Section section = in.getTableOfContents().annotationsDirectories;
    if (section.exists()) {
        Dex.Section directoryIn = in.open(section.off);
        for (int i = 0; i < section.size; i++) {
            transformAnnotationDirectory(directoryIn, indexMap);
        }
    }
}
 
Example 4
Source File: DexMerger.java    From Box with Apache License 2.0 5 votes vote down vote up
private void transformStaticValues(Dex in, IndexMap indexMap) {
    TableOfContents.Section section = in.getTableOfContents().encodedArrays;
    if (section.exists()) {
        Dex.Section staticValuesIn = in.open(section.off);
        for (int i = 0; i < section.size; i++) {
            transformStaticValues(staticValuesIn, indexMap);
        }
    }
}
 
Example 5
Source File: DexMerger.java    From Box with Apache License 2.0 5 votes vote down vote up
private void transformAnnotationSets(Dex in, IndexMap indexMap) {
    TableOfContents.Section section = in.getTableOfContents().annotationSets;
    if (section.exists()) {
        Dex.Section setIn = in.open(section.off);
        for (int i = 0; i < section.size; i++) {
            transformAnnotationSet(indexMap, setIn);
        }
    }
}
 
Example 6
Source File: DexMerger.java    From Box with Apache License 2.0 5 votes vote down vote up
private void transformAnnotationSetRefLists(Dex in, IndexMap indexMap) {
    TableOfContents.Section section = in.getTableOfContents().annotationSetRefLists;
    if (section.exists()) {
        Dex.Section setIn = in.open(section.off);
        for (int i = 0; i < section.size; i++) {
            transformAnnotationSetRefList(indexMap, setIn);
        }
    }
}
 
Example 7
Source File: DexMerger.java    From Box with Apache License 2.0 5 votes vote down vote up
private void transformAnnotationDirectories(Dex in, IndexMap indexMap) {
    TableOfContents.Section section = in.getTableOfContents().annotationsDirectories;
    if (section.exists()) {
        Dex.Section directoryIn = in.open(section.off);
        for (int i = 0; i < section.size; i++) {
            transformAnnotationDirectory(directoryIn, indexMap);
        }
    }
}
 
Example 8
Source File: DexMerger.java    From Box with Apache License 2.0 5 votes vote down vote up
private void transformStaticValues(Dex in, IndexMap indexMap) {
    TableOfContents.Section section = in.getTableOfContents().encodedArrays;
    if (section.exists()) {
        Dex.Section staticValuesIn = in.open(section.off);
        for (int i = 0; i < section.size; i++) {
            transformStaticValues(staticValuesIn, indexMap);
        }
    }
}
 
Example 9
Source File: DexMerger.java    From buck with Apache License 2.0 5 votes vote down vote up
private void transformAnnotationSets(Dex in, IndexMap indexMap) {
    TableOfContents.Section section = in.getTableOfContents().annotationSets;
    if (section.exists()) {
        Dex.Section setIn = in.open(section.off);
        for (int i = 0; i < section.size; i++) {
            transformAnnotationSet(indexMap, setIn);
        }
    }
}
 
Example 10
Source File: DexMerger.java    From buck with Apache License 2.0 5 votes vote down vote up
private void transformAnnotationSetRefLists(Dex in, IndexMap indexMap) {
    TableOfContents.Section section = in.getTableOfContents().annotationSetRefLists;
    if (section.exists()) {
        Dex.Section setIn = in.open(section.off);
        for (int i = 0; i < section.size; i++) {
            transformAnnotationSetRefList(indexMap, setIn);
        }
    }
}
 
Example 11
Source File: DexMerger.java    From buck with Apache License 2.0 5 votes vote down vote up
private void transformAnnotationDirectories(Dex in, IndexMap indexMap) {
    TableOfContents.Section section = in.getTableOfContents().annotationsDirectories;
    if (section.exists()) {
        Dex.Section directoryIn = in.open(section.off);
        for (int i = 0; i < section.size; i++) {
            transformAnnotationDirectory(directoryIn, indexMap);
        }
    }
}
 
Example 12
Source File: DexMerger.java    From buck with Apache License 2.0 5 votes vote down vote up
private void transformStaticValues(Dex in, IndexMap indexMap) {
    TableOfContents.Section section = in.getTableOfContents().encodedArrays;
    if (section.exists()) {
        Dex.Section staticValuesIn = in.open(section.off);
        for (int i = 0; i < section.size; i++) {
            transformStaticValues(staticValuesIn, indexMap);
        }
    }
}
 
Example 13
Source File: DexMerger.java    From buck with Apache License 2.0 5 votes vote down vote up
private void plus(Dex d, boolean exact) {
    TableOfContents contents = d.getTableOfContents();
    idsDefs += contents.stringIds.size * SizeOf.STRING_ID_ITEM
            + contents.typeIds.size * SizeOf.TYPE_ID_ITEM
            + contents.protoIds.size * SizeOf.PROTO_ID_ITEM
            + contents.fieldIds.size * SizeOf.MEMBER_ID_ITEM
            + contents.methodIds.size * SizeOf.MEMBER_ID_ITEM
            + contents.classDefs.size * SizeOf.CLASS_DEF_ITEM;
    mapList = SizeOf.UINT + (contents.sections.length * SizeOf.MAP_ITEM);
    typeList += fourByteAlign(contents.typeLists.byteCount); // We count each dex's
    // typelists section as realigned on 4 bytes, because each typelist of each dex's
    // typelists section is aligned on 4 bytes. If we didn't, there is a case where each
    // size of both dex's typelists section is a multiple of 2 but not a multiple of 4,
    // and the sum of both sizes is a multiple of 4 but would not be sufficient to write
    // each typelist aligned on 4 bytes.
    stringData += contents.stringDatas.byteCount;
    annotationsDirectory += contents.annotationsDirectories.byteCount;
    annotationsSet += contents.annotationSets.byteCount;
    annotationsSetRefList += contents.annotationSetRefLists.byteCount;

    if (exact) {
        code += contents.codes.byteCount;
        classData += contents.classDatas.byteCount;
        encodedArray += contents.encodedArrays.byteCount;
        annotation += contents.annotations.byteCount;
        debugInfo += contents.debugInfos.byteCount;
    } else {
        // at most 1/4 of the bytes in a code section are uleb/sleb
        code += (int) Math.ceil(contents.codes.byteCount * 1.25);
        // at most 1/3 of the bytes in a class data section are uleb/sleb
        classData += (int) Math.ceil(contents.classDatas.byteCount * 1.34);
        // all of the bytes in an encoding arrays section may be uleb/sleb
        encodedArray += contents.encodedArrays.byteCount * 2;
        // all of the bytes in an annotations section may be uleb/sleb
        annotation += (int) Math.ceil(contents.annotations.byteCount * 2);
        // all of the bytes in a debug info section may be uleb/sleb
        debugInfo += computeDuplicatedDebugInfoSize(d) * 2;
    }
}
 
Example 14
Source File: DexMerger.java    From Box with Apache License 2.0 4 votes vote down vote up
private DexMerger(Dex[] dexes, CollisionPolicy collisionPolicy, DxContext context,
        WriterSizes writerSizes) throws IOException {
    this.dexes = dexes;
    this.collisionPolicy = collisionPolicy;
    this.context = context;
    this.writerSizes = writerSizes;

    dexOut = new Dex(writerSizes.size());

    indexMaps = new IndexMap[dexes.length];
    for (int i = 0; i < dexes.length; i++) {
        indexMaps[i] = new IndexMap(dexOut, dexes[i].getTableOfContents());
    }
    instructionTransformer = new InstructionTransformer();

    headerOut = dexOut.appendSection(writerSizes.header, "header");
    idsDefsOut = dexOut.appendSection(writerSizes.idsDefs, "ids defs");

    contentsOut = dexOut.getTableOfContents();
    contentsOut.dataOff = dexOut.getNextSectionStart();

    contentsOut.mapList.off = dexOut.getNextSectionStart();
    contentsOut.mapList.size = 1;
    mapListOut = dexOut.appendSection(writerSizes.mapList, "map list");

    contentsOut.typeLists.off = dexOut.getNextSectionStart();
    typeListOut = dexOut.appendSection(writerSizes.typeList, "type list");

    contentsOut.annotationSetRefLists.off = dexOut.getNextSectionStart();
    annotationSetRefListOut = dexOut.appendSection(
            writerSizes.annotationsSetRefList, "annotation set ref list");

    contentsOut.annotationSets.off = dexOut.getNextSectionStart();
    annotationSetOut = dexOut.appendSection(writerSizes.annotationsSet, "annotation sets");

    contentsOut.classDatas.off = dexOut.getNextSectionStart();
    classDataOut = dexOut.appendSection(writerSizes.classData, "class data");

    contentsOut.codes.off = dexOut.getNextSectionStart();
    codeOut = dexOut.appendSection(writerSizes.code, "code");

    contentsOut.stringDatas.off = dexOut.getNextSectionStart();
    stringDataOut = dexOut.appendSection(writerSizes.stringData, "string data");

    contentsOut.debugInfos.off = dexOut.getNextSectionStart();
    debugInfoOut = dexOut.appendSection(writerSizes.debugInfo, "debug info");

    contentsOut.annotations.off = dexOut.getNextSectionStart();
    annotationOut = dexOut.appendSection(writerSizes.annotation, "annotation");

    contentsOut.encodedArrays.off = dexOut.getNextSectionStart();
    encodedArrayOut = dexOut.appendSection(writerSizes.encodedArray, "encoded array");

    contentsOut.annotationsDirectories.off = dexOut.getNextSectionStart();
    annotationsDirectoryOut = dexOut.appendSection(
            writerSizes.annotationsDirectory, "annotations directory");

    contentsOut.dataSize = dexOut.getNextSectionStart() - contentsOut.dataOff;
}
 
Example 15
Source File: DexMerger.java    From Box with Apache License 2.0 4 votes vote down vote up
private DexMerger(Dex[] dexes, CollisionPolicy collisionPolicy, DxContext context,
        WriterSizes writerSizes) throws IOException {
    this.dexes = dexes;
    this.collisionPolicy = collisionPolicy;
    this.context = context;
    this.writerSizes = writerSizes;

    dexOut = new Dex(writerSizes.size());

    indexMaps = new IndexMap[dexes.length];
    for (int i = 0; i < dexes.length; i++) {
        indexMaps[i] = new IndexMap(dexOut, dexes[i].getTableOfContents());
    }
    instructionTransformer = new InstructionTransformer();

    headerOut = dexOut.appendSection(writerSizes.header, "header");
    idsDefsOut = dexOut.appendSection(writerSizes.idsDefs, "ids defs");

    contentsOut = dexOut.getTableOfContents();
    contentsOut.dataOff = dexOut.getNextSectionStart();

    contentsOut.mapList.off = dexOut.getNextSectionStart();
    contentsOut.mapList.size = 1;
    mapListOut = dexOut.appendSection(writerSizes.mapList, "map list");

    contentsOut.typeLists.off = dexOut.getNextSectionStart();
    typeListOut = dexOut.appendSection(writerSizes.typeList, "type list");

    contentsOut.annotationSetRefLists.off = dexOut.getNextSectionStart();
    annotationSetRefListOut = dexOut.appendSection(
            writerSizes.annotationsSetRefList, "annotation set ref list");

    contentsOut.annotationSets.off = dexOut.getNextSectionStart();
    annotationSetOut = dexOut.appendSection(writerSizes.annotationsSet, "annotation sets");

    contentsOut.classDatas.off = dexOut.getNextSectionStart();
    classDataOut = dexOut.appendSection(writerSizes.classData, "class data");

    contentsOut.codes.off = dexOut.getNextSectionStart();
    codeOut = dexOut.appendSection(writerSizes.code, "code");

    contentsOut.stringDatas.off = dexOut.getNextSectionStart();
    stringDataOut = dexOut.appendSection(writerSizes.stringData, "string data");

    contentsOut.debugInfos.off = dexOut.getNextSectionStart();
    debugInfoOut = dexOut.appendSection(writerSizes.debugInfo, "debug info");

    contentsOut.annotations.off = dexOut.getNextSectionStart();
    annotationOut = dexOut.appendSection(writerSizes.annotation, "annotation");

    contentsOut.encodedArrays.off = dexOut.getNextSectionStart();
    encodedArrayOut = dexOut.appendSection(writerSizes.encodedArray, "encoded array");

    contentsOut.annotationsDirectories.off = dexOut.getNextSectionStart();
    annotationsDirectoryOut = dexOut.appendSection(
            writerSizes.annotationsDirectory, "annotations directory");

    contentsOut.dataSize = dexOut.getNextSectionStart() - contentsOut.dataOff;
}
 
Example 16
Source File: DexMerger.java    From buck with Apache License 2.0 4 votes vote down vote up
private DexMerger(Dex[] dexes, CollisionPolicy collisionPolicy, DxContext context,
        WriterSizes writerSizes) throws IOException {
    this.dexes = dexes;
    this.collisionPolicy = collisionPolicy;
    this.context = context;
    this.writerSizes = writerSizes;

    dexOut = new Dex(writerSizes.size());

    indexMaps = new IndexMap[dexes.length];
    for (int i = 0; i < dexes.length; i++) {
        indexMaps[i] = new IndexMap(dexOut, dexes[i].getTableOfContents());
    }
    instructionTransformer = new InstructionTransformer();

    headerOut = dexOut.appendSection(writerSizes.header, "header");
    idsDefsOut = dexOut.appendSection(writerSizes.idsDefs, "ids defs");

    contentsOut = dexOut.getTableOfContents();
    contentsOut.dataOff = dexOut.getNextSectionStart();

    contentsOut.mapList.off = dexOut.getNextSectionStart();
    contentsOut.mapList.size = 1;
    mapListOut = dexOut.appendSection(writerSizes.mapList, "map list");

    contentsOut.typeLists.off = dexOut.getNextSectionStart();
    typeListOut = dexOut.appendSection(writerSizes.typeList, "type list");

    contentsOut.annotationSetRefLists.off = dexOut.getNextSectionStart();
    annotationSetRefListOut = dexOut.appendSection(
            writerSizes.annotationsSetRefList, "annotation set ref list");

    contentsOut.annotationSets.off = dexOut.getNextSectionStart();
    annotationSetOut = dexOut.appendSection(writerSizes.annotationsSet, "annotation sets");

    contentsOut.classDatas.off = dexOut.getNextSectionStart();
    classDataOut = dexOut.appendSection(writerSizes.classData, "class data");

    contentsOut.codes.off = dexOut.getNextSectionStart();
    codeOut = dexOut.appendSection(writerSizes.code, "code");

    contentsOut.stringDatas.off = dexOut.getNextSectionStart();
    stringDataOut = dexOut.appendSection(writerSizes.stringData, "string data");

    contentsOut.debugInfos.off = dexOut.getNextSectionStart();
    debugInfoOut = dexOut.appendSection(writerSizes.debugInfo, "debug info");

    contentsOut.annotations.off = dexOut.getNextSectionStart();
    annotationOut = dexOut.appendSection(writerSizes.annotation, "annotation");

    contentsOut.encodedArrays.off = dexOut.getNextSectionStart();
    encodedArrayOut = dexOut.appendSection(writerSizes.encodedArray, "encoded array");

    contentsOut.annotationsDirectories.off = dexOut.getNextSectionStart();
    annotationsDirectoryOut = dexOut.appendSection(
            writerSizes.annotationsDirectory, "annotations directory");

    contentsOut.dataSize = dexOut.getNextSectionStart() - contentsOut.dataOff;
}