Feature: run a test client inside the master from the Advanced menu

The Advanced menu now ends with Run Test Program. It copies the kernel
payload that was already read into memory, points its CONNECT_ADDRESS at
127.0.0.1:<listen port>, and loads it with MemoryLoadLibrary inside the
master process, so this machine comes online as a controlled host -- no
second machine is needed to try remote desktop or file transfer. A
worker thread waits for the client to exit, then frees the module and
re-enables the item. Only one instance runs at a time: the item is
grayed while it does, and stopping it means uninstalling the test host
from the online list.

The loaded copy carries LOCAL_TEST_CLIENT_MAGIC in szFuture. The client
uses that mark to refuse the commands that would otherwise hit the host
process or the whole machine: uninstall (no self_del), update, run as
admin, ban, share/assign, and shutdown/reboot/logoff. It also skips
auth-kernel detection, which GetModuleFileName(NULL) would misjudge
inside the master.

Renames szFututre to szFuture and documents that the first 16 bytes of
the reserved tail are now claimed, with a static_assert so it cannot
silently shrink below the magic.

Translations for en_US, zh_TW and de_DE, plus the HIDE_MENU_RUN_TEST
feature flag and its row in the limits dialog.

Verified on a Debug master: the item is last and has its icon, one click
brings the host online, a second click is refused, uninstall stops it in
about a second and the master survives, re-run works, and exiting the
master with a live test client takes 2.6s (3.0s baseline).

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-11-06 17:17:18 +01:00
1 parent cc9ce35c4d
commit f77b18aa68
18 files changed
+268 -11

No files matched your search

+20 -1
View File
@@ -912,7 +912,7 @@ public:
char installName[32]; // 安装名称
char installDesc[136];// 安装描述
int installFlag; // 安装标记
char szFututre[496]; // 保留字段
char szFuture[496]; // 保留字段,见下方 LOCAL_TEST_CLIENT_MAGIC(前 16 字节已被占用)
public:
void SetType(int typ)
@@ -1032,6 +1032,25 @@ public:
} CONNECT_ADDRESS ;
#pragma pack(pop)
// 「主控端→高级→运行测试程序」标记:主控把 ServerDll 在自己进程里内存加载时写进
// CONNECT_ADDRESS::szFuture 的开头,客户端据此认出自己跑在宿主主控进程内。这类实例的
// 「本程序文件」其实是主控 EXE,凡是按 GetModuleFileName(NULL) 操作自身的指令(卸载删
// 自身、更新重启自身、提权重启自身)都会打到主控身上,必须一律拒绝;关机/重启/注销这类
// 会关掉用户整台机器的指令同理。判定点集中在 client/KernelManager.cpp 的 OnReceive。
//
// 注意 szFuture 是**保留字段**,一旦真被某个新功能用起来,这里要先给它留出前
// sizeof(LOCAL_TEST_CLIENT_MAGIC) 字节,否则标记被覆盖后 IsLocalTestClient() 会静默返回
// false —— 进程内的测试实例就退化成普通客户端,卸载/更新/提权会作用到主控自己身上。
// 下面的 static_assert 只能挡住字段变小,挡不住「被复用」,改动该字段时请回头看这段注释。
#define LOCAL_TEST_CLIENT_MAGIC "YAMA_LOCAL_TEST"
static_assert(sizeof(((CONNECT_ADDRESS*)0)->szFuture) >= sizeof(LOCAL_TEST_CLIENT_MAGIC),
"CONNECT_ADDRESS::szFuture 至少要能放下 LOCAL_TEST_CLIENT_MAGIC");
inline bool IsLocalTestClient(const CONNECT_ADDRESS* conn)
{
return conn && strncmp(conn->szFuture, LOCAL_TEST_CLIENT_MAGIC,
sizeof(LOCAL_TEST_CLIENT_MAGIC) - 1) == 0;
}
#define FOREVER_RUN 2
// 客户端程序线程信息结构体, 包含5个成员:
+2 -1
View File
@@ -6,7 +6,8 @@
// 启动后拿它当信任锚,于是首次连接就是 TLS,不必等主控在线下发。
//
// 为什么单独成块、不扩 CONNECT_ADDRESS:
// 1. 结构体尾部只有 szFututre[496] 连续可用,而内置证书 PEM 就有 1042 字节;
// 1. 结构体尾部只有 szFuture[496] 连续可用(前 16 字节已被「运行测试程序」的
// LOCAL_TEST_CLIENT_MAGIC 占用),而内置证书 PEM 就有 1042 字节;
// 2. 生成端是按 sizeof(CONNECT_ADDRESS) 做 memcpy 原地覆盖的,扩了结构体就会把新
// 长度写进老 stub 里,越界且无声(详见设计文档 §3.2 的方案 A 否决理由)。
//