rapx/
cli.rs

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