Make this compatible to build with MSVS 2022

This commit is contained in:
kittnz 2026-02-23 16:30:49 +01:00
parent 590131590c
commit 9dd15ef922
9 changed files with 201 additions and 49 deletions

View file

@ -2,6 +2,7 @@
#include <openssl/sha.h>
#include <openssl/md5.h>
#include <openssl/hmac.h>
#include <openssl/evp.h>
namespace wowee {
namespace auth {
@ -19,7 +20,8 @@ std::vector<uint8_t> Crypto::sha1(const std::string& data) {
std::vector<uint8_t> Crypto::md5(const std::vector<uint8_t>& data) {
std::vector<uint8_t> hash(MD5_DIGEST_LENGTH);
MD5(data.data(), data.size(), hash.data());
unsigned int length = 0;
EVP_Digest(data.data(), data.size(), hash.data(), &length, EVP_md5(), nullptr);
return hash;
}

View file

@ -2,6 +2,9 @@
#include "core/logger.hpp"
#include "rendering/vk_context.hpp"
#include <SDL2/SDL_vulkan.h>
#ifdef _WIN32
#include <cstdlib>
#endif
namespace wowee {
namespace core {
@ -29,6 +32,33 @@ bool Window::initialize() {
return false;
}
// Explicitly load the Vulkan library before creating the window.
// SDL_CreateWindow with SDL_WINDOW_VULKAN fails on some platforms/drivers
// if the Vulkan loader hasn't been located yet; calling this first gives a
// clear error and avoids the misleading "not configured in SDL" message.
// SDL 2.28+ uses LoadLibraryExW(LOAD_LIBRARY_SEARCH_DEFAULT_DIRS) which does
// not search System32, so fall back to the explicit path on Windows if needed.
bool vulkanLoaded = (SDL_Vulkan_LoadLibrary(nullptr) == 0);
#ifdef _WIN32
if (!vulkanLoaded) {
const char* sysRoot = std::getenv("SystemRoot");
if (sysRoot && *sysRoot) {
std::string fallbackPath = std::string(sysRoot) + "\\System32\\vulkan-1.dll";
vulkanLoaded = (SDL_Vulkan_LoadLibrary(fallbackPath.c_str()) == 0);
if (vulkanLoaded) {
LOG_INFO("Loaded Vulkan library via explicit path: ", fallbackPath);
}
}
}
#endif
if (!vulkanLoaded) {
LOG_ERROR("Failed to load Vulkan library: ", SDL_GetError());
LOG_ERROR("Ensure the Vulkan runtime (vulkan-1.dll) is installed. "
"Install the latest GPU drivers or the Vulkan Runtime from https://vulkan.lunarg.com/");
SDL_Quit();
return false;
}
// Create Vulkan window (no GL attributes needed)
Uint32 flags = SDL_WINDOW_VULKAN | SDL_WINDOW_SHOWN;
if (config.fullscreen) {
@ -74,6 +104,7 @@ void Window::shutdown() {
window = nullptr;
}
SDL_Vulkan_UnloadLibrary();
SDL_Quit();
LOG_INFO("Window shutdown complete");
}

View file

@ -182,6 +182,7 @@ void WardenMemory::patchRuntimeGlobals() {
// uint32 dwAllocationGranularity
// uint16 wProcessorLevel
// uint16 wProcessorRevision
#pragma pack(push, 1)
struct {
uint16_t wProcessorArchitecture;
uint16_t wReserved;
@ -194,7 +195,7 @@ void WardenMemory::patchRuntimeGlobals() {
uint32_t dwAllocationGranularity;
uint16_t wProcessorLevel;
uint16_t wProcessorRevision;
} __attribute__((packed)) sysInfo = {
} sysInfo = {
0, // x86
0,
4096, // 4K page size
@ -207,6 +208,7 @@ void WardenMemory::patchRuntimeGlobals() {
6, // P6 family
0x3A09 // revision
};
#pragma pack(pop)
static_assert(sizeof(sysInfo) == 36, "SYSTEM_INFO must be 36 bytes");
uint32_t rva = sysInfoAddr - imageBase_;
if (rva + 36 <= imageSize_) {

View file

@ -8,6 +8,10 @@
#include <openssl/rsa.h>
#include <openssl/bn.h>
#include <openssl/sha.h>
#include <openssl/evp.h>
#include <openssl/pem.h>
#include <openssl/param_build.h>
#include <openssl/core_names.h>
#ifdef _WIN32
#ifndef WIN32_LEAN_AND_MEAN
@ -342,37 +346,47 @@ bool WardenModule::verifyRSASignature(const std::vector<uint8_t>& data) {
std::vector<uint8_t> expectedHash = auth::Crypto::sha1(dataToHash);
// Create RSA public key structure
RSA* rsa = RSA_new();
if (!rsa) {
std::cerr << "[WardenModule] Failed to create RSA structure" << '\n';
return false;
}
// Create RSA public key using EVP_PKEY_fromdata (OpenSSL 3.0 compatible)
BIGNUM* n = BN_bin2bn(modulus, 256, nullptr);
BIGNUM* e = BN_new();
BN_set_word(e, exponent);
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
// OpenSSL 1.1.0+
RSA_set0_key(rsa, n, e, nullptr);
#else
// OpenSSL 1.0.x
rsa->n = n;
rsa->e = e;
#endif
// Decrypt signature using public key
EVP_PKEY* pkey = nullptr;
EVP_PKEY_CTX* ctx = nullptr;
std::vector<uint8_t> decryptedSig(256);
int decryptedLen = RSA_public_decrypt(
256,
signature.data(),
decryptedSig.data(),
rsa,
RSA_NO_PADDING
);
int decryptedLen = -1;
RSA_free(rsa);
{
OSSL_PARAM_BLD* bld = OSSL_PARAM_BLD_new();
OSSL_PARAM_BLD_push_BN(bld, OSSL_PKEY_PARAM_RSA_N, n);
OSSL_PARAM_BLD_push_BN(bld, OSSL_PKEY_PARAM_RSA_E, e);
OSSL_PARAM* params = OSSL_PARAM_BLD_to_param(bld);
OSSL_PARAM_BLD_free(bld);
EVP_PKEY_CTX* fromCtx = EVP_PKEY_CTX_new_from_name(nullptr, "RSA", nullptr);
if (fromCtx && EVP_PKEY_fromdata_init(fromCtx) > 0) {
EVP_PKEY_fromdata(fromCtx, &pkey, EVP_PKEY_PUBLIC_KEY, params);
}
if (fromCtx) EVP_PKEY_CTX_free(fromCtx);
OSSL_PARAM_free(params);
if (pkey) {
ctx = EVP_PKEY_CTX_new(pkey, nullptr);
if (ctx && EVP_PKEY_verify_recover_init(ctx) > 0 &&
EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_NO_PADDING) > 0) {
size_t outLen = decryptedSig.size();
if (EVP_PKEY_verify_recover(ctx, decryptedSig.data(), &outLen,
signature.data(), 256) > 0) {
decryptedLen = static_cast<int>(outLen);
}
}
}
}
BN_free(n);
BN_free(e);
if (ctx) EVP_PKEY_CTX_free(ctx);
if (pkey) EVP_PKEY_free(pkey);
if (decryptedLen < 0) {
std::cerr << "[WardenModule] RSA public decrypt failed" << '\n';

View file

@ -11,6 +11,16 @@
#include <iomanip>
#include <zlib.h>
namespace {
inline uint32_t bswap32(uint32_t v) {
return ((v & 0xFF000000u) >> 24) | ((v & 0x00FF0000u) >> 8)
| ((v & 0x0000FF00u) << 8) | ((v & 0x000000FFu) << 24);
}
inline uint16_t bswap16(uint16_t v) {
return static_cast<uint16_t>(((v & 0xFF00u) >> 8) | ((v & 0x00FFu) << 8));
}
}
namespace wowee {
namespace game {
@ -3744,10 +3754,10 @@ bool TalentsInfoParser::parse(network::Packet& packet, TalentsInfoData& data) {
// These two counts are big-endian (network byte order)
uint32_t talentCountBE = packet.readUInt32();
uint32_t talentCount = __builtin_bswap32(talentCountBE);
uint32_t talentCount = bswap32(talentCountBE);
uint16_t entryCountBE = packet.readUInt16();
uint16_t entryCount = __builtin_bswap16(entryCountBE);
uint16_t entryCount = bswap16(entryCountBE);
// Sanity check: prevent corrupt packets from allocating excessive memory
if (entryCount > 64) {

View file

@ -28,8 +28,11 @@ bool TCPSocket::connect(const std::string& host, uint16_t port) {
net::setNonBlocking(sockfd);
// Resolve host
struct hostent* server = gethostbyname(host.c_str());
if (server == nullptr) {
struct addrinfo hints{};
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
struct addrinfo* res = nullptr;
if (getaddrinfo(host.c_str(), nullptr, &hints, &res) != 0 || res == nullptr) {
LOG_ERROR("Failed to resolve host: ", host);
net::closeSocket(sockfd);
sockfd = INVALID_SOCK;
@ -40,8 +43,9 @@ bool TCPSocket::connect(const std::string& host, uint16_t port) {
struct sockaddr_in serverAddr;
memset(&serverAddr, 0, sizeof(serverAddr));
serverAddr.sin_family = AF_INET;
memcpy(&serverAddr.sin_addr.s_addr, server->h_addr, server->h_length);
serverAddr.sin_addr = reinterpret_cast<struct sockaddr_in*>(res->ai_addr)->sin_addr;
serverAddr.sin_port = htons(port);
freeaddrinfo(res);
int result = ::connect(sockfd, (struct sockaddr*)&serverAddr, sizeof(serverAddr));
if (result < 0) {

View file

@ -100,8 +100,11 @@ bool WorldSocket::connect(const std::string& host, uint16_t port) {
net::setNonBlocking(sockfd);
// Resolve host
struct hostent* server = gethostbyname(host.c_str());
if (server == nullptr) {
struct addrinfo hints{};
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
struct addrinfo* res = nullptr;
if (getaddrinfo(host.c_str(), nullptr, &hints, &res) != 0 || res == nullptr) {
LOG_ERROR("Failed to resolve host: ", host);
net::closeSocket(sockfd);
sockfd = INVALID_SOCK;
@ -112,8 +115,9 @@ bool WorldSocket::connect(const std::string& host, uint16_t port) {
struct sockaddr_in serverAddr;
memset(&serverAddr, 0, sizeof(serverAddr));
serverAddr.sin_family = AF_INET;
memcpy(&serverAddr.sin_addr.s_addr, server->h_addr, server->h_length);
serverAddr.sin_addr = reinterpret_cast<struct sockaddr_in*>(res->ai_addr)->sin_addr;
serverAddr.sin_port = htons(port);
freeaddrinfo(res);
int result = ::connect(sockfd, (struct sockaddr*)&serverAddr, sizeof(serverAddr));
if (result < 0) {