From 3bcc1e11ed22b464905193e2502e8041b2489d89 Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Mon, 10 Mar 2025 12:30:15 +0000 Subject: [PATCH] chore: Move Windows event constants to constants file --- src/lib/common/common.h | 9 --------- src/lib/common/constants.h.in | 2 ++ src/lib/deskflow/win32/AppUtilWindows.cpp | 4 ++-- src/lib/platform/MSWindowsKeyState.cpp | 2 +- src/lib/platform/MSWindowsProcess.cpp | 2 +- src/lib/platform/MSWindowsWatchdog.cpp | 2 +- 6 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/lib/common/common.h b/src/lib/common/common.h index e085a03e0..ba127398d 100644 --- a/src/lib/common/common.h +++ b/src/lib/common/common.h @@ -41,12 +41,3 @@ enum kExitArgs = 3, // bad arguments kExitConfig = 4, // cannot read configuration }; - -#if WINAPI_MSWINDOWS -namespace deskflow::common { - -const auto kCloseEventName = "Global\\DeskflowClose"; -const auto kSendSasEventName = "Global\\DeskflowSendSAS"; - -} // namespace deskflow::common -#endif diff --git a/src/lib/common/constants.h.in b/src/lib/common/constants.h.in index bac4c0ca8..b721c9ae1 100644 --- a/src/lib/common/constants.h.in +++ b/src/lib/common/constants.h.in @@ -47,5 +47,7 @@ const auto kWindowsRuntimeMinor = @REQUIRED_MSVC_RUNTIME_MINOR@; // clang-format on const auto kWindowsRegistryKey = "SOFTWARE\\@CMAKE_PROJECT_PROPER_NAME@"; +const auto kCloseEventName = "Global\\DeskflowClose"; +const auto kSendSasEventName = "Global\\DeskflowSendSAS"; #endif diff --git a/src/lib/deskflow/win32/AppUtilWindows.cpp b/src/lib/deskflow/win32/AppUtilWindows.cpp index ba94010b8..37c4f1ce4 100644 --- a/src/lib/deskflow/win32/AppUtilWindows.cpp +++ b/src/lib/deskflow/win32/AppUtilWindows.cpp @@ -13,7 +13,7 @@ #include "base/IEventQueue.h" #include "base/Log.h" #include "base/log_outputters.h" -#include "common/common.h" +#include "common/constants.h" #include "deskflow/App.h" #include "deskflow/ArgsBase.h" #include "deskflow/Screen.h" @@ -261,7 +261,7 @@ void AppUtilWindows::showNotification(const std::string &title, const std::strin void AppUtilWindows::eventLoop() { - HANDLE hCloseEvent = CreateEventA(nullptr, TRUE, FALSE, deskflow::common::kCloseEventName); + HANDLE hCloseEvent = CreateEventA(nullptr, TRUE, FALSE, kCloseEventName); if (!hCloseEvent) { LOG_CRIT("failed to create event for windows event loop"); throw XArch(new XArchEvalWindows()); diff --git a/src/lib/platform/MSWindowsKeyState.cpp b/src/lib/platform/MSWindowsKeyState.cpp index 958ae9e30..c4e55ee46 100644 --- a/src/lib/platform/MSWindowsKeyState.cpp +++ b/src/lib/platform/MSWindowsKeyState.cpp @@ -760,7 +760,7 @@ bool MSWindowsKeyState::fakeCtrlAltDel() // History: It used to be possible to use `PostMessage` to send `MOD_CONTROL | MOD_ALT, VK_DELETE` // as a backup but this ability was removed by Microsoft for security in favor of requiring the // `SendSAS` event to be used, which makes DoS and social engineering attacks more difficult. - HANDLE hSendSasEvent = OpenEvent(EVENT_MODIFY_STATE, FALSE, deskflow::common::kSendSasEventName); + HANDLE hSendSasEvent = OpenEvent(EVENT_MODIFY_STATE, FALSE, kSendSasEventName); if (hSendSasEvent) { LOG_DEBUG("found SendSAS event, simulating ctrl+alt+del"); SetEvent(hSendSasEvent); diff --git a/src/lib/platform/MSWindowsProcess.cpp b/src/lib/platform/MSWindowsProcess.cpp index c38ce89f0..39ca0582e 100644 --- a/src/lib/platform/MSWindowsProcess.cpp +++ b/src/lib/platform/MSWindowsProcess.cpp @@ -122,7 +122,7 @@ void MSWindowsProcess::shutdown(HANDLE handle, DWORD pid, int timeout) LOG_DEBUG("shutting down process %d", pid); LOG_DEBUG("sending close event to close process gracefully"); - HANDLE hCloseEvent = OpenEvent(EVENT_MODIFY_STATE, FALSE, deskflow::common::kCloseEventName); + HANDLE hCloseEvent = OpenEvent(EVENT_MODIFY_STATE, FALSE, kCloseEventName); if (hCloseEvent != nullptr) { // NOSONAR -- Readability SetEvent(hCloseEvent); CloseHandle(hCloseEvent); diff --git a/src/lib/platform/MSWindowsWatchdog.cpp b/src/lib/platform/MSWindowsWatchdog.cpp index e54b0d20a..a355e32b8 100644 --- a/src/lib/platform/MSWindowsWatchdog.cpp +++ b/src/lib/platform/MSWindowsWatchdog.cpp @@ -567,7 +567,7 @@ void MSWindowsWatchdog::sendSas() const throw XArch("SendSAS function not initialized"); } - HANDLE sendSasEvent = CreateEvent(nullptr, FALSE, FALSE, deskflow::common::kSendSasEventName); + HANDLE sendSasEvent = CreateEvent(nullptr, FALSE, FALSE, kSendSasEventName); if (sendSasEvent == nullptr) { LOG_ERR("could not create SendSAS event"); throw XArch(new XArchEvalWindows());