rodecomp/Source/Security/ThemidaMgr.cpp
ragnarok-clanker cf115cb806 Decompile 2 functions in Source/Security/ThemidaMgr.cpp, Source/Security/ThemidaMgr.h
Batch #4634 by youko: 0 byte-identical, 2 confirmed by peer review.

- fn_08242 CThemidaMgr::Check: logic confirmed by peer review
- fn_08243 CThemidaMgr::StopThread: logic confirmed by peer review

Peer-reviewed-by: eAthena, Snow, Qwenkler3.8
Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes).
2026-10-30 04:19:14 +00:00

96 lines
2.4 KiB
C++

#include "Security/ThemidaMgr.h"
#include <new>
#include <random>
// GLOBAL: gl_24891
CThemidaMgr* g_themidaMgr;
void sub_6563E0(char* first, char* last, void* distribution);
struct ThemidaKeyRandom {
std::mt19937 engine;
std::uniform_int_distribution<int> distribution;
ThemidaKeyRandom(unsigned int seed) : engine(seed), distribution(1, 0xfe) {
}
};
struct ThemidaKeyEncoderA {
unsigned char* Generate(const unsigned char* input);
};
struct ThemidaKeyEncoderB {
unsigned char* Generate(const unsigned char* input);
};
// OFFSET: 0x0076EC00
// FUNCTION: fn_08235
CThemidaMgr::CThemidaMgr() : m_valid(true) {
}
// OFFSET: 0x0076EC10
// FUNCTION: fn_08236
CThemidaMgr::~CThemidaMgr() {
}
// OFFSET: 0x0076EC20
// FUNCTION: fn_08237
unsigned char* ThemidaKeyEncoderA::Generate(const unsigned char* input) {
auto* output = reinterpret_cast<unsigned char*>(this);
ThemidaKeyRandom random(std::random_device{}());
sub_6563E0(reinterpret_cast<char*>(output), reinterpret_cast<char*>(output) + 5, &random);
output[5] = input[0] ^ output[1] ^ output[0];
output[6] = input[1] ^ output[2] ^ output[1];
output[7] = input[2] ^ output[3] ^ output[2];
output[8] = output[4] ^ input[3] ^ output[3];
return output;
}
// OFFSET: 0x0076ECC0
// FUNCTION: fn_08238
unsigned char* ThemidaKeyEncoderB::Generate(const unsigned char* input) {
auto* output = reinterpret_cast<unsigned char*>(this);
ThemidaKeyRandom random(std::random_device{}());
sub_6563E0(reinterpret_cast<char*>(output), reinterpret_cast<char*>(output) + 5, &random);
output[5] = input[0] ^ output[1] ^ output[0];
output[6] = input[1] ^ output[2] ^ output[1];
output[7] = input[2] ^ output[3] ^ output[2];
output[8] = output[4] ^ input[3] ^ output[3];
return output;
}
// OFFSET: 0x0076EDE0
// FUNCTION: fn_08240
bool CThemidaMgr::Create() {
if (g_themidaMgr == nullptr) {
g_themidaMgr = new (std::nothrow) CThemidaMgr();
if (g_themidaMgr != nullptr) {
if (g_themidaMgr->m_valid) {
return true;
}
delete g_themidaMgr;
g_themidaMgr = nullptr;
}
}
return false;
}
// OFFSET: 0x0076EE90
// FUNCTION: fn_08241
void CThemidaMgr::Destroy() {
if (g_themidaMgr != nullptr) {
delete g_themidaMgr;
g_themidaMgr = nullptr;
}
}
// OFFSET: 0x0076EEB0
// FUNCTION: fn_08242
void CThemidaMgr::Check() {
}
// OFFSET: 0x0076F050
// FUNCTION: fn_08243
void CThemidaMgr::StopThread() {
}