Skip to content

Commit 554184e

Browse files
committed
OS (Windows): restores compatibility with WINE
Revert "OS (Windows): hard linking winbrand" This reverts commit 4146bb6.
1 parent 7a055a2 commit 554184e

File tree

2 files changed

+41
-8
lines changed

2 files changed

+41
-8
lines changed

CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ elseif(WIN32)
10351035
src/detection/physicalmemory/physicalmemory_linux.c
10361036
src/detection/netio/netio_windows.c
10371037
src/detection/opengl/opengl_windows.c
1038-
src/detection/os/os_windows.c
1038+
src/detection/os/os_windows.cpp
10391039
src/detection/packages/packages_windows.c
10401040
src/detection/poweradapter/poweradapter_nosupport.c
10411041
src/detection/processes/processes_windows.c
@@ -1689,7 +1689,6 @@ elseif(WIN32)
16891689
PRIVATE "wtsapi32"
16901690
PRIVATE "imagehlp"
16911691
PRIVATE "cfgmgr32"
1692-
PRIVATE "winbrand"
16931692
PRIVATE "propsys"
16941693
PRIVATE "secur32"
16951694
)

src/detection/os/os_windows.c renamed to src/detection/os/os_windows.cpp

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
1+
extern "C" {
12
#include "os.h"
23
#include "common/library.h"
3-
#include "util/windows/unicode.h"
44
#include "util/stringUtils.h"
55
#include "util/windows/registry.h"
6+
}
7+
#include "util/windows/unicode.hpp"
8+
#include "util/windows/wmi.hpp"
9+
10+
static const char* getOsNameByWmi(FFstrbuf* osName)
11+
{
12+
FFWmiQuery query(L"SELECT Caption FROM Win32_OperatingSystem");
13+
if(!query)
14+
return "Query WMI service failed";
15+
16+
if(FFWmiRecord record = query.next())
17+
{
18+
if(auto vtCaption = record.get(L"Caption"))
19+
{
20+
ffStrbufSetWSV(osName, vtCaption.get<std::wstring_view>());
21+
ffStrbufTrimRight(osName, ' ');
22+
return NULL;
23+
}
24+
return "Get Caption failed";
25+
}
626

7-
#include <windows.h>
27+
return "No WMI result returned";
28+
}
829

930
PWSTR WINAPI BrandingFormatString(PCWSTR format);
1031

@@ -24,19 +45,32 @@ static bool getCodeName(FFOSResult* os)
2445
return true;
2546
}
2647

27-
void ffDetectOSImpl(FFOSResult* os)
48+
static const char* getOsNameByWinbrand(FFstrbuf* osName)
2849
{
2950
//https://dennisbabkin.com/blog/?t=how-to-tell-the-real-version-of-windows-your-app-is-running-on#ver_string
30-
const wchar_t* rawName = BrandingFormatString(L"%WINDOWS_LONG%");
31-
ffStrbufSetWS(&os->variant, rawName);
51+
FF_LIBRARY_LOAD(winbrand, "dlopen winbrand" FF_LIBRARY_EXTENSION " failed", "winbrand" FF_LIBRARY_EXTENSION, 1);
52+
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(winbrand, BrandingFormatString);
53+
54+
const wchar_t* rawName = ffBrandingFormatString(L"%WINDOWS_LONG%");
55+
ffStrbufSetWS(osName, rawName);
3256
GlobalFree((HGLOBAL)rawName);
33-
ffStrbufSet(&os->prettyName, &os->variant);
57+
return NULL;
58+
}
59+
60+
extern "C"
61+
void ffDetectOSImpl(FFOSResult* os)
62+
{
63+
if(getOsNameByWinbrand(&os->variant) && getOsNameByWmi(&os->variant))
64+
return;
65+
3466
ffStrbufTrimRight(&os->variant, ' ');
3567

3668
//WMI returns the "Microsoft" prefix while BrandingFormatString doesn't. Make them consistent.
3769
if(ffStrbufStartsWithS(&os->variant, "Microsoft "))
3870
ffStrbufSubstrAfter(&os->variant, strlen("Microsoft ") - 1);
3971

72+
ffStrbufSet(&os->prettyName, &os->variant);
73+
4074
if(ffStrbufStartsWithS(&os->variant, "Windows "))
4175
{
4276
ffStrbufAppendS(&os->name, "Windows");

0 commit comments

Comments
 (0)