Skip to content

Commit

Permalink
Add "modules" subcommand to "debug".
Browse files Browse the repository at this point in the history
Add the ability to print available modules via "yr debug modules".

I experimented with making it take a "verbose" flag that would also print the
protobuf definition of the module, which would make it easier for users to find
out what is "available" to use from the module in their rules, but it was a lot
to print out and would require users to translate from the protobuf types into
YARA types, which is probably more than they want to do.
  • Loading branch information
wxsBSD committed Aug 16, 2024
1 parent fb15a01 commit 7cc5459
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cli/src/commands/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -47,13 +51,15 @@ pub fn debug() -> Command {
.subcommand(ast())
.subcommand(cst())
.subcommand(wasm())
.subcommand(modules())
}

pub fn exec_debug(args: &ArgMatches) -> anyhow::Result<()> {
match args.subcommand() {
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!(),
}
}
Expand Down Expand Up @@ -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(())
}
8 changes: 8 additions & 0 deletions lib/src/modules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,12 @@ pub mod mods {
info.lnk = protobuf::MessageField(invoke::<Lnk>(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()
}
}

0 comments on commit 7cc5459

Please sign in to comment.