Skip to content

Commit

Permalink
detect whether it is windows 7 SP1 using internal PEB
Browse files Browse the repository at this point in the history
  • Loading branch information
stevefan1999-personal authored and mingkuang-Chuyu committed Oct 17, 2024
1 parent 3aec9ad commit da18787
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Thunks/WS2_32.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1485,11 +1485,17 @@ namespace YY::Thunks
{
if (auto const pWSASocketW = try_get_WSASocketW())
{
if (!IsWindows7SP1OrGreater())
// This include Windows 7 non-SP1
if (internal::GetSystemVersion() <= internal::MakeVersion(6, 1))
{
// This flag is supported on Windows 7 with SP1, Windows Server 2008 R2 with SP1, and later
// So we strip it to prevent error
dwFlags &= ~WSA_FLAG_NO_HANDLE_INHERIT;
const auto _pPeb = ((TEB*)NtCurrentTeb())->ProcessEnvironmentBlock;
// This indicates a build version of 7601 on the lower 16-bit
if ((_pPeb->OSBuildNumber & 0xFFFF) != 7601)
{
// This flag is supported on Windows 7 with SP1, Windows Server 2008 R2 with SP1, and later
// So we strip it to prevent error on prior OS, because process handle inheritance doesn't really matter at that point
dwFlags &= ~WSA_FLAG_NO_HANDLE_INHERIT;
}
}
return pWSASocketW(af, type, protocol, lpProtocolInfo, g, dwFlags);
}
Expand Down

0 comments on commit da18787

Please sign in to comment.