Skip to content

Commit f59914d

Browse files
detect whether it is windows 7 SP1 using internal PEB
1 parent 9e7dd59 commit f59914d

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/Thunks/WS2_32.hpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,11 +1485,17 @@ namespace YY::Thunks
14851485
{
14861486
if (auto const pWSASocketW = try_get_WSASocketW())
14871487
{
1488-
if (!IsWindows7SP1OrGreater())
1488+
// This include Windows 7 non-SP1
1489+
if (internal::GetSystemVersion() <= internal::MakeVersion(6, 1))
14891490
{
1490-
// This flag is supported on Windows 7 with SP1, Windows Server 2008 R2 with SP1, and later
1491-
// So we strip it to prevent error
1492-
dwFlags &= ~WSA_FLAG_NO_HANDLE_INHERIT;
1491+
const auto _pPeb = ((TEB*)NtCurrentTeb())->ProcessEnvironmentBlock;
1492+
// This indicates a build version of 7601 on the lower 16-bit
1493+
if ((_pPeb->OSBuildNumber & 0xFFFF) != 7601)
1494+
{
1495+
// This flag is supported on Windows 7 with SP1, Windows Server 2008 R2 with SP1, and later
1496+
// So we strip it to prevent error on prior OS, because process handle inheritance doesn't really matter at that point
1497+
dwFlags &= ~WSA_FLAG_NO_HANDLE_INHERIT;
1498+
}
14931499
}
14941500
return pWSASocketW(af, type, protocol, lpProtocolInfo, g, dwFlags);
14951501
}

0 commit comments

Comments
 (0)