Java Code Examples for com.android.dex.Dex#Section

The following examples show how to use com.android.dex.Dex#Section . 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: ClassNode.java    From Box with Apache License 2.0 6 votes vote down vote up
private void loadStaticValues(ClassDef cls, List<FieldNode> staticFields) throws DecodeException {
	for (FieldNode f : staticFields) {
		if (f.getAccessFlags().isFinal()) {
			f.addAttr(FieldInitAttr.NULL_VALUE);
		}
	}
	int offset = cls.getStaticValuesOffset();
	if (offset == 0) {
		return;
	}
	Dex.Section section = dex.openSection(offset);
	StaticValuesParser parser = new StaticValuesParser(dex, section);
	parser.processFields(staticFields);

	// process const fields
	root().getConstValues().processConstFields(this, staticFields);
}
 
Example 2
Source File: ClassNode.java    From Box with Apache License 2.0 6 votes vote down vote up
private void loadStaticValues(ClassDef cls, List<FieldNode> staticFields) throws DecodeException {
	for (FieldNode f : staticFields) {
		if (f.getAccessFlags().isFinal()) {
			f.addAttr(FieldInitAttr.NULL_VALUE);
		}
	}
	int offset = cls.getStaticValuesOffset();
	if (offset == 0) {
		return;
	}
	Dex.Section section = dex.openSection(offset);
	StaticValuesParser parser = new StaticValuesParser(dex, section);
	parser.processFields(staticFields);

	// process const fields
	root().getConstValues().processConstFields(this, staticFields);
}
 
Example 3
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 4
Source File: DexMerger.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Merges already-sorted sections, reading one value from each dex into memory
 * at a time.
 */
public final void mergeSorted() {
    TableOfContents.Section[] sections = new TableOfContents.Section[dexes.length];
    Dex.Section[] dexSections = new Dex.Section[dexes.length];
    int[] offsets = new int[dexes.length];
    int[] indexes = new int[dexes.length];

    // values contains one value from each dex, sorted for fast retrieval of
    // the smallest value. The list associated with a value has the indexes
    // of the dexes that had that value.
    TreeMap<T, List<Integer>> values = new TreeMap<T, List<Integer>>();

    for (int i = 0; i < dexes.length; i++) {
        sections[i] = getSection(dexes[i].getTableOfContents());
        dexSections[i] = sections[i].exists() ? dexes[i].open(sections[i].off) : null;
        // Fill in values with the first value of each dex.
        offsets[i] = readIntoMap(
                dexSections[i], sections[i], indexMaps[i], indexes[i], values, i);
    }
    getSection(contentsOut).off = out.getPosition();

    int outCount = 0;
    while (!values.isEmpty()) {
        Map.Entry<T, List<Integer>> first = values.pollFirstEntry();
        for (Integer dex : first.getValue()) {
            updateIndex(offsets[dex], indexMaps[dex], indexes[dex]++, outCount);
            // Fetch the next value of the dexes we just polled out
            offsets[dex] = readIntoMap(dexSections[dex], sections[dex],
                    indexMaps[dex], indexes[dex], values, dex);
        }
        write(first.getKey());
        outCount++;
    }

    getSection(contentsOut).size = outCount;
}
 
Example 5
Source File: DexMerger.java    From Box with Apache License 2.0 5 votes vote down vote up
private List<UnsortedValue> readUnsortedValues(Dex source, IndexMap indexMap) {
    TableOfContents.Section section = getSection(source.getTableOfContents());
    if (!section.exists()) {
        return Collections.emptyList();
    }

    List<UnsortedValue> result = new ArrayList<UnsortedValue>();
    Dex.Section in = source.open(section.off);
    for (int i = 0; i < section.size; i++) {
        int offset = in.getPosition();
        T value = read(in, indexMap, 0);
        result.add(new UnsortedValue(source, indexMap, value, i, offset));
    }
    return result;
}
 
Example 6
Source File: DexMerger.java    From buck with Apache License 2.0 5 votes vote down vote up
private int readIntoMap(Dex.Section in, TableOfContents.Section section, IndexMap indexMap,
                        int index, TreeMap<T, List<Integer>> values, int dex) {
    int offset = in != null ? in.getPosition() : -1;
    if (index < section.size) {
        T v = read(in, indexMap, index);
        List<Integer> l = values.get(v);
        if (l == null) {
            l = new ArrayList<Integer>();
            values.put(v, l);
        }
        l.add(new Integer(dex));
    }
    return offset;
}
 
Example 7
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 8
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 9
Source File: DexMerger.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Transform all annotation set ref lists.
 */
private void transformAnnotationSetRefList(IndexMap indexMap, Dex.Section refListIn) {
    contentsOut.annotationSetRefLists.size++;
    annotationSetRefListOut.assertFourByteAligned();
    indexMap.putAnnotationSetRefListOffset(
            refListIn.getPosition(), annotationSetRefListOut.getPosition());

    int parameterCount = refListIn.readInt();
    annotationSetRefListOut.writeInt(parameterCount);
    for (int p = 0; p < parameterCount; p++) {
        annotationSetRefListOut.writeInt(indexMap.adjustAnnotationSet(refListIn.readInt()));
    }
}
 
Example 10
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 11
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 12
Source File: DexMerger.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Transform all annotation set ref lists.
 */
private void transformAnnotationSetRefList(IndexMap indexMap, Dex.Section refListIn) {
    contentsOut.annotationSetRefLists.size++;
    annotationSetRefListOut.assertFourByteAligned();
    indexMap.putAnnotationSetRefListOffset(
            refListIn.getPosition(), annotationSetRefListOut.getPosition());

    int parameterCount = refListIn.readInt();
    annotationSetRefListOut.writeInt(parameterCount);
    for (int p = 0; p < parameterCount; p++) {
        annotationSetRefListOut.writeInt(indexMap.adjustAnnotationSet(refListIn.readInt()));
    }
}
 
Example 13
Source File: DexMerger.java    From Box with Apache License 2.0 5 votes vote down vote up
private void transformTries(Dex.Section out, Code.Try[] tries,
        int[] catchHandlerOffsets) {
    for (Code.Try tryItem : tries) {
        out.writeInt(tryItem.getStartAddress());
        out.writeUnsignedShort(tryItem.getInstructionCount());
        out.writeUnsignedShort(catchHandlerOffsets[tryItem.getCatchHandlerIndex()]);
    }
}
 
Example 14
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 15
Source File: DexMerger.java    From buck with Apache License 2.0 4 votes vote down vote up
private int getDebugProgramSize(Dex.Section debugInfo) {
    int initPosition = debugInfo.getPosition();

    debugInfo.readUleb128(); // line start
    int parametersSize = debugInfo.readUleb128();
    for (int p = 0; p < parametersSize; p++) {
        debugInfo.readUleb128p1(); // parameter name
    }

    while (true) {
        int opcode = debugInfo.readByte();

        switch (opcode) {
        case DBG_END_SEQUENCE:
            int finalPosition = debugInfo.getPosition();
            return finalPosition - initPosition;

        case DBG_END_LOCAL:
        case DBG_RESTART_LOCAL:
        case DBG_ADVANCE_PC:
            debugInfo.readUleb128();
            break;

        case DBG_ADVANCE_LINE:
            debugInfo.readSleb128();
            break;

        case DBG_START_LOCAL:
        case DBG_START_LOCAL_EXTENDED:
            debugInfo.readUleb128();
            debugInfo.readUleb128p1();
            debugInfo.readUleb128p1();
            if (opcode == DBG_START_LOCAL_EXTENDED) {
                debugInfo.readUleb128p1();
            }
            break;

        case DBG_SET_FILE:
            debugInfo.readUleb128p1();
            break;

        case DBG_SET_PROLOGUE_END:
        case DBG_SET_EPILOGUE_BEGIN:
        default:
            break;
        }
    }
}
 
Example 16
Source File: DexMerger.java    From Box with Apache License 2.0 4 votes vote down vote up
private void transformStaticValues(Dex.Section in, IndexMap indexMap) {
    contentsOut.encodedArrays.size++;
    indexMap.putEncodedArrayValueOffset(in.getPosition(), encodedArrayOut.getPosition());
    indexMap.adjustEncodedArray(in.readEncodedArray()).writeTo(encodedArrayOut);
}
 
Example 17
Source File: DexMerger.java    From buck with Apache License 2.0 4 votes vote down vote up
private void transformStaticValues(Dex.Section in, IndexMap indexMap) {
    contentsOut.encodedArrays.size++;
    indexMap.putStaticValuesOffset(in.getPosition(), encodedArrayOut.getPosition());
    indexMap.adjustEncodedArray(in.readEncodedArray()).writeTo(encodedArrayOut);
}
 
Example 18
Source File: DexMerger.java    From buck with Apache License 2.0 4 votes vote down vote up
protected IdMerger(Dex.Section out) {
    this.out = out;
}
 
Example 19
Source File: DexMerger.java    From buck with Apache License 2.0 votes vote down vote up
abstract T read(Dex.Section in, IndexMap indexMap, int index); 
Example 20
Source File: DexMerger.java    From Box with Apache License 2.0 votes vote down vote up
abstract T read(Dex.Section in, IndexMap indexMap, int index);