chore: Move Windows event constants to constants file

This commit is contained in:
Nick Bolton 2025-03-10 12:30:15 +00:00 committed by Chris Rizzitello
parent d26c75a784
commit 3bcc1e11ed
6 changed files with 7 additions and 14 deletions

View file

@ -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

View file

@ -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

View file

@ -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());

View file

@ -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);

View file

@ -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);

View file

@ -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());