Skip to content

Commit

Permalink
Fea #76, 新增ProcessPrng
Browse files Browse the repository at this point in the history
  • Loading branch information
mingkuang-Chuyu committed May 2, 2024
1 parent 8775cae commit 4db5161
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 2 deletions.
5 changes: 5 additions & 0 deletions ThunksList.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@
| BCryptCloseAlgorithmProvider | 内部实现。
| BCryptGenRandom | 不存在时调用,RtlGenRandom。

## bcryptprimitives.dll
| 函数 | Fallback
| ---- | -----------
| ProcessPrng | 不存在时调用,RtlGenRandom。

## bluetoothapis.dll
| 函数 | Fallback
| ---- | -----------
Expand Down
41 changes: 41 additions & 0 deletions src/Thunks/BCryptPrimitives.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

extern "C" BOOL WINAPI ProcessPrng(
_Out_writes_bytes_(_cbBuffer) PUCHAR _pbBuffer,
_In_ ULONG _cbBuffer
);

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

// 最低受支持的客户端 Windows Vista [桌面应用|UWP 应用]
// 最低受支持的服务器 Windows Server 2008[桌面应用 | UWP 应用]
__DEFINE_THUNK(
bcryptprimitives,
8,
BOOL,
WINAPI,
ProcessPrng,
_Out_writes_bytes_(_cbBuffer) PUCHAR _pbBuffer,
_In_ ULONG _cbBuffer
)
{
if (auto _pfnProcessPrng = try_get_ProcessPrng())
{
return _pfnProcessPrng(_pbBuffer, _cbBuffer);
}

const auto _pfnRtlGenRandom = try_get_SystemFunction036();
if (!_pfnRtlGenRandom)
{
SetLastError(ERROR_FUNCTION_FAILED);
return FALSE;
}

return _pfnRtlGenRandom(_pbBuffer, _cbBuffer);
}
#endif
} // namespace Thunks
} // namespace YY
1 change: 1 addition & 0 deletions src/Thunks/YY_Thunks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
_APPLY(version, "version" , 0 ) \
_APPLY(advapi32, "advapi32" , 0 ) \
_APPLY(bcrypt, "bcrypt" , 0 ) \
_APPLY(bcryptprimitives, "bcryptprimitives" , 0 ) \
_APPLY(user32, "user32" , 0 ) \
_APPLY(ws2_32, "ws2_32" , 0 ) \
_APPLY(shell32, "shell32" , 0 ) \
Expand Down
4 changes: 2 additions & 2 deletions src/Thunks/bcrypt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ namespace YY
WINAPI,
BCryptGenRandom,
_In_opt_ BCRYPT_ALG_HANDLE _hAlgorithm,
_Out_writes_bytes_(cbBuffer) PUCHAR _pbBuffer,
_Out_writes_bytes_(_cbBuffer) PUCHAR _pbBuffer,
_In_ ULONG _cbBuffer,
_In_ ULONG _fFlags
)
Expand Down Expand Up @@ -180,4 +180,4 @@ namespace YY
}
#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 @@ -198,6 +198,7 @@
<ClInclude Include="..\Thunks\api-ms-win-eventing-provider.hpp" />
<ClInclude Include="..\Thunks\api-ms-win-power-base.hpp" />
<ClInclude Include="..\Thunks\bcrypt.hpp" />
<ClInclude Include="..\Thunks\BCryptPrimitives.hpp" />
<ClInclude Include="..\Thunks\bluetoothapis.hpp" />
<ClInclude Include="..\Thunks\dwmapi.hpp" />
<ClInclude Include="..\Thunks\ext-ms-win-ntuser-powermanagement.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 @@ -236,6 +236,9 @@
<ClInclude Include="..\Thunks\dwmapi.hpp">
<Filter>Thunks</Filter>
</ClInclude>
<ClInclude Include="..\Thunks\BCryptPrimitives.hpp">
<Filter>Thunks</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\def\x86\PSAPI2Kernel32.def">
Expand Down

0 comments on commit 4db5161

Please sign in to comment.