Domanda

I'm making an application that uses the dex2jar library to convert a dex file (from an android application package) to a jar file. But the process takes quite long especially due to android.support.x classes. Is there a way to make dex2jar skip certain classes (that we specify) while decompiling ?

This is the code that I'm currently using:

DexFileReader reader = new DexFileReader(new File(PackageDir));
Dex2jar.from(reader)
.reUseReg(reuseReg)
.topoLogicalSort(topologicalSort || topologicalSort1)
.skipDebug(!debugInfo)
.optimizeSynchronized(optmizeSynchronized)
.printIR(printIR)
.verbose(verbose)
.to(file);
È stato utile?

Soluzione

You could use dexlib2 to load the dex file, remove the classes you're not interested in, and then build a new dex file

int api = 19;
DexFile dexFile = DexFileFactory.loadDexFile(dexFilePath, api);

List<ClassDef> classes = new ArrayList<ClassDef>();

for (ClassDef classDef: dexFile.getClasses()) {
    if (!classDef.getType().startsWith("Landroid/support/")) {
        classes.add(classDef);
    }
}

dexFile = new ImmutableDexFile(classes);
DexFileFactory.writeDexFile(dexFilePath, dexFile);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top