Java Code Examples for org.jf.dexlib2.iface.DexFile

Following code examples demonstrate how to use org.jf.dexlib2.iface.DexFilefrom android. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.jf.dexlib2.iface.DexFileand various code implementation of this class.

    public DexFileWrapper(DexFile dexFile) {
        this.dexFile = dexFile;

        ClassDefSet set = new ClassDefSet();
        Set<? extends ClassDef> classDefs = dexFile.getClasses();
        for (ClassDef classDef : classDefs) {
        classes = set;

    public static DexFile loadDexFile(File binaryArchiveFile) throws Exception {
        DexBackedDexFile newDexFile = DexFileFactory.loadDexFile(binaryArchiveFile,

        return newDexFile;

    public static List<String> readClassNamesFromDex(File binaryArchiveFile) throws Exception {
        DexFile dexFile = DexlibLoader.loadDexFile(binaryArchiveFile);
        List<String> result = new ArrayList<>();

        for (ClassDef classDef : dexFile.getClasses()) {
            result.add(classDef.getType().replaceAll("/", ".").
                    substring(1, classDef.getType().length() - 1));

        return result;

	public void deOdex(DexFile parentFile) {
		if (!(parentFile instanceof DexBackedOdexFile))
			throw new RuntimeException("ODEX instruction in non-ODEX file");
		DexBackedOdexFile odexFile = (DexBackedOdexFile) parentFile;
		InlineMethodResolver inlineMethodResolver = InlineMethodResolver.createInlineMethodResolver(
		targetMethod = inlineMethodResolver.resolveExecuteInline(
				new AnalyzedInstruction(instruction, -1, -1));

This class is a high level representation of a dex file - essentially a set of class definitions.