diff --git a/aderyn/src/main.rs b/aderyn/src/main.rs index fa8d0f001..b2f3f6322 100644 --- a/aderyn/src/main.rs +++ b/aderyn/src/main.rs @@ -39,6 +39,10 @@ pub struct CommandLineArgs { #[arg(short, long)] no_snippets: bool, + /// Print the output to stdout instead of a file + #[arg(long)] + stdout: bool, + /// Path to aderyn.config.json #[arg(short, long)] config_file: Option, @@ -81,6 +85,7 @@ fn main() { scope: cmd_args.scope, exclude: cmd_args.exclude, no_snippets: cmd_args.no_snippets, + stdout: cmd_args.stdout, }; let aderyn_config_path = match cmd_args.config_file { @@ -176,6 +181,7 @@ fn main() { scope: scope_lines, exclude: args.exclude, no_snippets: args.no_snippets, + stdout: args.stdout, }; driver::drive_with(new_args, subscriptions); } diff --git a/aderyn_core/src/lib.rs b/aderyn_core/src/lib.rs index 6eb24a015..556671304 100644 --- a/aderyn_core/src/lib.rs +++ b/aderyn_core/src/lib.rs @@ -27,6 +27,7 @@ pub fn run_with_printer( reporter: T, root_rel_path: PathBuf, no_snippets: bool, + stdout: bool, ) -> Result<(), Box> where T: ReportPrinter<()>, @@ -38,6 +39,7 @@ where reporter, root_rel_path, no_snippets, + stdout, detectors, ) } @@ -48,6 +50,7 @@ pub fn run_with_printer_and_given_detectors( reporter: T, root_rel_path: PathBuf, no_snippets: bool, + stdout: bool, mut detectors: Vec>, ) -> Result<(), Box> where @@ -104,21 +107,34 @@ where println!("Detectors run, processing found issues"); println!("Found issues processed. Printing report"); - reporter.print_report( - get_markdown_writer(&output_file_path)?, - &report, - context, - root_rel_path, - Some(output_file_path.clone()), - no_snippets, - detectors_used, - )?; - - println!("Report printed to {}", output_file_path); + if !stdout { + reporter.print_report( + get_writer(&output_file_path)?, + &report, + context, + root_rel_path, + Some(output_file_path.clone()), + no_snippets, + stdout, + detectors_used, + )?; + println!("Report printed to {}", output_file_path); + } else { + reporter.print_report( + io::stdout(), + &report, + context, + root_rel_path, + Some(output_file_path.clone()), + no_snippets, + stdout, + detectors_used, + )?; + } Ok(()) } -fn get_markdown_writer(filename: &str) -> io::Result { +fn get_writer(filename: &str) -> io::Result { let file_path = Path::new(filename); if let Some(parent_dir) = file_path.parent() { std::fs::create_dir_all(parent_dir)?; diff --git a/aderyn_core/src/report/json_printer.rs b/aderyn_core/src/report/json_printer.rs index c0cc63075..a06a4dfe4 100644 --- a/aderyn_core/src/report/json_printer.rs +++ b/aderyn_core/src/report/json_printer.rs @@ -1,5 +1,5 @@ use std::{ - io::{Result, Write}, + io::{self, Result, Write}, path::PathBuf, }; @@ -47,6 +47,7 @@ impl ReportPrinter<()> for JsonPrinter { _: PathBuf, _: Option, _: bool, + stdout: bool, detectors_used: &[(String, String)], ) -> Result<()> { let detectors_used_names: Vec<_> = detectors_used.iter().map(|x| x.0.clone()).collect(); @@ -63,6 +64,12 @@ impl ReportPrinter<()> for JsonPrinter { detectors_used: detectors_used_names, }; let value = serde_json::to_value(content).unwrap(); + if stdout { + println!("STDOUT START"); + let _ = serde_json::to_writer_pretty(io::stdout(), &value); + println!("STDOUT END"); + return Ok(()); + } _ = serde_json::to_writer_pretty(writer, &value); Ok(()) } diff --git a/aderyn_core/src/report/markdown_printer.rs b/aderyn_core/src/report/markdown_printer.rs index 4264db9e1..204dcd6a2 100644 --- a/aderyn_core/src/report/markdown_printer.rs +++ b/aderyn_core/src/report/markdown_printer.rs @@ -21,6 +21,7 @@ impl ReportPrinter<()> for MarkdownReportPrinter { root_path: PathBuf, output_rel_path: Option, no_snippets: bool, + _: bool, detectors_used: &[(String, String)], ) -> Result<()> { self.print_title_and_disclaimer(&mut writer)?; diff --git a/aderyn_core/src/report/printer.rs b/aderyn_core/src/report/printer.rs index 8063b3362..b7f873f43 100644 --- a/aderyn_core/src/report/printer.rs +++ b/aderyn_core/src/report/printer.rs @@ -17,6 +17,7 @@ pub trait ReportPrinter { root_rel_path: PathBuf, output_rel_path: Option, // you writer 'W' may or may not be writing a file. Eg: it can simply consume and forget :P no_snippets: bool, + stdout: bool, detectors_used: &[(String, String)], ) -> Result; } diff --git a/aderyn_driver/src/driver.rs b/aderyn_driver/src/driver.rs index c72a83c46..0f5c6d62f 100644 --- a/aderyn_driver/src/driver.rs +++ b/aderyn_driver/src/driver.rs @@ -14,6 +14,7 @@ pub struct Args { pub exclude: Option>, pub scope: Option>, pub no_snippets: bool, + pub stdout: bool, } enum Framework { @@ -35,6 +36,7 @@ pub fn drive(args: Args) { JsonPrinter, root_rel_path, args.no_snippets, + args.stdout, ) .unwrap_or_else(|err| { // Exit with a non-zero exit code @@ -50,6 +52,7 @@ pub fn drive(args: Args) { MarkdownReportPrinter, root_rel_path, args.no_snippets, + args.stdout, ) .unwrap_or_else(|err| { // Exit with a non-zero exit code @@ -74,6 +77,7 @@ pub fn drive_with(args: Args, detectors: Vec>) { JsonPrinter, root_rel_path, args.no_snippets, + args.stdout, detectors, ) .unwrap_or_else(|err| { @@ -90,6 +94,7 @@ pub fn drive_with(args: Args, detectors: Vec>) { MarkdownReportPrinter, root_rel_path, args.no_snippets, + args.stdout, detectors, ) .unwrap_or_else(|err| { diff --git a/aderyn_py/src/lib.rs b/aderyn_py/src/lib.rs index 8d80daacc..4797d2b5c 100644 --- a/aderyn_py/src/lib.rs +++ b/aderyn_py/src/lib.rs @@ -13,6 +13,7 @@ fn main() { no_snippets: false, // TODO support this later scope: None, // TODO support this later exclude: None, // TODO support this later + stdout: false, // TODO support this later }; driver::drive(args); } diff --git a/bot/src/bot_brain/custom_detectors.rs b/bot/src/bot_brain/custom_detectors.rs index 53eb635e9..6295fbb78 100644 --- a/bot/src/bot_brain/custom_detectors.rs +++ b/bot/src/bot_brain/custom_detectors.rs @@ -56,6 +56,7 @@ pub fn generate_report_for_judge( exclude, scope, no_snippets, + stdout: false, }, custom_detectors(), ) diff --git a/bot/src/runner.rs b/bot/src/runner.rs index 1f944d4eb..cc94c873b 100644 --- a/bot/src/runner.rs +++ b/bot/src/runner.rs @@ -20,6 +20,7 @@ pub fn run() { exclude: None, scope: None, no_snippets: false, + stdout: false, }, subscriptions, ) diff --git a/bot_example/src/main.rs b/bot_example/src/main.rs index 8c4ea7b01..14126bc92 100644 --- a/bot_example/src/main.rs +++ b/bot_example/src/main.rs @@ -33,6 +33,7 @@ fn main() { output: format!("bot_reports/{}default_analysis_report.md", cmd_args.prefix).to_string(), exclude: None, no_snippets: false, + stdout: false, scope: None, }); @@ -54,6 +55,7 @@ fn main() { .to_string(), exclude: None, no_snippets: false, + stdout: false, scope: None, }, subscribe_to, // inject subscriptions here @@ -80,6 +82,7 @@ fn main() { .to_string(), exclude: None, no_snippets: false, + stdout: false, scope: None, }, subscribe_to_hybrid, // inject subscriptions here diff --git a/nyth/archive.zip b/nyth/archive.zip index 899e691e8..ce1571237 100644 Binary files a/nyth/archive.zip and b/nyth/archive.zip differ