Java Code Examples for com.android.dex.ClassDef#getStaticValuesOffset()

The following examples show how to use com.android.dex.ClassDef#getStaticValuesOffset() . 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: DexMerger.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Reads a class_def_item beginning at {@code in} and writes the index and
 * data.
 */
private void transformClassDef(Dex in, ClassDef classDef, IndexMap indexMap) {
    idsDefsOut.assertFourByteAligned();
    idsDefsOut.writeInt(classDef.getTypeIndex());
    idsDefsOut.writeInt(classDef.getAccessFlags());
    idsDefsOut.writeInt(classDef.getSupertypeIndex());
    idsDefsOut.writeInt(classDef.getInterfacesOffset());

    int sourceFileIndex = indexMap.adjustString(classDef.getSourceFileIndex());
    idsDefsOut.writeInt(sourceFileIndex);

    int annotationsOff = classDef.getAnnotationsOffset();
    idsDefsOut.writeInt(indexMap.adjustAnnotationDirectory(annotationsOff));

    int classDataOff = classDef.getClassDataOffset();
    if (classDataOff == 0) {
        idsDefsOut.writeInt(0);
    } else {
        idsDefsOut.writeInt(classDataOut.getPosition());
        ClassData classData = in.readClassData(classDef);
        transformClassData(in, classData, indexMap);
    }

    int staticValuesOff = classDef.getStaticValuesOffset();
    idsDefsOut.writeInt(indexMap.adjustEncodedArray(staticValuesOff));
}
 
Example 3
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 4
Source File: DexMerger.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Reads a class_def_item beginning at {@code in} and writes the index and
 * data.
 */
private void transformClassDef(Dex in, ClassDef classDef, IndexMap indexMap) {
    idsDefsOut.assertFourByteAligned();
    idsDefsOut.writeInt(classDef.getTypeIndex());
    idsDefsOut.writeInt(classDef.getAccessFlags());
    idsDefsOut.writeInt(classDef.getSupertypeIndex());
    idsDefsOut.writeInt(classDef.getInterfacesOffset());

    int sourceFileIndex = indexMap.adjustString(classDef.getSourceFileIndex());
    idsDefsOut.writeInt(sourceFileIndex);

    int annotationsOff = classDef.getAnnotationsOffset();
    idsDefsOut.writeInt(indexMap.adjustAnnotationDirectory(annotationsOff));

    int classDataOff = classDef.getClassDataOffset();
    if (classDataOff == 0) {
        idsDefsOut.writeInt(0);
    } else {
        idsDefsOut.writeInt(classDataOut.getPosition());
        ClassData classData = in.readClassData(classDef);
        transformClassData(in, classData, indexMap);
    }

    int staticValuesOff = classDef.getStaticValuesOffset();
    idsDefsOut.writeInt(indexMap.adjustEncodedArray(staticValuesOff));
}
 
Example 5
Source File: DexMerger.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Reads a class_def_item beginning at {@code in} and writes the index and
 * data.
 */
private void transformClassDef(Dex in, ClassDef classDef, IndexMap indexMap) {
    idsDefsOut.assertFourByteAligned();
    idsDefsOut.writeInt(classDef.getTypeIndex());
    idsDefsOut.writeInt(classDef.getAccessFlags());
    idsDefsOut.writeInt(classDef.getSupertypeIndex());
    idsDefsOut.writeInt(classDef.getInterfacesOffset());

    int sourceFileIndex = indexMap.adjustString(classDef.getSourceFileIndex());
    idsDefsOut.writeInt(sourceFileIndex);

    int annotationsOff = classDef.getAnnotationsOffset();
    idsDefsOut.writeInt(indexMap.adjustAnnotationDirectory(annotationsOff));

    int classDataOff = classDef.getClassDataOffset();
    if (classDataOff == 0) {
        idsDefsOut.writeInt(0);
    } else {
        idsDefsOut.writeInt(classDataOut.getPosition());
        ClassData classData = in.readClassData(classDef);
        transformClassData(in, classData, indexMap);
    }

    int staticValuesOff = classDef.getStaticValuesOffset();
    idsDefsOut.writeInt(indexMap.adjustStaticValues(staticValuesOff));
}
 
Example 6
Source File: IndexMap.java    From Box with Apache License 2.0 5 votes vote down vote up
public ClassDef adjust(ClassDef classDef) {
    return new ClassDef(target, classDef.getOffset(), adjustType(classDef.getTypeIndex()),
            classDef.getAccessFlags(), adjustType(classDef.getSupertypeIndex()),
            adjustTypeListOffset(classDef.getInterfacesOffset()), classDef.getSourceFileIndex(),
            classDef.getAnnotationsOffset(), classDef.getClassDataOffset(),
            classDef.getStaticValuesOffset());
}
 
Example 7
Source File: Grep.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Prints usages to out. Returns the number of matches found.
 */
public int grep() {
    for (ClassDef classDef : dex.classDefs()) {
        currentClass = classDef;
        currentMethod = null;

        if (classDef.getClassDataOffset() == 0) {
            continue;
        }

        ClassData classData = dex.readClassData(classDef);

        // find the strings in encoded constants
        int staticValuesOffset = classDef.getStaticValuesOffset();
        if (staticValuesOffset != 0) {
            readArray(new EncodedValueReader(dex.open(staticValuesOffset)));
        }

        // find the strings in method bodies
        for (ClassData.Method method : classData.allMethods()) {
            currentMethod = method;
            if (method.getCodeOffset() != 0) {
                codeReader.visitAll(dex.readCode(method).getInstructions());
            }
        }
    }

    currentClass = null;
    currentMethod = null;
    return count;
}
 
Example 8
Source File: IndexMap.java    From Box with Apache License 2.0 5 votes vote down vote up
public ClassDef adjust(ClassDef classDef) {
    return new ClassDef(target, classDef.getOffset(), adjustType(classDef.getTypeIndex()),
            classDef.getAccessFlags(), adjustType(classDef.getSupertypeIndex()),
            adjustTypeListOffset(classDef.getInterfacesOffset()), classDef.getSourceFileIndex(),
            classDef.getAnnotationsOffset(), classDef.getClassDataOffset(),
            classDef.getStaticValuesOffset());
}
 
Example 9
Source File: Grep.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Prints usages to out. Returns the number of matches found.
 */
public int grep() {
    for (ClassDef classDef : dex.classDefs()) {
        currentClass = classDef;
        currentMethod = null;

        if (classDef.getClassDataOffset() == 0) {
            continue;
        }

        ClassData classData = dex.readClassData(classDef);

        // find the strings in encoded constants
        int staticValuesOffset = classDef.getStaticValuesOffset();
        if (staticValuesOffset != 0) {
            readArray(new EncodedValueReader(dex.open(staticValuesOffset)));
        }

        // find the strings in method bodies
        for (ClassData.Method method : classData.allMethods()) {
            currentMethod = method;
            if (method.getCodeOffset() != 0) {
                codeReader.visitAll(dex.readCode(method).getInstructions());
            }
        }
    }

    currentClass = null;
    currentMethod = null;
    return count;
}
 
Example 10
Source File: IndexMap.java    From buck with Apache License 2.0 5 votes vote down vote up
public ClassDef adjust(ClassDef classDef) {
    return new ClassDef(target, classDef.getOffset(), adjustType(classDef.getTypeIndex()),
            classDef.getAccessFlags(), adjustType(classDef.getSupertypeIndex()),
            adjustTypeListOffset(classDef.getInterfacesOffset()), classDef.getSourceFileIndex(),
            classDef.getAnnotationsOffset(), classDef.getClassDataOffset(),
            classDef.getStaticValuesOffset());
}
 
Example 11
Source File: Grep.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Prints usages to out. Returns the number of matches found.
 */
public int grep() {
    for (ClassDef classDef : dex.classDefs()) {
        currentClass = classDef;
        currentMethod = null;

        if (classDef.getClassDataOffset() == 0) {
            continue;
        }

        ClassData classData = dex.readClassData(classDef);

        // find the strings in encoded constants
        int staticValuesOffset = classDef.getStaticValuesOffset();
        if (staticValuesOffset != 0) {
            readArray(new EncodedValueReader(dex.open(staticValuesOffset)));
        }

        // find the strings in method bodies
        for (ClassData.Method method : classData.allMethods()) {
            currentMethod = method;
            if (method.getCodeOffset() != 0) {
                codeReader.visitAll(dex.readCode(method).getInstructions());
            }
        }
    }

    currentClass = null;
    currentMethod = null;
    return count;
}