-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
144 lines (113 loc) · 4.36 KB
/
Copy pathmain.cpp
File metadata and controls
144 lines (113 loc) · 4.36 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include <iostream>
#include <filesystem>
#include <fstream>
#include <string>
#include <mutex>
#include <chrono>
#include <thread>
#include <nlohmann/json.hpp>
#include "ThreadPool.hpp"
#include "utility.h"
using json = nlohmann::json;
int main()
{
std::string encryptionKey;
std::string encryptedFile;
std::cout << "Enter the encryption key to the database: ";
std::getline(std::cin, encryptionKey);
std::cout << std::endl;
std::cout << "Enter the ENCRYPTED Dumped Json File: ";
std::getline(std::cin, encryptedFile);
std::cout << std::endl;
std::ifstream fileContentsStream{ encryptedFile };
if (!fileContentsStream.is_open()) {
std::cerr << "Failed to open file: " << encryptedFile << "\n";
return 1;
}
std::cout << "-------------------------------------------\n";
std::cout << "Discord Tickets Fast Dump (aes-256-gcm)\n";
std::cout << "Encryption Key: " << encryptionKey << "\n";
std::cout << "Filename: " << encryptedFile << "\n";
std::cout << "-------------------------------------------\n";
std::cout << "DUMPING DATABASE WITH ENC KEY..... Lines/Objects Count: ";
size_t lineCount = 0;
std::string jsonLine;
while (std::getline(fileContentsStream, jsonLine))
{
if (!jsonLine.empty()) lineCount++;
}
std::cout << lineCount << std::endl << "\n\n";
std::vector<std::string> decryptedLines(lineCount); // MUST BE HERE!!
lineCount = 0;
// - This reopens the file - //
fileContentsStream.clear();
fileContentsStream.seekg(0);
// While loop below is to actually decode the lines
std::vector<std::future<void>> processingFutures;
std::mutex coutMutex;
auto totalStart = std::chrono::high_resolution_clock::now();
/*
JSONL is for making json objects but faster (? jsons/per line, not sure)
Encoded Variables:
content
avatar
displayName
username
comment
value
topic */
while (std::getline(fileContentsStream, jsonLine))
{
lineCount++;
if (jsonLine.empty())
{
std::lock_guard<std::mutex> lock(coutMutex);
std::cout << "[!!] Detected Empty Line At " << lineCount << "\n";
continue;
}
const size_t currentLine = lineCount;
const std::string lineCopy = jsonLine;
processingFutures.emplace_back(ThreadPool->Run([=, &coutMutex, &decryptedLines]() {
auto lineStart = std::chrono::high_resolution_clock::now();
try
{
json data = json::parse(lineCopy);
decryptNestedFields(data, encryptionKey);
auto lineEnd = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(lineEnd - lineStart);
decryptedLines[currentLine - 1] = data.dump();
std::lock_guard<std::mutex> lock(coutMutex);
std::cout << "Line #" << currentLine << " decrypted in: " << duration.count() << " ms\n";
}
catch (const nlohmann::json_abi_v3_12_0::detail::type_error& e)
{
std::lock_guard<std::mutex> lock(coutMutex);
std::cerr << "[!] Error processing line " << currentLine << ": " << e.what() << "\n"; // !! Important to catch this specific error !! //
}
catch (const std::exception& e)
{
std::lock_guard<std::mutex> lock(coutMutex);
std::cerr << "[!] General error processing line " << currentLine << ": " << e.what() << "\n";
}
}));
}
for (auto& future : processingFutures)
{
future.wait();
}
std::ofstream outFile("decrypted_output.jsonl");
if (!outFile.is_open()) {
std::cerr << "Failed to open output file for writing.\n";
return 1;
}
for (const auto& line : decryptedLines) {
outFile << line << "\n";
}
outFile.close();
std::cout << "\nDecrypted output written to: decrypted_output.jsonl\n";
fileContentsStream.close();
auto totalEnd = std::chrono::high_resolution_clock::now();
auto totalDuration = std::chrono::duration_cast<std::chrono::milliseconds>(totalEnd - totalStart);
std::cout << "\nTotal processing time: " << totalDuration.count() << " milliseconds\n";
std::cout << "Average time per line: " << (totalDuration.count() / lineCount) << " milliseconds\n";
}