mirror of
https://github.com/revanced/Apktool.git
synced 2025-01-05 17:45:52 +01:00
Androlib, ApkDecoder: added support for debug mode.
This commit is contained in:
parent
2891abf96b
commit
fe6580427f
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user