Androlib, ApkDecoder: added support for debug mode.

This commit is contained in:
Ryszard Wiśniewski 2010-04-27 21:44:59 +02:00
parent 2891abf96b
commit fe6580427f
2 changed files with 33 additions and 22 deletions

View File

@ -41,9 +41,12 @@ public class Androlib {
return mAndRes.getResTable(apkFile); return mAndRes.getResTable(apkFile);
} }
public void decodeSourcesRaw(ExtFile apkFile, File outDir) public void decodeSourcesRaw(ExtFile apkFile, File outDir, boolean debug)
throws AndrolibException { throws AndrolibException {
try { try {
if (debug) {
LOGGER.warning("Debug mode not available.");
}
Directory apk = apkFile.getDirectory(); Directory apk = apkFile.getDirectory();
if (apk.containsFile("classes.dex")) { if (apk.containsFile("classes.dex")) {
LOGGER.info("Copying raw classes.dex file..."); LOGGER.info("Copying raw classes.dex file...");
@ -54,20 +57,20 @@ public class Androlib {
} }
} }
public void decodeSourcesSmali(File apkFile, File outDir) public void decodeSourcesSmali(File apkFile, File outDir, boolean debug)
throws AndrolibException { throws AndrolibException {
try { try {
File smaliDir = new File(outDir, SMALI_DIRNAME); File smaliDir = new File(outDir, SMALI_DIRNAME);
OS.rmdir(smaliDir); OS.rmdir(smaliDir);
smaliDir.mkdirs(); smaliDir.mkdirs();
LOGGER.info("Baksmaling..."); LOGGER.info("Baksmaling...");
SmaliDecoder.decode(apkFile, smaliDir, false); SmaliDecoder.decode(apkFile, smaliDir, debug);
} catch (BrutException ex) { } catch (BrutException ex) {
throw new AndrolibException(ex); throw new AndrolibException(ex);
} }
} }
public void decodeSourcesJava(ExtFile apkFile, File outDir) public void decodeSourcesJava(ExtFile apkFile, File outDir, boolean debug)
throws AndrolibException { throws AndrolibException {
LOGGER.info("Decoding Java sources..."); LOGGER.info("Decoding Java sources...");
new AndrolibJava().decode(apkFile, outDir); new AndrolibJava().decode(apkFile, outDir);
@ -109,39 +112,42 @@ public class Androlib {
} }
} }
public void build(File appDir, boolean forceBuildAll) public void build(File appDir, boolean forceBuildAll, boolean debug)
throws AndrolibException { throws AndrolibException {
build(new ExtFile(appDir), forceBuildAll); build(new ExtFile(appDir), forceBuildAll, debug);
} }
public void build(ExtFile appDir, boolean forceBuildAll) public void build(ExtFile appDir, boolean forceBuildAll, boolean debug)
throws AndrolibException { throws AndrolibException {
boolean framework = mAndRes.detectWhetherAppIsFramework(appDir); boolean framework = mAndRes.detectWhetherAppIsFramework(appDir);
new File(appDir, APK_DIRNAME).mkdirs(); new File(appDir, APK_DIRNAME).mkdirs();
buildSources(appDir, forceBuildAll); buildSources(appDir, forceBuildAll, debug);
buildResources(appDir, forceBuildAll, framework); buildResources(appDir, forceBuildAll, framework);
buildLib(appDir, forceBuildAll); buildLib(appDir, forceBuildAll);
buildApk(appDir, framework); buildApk(appDir, framework);
} }
public void buildSources(File appDir, boolean forceBuildAll) public void buildSources(File appDir, boolean forceBuildAll, boolean debug)
throws AndrolibException { throws AndrolibException {
if (! buildSourcesRaw(appDir, forceBuildAll) if (! buildSourcesRaw(appDir, forceBuildAll, debug)
&& ! buildSourcesSmali(appDir, forceBuildAll) && ! buildSourcesSmali(appDir, forceBuildAll, debug)
&& ! buildSourcesJava(appDir, forceBuildAll) && ! buildSourcesJava(appDir, forceBuildAll, debug)
) { ) {
LOGGER.warning("Could not find sources"); LOGGER.warning("Could not find sources");
} }
} }
public boolean buildSourcesRaw(File appDir, boolean forceBuildAll) public boolean buildSourcesRaw(File appDir, boolean forceBuildAll,
throws AndrolibException { boolean debug) throws AndrolibException {
try { try {
File working = new File(appDir, "classes.dex"); File working = new File(appDir, "classes.dex");
if (! working.exists()) { if (! working.exists()) {
return false; return false;
} }
if (debug) {
LOGGER.warning("Debug mode not available.");
}
File stored = new File(appDir, APK_DIRNAME + "/classes.dex"); File stored = new File(appDir, APK_DIRNAME + "/classes.dex");
if (forceBuildAll || isModified(working, stored)) { if (forceBuildAll || isModified(working, stored)) {
LOGGER.info("Copying classes.dex file..."); LOGGER.info("Copying classes.dex file...");
@ -154,8 +160,8 @@ public class Androlib {
} }
} }
public boolean buildSourcesSmali(File appDir, boolean forceBuildAll) public boolean buildSourcesSmali(File appDir, boolean forceBuildAll,
throws AndrolibException { boolean debug) throws AndrolibException {
ExtFile smaliDir = new ExtFile(appDir, "smali"); ExtFile smaliDir = new ExtFile(appDir, "smali");
if (! smaliDir.exists()) { if (! smaliDir.exists()) {
return false; return false;
@ -167,13 +173,13 @@ public class Androlib {
if (forceBuildAll || isModified(smaliDir, dex)) { if (forceBuildAll || isModified(smaliDir, dex)) {
LOGGER.info("Smaling..."); LOGGER.info("Smaling...");
dex.delete(); dex.delete();
SmaliBuilder.build(smaliDir, dex, false); SmaliBuilder.build(smaliDir, dex, debug);
} }
return true; return true;
} }
public boolean buildSourcesJava(File appDir, boolean forceBuildAll) public boolean buildSourcesJava(File appDir, boolean forceBuildAll,
throws AndrolibException { boolean debug) throws AndrolibException {
File javaDir = new File(appDir, "src"); File javaDir = new File(appDir, "src");
if (! javaDir.exists()) { if (! javaDir.exists()) {
return false; return false;

View File

@ -63,13 +63,13 @@ public class ApkDecoder {
switch (mDecodeSources) { switch (mDecodeSources) {
case DECODE_SOURCES_NONE: case DECODE_SOURCES_NONE:
mAndrolib.decodeSourcesRaw(mApkFile, outDir); mAndrolib.decodeSourcesRaw(mApkFile, outDir, mDebug);
break; break;
case DECODE_SOURCES_SMALI: case DECODE_SOURCES_SMALI:
mAndrolib.decodeSourcesSmali(mApkFile, outDir); mAndrolib.decodeSourcesSmali(mApkFile, outDir, mDebug);
break; break;
case DECODE_SOURCES_JAVA: case DECODE_SOURCES_JAVA:
mAndrolib.decodeSourcesJava(mApkFile, outDir); mAndrolib.decodeSourcesJava(mApkFile, outDir, mDebug);
break; break;
} }
switch (mDecodeResources) { switch (mDecodeResources) {
@ -98,6 +98,10 @@ public class ApkDecoder {
mDecodeResources = mode; mDecodeResources = mode;
} }
public void setDebugMode(boolean debug) {
mDebug = debug;
}
public ResTable getResTable() throws AndrolibException { public ResTable getResTable() throws AndrolibException {
if (mResTable == null) { if (mResTable == null) {
mResTable = mAndrolib.getResTable(mApkFile); mResTable = mAndrolib.getResTable(mApkFile);
@ -128,4 +132,5 @@ public class ApkDecoder {
private ResTable mResTable; private ResTable mResTable;
private short mDecodeSources = DECODE_SOURCES_SMALI; private short mDecodeSources = DECODE_SOURCES_SMALI;
private short mDecodeResources = DECODE_RESOURCES_FULL; private short mDecodeResources = DECODE_RESOURCES_FULL;
private boolean mDebug = false;
} }