1
1
#![ deny( unsafe_code) ]
2
2
3
+ use std:: io;
4
+
5
+ use clap:: {
6
+ builder:: { styling:: AnsiColor , Styles } ,
7
+ crate_authors, crate_description, crate_name, crate_version, value_parser, Arg , ArgAction ,
8
+ Command ,
9
+ } ;
10
+ use clap_complete:: { generate, Generator , Shell } ;
11
+ fn build_cli ( ) -> Command {
12
+ Command :: new ( crate_name ! ( ) )
13
+ . arg_required_else_help ( true )
14
+ . author ( crate_authors ! ( ) )
15
+ . about ( crate_description ! ( ) )
16
+ . version ( crate_version ! ( ) )
17
+ . long_about ( HELP )
18
+ . subcommand ( Command :: new ( "uaf" ) . about ( "Run the use-after-free bug" ) )
19
+ . subcommand (
20
+ Command :: new ( "bo" ) . about ( "Run the buffer overflow exploit. Optionally take a shower" ) ,
21
+ )
22
+ . subcommand ( Command :: new ( "transition" ) . about ( "Safely transmute a Boy to a Girl" ) )
23
+ . subcommand ( Command :: new ( "segfault" ) . about ( "Segfault yourself" ) )
24
+ . subcommand (
25
+ Command :: new ( "completions" )
26
+ . about ( "Return shell completions" )
27
+ . arg (
28
+ Arg :: new ( "shell" )
29
+ . action ( ArgAction :: Set )
30
+ . value_parser ( value_parser ! ( Shell ) )
31
+ . required ( true ) ,
32
+ ) ,
33
+ )
34
+ . styles ( STYLE )
35
+ . help_template ( TEMPLATE )
36
+ }
3
37
fn main ( ) {
4
- let mut args = std:: env:: args ( ) ;
5
- let _program = args. next ( ) ;
6
- let Some ( subcommand) = args. next ( ) else {
7
- println ! ( "{HELP}" ) ;
8
- return ;
9
- } ;
10
-
11
- match subcommand. as_str ( ) {
38
+ let mut command = build_cli ( ) ;
39
+ let matches = build_cli ( ) . clone ( ) . get_matches ( ) ;
40
+ let subcommand = matches. subcommand ( ) . unwrap ( ) ;
41
+ match subcommand. 0 {
12
42
"uaf" => cve_rs:: use_after_free ( ) ,
13
43
"segfault" => cve_rs:: segfault ( ) ,
14
44
"bo" => cve_rs:: buffer_overflow ( ) . unwrap ( ) ,
15
45
"transition" => transmute_demo ( ) . unwrap ( ) ,
16
- "help" | "--help" | "h" | "-h" | "?" | "-?" => println ! ( "{HELP}" ) ,
17
- other => println ! ( "Error: Unknown command `{other}`.\n {HELP}" ) ,
46
+ "completions" => print_completions (
47
+ subcommand. 1 . get_one :: < Shell > ( "shell" ) . copied ( ) . unwrap ( ) ,
48
+ & mut command,
49
+ ) ,
50
+ _ => unreachable ! ( ) ,
18
51
}
19
52
}
20
53
54
+ fn print_completions < G : Generator > ( gen : G , cmd : & mut Command ) {
55
+ generate ( gen, cmd, cmd. get_name ( ) . to_string ( ) , & mut io:: stdout ( ) ) ;
56
+ }
57
+
58
+ const STYLE : Styles = Styles :: styled ( )
59
+ . header ( AnsiColor :: Yellow . on_default ( ) )
60
+ . usage ( AnsiColor :: Green . on_default ( ) )
61
+ . literal ( AnsiColor :: Green . on_default ( ) )
62
+ . placeholder ( AnsiColor :: Green . on_default ( ) ) ;
63
+
64
+ const TEMPLATE : & str = "\
65
+ {before-help}{name} {version}
66
+ {author-with-newline}{about-with-newline}
67
+ {usage-heading} {usage}
68
+
69
+ {all-args}{after-help}
70
+ " ;
71
+
21
72
const HELP : & str = r"
22
73
cve-rs: Blazingly fast memory vulnerabilities, written in 100% safe rust.
23
74
@@ -27,13 +78,6 @@ cve-rs exploits a soundness hole in lifetimes that lets us cast any lifetime to
27
78
See: https://github.com/rust-lang/rust/issues/25860
28
79
29
80
This program is open-source! View the source for all these exploits here: https://github.com/Speykious/cve-rs
30
-
31
- Commands:
32
- help Show this help message.
33
- uaf Run the use-after-free bug.
34
- bo Run the buffer overflow exploit. Optionally take a shower.
35
- transition Safely transmute a Boy to a Girl.
36
- segfault Segfault yourself.
37
81
" ;
38
82
39
83
#[ repr( C ) ]
0 commit comments