From fe6580427f39080d4cf32997b39813ca02c30d67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ryszard=20Wi=C5=9Bniewski?= Date: Tue, 27 Apr 2010 21:44:59 +0200 Subject: [PATCH] Androlib, ApkDecoder: added support for debug mode. --- src/brut/androlib/Androlib.java | 44 ++++++++++++++++++------------- src/brut/androlib/ApkDecoder.java | 11 +++++--- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/brut/androlib/Androlib.java b/src/brut/androlib/Androlib.java index 79b1eedc..33c62f11 100644 --- a/src/brut/androlib/Androlib.java +++ b/src/brut/androlib/Androlib.java @@ -41,9 +41,12 @@ public class Androlib { return mAndRes.getResTable(apkFile); } - public void decodeSourcesRaw(ExtFile apkFile, File outDir) + public void decodeSourcesRaw(ExtFile apkFile, File outDir, boolean debug) throws AndrolibException { try { + if (debug) { + LOGGER.warning("Debug mode not available."); + } Directory apk = apkFile.getDirectory(); if (apk.containsFile("classes.dex")) { 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 { try { File smaliDir = new File(outDir, SMALI_DIRNAME); OS.rmdir(smaliDir); smaliDir.mkdirs(); LOGGER.info("Baksmaling..."); - SmaliDecoder.decode(apkFile, smaliDir, false); + SmaliDecoder.decode(apkFile, smaliDir, debug); } catch (BrutException ex) { throw new AndrolibException(ex); } } - public void decodeSourcesJava(ExtFile apkFile, File outDir) + public void decodeSourcesJava(ExtFile apkFile, File outDir, boolean debug) throws AndrolibException { LOGGER.info("Decoding Java sources..."); 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 { - 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 { boolean framework = mAndRes.detectWhetherAppIsFramework(appDir); new File(appDir, APK_DIRNAME).mkdirs(); - buildSources(appDir, forceBuildAll); + buildSources(appDir, forceBuildAll, debug); buildResources(appDir, forceBuildAll, framework); buildLib(appDir, forceBuildAll); buildApk(appDir, framework); } - public void buildSources(File appDir, boolean forceBuildAll) + public void buildSources(File appDir, boolean forceBuildAll, boolean debug) throws AndrolibException { - if (! buildSourcesRaw(appDir, forceBuildAll) - && ! buildSourcesSmali(appDir, forceBuildAll) - && ! buildSourcesJava(appDir, forceBuildAll) + if (! buildSourcesRaw(appDir, forceBuildAll, debug) + && ! buildSourcesSmali(appDir, forceBuildAll, debug) + && ! buildSourcesJava(appDir, forceBuildAll, debug) ) { LOGGER.warning("Could not find sources"); } } - public boolean buildSourcesRaw(File appDir, boolean forceBuildAll) - throws AndrolibException { + public boolean buildSourcesRaw(File appDir, boolean forceBuildAll, + boolean debug) throws AndrolibException { try { File working = new File(appDir, "classes.dex"); if (! working.exists()) { return false; } + if (debug) { + LOGGER.warning("Debug mode not available."); + } File stored = new File(appDir, APK_DIRNAME + "/classes.dex"); if (forceBuildAll || isModified(working, stored)) { LOGGER.info("Copying classes.dex file..."); @@ -154,8 +160,8 @@ public class Androlib { } } - public boolean buildSourcesSmali(File appDir, boolean forceBuildAll) - throws AndrolibException { + public boolean buildSourcesSmali(File appDir, boolean forceBuildAll, + boolean debug) throws AndrolibException { ExtFile smaliDir = new ExtFile(appDir, "smali"); if (! smaliDir.exists()) { return false; @@ -167,13 +173,13 @@ public class Androlib { if (forceBuildAll || isModified(smaliDir, dex)) { LOGGER.info("Smaling..."); dex.delete(); - SmaliBuilder.build(smaliDir, dex, false); + SmaliBuilder.build(smaliDir, dex, debug); } return true; } - public boolean buildSourcesJava(File appDir, boolean forceBuildAll) - throws AndrolibException { + public boolean buildSourcesJava(File appDir, boolean forceBuildAll, + boolean debug) throws AndrolibException { File javaDir = new File(appDir, "src"); if (! javaDir.exists()) { return false; diff --git a/src/brut/androlib/ApkDecoder.java b/src/brut/androlib/ApkDecoder.java index c521d1e6..1a7905fd 100644 --- a/src/brut/androlib/ApkDecoder.java +++ b/src/brut/androlib/ApkDecoder.java @@ -63,13 +63,13 @@ public class ApkDecoder { switch (mDecodeSources) { case DECODE_SOURCES_NONE: - mAndrolib.decodeSourcesRaw(mApkFile, outDir); + mAndrolib.decodeSourcesRaw(mApkFile, outDir, mDebug); break; case DECODE_SOURCES_SMALI: - mAndrolib.decodeSourcesSmali(mApkFile, outDir); + mAndrolib.decodeSourcesSmali(mApkFile, outDir, mDebug); break; case DECODE_SOURCES_JAVA: - mAndrolib.decodeSourcesJava(mApkFile, outDir); + mAndrolib.decodeSourcesJava(mApkFile, outDir, mDebug); break; } switch (mDecodeResources) { @@ -98,6 +98,10 @@ public class ApkDecoder { mDecodeResources = mode; } + public void setDebugMode(boolean debug) { + mDebug = debug; + } + public ResTable getResTable() throws AndrolibException { if (mResTable == null) { mResTable = mAndrolib.getResTable(mApkFile); @@ -128,4 +132,5 @@ public class ApkDecoder { private ResTable mResTable; private short mDecodeSources = DECODE_SOURCES_SMALI; private short mDecodeResources = DECODE_RESOURCES_FULL; + private boolean mDebug = false; }