Skip to content

Commit 85545cc

Browse files
committed
Add ability to transmute girl to boy
Resolves issue #45
1 parent 57799e7 commit 85545cc

File tree

1 file changed

+42
-12
lines changed

1 file changed

+42
-12
lines changed

src/main.rs

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use clap::{
88
Command,
99
};
1010
use clap_complete::{generate, Generator, Shell};
11+
1112
fn build_cli() -> Command {
1213
Command::new(crate_name!())
1314
.arg_required_else_help(true)
@@ -19,7 +20,12 @@ fn build_cli() -> Command {
1920
.subcommand(
2021
Command::new("bo").about("Run the buffer overflow exploit. Optionally take a shower"),
2122
)
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+
)
2329
.subcommand(Command::new("segfault").about("Segfault yourself"))
2430
.subcommand(
2531
Command::new("completions")
@@ -34,6 +40,7 @@ fn build_cli() -> Command {
3440
.styles(STYLE)
3541
.help_template(TEMPLATE)
3642
}
43+
3744
fn main() {
3845
let mut command = build_cli();
3946
let matches = build_cli().clone().get_matches();
@@ -42,7 +49,10 @@ fn main() {
4249
"uaf" => cve_rs::use_after_free(),
4350
"segfault" => cve_rs::segfault(),
4451
"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+
}
4656
"completions" => print_completions(
4757
subcommand.1.get_one::<Shell>("shell").copied().unwrap(),
4858
&mut command,
@@ -96,14 +106,18 @@ struct Girl {
96106
github_username: String,
97107
}
98108

99-
fn transmute_demo() -> std::io::Result<()> {
109+
fn transmute_demo(command: &str) -> std::io::Result<()> {
100110
use std::io::Write as _;
101111

102112
let stdin = std::io::stdin();
103113
let mut stdout = std::io::stdout();
104114
let mut input_buf = String::new();
105115

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+
}
107121

108122
let age = {
109123
stdout.write_all(b"Enter age: ")?;
@@ -135,17 +149,33 @@ fn transmute_demo() -> std::io::Result<()> {
135149
input_buf.trim().to_owned()
136150
};
137151

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+
}
143164

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:?}");
145172

146-
let girl: Girl = cve_rs::transmute(boy);
173+
let boy: Boy = cve_rs::transmute(girl);
174+
println!("After transmute: {boy:?}");
175+
}
147176

148-
println!("After transmute: {girl:?}");
177+
_ => unreachable!(),
178+
}
149179

150180
Ok(())
151181
}

0 commit comments

Comments
 (0)