From 7d3b731d62e385f85cc17ff20ad1825bdec0ace8 Mon Sep 17 00:00:00 2001 From: mingkuang Date: Thu, 22 Jun 2023 00:32:45 +0800 Subject: [PATCH] =?UTF-8?q?Fea=20#29=EF=BC=8C=E6=B7=BB=E5=8A=A0GetThreadIn?= =?UTF-8?q?formation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ThunksList.md | 1 + src/Thunks/api-ms-win-core-processthreads.hpp | 52 +++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/ThunksList.md b/ThunksList.md index 5d7c650..b42541c 100644 --- a/ThunksList.md +++ b/ThunksList.md @@ -279,6 +279,7 @@ | GetProcessMitigationPolicy | 不存在时,调用NtQueryInformationProcess。 | SetProcessMitigationPolicy | 不存在时,调用NtSetInformationProcess。 | SetProcessInformation | 不存在时,调用NtSetInformationProcess。 +| GetThreadInformation | 不存在时,调用NtQueryInformationThread。 | SetThreadInformation | 不存在时,调用NtSetInformationThread。 | PowerCreateRequest | 不存在时,内部实现。 | PowerSetRequest | 不存在时,调用 SetThreadExecutionState。 diff --git a/src/Thunks/api-ms-win-core-processthreads.hpp b/src/Thunks/api-ms-win-core-processthreads.hpp index 43bff25..a74e9e1 100644 --- a/src/Thunks/api-ms-win-core-processthreads.hpp +++ b/src/Thunks/api-ms-win-core-processthreads.hpp @@ -1026,6 +1026,58 @@ namespace YY } #endif + +#if (YY_Thunks_Support_Version < NTDDI_WIN8) + + // 最低受支持的客户端 Windows 8 [桌面应用|UWP 应用] + // 最低受支持的服务器 Windows Server 2012[桌面应用 | UWP 应用] + __DEFINE_THUNK( + kernel32, + 16, + BOOL, + WINAPI, + GetThreadInformation, + _In_ HANDLE _hThread, + _In_ THREAD_INFORMATION_CLASS _eThreadInformationClass, + _Out_writes_bytes_(_cbThreadInformationSize) LPVOID _pThreadInformation, + _In_ DWORD _cbThreadInformationSize + ) + { + if (const auto _pfnGetThreadInformation = try_get_GetThreadInformation()) + { + return _pfnGetThreadInformation(_hThread, _eThreadInformationClass, _pThreadInformation, _cbThreadInformationSize); + } + + const auto _pfnNtQueryInformationThread = try_get_NtQueryInformationThread(); + if (!_pfnNtQueryInformationThread) + { + SetLastError(ERROR_NOT_SUPPORTED); + return FALSE; + } + + long _Status; + if (_eThreadInformationClass == ThreadMemoryPriority) + { + _Status = _pfnNtQueryInformationThread(_hThread, ThreadPagePriority, _pThreadInformation, _cbThreadInformationSize, nullptr); + } + else if (_eThreadInformationClass == ThreadAbsoluteCpuPriority) + { + _Status = _pfnNtQueryInformationThread(_hThread, ThreadActualBasePriority, _pThreadInformation, _cbThreadInformationSize, nullptr); + } + else + { + _Status = STATUS_INVALID_PARAMETER; + } + + if (_Status < 0) + { + internal::BaseSetLastNTError(_Status); + return FALSE; + } + + return TRUE; + } +#endif }//namespace Thunks } //namespace YY \ No newline at end of file