Skip to main content

rapx/
cli.rs

1mod analyze;
2mod check;
3mod verify;
4
5pub use analyze::*;
6pub use check::*;
7use clap::{Args, Subcommand};
8pub use verify::PostfixRepeat;
9pub use verify::*;
10
11#[derive(Args, Debug, Clone)]
12pub struct RapxArgs {
13    #[command(subcommand)]
14    pub command: Commands,
15    #[arg(long, help = "specify the timeout seconds in running rapx")]
16    pub timeout: Option<u64>,
17    #[arg(long, help = "specify the tested package in the workspace")]
18    pub test_crate: Option<String>,
19}
20
21// NOTE: docstring is automatically used to generate help messages,
22// so please use it to explain the command instead of `help` attribute in `arg` macro.
23#[derive(Debug, Clone, Subcommand)]
24pub enum Commands {
25    /// perform various analyses on the crate, e.g., alias analysis, callgraph generation
26    #[command(arg_required_else_help = true)]
27    Analyze {
28        #[command(subcommand)]
29        kind: AnalysisKind,
30    },
31    /// check potential vulnerabilities in the crate,
32    /// e.g., use-after-free, memory leak
33    Check(CheckArgs),
34    /// detect code optimization opportunities
35    Opt,
36    /// verify annotated functions in the crate, e.g., identify #[rapx::verify] targets
37    Verify(VerifyArgs),
38}
39
40impl RapxArgs {
41    pub fn init_env(&self) {
42        let Commands::Check(CheckArgs {
43            uaf: Some(level), ..
44        }) = &self.command
45        else {
46            return;
47        };
48        unsafe {
49            std::env::set_var("MOP", level.to_string());
50        }
51    }
52}