Skip to content

Commit

Permalink
Frontend/WinHelper: Use UserSharedData for Windows build number.
Browse files Browse the repository at this point in the history
Remove RtlGetVersion call.
Make GetWindowsBuild function as a marco of KUSER_SHARED_DATA.NtBuildNumber.
  • Loading branch information
Biswa96 committed Oct 24, 2020
1 parent 85c8a68 commit e4b44dd
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/GetVmId.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ HRESULT GetVmId(

assert(hRes == 0);

DWORD BuildNumber = GetWindowsBuild();
const DWORD BuildNumber = GetWindowsBuild();

/* Before Windows 10 Build 20211 RS */
if (BuildNumber < 20211)
Expand Down
23 changes: 0 additions & 23 deletions src/WinHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ typedef HRESULT (WINAPI *GETDISTROCONFIGPROC)(
char **defaultEnvironmentVariables,
int *defaultEnvironmentVariableCount);

typedef void (WINAPI *RTLGETVERSIONPROC)(
OSVERSIONINFOW *lpVersionInformation);

std::string GetErrorMessage(DWORD MessageId)
{
wchar_t *Buffer = NULL;
Expand Down Expand Up @@ -147,23 +144,3 @@ bool IsWslTwo(std::wstring DistroName)
else
return false;
}

DWORD GetWindowsBuild(void)
{
HMODULE hMod = LoadLibraryExW(
L"ntdll.dll",
NULL,
LOAD_LIBRARY_SEARCH_SYSTEM32);
assert(hMod != NULL);

RTLGETVERSIONPROC pfnRtlGetVersion = (RTLGETVERSIONPROC)
GetProcAddress(hMod, "RtlGetVersion");
assert(pfnRtlGetVersion != NULL);

OSVERSIONINFOW info = {};
info.dwOSVersionInfoSize = sizeof info;
pfnRtlGetVersion(&info);
FreeLibrary(hMod);

return info.dwBuildNumber;
}
4 changes: 3 additions & 1 deletion src/WinHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
#ifndef WINHELPER_HPP
#define WINHELPER_HPP

/* KUSER_SHARED_DATA.NtBuildNumber */
#define GetWindowsBuild() (*(unsigned int *)(0x7FFE0000 + 0x0260))

std::string GetErrorMessage(DWORD MessageId);
bool IsWslTwo(std::wstring DistroName);
DWORD GetWindowsBuild(void);

#endif /* WINHELPER_HPP */

0 comments on commit e4b44dd

Please sign in to comment.