diff --git a/Source/AuProcAddresses.NT.cpp b/Source/AuProcAddresses.NT.cpp index 54f91fc1..cb2c3f43 100644 --- a/Source/AuProcAddresses.NT.cpp +++ b/Source/AuProcAddresses.NT.cpp @@ -50,6 +50,7 @@ namespace Aurora ADD_LOAD_LIB(WinTrust); ADD_LOAD_LIB(IPHelper); ADD_LOAD_LIB(COM); + ADD_LOAD_LIB(User32); #define ADD_GET_PROC(name, proc) \ if (h ## name) \ @@ -198,6 +199,19 @@ namespace Aurora ADD_GET_PROC(Shell, CommandLineToArgvW) ADD_GET_PROC(Shell, ShellExecuteW) + ADD_GET_PROC(User32, GetClipboardData); + ADD_GET_PROC(User32, MapVirtualKeyA); + ADD_GET_PROC(User32, CloseClipboard); + ADD_GET_PROC(User32, GetWindowThreadProcessId); + ADD_GET_PROC(User32, SendMessageA); + ADD_GET_PROC(User32, EnumThreadWindows); + ADD_GET_PROC(User32, DispatchMessageW); + ADD_GET_PROC(User32, TranslateMessage); + ADD_GET_PROC(User32, MsgWaitForMultipleObjectsEx); + ADD_GET_PROC(User32, MsgWaitForMultipleObjects); + ADD_GET_PROC(User32, PeekMessageW); + ADD_GET_PROC(User32, SetPropW); + ADD_GET_PROC(User32, OpenClipboard); if (pNtCreateKeyedEvent && Threading::Primitives::gKeyedEventHandle == INVALID_HANDLE_VALUE) diff --git a/Source/AuProcAddresses.NT.hpp b/Source/AuProcAddresses.NT.hpp index 8991c7a6..e857e265 100644 --- a/Source/AuProcAddresses.NT.hpp +++ b/Source/AuProcAddresses.NT.hpp @@ -55,6 +55,7 @@ namespace Aurora static const wchar_t *kWinTrustDllName { L"WINTRUST.dll" }; static const wchar_t *kIPHelperDllName { L"IPHLPAPI.dll" }; static const wchar_t *kCOMDllName { L"ole32.dll" }; + static const wchar_t *kUser32DllName { L"User32.dll" }; struct WIN32_MEMORY_RANGE_ENTRY2 { @@ -675,6 +676,80 @@ namespace Aurora VOID * pSid ); + // USER32 - the shit microsoft will probably try to phase out and remove over time + // [then give up and write a win32 emulator in a memelang, probably] + + inline BOOL(__stdcall *pOpenClipboard)( + HWND hWndNewOwner + ); + + inline HANDLE(__stdcall *pGetClipboardData)( + UINT uFormat + ); + + inline BOOL(__stdcall *pCloseClipboard)(); + + inline UINT(__stdcall *pMapVirtualKeyA)( + UINT uCode, + UINT uMapType + ); + + inline DWORD(__stdcall *pGetWindowThreadProcessId)( + HWND hWnd, + LPDWORD lpdwProcessId + ); + + inline LRESULT(__stdcall *pSendMessageA)( + HWND hWnd, + UINT Msg, + WPARAM wParam, + LPARAM lParam + ); + + inline BOOL(__stdcall *pEnumThreadWindows)( + DWORD dwThreadId, + WNDENUMPROC lpfn, + LPARAM lParam + ); + + inline BOOL(__stdcall *pTranslateMessage)( + MSG * lpMsg + ); + + inline LRESULT(__stdcall *pDispatchMessageW)( + MSG * lpMsg + ); + + inline DWORD(__stdcall *pMsgWaitForMultipleObjects)( + DWORD nCount, + CONST HANDLE * pHandles, + BOOL fWaitAll, + DWORD dwMilliseconds, + DWORD dwWakeMask + ); + + inline DWORD(__stdcall *pMsgWaitForMultipleObjectsEx)( + DWORD nCount, + CONST HANDLE * pHandles, + DWORD dwMilliseconds, + DWORD dwWakeMask, + DWORD dwFlags + ); + + inline BOOL(__stdcall *pPeekMessageW)( + LPMSG lpMsg, + HWND hWnd, + UINT wMsgFilterMin, + UINT wMsgFilterMax, + UINT wRemoveMsg + ); + + inline BOOL(__stdcall *pSetPropW)( + HWND hWnd, + LPCWSTR lpString, + HANDLE hData + ); + inline bool gUseNativeWaitMutex {}; inline bool gUseNativeWaitCondvar {}; inline bool gUseNativeWaitSemapahore {}; diff --git a/Source/Console/ConsoleStd/ConsoleStd.cpp b/Source/Console/ConsoleStd/ConsoleStd.cpp index 6dfdb2f6..d2ca1ca8 100755 --- a/Source/Console/ConsoleStd/ConsoleStd.cpp +++ b/Source/Console/ConsoleStd/ConsoleStd.cpp @@ -143,15 +143,22 @@ namespace Aurora::Console::ConsoleStd static AuUInt64 gLastHash {}; AuString str; - if (!::OpenClipboard(nullptr)) + if (!pOpenClipboard || + !pCloseClipboard || + !pGetClipboardData) { return; } - auto hClipboardData = ::GetClipboardData(CF_UNICODETEXT); + if (!pOpenClipboard(nullptr)) + { + return; + } + + auto hClipboardData = pGetClipboardData(CF_UNICODETEXT); if (hClipboardData == nullptr) { - ::CloseClipboard(); + pCloseClipboard(); return; } @@ -173,7 +180,7 @@ namespace Aurora::Console::ConsoleStd gLastHash = newHash; } - ::CloseClipboard(); + pCloseClipboard(); } static void ProcessLines(AuList &lines); @@ -182,15 +189,22 @@ namespace Aurora::Console::ConsoleStd { AuString str; - if (!::OpenClipboard(nullptr)) + if (!pOpenClipboard || + !pCloseClipboard || + !pGetClipboardData) { return; } - auto hClipboardData = ::GetClipboardData(CF_UNICODETEXT); + if (!pOpenClipboard(nullptr)) + { + return; + } + + auto hClipboardData = pGetClipboardData(CF_UNICODETEXT); if (hClipboardData == nullptr) { - ::CloseClipboard(); + pCloseClipboard(); return; } @@ -231,7 +245,7 @@ namespace Aurora::Console::ConsoleStd } } - ::CloseClipboard(); + pCloseClipboard(); } void ProcessCanonical(HANDLE h) @@ -571,7 +585,7 @@ namespace Aurora::Console::ConsoleStd niceWorkMicrosoft[0].Event.KeyEvent.wRepeatCount = 1; niceWorkMicrosoft[0].Event.KeyEvent.wVirtualKeyCode = VK_RETURN; niceWorkMicrosoft[0].Event.KeyEvent.uChar.UnicodeChar = '\r'; - niceWorkMicrosoft[0].Event.KeyEvent.wVirtualScanCode = MapVirtualKey(VK_RETURN, MAPVK_VK_TO_VSC); + niceWorkMicrosoft[0].Event.KeyEvent.wVirtualScanCode = pMapVirtualKeyA(VK_RETURN, MAPVK_VK_TO_VSC); niceWorkMicrosoft[1].EventType = KEY_EVENT; niceWorkMicrosoft[1].Event.KeyEvent.bKeyDown = FALSE; @@ -579,7 +593,7 @@ namespace Aurora::Console::ConsoleStd niceWorkMicrosoft[1].Event.KeyEvent.wRepeatCount = 1; niceWorkMicrosoft[1].Event.KeyEvent.wVirtualKeyCode = VK_RETURN; niceWorkMicrosoft[1].Event.KeyEvent.uChar.UnicodeChar = '\r'; - niceWorkMicrosoft[1].Event.KeyEvent.wVirtualScanCode = MapVirtualKey(VK_RETURN, MAPVK_VK_TO_VSC); + niceWorkMicrosoft[1].Event.KeyEvent.wVirtualScanCode = pMapVirtualKeyA(VK_RETURN, MAPVK_VK_TO_VSC); DWORD idc; WriteConsoleInputW(gInputStream, niceWorkMicrosoft, 2, &idc); diff --git a/Source/Extensions/Win32/DarkTheme.cpp b/Source/Extensions/Win32/DarkTheme.cpp index 10b2ee97..6410350f 100644 --- a/Source/Extensions/Win32/DarkTheme.cpp +++ b/Source/Extensions/Win32/DarkTheme.cpp @@ -74,7 +74,10 @@ namespace Aurora::Extensions::Win32 if (g_buildNumber < 18362) { - SetPropW(hWnd, L"UseImmersiveDarkModeColors", reinterpret_cast(static_cast(dark))); + if (pSetPropW) + { + pSetPropW(hWnd, L"UseImmersiveDarkModeColors", reinterpret_cast(static_cast(dark))); + } } else if (_SetWindowCompositionAttribute) { diff --git a/Source/IO/Loop/LSWin32.NT.cpp b/Source/IO/Loop/LSWin32.NT.cpp index 31b09e79..013f2ddc 100644 --- a/Source/IO/Loop/LSWin32.NT.cpp +++ b/Source/IO/Loop/LSWin32.NT.cpp @@ -8,19 +8,33 @@ #include #include "LSWin32.NT.hpp" +#if !defined(PM_NOREMOVE) + #define PM_NOREMOVE 0x0000 +#endif + namespace Aurora::IO::Loop { bool Win32Dummy::IsSignaled() { MSG askers; - return PeekMessageW(&askers, 0, 0, 0, PM_NOREMOVE); + return pPeekMessageW && + pPeekMessageW(&askers, 0, 0, 0, PM_NOREMOVE); } bool Win32Dummy::WaitOn(AuUInt32 timeout) { // TODO: Close static HANDLE kAlwaysOffMutex = CreateEventW(nullptr, true, false, nullptr); - return MsgWaitForMultipleObjects(0, &kAlwaysOffMutex, false, timeout ? timeout : INFINITE, QS_ALLEVENTS) == WAIT_OBJECT_0 + 1; + if (!pMsgWaitForMultipleObjects) + { + return false; + } + + #if defined(QS_ALLEVENTS) + return pMsgWaitForMultipleObjects(0, &kAlwaysOffMutex, false, timeout ? timeout : INFINITE, QS_ALLEVENTS) == WAIT_OBJECT_0 + 1; + #else + return false; + #endif } ELoopSource Win32Dummy::GetType() diff --git a/Source/IO/Loop/Loop.NT.cpp b/Source/IO/Loop/Loop.NT.cpp index 5d98ce51..750d5970 100644 --- a/Source/IO/Loop/Loop.NT.cpp +++ b/Source/IO/Loop/Loop.NT.cpp @@ -69,9 +69,10 @@ namespace Aurora::IO::Loop } DWORD ret; - if (isWinLoop) + if (isWinLoop && + pMsgWaitForMultipleObjectsEx) { - ret = ::MsgWaitForMultipleObjectsEx(handleArray.size(), handleArray.data(), timeout ? timeout : INFINITE, QS_ALLPOSTMESSAGE | QS_ALLINPUT, MWMO_INPUTAVAILABLE | MWMO_ALERTABLE); + ret = pMsgWaitForMultipleObjectsEx(handleArray.size(), handleArray.data(), timeout ? timeout : INFINITE, QS_ALLPOSTMESSAGE | QS_ALLINPUT, MWMO_INPUTAVAILABLE | MWMO_ALERTABLE); } else { diff --git a/Source/IO/Loop/LoopQueue.NT.cpp b/Source/IO/Loop/LoopQueue.NT.cpp index c033b216..19f2c90c 100644 --- a/Source/IO/Loop/LoopQueue.NT.cpp +++ b/Source/IO/Loop/LoopQueue.NT.cpp @@ -655,9 +655,10 @@ namespace Aurora::IO::Loop do { - if (this->bIsWinLoop_) + if (this->bIsWinLoop_ && + pMsgWaitForMultipleObjectsEx) { - status = ::MsgWaitForMultipleObjectsEx(next, this->handleArrayAnd_.data() + index, timeDelta, QS_ALLPOSTMESSAGE | QS_ALLINPUT | QS_ALLEVENTS, MWMO_INPUTAVAILABLE | MWMO_ALERTABLE | MWMO_WAITALL); + status = pMsgWaitForMultipleObjectsEx(next, this->handleArrayAnd_.data() + index, timeDelta, QS_ALLPOSTMESSAGE | QS_ALLINPUT | QS_ALLEVENTS, MWMO_INPUTAVAILABLE | MWMO_ALERTABLE | MWMO_WAITALL); } else { @@ -887,11 +888,12 @@ namespace Aurora::IO::Loop } DWORD status {}; - if (this->bIsWinLoop_) + if (this->bIsWinLoop_ && + pMsgWaitForMultipleObjectsEx) { do { - status = ::MsgWaitForMultipleObjectsEx(next, this->handleArrayOr_.data() + index, sleepMS, QS_ALLINPUT | QS_ALLPOSTMESSAGE, MWMO_ALERTABLE); + status = pMsgWaitForMultipleObjectsEx(next, this->handleArrayOr_.data() + index, sleepMS, QS_ALLINPUT | QS_ALLPOSTMESSAGE, MWMO_ALERTABLE); { auto temp2 = status; @@ -997,7 +999,8 @@ namespace Aurora::IO::Loop sleepDelta = 0; } - if (this->bIsWinLoop_) + if (this->bIsWinLoop_ && + pMsgWaitForMultipleObjectsEx) { // TODO: this might be a symptom of something else if (!AuSwInfo::IsWindows10OrGreater() && @@ -1012,12 +1015,12 @@ namespace Aurora::IO::Loop if (!DoTryIf()) { - temp = ::MsgWaitForMultipleObjectsEx(this->handleArrayOr_.size(), this->handleArrayOr_.data(), sleepDelta, QS_ALLPOSTMESSAGE | QS_ALLINPUT | QS_ALLEVENTS, MWMO_INPUTAVAILABLE | MWMO_ALERTABLE); + temp = pMsgWaitForMultipleObjectsEx(this->handleArrayOr_.size(), this->handleArrayOr_.data(), sleepDelta, QS_ALLPOSTMESSAGE | QS_ALLINPUT | QS_ALLEVENTS, MWMO_INPUTAVAILABLE | MWMO_ALERTABLE); } } else { - temp = ::MsgWaitForMultipleObjectsEx(this->handleArrayOr_.size(), this->handleArrayOr_.data(), sleepDelta, QS_ALLPOSTMESSAGE | QS_ALLINPUT | QS_ALLEVENTS, MWMO_INPUTAVAILABLE | MWMO_ALERTABLE); + temp = pMsgWaitForMultipleObjectsEx(this->handleArrayOr_.size(), this->handleArrayOr_.data(), sleepDelta, QS_ALLPOSTMESSAGE | QS_ALLINPUT | QS_ALLEVENTS, MWMO_INPUTAVAILABLE | MWMO_ALERTABLE); } } else @@ -1272,34 +1275,37 @@ namespace Aurora::IO::Loop { return false; } - - if (AuStaticCast(this->msgSource_)->bIsPumping_) + + if (pPeekMessageW && + pTranslateMessage && + pDispatchMessageW) { MSG msg; - try + if (AuStaticCast(this->msgSource_)->bIsPumping_) { - while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) + try + { + while (pPeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) + { + pTranslateMessage(&msg); + pDispatchMessageW(&msg); + bMsgPump = true; + } + } + catch (...) + { + SysPushErrorCatch("Win32 Pump <-> Aur LoopQueue. Window handler threw a C++ exception."); + } + } + else + { + if (pPeekMessageW(&msg, NULL, 0, 0, PM_NOREMOVE)) { - TranslateMessage(&msg); - DispatchMessageW(&msg); bMsgPump = true; } } - catch (...) - { - SysPushErrorCatch("Win32 Pump <-> Aur LoopQueue. Window handler threw a C++ exception."); - } } - else - { - MSG msg; - if (PeekMessageW(&msg, NULL, 0, 0, PM_NOREMOVE)) - { - bMsgPump = true; - } - } - // Notify all and remove if unwanted if (bMsgPump) diff --git a/Source/Processes/AuProcess.Win32.cpp b/Source/Processes/AuProcess.Win32.cpp index f50695dd..c226ef3d 100644 --- a/Source/Processes/AuProcess.Win32.cpp +++ b/Source/Processes/AuProcess.Win32.cpp @@ -72,10 +72,17 @@ namespace Aurora::Processes DWORD windowpid; auto context = reinterpret_cast(a); auto pid = GetProcessId(context->base); - GetWindowThreadProcessId(handle, &windowpid); + + if (!pGetWindowThreadProcessId || + !pSendMessageA) + { + return true; + } + + pGetWindowThreadProcessId(handle, &windowpid); if (pid && pid == windowpid) { - SendMessageA(handle, WM_CLOSE, 0, 0); + pSendMessageA(handle, WM_CLOSE, 0, 0); context->count++; } return true; @@ -93,6 +100,11 @@ namespace Aurora::Processes te.dwSize = sizeof(te); te.th32OwnerProcessID = GetProcessId(handle); + if (!pEnumThreadWindows) + { + return false; + } + if (!te.th32OwnerProcessID) { return false; @@ -103,7 +115,7 @@ namespace Aurora::Processes { return false; } - + if (Thread32First(h, &te)) { do @@ -111,7 +123,7 @@ namespace Aurora::Processes if (te.dwSize >= FIELD_OFFSET(THREADENTRY32, th32OwnerProcessID) + sizeof(te.th32OwnerProcessID)) { - EnumThreadWindows(te.th32ThreadID, TermWinHandleWin32Thread, reinterpret_cast(&hello)); + pEnumThreadWindows(te.th32ThreadID, TermWinHandleWin32Thread, reinterpret_cast(&hello)); } te.dwSize = sizeof(te); } while (Thread32Next(h, &te));