Skip to content

Commit 8a3798d

Browse files
authored
Refactor RAPx CLI with enhanced argument parsing and help messages (#229)
* Refactor RAPx CLI - Added Clap for command-line argument parsing, enhancing usability and consistency with Cargo. - Introduced a new configuration module to manage command options and analysis types. - Removed deprecated help file and integrated help messages directly into the CLI structure. - Streamlined the analysis process by consolidating various analysis options into a unified command structure. - Updated the main execution flow to accommodate new command parsing and analysis initiation. - Removed unused functions and cleaned up the codebase for better maintainability. - Enhanced logging and error handling throughout the application. * feat: add CLI argument parsing with color-print support and enhance help messages * remove redundant imports * fix all tests * update README.md * fix typo errors * rename config to args * update rapx version to 0.7.0
1 parent fffe32d commit 8a3798d

14 files changed

Lines changed: 719 additions & 710 deletions

File tree

README.md

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -35,51 +35,39 @@ rustup default nightly-2025-12-06
3535
Check out supported options with `-help`:
3636

3737
```shell
38-
$ cargo rapx -help
39-
40-
Usage:
41-
cargo rapx [rapx options or rustc options] -- [cargo check options]
42-
43-
RAPx Options:
44-
45-
Application:
46-
-F or -uaf use-after-free/double free detection.
47-
-M or -mleak memory leakage detection.
48-
-O or -opt automatically detect code optimization chances.
49-
-I or -infer (under development) infer the safety properties required by unsafe APIs.
50-
-V or -verify (under development) verify if the safety requirements of unsafe API are satisfied.
51-
52-
Analysis:
53-
-alias perform alias analysis (meet-over-paths by default)
54-
-adg generate API dependency graphs
55-
-upg generate unsafety propagation graphs for each module.
56-
-upg-std generate unsafety propagation graphs for each module of the Rust standard library
57-
-callgraph generate callgraphs
58-
-dataflow generate dataflow graphs
59-
-ownedheap analyze if the type holds a piece of memory on heap
60-
-pathcond extract path constraints
61-
-range perform range analysis
62-
63-
General command:
64-
-help show help information
65-
-version show the version of RAPx
38+
$ cargo rapx --help
39+
40+
Usage: cargo rapx [OPTIONS] <COMMAND> [-- [CARGO_FLAGS]]
41+
42+
Commands:
43+
analyze perform various analyses on the crate, e.g., alias analysis, callgraph generation
44+
check check potential vulnerabilities in the crate, e.g., use-after-free, memory leak
45+
help Print this message or the help of the given subcommand(s)
46+
47+
Options:
48+
--timeout <TIMEOUT> specify the timeout seconds in running rapx
49+
--test-crate <TEST_CRATE> specify the tested package in the workspace
50+
-h, --help Print help
51+
-V, --version Print version
6652

6753
NOTE: multiple detections can be processed in single run by
68-
appending the options to the arguments. Like `cargo rapx -F -M`
54+
appending the options to the arguments. Like `cargo rapx -f -m`
6955
will perform two kinds of detection in a row.
7056

71-
e.g.
57+
Examples:
58+
7259
1. detect use-after-free and memory leak for a riscv target:
73-
cargo rapx -F -M -- --target riscv64gc-unknown-none-elf
60+
cargo rapx check -f -m -- --target riscv64gc-unknown-none-elf
7461
2. detect use-after-free and memory leak for tests:
75-
cargo rapx -F -M -- --tests
62+
cargo rapx check -f -m -- --tests
7663
3. detect use-after-free and memory leak for all members:
77-
cargo rapx -F -M -- --workspace
64+
cargo rapx check -f -m -- --workspace
7865

7966
Environment Variables (Values are case insensitive):
67+
8068
RAP_LOG verbosity of logging: trace, debug, info, warn
8169
trace: print all the detailed RAP execution traces.
82-
debug: display intermidiate analysis results.
70+
debug: display intermediate analysis results.
8371
warn: show bugs detected only.
8472

8573
RAP_CLEAN run cargo clean before check: true, false
@@ -98,7 +86,7 @@ If RAPx gets stuck after executing `cargo clean`, try manually downloading metad
9886
9987
RAPx supports the following environment variables (values are case insensitive):
10088
101-
| var | default when absent | one of these values | description |
89+
| var | default when absent | possible values | description |
10290
|-----------------|---------------------|---------------------|------------------------------|
10391
| `RAP_LOG` | info | debug, info, warn | verbosity of logging |
10492
| `RAP_CLEAN` | true | true, false | run cargo clean before check |

rapx/Cargo.lock

Lines changed: 177 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rapx/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rapx"
3-
version = "0.6.252"
3+
version = "0.7.0"
44
edition = "2024"
55
authors = ["Artisan-Lab <xuh@fudan.edu.cn>"]
66
default-run = "rapx"
@@ -47,6 +47,10 @@ itertools = "0.14.0"
4747
safety-parser = "0.4.1"
4848
syn = { version = "2", features = ["extra-traits", "full"] }
4949
rust_intervals = "0.3.0"
50+
clap = { version = "4.5.60"}
51+
clap-cargo = "0.18.3"
52+
shlex = "1.3.0"
53+
color-print = "0.3.7"
5054
[features]
5155
backtraces = ["snafu/backtraces", "snafu/backtraces-impl-backtrace-crate"]
5256

rapx/src/analysis/core/alias_analysis/default/alias.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl<'tcx> MopGraph<'tcx> {
203203
pub fn sync_field_alias(&mut self, lv: usize, rv: usize, depth: usize, clear_left: bool) {
204204
rap_debug!("sync field aliases for lv:{} rv:{}", lv, rv);
205205

206-
let max_field_depth =15;
206+
let max_field_depth = 15;
207207

208208
if depth > max_field_depth {
209209
return;

0 commit comments

Comments
 (0)