jad command support --source-only option. #496

This commit is contained in:
hengyunabc 2019-02-07 15:21:18 +08:00
parent c18bd53ed5
commit c4751931ce

View File

@ -40,6 +40,7 @@ import static com.taobao.text.ui.Element.label;
@Description(Constants.EXAMPLE +
" jad java.lang.String\n" +
" jad java.lang.String toString\n" +
" jad --source-only java.lang.String\n" +
" jad -c 39eb305e org/apache/log4j/Logger\n" +
" jad -c 39eb305e -E org\\\\.apache\\\\.*\\\\.StringUtils\n" +
Constants.WIKI + Constants.WIKI_HOME + "jad")
@ -52,6 +53,11 @@ public class JadCommand extends AnnotatedCommand {
private String code = null;
private boolean isRegEx = false;
/**
* jad output source code only
*/
private boolean sourceOnly = false;
@Argument(argName = "class-pattern", index = 0)
@Description("Class name pattern, use either '.' or '/' as separator")
public void setClassPattern(String classPattern) {
@ -77,6 +83,12 @@ public class JadCommand extends AnnotatedCommand {
isRegEx = regEx;
}
@Option(longName = "source-only", flag = true)
@Description("Output source code only")
public void setSourceOnly(boolean sourceOnly) {
this.sourceOnly = sourceOnly;
}
@Override
public void process(CommandProcess process) {
RowAffect affect = new RowAffect();
@ -97,7 +109,9 @@ public class JadCommand extends AnnotatedCommand {
processExactMatch(process, affect, inst, matchedClasses, withInnerClasses);
}
} finally {
process.write(affect + "\n");
if (!this.sourceOnly) {
process.write(affect + "\n");
}
process.end();
}
}
@ -120,6 +134,11 @@ public class JadCommand extends AnnotatedCommand {
source = "unknown";
}
if (this.sourceOnly) {
process.write(LangRenderUtil.render(source) + "\n");
return;
}
process.write("\n");
process.write(RenderUtil.render(new LabelElement("ClassLoader: ").style(Decoration.bold.fg(Color.red)), process.width()));