Skip to content

Commit 75e0ea0

Browse files
authored
improve: Encryption System
1 parent 30a3561 commit 75e0ea0

File tree

6 files changed

+21
-43
lines changed

6 files changed

+21
-43
lines changed

src/framework/config.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*/
2222

2323
#pragma once
24+
#include <obfuscate.h>
2425

2526
// APPEARANCES
2627
#define BYTES_IN_SPRITE_SHEET 384 * 384 * 4
@@ -35,8 +36,9 @@
3536
// You can compile it once and use this executable to only encrypt client files once with command --encrypt which will be using password below.
3637
#define ENABLE_ENCRYPTION_BUILDER 0
3738
// for security reasons make sure you are using password with at last 100+ characters
38-
#define ENCRYPTION_PASSWORD "SET_YOUR_PASSWORD_HERE"
39-
#define ENCRYPTION_HEADER "SET_YOUR_HEADER_HERE"
39+
#define ENCRYPTION_PASSWORD AY_OBFUSCATE("SET_YOUR_PASSWORD_HERE")
40+
// do not insert special characters in the header (ONLY UPPERCASE LETTERS, LOWERCASE LETTERS AND NUMBERS) | example: #define ENCRYPTION_HEADER AY_OBFUSCATE("21UsO5ARfRnIScs415BNMab")
41+
#define ENCRYPTION_HEADER AY_OBFUSCATE("SET_YOUR_HEADER_HERE")
4042

4143
// DISCORD RPC (https://discord.com/developers/applications)
4244
// Note: Only for VSSolution, doesn't work with CMAKE

src/framework/core/filestream.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ FileStream::~FileStream()
6161
close();
6262
}
6363

64-
void FileStream::cache(bool /*useEnc*/)
64+
void FileStream::cache(bool useEnc)
6565
{
6666
m_caching = true;
6767

@@ -472,4 +472,4 @@ void FileStream::throwError(const std::string_view message, const bool physfsErr
472472
if (physfsError)
473473
completeMessage += ": "s + PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode());
474474
throw Exception(completeMessage);
475-
}
475+
}

src/framework/core/resourcemanager.cpp

+12-35
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ std::string ResourceManager::readFileContents(const std::string& fileName)
209209
{
210210
const std::string fullPath = resolvePath(fileName);
211211

212-
if (fullPath.find(g_resources.getByteStrings(0)) != std::string::npos) {
212+
if (fullPath.find(AY_OBFUSCATE("/downloads")) != std::string::npos) {
213213
const auto dfile = g_http.getFile(fullPath.substr(10));
214214
if (dfile)
215215
return std::string(dfile->response.begin(), dfile->response.end());
@@ -225,21 +225,20 @@ std::string ResourceManager::readFileContents(const std::string& fileName)
225225
PHYSFS_close(file);
226226

227227
#if ENABLE_ENCRYPTION == 1
228-
bool hasHeader = false;
229-
if (buffer.size() >= std::string(ENCRYPTION_HEADER).size() &&
230-
buffer.substr(0, std::string(ENCRYPTION_HEADER).size()) == std::string(ENCRYPTION_HEADER)) {
231-
hasHeader = true;
232-
}
233-
234-
if (g_game.getFeature(Otc::GameAllowCustomBotScripts)) {
235-
if (fullPath.find(g_resources.getByteStrings(1)) != std::string::npos && !hasHeader) {
236-
return buffer;
237-
}
238-
}
228+
const auto headerSize = std::string(ENCRYPTION_HEADER).size();
229+
const bool hasHeader = (buffer.size() >= headerSize &&
230+
buffer.compare(0, headerSize, ENCRYPTION_HEADER) == 0);
239231

240232
if (hasHeader) {
241-
buffer = buffer.substr(std::string(ENCRYPTION_HEADER).size());
233+
buffer = buffer.substr(headerSize);
242234
buffer = decrypt(buffer);
235+
} else {
236+
if (fullPath.find(std::string(AY_OBFUSCATE("/bot/"))) != std::string::npos) {
237+
if (g_game.getFeature(Otc::GameAllowCustomBotScripts)) {
238+
return buffer;
239+
}
240+
return "";
241+
}
243242
}
244243
#endif
245244

@@ -759,25 +758,3 @@ std::unordered_map<std::string, std::string> ResourceManager::decompressArchive(
759758
std::unordered_map<std::string, std::string> ret;
760759
return ret;
761760
}
762-
763-
std::string ResourceManager::decodificateStrings(const std::vector<unsigned char>& bytes) {
764-
std::string result;
765-
for (const unsigned char c : bytes) {
766-
result.push_back(c ^ 0xAA);
767-
}
768-
return result;
769-
}
770-
771-
// used to obfuscate vulnerable strings (provisional)
772-
std::string ResourceManager::getByteStrings(const size_t line) {
773-
const std::vector<std::vector<unsigned char>> strTable = {
774-
{0x85, 0xCE, 0xC5, 0xDD, 0xC4, 0xC6, 0xC5, 0xCB, 0xCE, 0xD9}, // "/downloads"
775-
{0x85, 0xC8, 0xC5, 0xDE, 0x85}, // "/bot/"
776-
{0xE6, 0xC3, 0xC4, 0xC2, 0xCB, 0x8A, 0xCE, 0xCF, 0x8A, 0xD8, 0xCF, 0xDE, 0xC5, 0xD8, 0xC4, 0xC5, 0x8A, 0xC3, 0xC4, 0xDC, 0xCB, 0xC6, 0xC3, 0xCE, 0xCB}, // "Linha de retorno invalida"
777-
};
778-
779-
if (line < strTable.size()) {
780-
return decodificateStrings(strTable[line]);
781-
}
782-
return decodificateStrings(strTable[2]);
783-
}

src/framework/core/resourcemanager.h

-2
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ class ResourceManager
9393
bool launchCorrect(const std::vector<std::string>& args);
9494
std::string createArchive(const std::unordered_map<std::string, std::string>& files);
9595
std::unordered_map<std::string, std::string> decompressArchive(std::string dataOrPath);
96-
std::string decodificateStrings(const std::vector<unsigned char>& bytes);
97-
std::string getByteStrings(size_t line);
9896

9997
std::string getBinaryPath() { return m_binaryPath.string(); }
10098

src/main.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ extern "C" {
6161
#if ENABLE_ENCRYPTION == 1 && ENABLE_ENCRYPTION_BUILDER == 1
6262
if (std::find(args.begin(), args.end(), "--encrypt") != args.end()) {
6363
g_lua.init();
64-
g_resources.runEncryption(args.size() >= 3 ? args[2] : ENCRYPTION_PASSWORD);
64+
g_resources.runEncryption(args.size() >= 3 ? args[2] : std::string(ENCRYPTION_PASSWORD));
6565
std::cout << "Encryption complete" << std::endl;
6666
#ifdef WIN32
6767
MessageBoxA(NULL, "Encryption complete", "Success", 0);
@@ -124,4 +124,4 @@ extern "C" {
124124
}
125125
#ifdef ANDROID
126126
}
127-
#endif
127+
#endif

vcpkg.json

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"cpp-httplib",
88
"discord-rpc",
99
"liblzma",
10+
"libobfuscate",
1011
"libogg",
1112
"libvorbis",
1213
"nlohmann-json",

0 commit comments

Comments
 (0)