Skip to content

Commit

Permalink
fix versionhelpers for legacy build
Browse files Browse the repository at this point in the history
  • Loading branch information
FunkyFr3sh committed Sep 28, 2024
1 parent 1017b23 commit 6f4339f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
11 changes: 5 additions & 6 deletions inc/versionhelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,20 @@
#endif

#if (_WIN32_WINNT < _WIN32_WINNT_WIN2K)
#define RtlVerifyVersionInfo(a,b,c) 1
#define VerifyVersionInfoW(a,b,c) 0
#define VerSetConditionMask(a,b,c) 0
#endif

void verhelp_init();
BOOL verhelp_verify_version(PRTL_OSVERSIONINFOEXW versionInfo, ULONG typeMask, ULONGLONG conditionMask);
ULONGLONG verhelp_set_mask(ULONGLONG ConditionMask, DWORD TypeMask, BYTE Condition);
const char* verhelp_wine_get_version();
void verhelp_wine_get_host_version(const char** sysname, const char** release);

VERSIONHELPERAPI IsWindowsVersionOrGreater(DWORD major, DWORD minor, DWORD build, WORD servpack)
{
RTL_OSVERSIONINFOEXW vi = { sizeof(vi),major,minor,build,0,{0},servpack };
return verhelp_verify_version(&vi, VER_MAJORVERSION | VER_MINORVERSION | VER_BUILDNUMBER | VER_SERVICEPACKMAJOR,
VerSetConditionMask(VerSetConditionMask(VerSetConditionMask(VerSetConditionMask(0,
verhelp_set_mask(verhelp_set_mask(verhelp_set_mask(verhelp_set_mask(0,
VER_MAJORVERSION, VER_GREATER_EQUAL),
VER_MINORVERSION, VER_GREATER_EQUAL),
VER_BUILDNUMBER, VER_GREATER_EQUAL),
Expand All @@ -54,7 +53,7 @@ VERSIONHELPERAPI IsWindowsVersion(DWORD major, DWORD minor, DWORD build, WORD se
{
RTL_OSVERSIONINFOEXW vi = { sizeof(vi),major,minor,build,0,{0},servpack };
return verhelp_verify_version(&vi, VER_MAJORVERSION | VER_MINORVERSION | VER_BUILDNUMBER | VER_SERVICEPACKMAJOR,
VerSetConditionMask(VerSetConditionMask(VerSetConditionMask(VerSetConditionMask(0,
verhelp_set_mask(verhelp_set_mask(verhelp_set_mask(verhelp_set_mask(0,
VER_MAJORVERSION, VER_EQUAL),
VER_MINORVERSION, VER_EQUAL),
VER_BUILDNUMBER, VER_GREATER_EQUAL),
Expand All @@ -65,7 +64,7 @@ VERSIONHELPERAPI IsWindowsVersionAnySP(DWORD major, DWORD minor, DWORD build)
{
RTL_OSVERSIONINFOEXW vi = { sizeof(vi),major,minor,build,0,{0},0 };
return verhelp_verify_version(&vi, VER_MAJORVERSION | VER_MINORVERSION | VER_BUILDNUMBER | VER_SERVICEPACKMAJOR,
VerSetConditionMask(VerSetConditionMask(VerSetConditionMask(VerSetConditionMask(0,
verhelp_set_mask(verhelp_set_mask(verhelp_set_mask(verhelp_set_mask(0,
VER_MAJORVERSION, VER_EQUAL),
VER_MINORVERSION, VER_EQUAL),
VER_BUILDNUMBER, VER_GREATER_EQUAL),
Expand Down Expand Up @@ -134,7 +133,7 @@ VERSIONHELPERAPI IsWindows11OrGreater(void) {

VERSIONHELPERAPI IsWindowsServer(void) {
OSVERSIONINFOEXW vi = {sizeof(vi),0,0,0,0,{0},0,0,0,VER_NT_WORKSTATION};
return !verhelp_verify_version(&vi, VER_PRODUCT_TYPE, VerSetConditionMask(0, VER_PRODUCT_TYPE, VER_EQUAL));
return !verhelp_verify_version(&vi, VER_PRODUCT_TYPE, verhelp_set_mask(0, VER_PRODUCT_TYPE, VER_EQUAL));
}

VERSIONHELPERAPI IsWindowsXP(void) {
Expand Down
13 changes: 13 additions & 0 deletions src/versionhelpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
#include "versionhelpers.h"

typedef NTSTATUS(WINAPI* RTLVERIFYVERSIONINFOPROC)(PRTL_OSVERSIONINFOEXW, ULONG, ULONGLONG);
typedef ULONGLONG(WINAPI* VERSETCONDITIONMASKPROC)(ULONGLONG, DWORD, BYTE);
typedef const char* (CDECL* WINE_GET_VERSIONPROC)();
typedef void (CDECL* WINE_GET_HOST_VERSIONPROC)(const char** sysname, const char** release);

static RTLVERIFYVERSIONINFOPROC RtlVerifyVersionInfo;
static VERSETCONDITIONMASKPROC VerSetConditionMaskProc;
static WINE_GET_VERSIONPROC wine_get_version;
static WINE_GET_HOST_VERSIONPROC wine_get_host_version;

Expand All @@ -19,6 +21,12 @@ void verhelp_init()
wine_get_version = (WINE_GET_VERSIONPROC)GetProcAddress(mod, "wine_get_version");
wine_get_host_version = (WINE_GET_HOST_VERSIONPROC)GetProcAddress(mod, "wine_get_host_version");
}

mod = GetModuleHandleA("Kernel32.dll");
if (mod)
{
VerSetConditionMaskProc = (VERSETCONDITIONMASKPROC)GetProcAddress(mod, "VerSetConditionMask");
}
}

BOOL verhelp_verify_version(PRTL_OSVERSIONINFOEXW versionInfo, ULONG typeMask, ULONGLONG conditionMask)
Expand All @@ -28,6 +36,11 @@ BOOL verhelp_verify_version(PRTL_OSVERSIONINFOEXW versionInfo, ULONG typeMask, U
VerifyVersionInfoW(versionInfo, typeMask, conditionMask);
}

ULONGLONG verhelp_set_mask(ULONGLONG ConditionMask, DWORD TypeMask, BYTE Condition)
{
return VerSetConditionMaskProc ? VerSetConditionMaskProc(ConditionMask, TypeMask, Condition) : 0;
}

const char* verhelp_wine_get_version()
{
return wine_get_version ? wine_get_version() : NULL;
Expand Down

0 comments on commit 6f4339f

Please sign in to comment.