diff --git a/cli/src/commands/debug.rs b/cli/src/commands/debug.rs index f29a80e3f..22027c7ef 100644 --- a/cli/src/commands/debug.rs +++ b/cli/src/commands/debug.rs @@ -39,6 +39,10 @@ pub fn wasm() -> Command { ) } +pub fn modules() -> Command { + super::command("modules").about("List available modules") +} + pub fn debug() -> Command { super::command("debug") .about("Debug utilities") @@ -47,6 +51,7 @@ pub fn debug() -> Command { .subcommand(ast()) .subcommand(cst()) .subcommand(wasm()) + .subcommand(modules()) } pub fn exec_debug(args: &ArgMatches) -> anyhow::Result<()> { @@ -54,6 +59,7 @@ pub fn exec_debug(args: &ArgMatches) -> anyhow::Result<()> { Some(("ast", args)) => exec_ast(args), Some(("cst", args)) => exec_cst(args), Some(("wasm", args)) => exec_wasm(args), + Some(("modules", args)) => exec_modules(args), _ => unreachable!(), } } @@ -104,3 +110,10 @@ fn exec_wasm(args: &ArgMatches) -> anyhow::Result<()> { Ok(()) } + +fn exec_modules(_args: &ArgMatches) -> anyhow::Result<()> { + for name in yara_x::mods::module_names() { + println!("{}", name); + } + Ok(()) +} diff --git a/lib/src/modules/mod.rs b/lib/src/modules/mod.rs index 7af5cae14..52c7e9259 100644 --- a/lib/src/modules/mod.rs +++ b/lib/src/modules/mod.rs @@ -256,4 +256,12 @@ pub mod mods { info.lnk = protobuf::MessageField(invoke::(data)); info } + + /// A vector of all module names. Useful for displaying currently compiled + /// modules. + /// + /// See the "debug modules" command. + pub fn module_names() -> Vec<&'static str> { + super::BUILTIN_MODULES.keys().map(|&k| k).collect() + } }