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")) {
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")) {
decoder.setBaksmaliDebugMode(false);
}
@ -278,6 +281,12 @@ public class Main {
.withDescription("Decode in debug mode. Check project page for more info.")
.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")
.withDescription("Builds in debug mode. Check project page for more info.")
.create("d");
@ -355,6 +364,7 @@ public class Main {
// check for advance mode
if (isAdvanceMode()) {
DecodeOptions.addOption(debugLinePrefix);
DecodeOptions.addOption(debugDecOption);
DecodeOptions.addOption(noDbgOption);
DecodeOptions.addOption(keepResOption);
@ -398,6 +408,7 @@ public class Main {
for (Object op : frameOptions.getOptions()) {
allOptions.addOption((Option)op);
}
allOptions.addOption(debugLinePrefix);
allOptions.addOption(debugDecOption);
allOptions.addOption(noDbgOption);
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 {
try {
File smaliDir = new File(outDir, SMALI_DIRNAME);
OS.rmdir(smaliDir);
smaliDir.mkdirs();
LOGGER.info("Baksmaling...");
SmaliDecoder.decode(apkFile, smaliDir, debug, bakdeb);
SmaliDecoder.decode(apkFile, smaliDir, debug, debugLinePrefix, bakdeb);
} catch (BrutException ex) {
throw new AndrolibException(ex);
}

View File

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

View File

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