Skip to content

Commit

Permalink
Fea #71, 让qt5.15.12支持XP,改进dbghelp支持
Browse files Browse the repository at this point in the history
  - 添加 SymSetSearchPathW
  - 添加 SymGetSearchPathW
  • Loading branch information
mingkuang-Chuyu committed May 20, 2024
1 parent 3f59f23 commit 8c80dbf
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ThunksList.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@
| CryptProtectMemory | 不存在时,返回TRUE。
| CryptUnprotectMemory | 不存在时,返回TRUE。

## DbgHelp.dll
| 函数 | Fallback
| ---- | -----------
| SymSetSearchPathW | 不存在时,调用SymSetSearchPath。
| SymGetSearchPathW | 不存在时,调用SymGetSearchPath。

## dwmapi.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 @@ -7,6 +7,7 @@
_APPLY(kernel32, "kernel32" , USING_UNSAFE_LOAD ) \
_APPLY(crypt32, "crypt32" , 0 ) \
_APPLY(dwmapi, "dwmapi" , 0 ) \
_APPLY(dbghelp, "dbghelp" , USING_UNSAFE_LOAD ) \
_APPLY(psapi, "psapi" , 0 ) \
_APPLY(pdh, "pdh" , 0 ) \
_APPLY(version, "version" , 0 ) \
Expand Down
86 changes: 86 additions & 0 deletions src/Thunks/dbghelp.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include <dbghelp.h>

#if (YY_Thunks_Support_Version < NTDDI_WIN6)
#pragma comment(lib, "Dbghelp.lib")
#endif

namespace YY::Thunks
{
#if (YY_Thunks_Support_Version < NTDDI_WIN6)

// XP SP3自带的没有W版
__DEFINE_THUNK(
dbghelp,
8,
BOOL,
WINAPI,
SymSetSearchPathW,
_In_ HANDLE hProcess,
_In_opt_ PCWSTR SearchPath
)
{
if (const auto _pfnSymSetSearchPathW = try_get_SymSetSearchPathW())
{
return _pfnSymSetSearchPathW(hProcess, SearchPath);
}

PCSTR _szSearchPathANSI = nullptr;

internal::StringBuffer<char> _szBuffer;
if (SearchPath)
{
auto _lStatus = internal::Convert(SearchPath, -1, &_szBuffer);
if (_lStatus)
{
SetLastError(_lStatus);
return FALSE;
}

_szSearchPathANSI = _szBuffer.GetC_String();
}
return ::SymSetSearchPath(hProcess, _szSearchPathANSI);
}
#endif


#if (YY_Thunks_Support_Version < NTDDI_WIN6)

// XP SP3自带的没有W版
__DEFINE_THUNK(
dbghelp,
12,
BOOL,
WINAPI,
SymGetSearchPathW,
_In_ HANDLE hProcess,
_Out_writes_(SearchPathLength) PWSTR SearchPath,
_In_ DWORD SearchPathLength
)
{
if (const auto _pfnSymGetSearchPathW = try_get_SymGetSearchPathW())
{
return _pfnSymGetSearchPathW(hProcess, SearchPath, SearchPathLength);
}

if (SearchPath == nullptr || SearchPathLength == 0)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}

char _szANSISearchPathBuffer[2048];
if (!SymGetSearchPath(hProcess, _szANSISearchPathBuffer, _countof(_szANSISearchPathBuffer)))
{
return FALSE;
}

if (*_szANSISearchPathBuffer == L'\0')
{
SearchPath[0] = L'\0';
return TRUE;
}

return MultiByteToWideChar(CP_ACP, 0, _szANSISearchPathBuffer, -1, SearchPath, SearchPathLength) == 0;
}
#endif
}
1 change: 1 addition & 0 deletions src/YY-Thunks.UnitTest/YY-Thunks.UnitTest.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@
<ClInclude Include="..\Thunks\BCryptPrimitives.hpp" />
<ClInclude Include="..\Thunks\bluetoothapis.hpp" />
<ClInclude Include="..\Thunks\Crypt32.hpp" />
<ClInclude Include="..\Thunks\dbghelp.hpp" />
<ClInclude Include="..\Thunks\dwmapi.hpp" />
<ClInclude Include="..\Thunks\ext-ms-win-ntuser-powermanagement.hpp" />
<ClInclude Include="..\Thunks\ext-ms-win-ntuser-window.hpp" />
Expand Down
3 changes: 3 additions & 0 deletions src/YY-Thunks.UnitTest/YY-Thunks.UnitTest.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@
<ClInclude Include="..\Shared\Heap.h">
<Filter>Shared</Filter>
</ClInclude>
<ClInclude Include="..\Thunks\dbghelp.hpp">
<Filter>Thunks</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\def\x86\PSAPI2Kernel32.def">
Expand Down

0 comments on commit 8c80dbf

Please sign in to comment.