-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
77 lines (68 loc) · 2.46 KB
/
main.cpp
File metadata and controls
77 lines (68 loc) · 2.46 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
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <filesystem>
#include <sstream>
namespace fs = std::filesystem;
void reconstruct(const std::string& old_p, const std::string& new_p, const std::string& hex) {
if (!fs::exists(new_p)) return;
std::vector<char> bytes;
for (size_t i = 0; i < hex.length(); i += 2) {
bytes.push_back((char)std::stoul(hex.substr(i, 2), nullptr, 16));
}
std::fstream file(new_p, std::ios::in | std::ios::out | std::ios::binary);
if (file.is_open()) {
file.seekp(0);
file.write(bytes.data(), bytes.size());
file.close();
fs::rename(new_p, old_p);
}
}
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";
// After the "Reality Restored" message
// 1. Check if the drive is already available
if (fs::exists(MOUNT_POINT)) {
std::cout << "[*] The Void is already mounted. Proceeding to reconstruct..." << std::endl;
} else {
// 2. TRIGGER POLKIT (Only if not mounted)
std::cout << "[*] Identity Check required..." << std::endl;
std::string mount_cmd = "udisksctl mount -b /dev/disk/by-uuid/" + UUID;
if (std::system(mount_cmd.c_str()) != 0) {
// Check again just in case udisksctl failed but it's somehow mounted
if (!fs::exists(MOUNT_POINT)) {
std::cerr << "[!] Authentication failed or drive missing." << std::endl;
return 1;
}
}
}
// 3. FILE RECONSTRUCTION
if (!fs::exists(MOUNT_POINT)) {
std::cerr << "[!] Mount point inaccessible." << std::endl;
return 1;
}
std::ifstream reg(REGISTRY);
if (!reg.is_open()) {
std::cerr << "[!] Registry file missing." << std::endl;
return 1;
}
fs::current_path(MOUNT_POINT);
std::string line;
while (std::getline(reg, line)) {
if (line.empty()) continue;
std::stringstream ss(line);
std::string o, n, h;
if (std::getline(ss, o, '|') && std::getline(ss, n, '|') && std::getline(ss, h, '|')) {
reconstruct(o, n, h);
}
}
std::cout << "[+] Reality Restored." << std::endl;
if (fs::exists(REGISTRY)) {
fs::remove(REGISTRY);
std::cout << "[*] Registry purged. Ready for next cycle." << std::endl;
}
return 0;
}