@@ -24,6 +24,8 @@ HMODULE hNtdll = nullptr;
24
24
HMODULE hWsaClient = nullptr ;
25
25
26
26
RTL_OSVERSIONINFOEXW gOsVersionInfo = {0 };
27
+ bool gIsPatchVersionNumber = false ;
28
+ bool gIsPatchProductType = false ;
27
29
28
30
#define NT_SUCCESS (Status ) (((NTSTATUS)(Status)) >= 0 )
29
31
#define STATUS_SUCCESS ((NTSTATUS)0x00000000L )
@@ -50,12 +52,17 @@ void defaultLogHandler(Log::Level level, const WCHAR *tag, const WCHAR *msg) {
50
52
using FuncRtlGetVersion = NTSYSAPI NTSTATUS (*)(PRTL_OSVERSIONINFOW lpVersionInformation);
51
53
52
54
NTSTATUS WINAPI FakeRtlGetVersion (PRTL_OSVERSIONINFOW lpVersionInformation) {
53
- // 10.0.22000.1
55
+ // The minimal version is 10.0.22000.120 VER_NT_WORKSTATION
54
56
LOGD (L" -FakeRtlGetVersion" );
55
57
DWORD size = lpVersionInformation->dwOSVersionInfoSize ;
56
58
memcpy (lpVersionInformation, &gOsVersionInfo , size);
57
59
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
+ }
59
66
return STATUS_SUCCESS;
60
67
}
61
68
@@ -184,7 +191,7 @@ bool OnLoad(HINSTANCE hInstDLL) {
184
191
}
185
192
if (wcsstr (filename, L" \\ wsaclinent.exe" ) == nullptr ) {
186
193
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);
188
195
MessageBoxW (nullptr , buf, L" wsapatch.dll" , MB_OK | MB_ICONERROR);
189
196
return false ;
190
197
}
@@ -205,10 +212,14 @@ bool OnLoad(HINSTANCE hInstDLL) {
205
212
}
206
213
LOGD (L" RtlGetVersion: dwMajorVersion=%d, dwMinorVersion=%d, dwBuildNumber=%d, dwPlatformId=%d" ,
207
214
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" );
210
220
return true ;
211
221
}
222
+ LOGD (L" Need to patch, gIsPatchVersionNumber=%d, gIsPatchProductType=%d" , gIsPatchVersionNumber , gIsPatchProductType );
212
223
int count = HookIATProcedure (hWsaClient, " GetProcAddress" , reinterpret_cast <FARPROC>(&BadGetProcAddress));
213
224
if (count == 0 ) {
214
225
LOGE (L" HookIATProcedure failed, count=%d" , count);
0 commit comments