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); return mAndRes.getResTable(apkFile, loadMainPkg);
} }
public void decodeSourcesRaw(ExtFile apkFile, File outDir) public void decodeSourcesRaw(ExtFile apkFile, File outDir, String filename)
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)
throws AndrolibException { throws AndrolibException {
try { try {
LOGGER.info("Copying raw classes.dex file...");
apkFile.getDirectory().copyToDir(outDir, filename); apkFile.getDirectory().copyToDir(outDir, filename);
} catch (DirectoryException ex) { } catch (DirectoryException ex) {
throw new AndrolibException(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 { 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 { try {
File smaliDir = new File(outDir, SMALI_DIRNAME + "_" + filename.substring(0, filename.indexOf("."))); File smaliDir = new File(outDir, SMALI_DIRNAME + "_" + filename.substring(0, filename.indexOf(".")));
OS.rmdir(smaliDir); OS.rmdir(smaliDir);
smaliDir.mkdirs();
LOGGER.info("Baksmaling " + filename + "..."); LOGGER.info("Baksmaling " + filename + "...");
SmaliDecoder.decode(apkFile, smaliDir, debug, debugLinePrefix, bakdeb, api); SmaliDecoder.decode(apkFile, smaliDir, filename, debug, debugLinePrefix, bakdeb, api);
} catch (BrutException ex) { } catch (BrutException ex) {
throw new AndrolibException(ex); throw new AndrolibException(ex);
} }

View File

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

View File

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