Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ path = "src/main.rs"
# to work fine in Linux.
profiling = ["pprof"]

# Enable the "debug" command. Calling it "developer" here because calling it
# "debug" is confusing as that implies a debug build.
developer = []

# When this feature is enabled the CLI program prints debug logs if
# the RUST_LOG environment variable is set to any of the debug levels:
#
Expand Down
15 changes: 14 additions & 1 deletion cli/src/commands/debug.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg(feature = "developer")]
use std::fs;
use std::path::PathBuf;

Expand Down Expand Up @@ -39,21 +40,26 @@ 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")
.arg_required_else_help(true)
.hide(true)
.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(())
}
2 changes: 2 additions & 0 deletions cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mod scan;
pub use check::*;
pub use compile::*;
pub use completion::*;
#[cfg(feature = "developer")]
pub use debug::*;
pub use dump::*;
pub use fix::*;
Expand Down Expand Up @@ -54,6 +55,7 @@ pub fn cli() -> Command {
commands::scan(),
commands::compile(),
commands::check(),
#[cfg(feature = "developer")]
commands::debug(),
commands::dump(),
commands::fmt(),
Expand Down
1 change: 1 addition & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ fn main() -> anyhow::Result<()> {
}));

let result = match args.subcommand() {
#[cfg(feature = "developer")]
Some(("debug", args)) => commands::exec_debug(args),
Some(("check", args)) => commands::exec_check(args),
Some(("fix", args)) => commands::exec_fix(args),
Expand Down
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()
}
}