Multiple Dex Support - part 3

- dexlib2 handles non classes.dex
 - cleaned up functions
 - cs fixes
This commit is contained in:
Connor Tumbleson 2014-08-16 08:45:43 -05:00
parent 292e49de0a
commit 7ef993cc75
3 changed files with 15 additions and 38 deletions

View File

@ -58,48 +58,24 @@ public class Androlib {
return mAndRes.getResTable(apkFile, loadMainPkg);
}
public void decodeSourcesRaw(ExtFile apkFile, File outDir)
throws AndrolibException {
LOGGER.info("Copying raw classes.dex file...");
copySourceRaw(apkFile, outDir, "classes.dex");
}
public void decodeNonDefaultSourcesRaw(ExtFile apkFile, File outDir, String filename)
throws AndrolibException {
LOGGER.info("Copying raw " + filename + " file...");
copySourceRaw(apkFile, outDir, filename);
}
public void copySourceRaw(ExtFile apkFile, File outDir, String filename)
public void decodeSourcesRaw(ExtFile apkFile, File outDir, String filename)
throws AndrolibException {
try {
LOGGER.info("Copying raw classes.dex file...");
apkFile.getDirectory().copyToDir(outDir, filename);
} catch (DirectoryException ex) {
throw new AndrolibException(ex);
}
}
public void decodeSourcesSmali(File apkFile, File outDir, boolean debug, String debugLinePrefix,
public void decodeSourcesSmali(File apkFile, File outDir, String filename, boolean debug, String debugLinePrefix,
boolean bakdeb, int api) throws AndrolibException {
try {
File smaliDir = new File(outDir, SMALI_DIRNAME);
OS.rmdir(smaliDir);
smaliDir.mkdirs();
LOGGER.info("Baksmaling classes.dex...");
SmaliDecoder.decode(apkFile, smaliDir, debug, debugLinePrefix, bakdeb, api);
} catch (BrutException ex) {
throw new AndrolibException(ex);
}
}
public void decodeNonDefaultSourcesSmali(File apkFile, File outDir, String filename, boolean debug,
String debugLinePrefix, boolean bakdeb, int api) throws AndrolibException {
try {
File smaliDir = new File(outDir, SMALI_DIRNAME + "_" + filename.substring(0, filename.indexOf(".")));
OS.rmdir(smaliDir);
smaliDir.mkdirs();
LOGGER.info("Baksmaling " + filename + "...");
SmaliDecoder.decode(apkFile, smaliDir, debug, debugLinePrefix, bakdeb, api);
SmaliDecoder.decode(apkFile, smaliDir, filename, debug, debugLinePrefix, bakdeb, api);
} catch (BrutException ex) {
throw new AndrolibException(ex);
}

View File

@ -134,10 +134,10 @@ public class ApkDecoder {
if (hasSources()) {
switch (mDecodeSources) {
case DECODE_SOURCES_NONE:
mAndrolib.decodeSourcesRaw(mApkFile, outDir);
mAndrolib.decodeSourcesRaw(mApkFile, outDir, "classes.dex");
break;
case DECODE_SOURCES_SMALI:
mAndrolib.decodeSourcesSmali(mApkFile, outDir, mDebug, mDebugLinePrefix, mBakDeb, mApi);
mAndrolib.decodeSourcesSmali(mApkFile, outDir, "classes.dex", mDebug, mDebugLinePrefix, mBakDeb, mApi);
break;
case DECODE_SOURCES_JAVA:
mAndrolib.decodeSourcesJava(mApkFile, outDir, mDebug);
@ -153,10 +153,10 @@ public class ApkDecoder {
if (! file.equalsIgnoreCase("classes.dex")) {
switch(mDecodeSources) {
case DECODE_SOURCES_NONE:
mAndrolib.decodeNonDefaultSourcesRaw(mApkFile, outDir, file);
mAndrolib.decodeSourcesRaw(mApkFile, outDir, file);
break;
case DECODE_SOURCES_SMALI:
mAndrolib.decodeNonDefaultSourcesSmali(mApkFile, outDir, file, mDebug, mDebugLinePrefix, mBakDeb, mApi);
mAndrolib.decodeSourcesSmali(mApkFile, outDir, file, mDebug, mDebugLinePrefix, mBakDeb, mApi);
break;
case DECODE_SOURCES_JAVA:
mAndrolib.decodeSourcesJava(mApkFile, outDir, mDebug);

View File

@ -41,15 +41,16 @@ import java.nio.file.attribute.BasicFileAttributes;
*/
public class SmaliDecoder {
public static void decode(File apkFile, File outDir, boolean debug, String debugLinePrefix,
public static void decode(File apkFile, File outDir, String dexName, boolean debug, String debugLinePrefix,
boolean bakdeb, int api) throws AndrolibException {
new SmaliDecoder(apkFile, outDir, debug, debugLinePrefix, bakdeb, api).decode();
new SmaliDecoder(apkFile, outDir, dexName, debug, debugLinePrefix, bakdeb, api).decode();
}
private SmaliDecoder(File apkFile, File outDir, boolean debug, String debugLinePrefix,
private SmaliDecoder(File apkFile, File outDir, String dexName, boolean debug, String debugLinePrefix,
boolean bakdeb, int api) {
mApkFile = apkFile;
mOutDir = outDir.toPath();
mDexFile = dexName;
mDebug = debug;
mDebugLinePrefix = debugLinePrefix;
mBakDeb = bakdeb;
@ -90,7 +91,7 @@ public class SmaliDecoder {
}
// create the dex
DexBackedDexFile dexFile = DexFileFactory.loadDexFile(mApkFile, mApi);
DexBackedDexFile dexFile = DexFileFactory.loadDexFile(mApkFile, mDexFile, mApi);
if (dexFile.isOdexFile()) {
throw new AndrolibException("Warning: You are disassembling an odex file without deodexing it.");
@ -115,10 +116,10 @@ public class SmaliDecoder {
private final Path mOutDir;
private final boolean mDebug;
private final String mDebugLinePrefix;
private final String mDexFile;
private final boolean mBakDeb;
private final int mApi;
private class SmaliFileVisitor extends SimpleFileVisitor<Path> {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {