CTF writeup · · 1 min
picoCTF rust fix me: Repairing a Broken XOR Decryptor
A Rust program that XOR-decrypts the flag won't compile. Fixing the missing crate and the commented-out unsafe block gets it running.

- downloaded the tar.gz Archive
- extracted the archive to get the files

- cat the main.rs file to view the Rust file and see what it may have

Step-by-Step Fix
🛠️ 1. Import Missing Crate
text
The code uses xor_cryptor::XORCryptor, but this crate isn’t standard in Rust.
Check Cargo.toml. If xor_cryptor isn’t in [dependencies], add:
[dependencies]
xor-crypt = "0.1.1"
If xor_cryptor is a custom module, you’ll need to include its file locally and ensure it’s referenced properly (mod xor_cryptor; instead of use).
⚠️ 2. Fix Unsafe Block
You commented out the unsafe block here:
text
// unsafe {
...
text
// }
But Rust requires unsafe { ... } to use:
let decrypted_slice = std::slice::from_raw_parts(decrypted_ptr, decrypted_len);
✅ Fix:
Uncomment the unsafe block:
text
unsafe {
let decrypted_slice = std::slice::from_raw_parts(decrypted_ptr, decrypted_len);
borrowed_string.push_str(&String::from_utf8_lossy(decrypted_slice));
}

4. Compile and Run
text
cargo build
cargo run

failed
- CTF
- Reverse Engineering
- picoCTF
- Rust