@@ -24,6 +24,8 @@ HMODULE hNtdll = nullptr;
2424HMODULE hWsaClient = nullptr ;
2525
2626RTL_OSVERSIONINFOEXW gOsVersionInfo = {0 };
27+ bool gIsPatchVersionNumber = false ;
28+ bool gIsPatchProductType = false ;
2729
2830#define NT_SUCCESS (Status ) (((NTSTATUS)(Status)) >= 0 )
2931#define STATUS_SUCCESS ((NTSTATUS)0x00000000L )
@@ -50,12 +52,17 @@ void defaultLogHandler(Log::Level level, const WCHAR *tag, const WCHAR *msg) {
5052using FuncRtlGetVersion = NTSYSAPI NTSTATUS (*)(PRTL_OSVERSIONINFOW lpVersionInformation);
5153
5254NTSTATUS WINAPI FakeRtlGetVersion (PRTL_OSVERSIONINFOW lpVersionInformation) {
53- // 10.0.22000.1
55+ // The minimal version is 10.0.22000.120 VER_NT_WORKSTATION
5456 LOGD (L" -FakeRtlGetVersion" );
5557 DWORD size = lpVersionInformation->dwOSVersionInfoSize ;
5658 memcpy (lpVersionInformation, &gOsVersionInfo , size);
5759 lpVersionInformation->dwOSVersionInfoSize = size;
58- lpVersionInformation->dwBuildNumber = 22000 ;
60+ if (gIsPatchVersionNumber ) {
61+ lpVersionInformation->dwBuildNumber = 22000 ;
62+ }
63+ if (gIsPatchProductType && size >= sizeof (OSVERSIONINFOEXW)) {
64+ ((PRTL_OSVERSIONINFOEXW) lpVersionInformation)->wProductType = VER_NT_WORKSTATION;
65+ }
5966 return STATUS_SUCCESS;
6067}
6168
@@ -184,7 +191,7 @@ bool OnLoad(HINSTANCE hInstDLL) {
184191 }
185192 if (wcsstr (filename, L" \\ wsaclinent.exe" ) == nullptr ) {
186193 WCHAR buf[1024 ] = {};
187- StringCbPrintfW (buf, 1024 , L" GetModuleHandleW(L\" WsaClient.dll \" ) is NULL.\n Is wsapatch.dll loaded into wrong process?\n %s" , filename);
194+ StringCbPrintfW (buf, 1024 , L" GetModuleHandleW(L\" WsaClient.exe \" ) is NULL.\n Is wsapatch.dll loaded into wrong process?\n %s" , filename);
188195 MessageBoxW (nullptr , buf, L" wsapatch.dll" , MB_OK | MB_ICONERROR);
189196 return false ;
190197 }
@@ -205,10 +212,14 @@ bool OnLoad(HINSTANCE hInstDLL) {
205212 }
206213 LOGD (L" RtlGetVersion: dwMajorVersion=%d, dwMinorVersion=%d, dwBuildNumber=%d, dwPlatformId=%d" ,
207214 gOsVersionInfo .dwMajorVersion , gOsVersionInfo .dwMinorVersion , gOsVersionInfo .dwBuildNumber , gOsVersionInfo .dwPlatformId );
208- if (gOsVersionInfo .dwMajorVersion >= 10 && gOsVersionInfo .dwMinorVersion >= 0 && gOsVersionInfo .dwBuildNumber >= 22000 ) {
209- LOGW (L" Windows 11 detected, no need to patch" );
215+ bool isWin11 = gOsVersionInfo .dwMajorVersion >= 10 && gOsVersionInfo .dwMinorVersion >= 0 && gOsVersionInfo .dwBuildNumber >= 22000 ;
216+ gIsPatchVersionNumber = !isWin11;
217+ gIsPatchProductType = (gOsVersionInfo .wProductType != VER_NT_WORKSTATION);
218+ if (!gIsPatchVersionNumber && !gIsPatchProductType ) {
219+ LOGW (L" Windows 11 workstation detected, no need to patch" );
210220 return true ;
211221 }
222+ LOGD (L" Need to patch, gIsPatchVersionNumber=%d, gIsPatchProductType=%d" , gIsPatchVersionNumber , gIsPatchProductType );
212223 int count = HookIATProcedure (hWsaClient, " GetProcAddress" , reinterpret_cast <FARPROC>(&BadGetProcAddress));
213224 if (count == 0 ) {
214225 LOGE (L" HookIATProcedure failed, count=%d" , count);
0 commit comments