Skip to content

Commit

Permalink
Fea, 添加GetThreadDescription、SetThreadDescription
Browse files Browse the repository at this point in the history
  • Loading branch information
mingkuang-Chuyu committed Oct 30, 2024
1 parent 1149c82 commit ff19a64
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ThunksList.md
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,8 @@
| SetDefaultDllDirectories | 不存在时,手工控制LoadLibrary加载顺序。
| GetCurrentPackageFullName | 返回 APPMODEL_ERROR_NO_PACKAGE。
| OpenProcess | 额外处理 PROCESS_QUERY_LIMITED_INFORMATION、PROCESS_SET_LIMITED_INFORMATION。
| GetThreadDescription | 返回空字符串。
| SetThreadDescription | 返回 `E_NOTIMPL`

## mfplat.dll
| 函数 | Fallback
Expand Down
1 change: 1 addition & 0 deletions src/Thunks/YY_Thunks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ YY-Thunks支持的控制宏:
#define _YY_APPLY_TO_LATE_BOUND_MODULES(_APPLY) \
_APPLY(ntdll, "ntdll" , USING_GET_MODULE_HANDLE ) \
_APPLY(kernel32, "kernel32" , USING_GET_MODULE_HANDLE ) \
_APPLY(kernelbase, "kernelbase" , USING_GET_MODULE_HANDLE ) \
_APPLY(cfgmgr32, "cfgmgr32" , 0 ) \
_APPLY(crypt32, "crypt32" , 0 ) \
_APPLY(dwmapi, "dwmapi" , 0 ) \
Expand Down
61 changes: 60 additions & 1 deletion src/Thunks/api-ms-win-core-processthreads.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if (YY_Thunks_Target < __WindowsNT6_2)
#if (YY_Thunks_Target < __WindowsNT10_15063)
#include <processthreadsapi.h>
#endif

Expand Down Expand Up @@ -1300,4 +1300,63 @@ namespace YY ::Thunks
return _pfnOpenThread(_fDesiredAccess, _bInheritHandle, _uThreadId);
}
#endif


#if (YY_Thunks_Target < __WindowsNT10_15063)

// 最低受支持的客户端 Windows 10版本 1607 [桌面应用 |UWP 应用]
// 最低受支持的服务器 Windows Server 2016[桌面应用 | UWP 应用]
// 虽然14393就有这个接口,但是14393必须从 kernelbase加载,因此也需要修正。
__DEFINE_THUNK(
kernelbase,
8,
HRESULT,
WINAPI,
GetThreadDescription,
_In_ HANDLE _hThread,
_Outptr_result_z_ PWSTR* _pszThreadDescription
)
{
if (const auto _pfnGetThreadDescription = try_get_GetThreadDescription())
{
return _pfnGetThreadDescription(_hThread, _pszThreadDescription);
}

// 假装自己是一个空的 ThreadDescription

*_pszThreadDescription = nullptr;
auto _szThreadDescription = (wchar_t*)LocalAlloc(LMEM_FIXED, sizeof(wchar_t));
if (!_szThreadDescription)
return E_OUTOFMEMORY;

*_szThreadDescription = L'\0';
*_pszThreadDescription = _szThreadDescription;
return 0x10000000;
}
#endif


#if (YY_Thunks_Target < __WindowsNT10_15063)

// 最低受支持的客户端 Windows 10版本 1607 [桌面应用 |UWP 应用]
// 最低受支持的服务器 Windows Server 2016[桌面应用 | UWP 应用]
// 虽然14393就有这个接口,但是14393必须从 kernelbase加载,因此也需要修正。
__DEFINE_THUNK(
kernelbase,
8,
HRESULT,
WINAPI,
SetThreadDescription,
_In_ HANDLE _hThread,
_In_ PCWSTR _szThreadDescription
)
{
if (const auto _pfnSetThreadDescription = try_get_SetThreadDescription())
{
return _pfnSetThreadDescription(_hThread, _szThreadDescription);
}

return E_NOTIMPL;
}
#endif
} //namespace YY::Thunks

0 comments on commit ff19a64

Please sign in to comment.