[*] Drop all static references to User32.dll

This commit is contained in:
Reece Wilson 2023-10-13 00:10:44 +01:00
parent f5f79bb184
commit 7db0e2e688
8 changed files with 184 additions and 45 deletions

View File

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

View File

@ -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 {};

View File

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

View File

@ -74,7 +74,10 @@ namespace Aurora::Extensions::Win32
if (g_buildNumber < 18362)
{
SetPropW(hWnd, L"UseImmersiveDarkModeColors", reinterpret_cast<HANDLE>(static_cast<INT_PTR>(dark)));
if (pSetPropW)
{
pSetPropW(hWnd, L"UseImmersiveDarkModeColors", reinterpret_cast<HANDLE>(static_cast<INT_PTR>(dark)));
}
}
else if (_SetWindowCompositionAttribute)
{

View File

@ -8,19 +8,33 @@
#include <Source/RuntimeInternal.hpp>
#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()

View File

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

View File

@ -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
@ -1273,33 +1276,36 @@ namespace Aurora::IO::Loop
return false;
}
if (AuStaticCast<Win32Dummy>(this->msgSource_)->bIsPumping_)
if (pPeekMessageW &&
pTranslateMessage &&
pDispatchMessageW)
{
MSG msg;
try
if (AuStaticCast<Win32Dummy>(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)

View File

@ -72,10 +72,17 @@ namespace Aurora::Processes
DWORD windowpid;
auto context = reinterpret_cast<Hack *>(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;
@ -111,7 +123,7 @@ namespace Aurora::Processes
if (te.dwSize >= FIELD_OFFSET(THREADENTRY32, th32OwnerProcessID) +
sizeof(te.th32OwnerProcessID))
{
EnumThreadWindows(te.th32ThreadID, TermWinHandleWin32Thread, reinterpret_cast<LPARAM>(&hello));
pEnumThreadWindows(te.th32ThreadID, TermWinHandleWin32Thread, reinterpret_cast<LPARAM>(&hello));
}
te.dwSize = sizeof(te);
} while (Thread32Next(h, &te));