3

我正在制作一个使用dex2jar库将 dex 文件(从 android 应用程序包)转换为 jar 文件的应用程序。但是这个过程需要很长时间,尤其是由于 android.support。x类。有没有办法让 dex2jar 在反编译时跳过某些类(我们指定)?

这是我目前正在使用的代码:

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);
4

1 回答 1

2

您可以使用dexlib2加载 dex 文件,删除您不感兴趣的类,然后构建一个新的 dex 文件

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);
于 2014-02-07T18:04:15.630 回答