Added debugLinePrefix CLI option.

This commit is contained in:
Ryszard Wiśniewski 2013-05-04 22:04:26 +02:00
parent 0b37a23874
commit 89133557ca
4 changed files with 26 additions and 7 deletions

View File

@ -120,6 +120,9 @@ public class Main {
if (cli.hasOption("d") || cli.hasOption("debug")) { if (cli.hasOption("d") || cli.hasOption("debug")) {
decoder.setDebugMode(true); decoder.setDebugMode(true);
} }
if (cli.hasOption("debug-line-prefix")) {
decoder.setDebugLinePrefix(cli.getOptionValue("debug-line-prefix"));
}
if (cli.hasOption("b") || cli.hasOption("no-debug-info")) { if (cli.hasOption("b") || cli.hasOption("no-debug-info")) {
decoder.setBaksmaliDebugMode(false); decoder.setBaksmaliDebugMode(false);
} }
@ -278,6 +281,12 @@ public class Main {
.withDescription("Decode in debug mode. Check project page for more info.") .withDescription("Decode in debug mode. Check project page for more info.")
.create("d"); .create("d");
Option debugLinePrefix = OptionBuilder.withLongOpt("debug-line-prefix")
.withDescription("Smali line prefix when decoding in debug mode. Default is \"a=0;// \".")
.hasArg(true)
.withArgName("prefix")
.create();
Option debugBuiOption = OptionBuilder.withLongOpt("debug") Option debugBuiOption = OptionBuilder.withLongOpt("debug")
.withDescription("Builds in debug mode. Check project page for more info.") .withDescription("Builds in debug mode. Check project page for more info.")
.create("d"); .create("d");
@ -355,6 +364,7 @@ public class Main {
// check for advance mode // check for advance mode
if (isAdvanceMode()) { if (isAdvanceMode()) {
DecodeOptions.addOption(debugLinePrefix);
DecodeOptions.addOption(debugDecOption); DecodeOptions.addOption(debugDecOption);
DecodeOptions.addOption(noDbgOption); DecodeOptions.addOption(noDbgOption);
DecodeOptions.addOption(keepResOption); DecodeOptions.addOption(keepResOption);
@ -398,6 +408,7 @@ public class Main {
for (Object op : frameOptions.getOptions()) { for (Object op : frameOptions.getOptions()) {
allOptions.addOption((Option)op); allOptions.addOption((Option)op);
} }
allOptions.addOption(debugLinePrefix);
allOptions.addOption(debugDecOption); allOptions.addOption(debugDecOption);
allOptions.addOption(noDbgOption); allOptions.addOption(noDbgOption);
allOptions.addOption(keepResOption); allOptions.addOption(keepResOption);

View File

@ -64,14 +64,14 @@ public class Androlib {
} }
} }
public void decodeSourcesSmali(File apkFile, File outDir, boolean debug, public void decodeSourcesSmali(File apkFile, File outDir, boolean debug, String debugLinePrefix,
boolean bakdeb) throws AndrolibException { boolean bakdeb) 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, debug, bakdeb); SmaliDecoder.decode(apkFile, smaliDir, debug, debugLinePrefix, bakdeb);
} catch (BrutException ex) { } catch (BrutException ex) {
throw new AndrolibException(ex); throw new AndrolibException(ex);
} }

View File

@ -87,7 +87,7 @@ public class ApkDecoder {
mAndrolib.decodeSourcesRaw(mApkFile, outDir, mDebug); mAndrolib.decodeSourcesRaw(mApkFile, outDir, mDebug);
break; break;
case DECODE_SOURCES_SMALI: case DECODE_SOURCES_SMALI:
mAndrolib.decodeSourcesSmali(mApkFile, outDir, mDebug, mBakDeb); mAndrolib.decodeSourcesSmali(mApkFile, outDir, mDebug, mDebugLinePrefix, mBakDeb);
break; break;
case DECODE_SOURCES_JAVA: case DECODE_SOURCES_JAVA:
mAndrolib.decodeSourcesJava(mApkFile, outDir, mDebug); mAndrolib.decodeSourcesJava(mApkFile, outDir, mDebug);
@ -157,6 +157,10 @@ public class ApkDecoder {
mDebug = debug; mDebug = debug;
} }
public void setDebugLinePrefix(String debugLinePrefix) {
mDebugLinePrefix = debugLinePrefix;
}
public void setBaksmaliDebugMode(boolean bakdeb) { public void setBaksmaliDebugMode(boolean bakdeb) {
mBakDeb = bakdeb; mBakDeb = bakdeb;
} }
@ -328,6 +332,7 @@ public class ApkDecoder {
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; private boolean mDebug = false;
private String mDebugLinePrefix = "a=0;// ";
private boolean mForceDelete = false; private boolean mForceDelete = false;
private String mFrameTag; private String mFrameTag;
private boolean mKeepBrokenResources = false; private boolean mKeepBrokenResources = false;

View File

@ -37,16 +37,17 @@ import java.nio.file.attribute.BasicFileAttributes;
*/ */
public class SmaliDecoder { public class SmaliDecoder {
public static void decode(File apkFile, File outDir, boolean debug, public static void decode(File apkFile, File outDir, boolean debug, String debugLinePrefix,
boolean bakdeb) throws AndrolibException { boolean bakdeb) throws AndrolibException {
new SmaliDecoder(apkFile, outDir, debug, bakdeb).decode(); new SmaliDecoder(apkFile, outDir, debug, debugLinePrefix, bakdeb).decode();
} }
private SmaliDecoder(File apkFile, File outDir, boolean debug, private SmaliDecoder(File apkFile, File outDir, boolean debug, String debugLinePrefix,
boolean bakdeb) { boolean bakdeb) {
mApkFile = apkFile; mApkFile = apkFile;
mOutDir = outDir.toPath(); mOutDir = outDir.toPath();
mDebug = debug; mDebug = debug;
mDebugLinePrefix = debugLinePrefix;
mBakDeb = bakdeb; mBakDeb = bakdeb;
} }
@ -69,6 +70,7 @@ public class SmaliDecoder {
private final File mApkFile; private final File mApkFile;
private final Path mOutDir; private final Path mOutDir;
private final boolean mDebug; private final boolean mDebug;
private final String mDebugLinePrefix;
private final boolean mBakDeb; private final boolean mBakDeb;
@ -90,8 +92,9 @@ public class SmaliDecoder {
out.newLine(); out.newLine();
String line; String line;
final String debugLinePrefix = mDebugLinePrefix;
while ((line = in.readLine()) != null) { while ((line = in.readLine()) != null) {
out.write(";// "); out.write(debugLinePrefix);
out.write(line); out.write(line);
out.newLine(); out.newLine();
} }