@@ -8,6 +8,7 @@ use clap::{
8
8
Command ,
9
9
} ;
10
10
use clap_complete:: { generate, Generator , Shell } ;
11
+
11
12
fn build_cli ( ) -> Command {
12
13
Command :: new ( crate_name ! ( ) )
13
14
. arg_required_else_help ( true )
@@ -19,7 +20,12 @@ fn build_cli() -> Command {
19
20
. subcommand (
20
21
Command :: new ( "bo" ) . about ( "Run the buffer overflow exploit. Optionally take a shower" ) ,
21
22
)
22
- . subcommand ( Command :: new ( "transition" ) . about ( "Safely transmute a Boy to a Girl" ) )
23
+ . subcommand (
24
+ Command :: new ( "transition" )
25
+ . about ( "Safely transmute A to B" )
26
+ . subcommand ( Command :: new ( "boy-to-girl" ) . about ( "Safely transmute a Boy to a Girl" ) )
27
+ . subcommand ( Command :: new ( "girl-to-boy" ) . about ( "Safely transmute a Girl to a Boy" ) ) ,
28
+ )
23
29
. subcommand ( Command :: new ( "segfault" ) . about ( "Segfault yourself" ) )
24
30
. subcommand (
25
31
Command :: new ( "completions" )
@@ -34,6 +40,7 @@ fn build_cli() -> Command {
34
40
. styles ( STYLE )
35
41
. help_template ( TEMPLATE )
36
42
}
43
+
37
44
fn main ( ) {
38
45
let mut command = build_cli ( ) ;
39
46
let matches = build_cli ( ) . clone ( ) . get_matches ( ) ;
@@ -42,7 +49,10 @@ fn main() {
42
49
"uaf" => cve_rs:: use_after_free ( ) ,
43
50
"segfault" => cve_rs:: segfault ( ) ,
44
51
"bo" => cve_rs:: buffer_overflow ( ) . unwrap ( ) ,
45
- "transition" => transmute_demo ( ) . unwrap ( ) ,
52
+ "transition" => {
53
+ let command = subcommand. 1 . subcommand ( ) . expect ( "Invalid transition" ) . 0 ;
54
+ transmute_demo ( command) . unwrap ( )
55
+ }
46
56
"completions" => print_completions (
47
57
subcommand. 1 . get_one :: < Shell > ( "shell" ) . copied ( ) . unwrap ( ) ,
48
58
& mut command,
@@ -96,14 +106,18 @@ struct Girl {
96
106
github_username : String ,
97
107
}
98
108
99
- fn transmute_demo ( ) -> std:: io:: Result < ( ) > {
109
+ fn transmute_demo ( command : & str ) -> std:: io:: Result < ( ) > {
100
110
use std:: io:: Write as _;
101
111
102
112
let stdin = std:: io:: stdin ( ) ;
103
113
let mut stdout = std:: io:: stdout ( ) ;
104
114
let mut input_buf = String :: new ( ) ;
105
115
106
- stdout. write_all ( b"Creating a Boy struct\n " ) ?;
116
+ match command {
117
+ "boy-to-girl" => stdout. write_all ( b"Creating a Boy struct\n " ) ?,
118
+ "girl-to-boy" => stdout. write_all ( b"Creating a Girl struct\n " ) ?,
119
+ _ => unreachable ! ( ) ,
120
+ }
107
121
108
122
let age = {
109
123
stdout. write_all ( b"Enter age: " ) ?;
@@ -135,17 +149,33 @@ fn transmute_demo() -> std::io::Result<()> {
135
149
input_buf. trim ( ) . to_owned ( )
136
150
} ;
137
151
138
- let boy: Boy = Boy {
139
- age,
140
- name,
141
- github_username,
142
- } ;
152
+ match command {
153
+ "boy-to-girl" => {
154
+ let boy: Boy = Boy {
155
+ age,
156
+ name,
157
+ github_username,
158
+ } ;
159
+ println ! ( "Before transmute: {boy:?}" ) ;
160
+
161
+ let girl: Girl = cve_rs:: transmute ( boy) ;
162
+ println ! ( "After transmute: {girl:?}" ) ;
163
+ }
143
164
144
- println ! ( "Before transmute: {boy:?}" ) ;
165
+ "girl-to-boy" => {
166
+ let girl: Girl = Girl {
167
+ age,
168
+ name,
169
+ github_username,
170
+ } ;
171
+ println ! ( "Before transmute: {girl:?}" ) ;
145
172
146
- let girl: Girl = cve_rs:: transmute ( boy) ;
173
+ let boy: Boy = cve_rs:: transmute ( girl) ;
174
+ println ! ( "After transmute: {boy:?}" ) ;
175
+ }
147
176
148
- println ! ( "After transmute: {girl:?}" ) ;
177
+ _ => unreachable ! ( ) ,
178
+ }
149
179
150
180
Ok ( ( ) )
151
181
}
0 commit comments