-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscramble.cpp
More file actions
92 lines (72 loc) · 3.07 KB
/
scramble.cpp
File metadata and controls
92 lines (72 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <filesystem>
#include <random>
#include <iomanip>
namespace fs = std::filesystem;
std::string random_hex(size_t len) {
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dis(0, 15);
std::stringstream ss;
for (size_t i = 0; i < len; ++i) ss << std::hex << dis(gen);
return ss.str();
}
std::string to_hex(const std::vector<char>& data) {
std::stringstream ss;
for (unsigned char c : data) ss << std::hex << std::setw(2) << std::setfill('0') << (int)c;
return ss.str();
}
int main() {
const std::string UUID = "FFBD-FEF3";
const std::string MOUNT_POINT = "/run/media/shiro/" + UUID;
const std::string REGISTRY = std::string(getenv("HOME")) + "/.vault_registry";
// --- SAFETY LOCK ---
// If registry exists and has content, the drive is already scrambled.
if (fs::exists(REGISTRY) && fs::file_size(REGISTRY) > 0) {
std::cerr << "\033[1;31m[!] CRITICAL: Registry detected. Drive is already scrambled.\033[0m" << std::endl;
std::cerr << "Run 'unleash' before attempting to scramble again." << std::endl;
return 1;
}
if (!fs::exists(MOUNT_POINT)) {
std::cerr << "[!] The Void is not present." << std::endl;
return 1;
}
std::ofstream reg_file(REGISTRY);
std::cout << "[*] Withering the tree..." << std::endl;
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<int> dist(0, 255);
for (const auto& entry : fs::recursive_directory_iterator(MOUNT_POINT)) {
if (!entry.is_regular_file()) continue;
fs::path file_path = entry.path();
// Skip hidden files or the registry if it's on the drive
if (file_path.filename().string().find(".") == 0) continue;
std::string relative_path = fs::relative(file_path, MOUNT_POINT).string();
std::ifstream file_in(file_path, std::ios::binary);
std::vector<char> header(128);
file_in.read(header.data(), 128);
size_t bytes_read = file_in.gcount();
file_in.close();
std::string new_name = "sys-" + random_hex(8) + ".bin";
fs::path new_path = file_path.parent_path() / new_name;
std::string relative_new_path = fs::relative(new_path, MOUNT_POINT).string();
reg_file << "./" << relative_path << "|./" << relative_new_path << "|" << to_hex(header) << "\n";
std::fstream file_out(file_path, std::ios::in | std::ios::out | std::ios::binary);
if (file_out.is_open()) {
std::vector<char> junk(bytes_read);
for (auto& b : junk) b = static_cast<char>(dist(gen));
file_out.seekp(0);
file_out.write(junk.data(), junk.size());
file_out.close();
}
fs::rename(file_path, new_path);
}
reg_file.close();
std::cout << "[*] Cutting ties..." << std::endl;
std::system(("udisksctl unmount -b /dev/disk/by-uuid/" + UUID).c_str());
std::cout << "\033[1;32m[SUCCESS] The Void is secured.\033[0m" << std::endl;
return 0;
}