Skip to content

Commit

Permalink
Fea #29,添加GetThreadInformation
Browse files Browse the repository at this point in the history
  • Loading branch information
mingkuang-Chuyu committed Jun 21, 2023
1 parent 68b0fc5 commit 7d3b731
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions ThunksList.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@
| GetProcessMitigationPolicy | 不存在时,调用NtQueryInformationProcess。
| SetProcessMitigationPolicy | 不存在时,调用NtSetInformationProcess。
| SetProcessInformation | 不存在时,调用NtSetInformationProcess。
| GetThreadInformation | 不存在时,调用NtQueryInformationThread。
| SetThreadInformation | 不存在时,调用NtSetInformationThread。
| PowerCreateRequest | 不存在时,内部实现。
| PowerSetRequest | 不存在时,调用 SetThreadExecutionState。
Expand Down
52 changes: 52 additions & 0 deletions src/Thunks/api-ms-win-core-processthreads.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7d3b731

Please sign in to comment.