Skip to content

Commit 0fde835

Browse files
committed
WM (Windows): detect version of DWM
1 parent f373e07 commit 0fde835

File tree

7 files changed

+74
-71
lines changed

7 files changed

+74
-71
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,7 @@ elseif(WIN32)
10031003
src/util/windows/registry.c
10041004
src/util/windows/unicode.c
10051005
src/util/windows/wmi.cpp
1006+
src/util/windows/version.c
10061007
src/util/platform/FFPlatform_windows.c
10071008
src/util/binary_windows.c
10081009
)

src/detection/terminalshell/terminalshell.c

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,18 @@
1515
#define _PATH_LOCALBASE "/usr/local"
1616
#elif __NetBSD__
1717
#define _PATH_LOCALBASE "/usr/pkg"
18-
#endif
19-
20-
#ifdef _WIN32
21-
22-
#include "util/mallocHelper.h"
18+
#elif _WIN32
2319

24-
#include <winver.h>
20+
#include "util/windows/version.h"
21+
#include <windows.h>
2522

26-
static bool getFileVersion(const char* exePath, FFstrbuf* version)
23+
static bool getFileVersion(const FFstrbuf* exePath, FFstrbuf* version)
2724
{
28-
DWORD handle;
29-
DWORD size = GetFileVersionInfoSizeA(exePath, &handle);
30-
if(size > 0)
31-
{
32-
FF_AUTO_FREE void* versionData = malloc(size);
33-
if(GetFileVersionInfoA(exePath, handle, size, versionData))
34-
{
35-
VS_FIXEDFILEINFO* verInfo;
36-
UINT len;
37-
if(VerQueryValueW(versionData, L"\\", (void**)&verInfo, &len) && len && verInfo->dwSignature == 0xFEEF04BD)
38-
{
39-
ffStrbufAppendF(version, "%u.%u.%u.%u",
40-
(unsigned)(( verInfo->dwFileVersionMS >> 16 ) & 0xffff),
41-
(unsigned)(( verInfo->dwFileVersionMS >> 0 ) & 0xffff),
42-
(unsigned)(( verInfo->dwFileVersionLS >> 16 ) & 0xffff),
43-
(unsigned)(( verInfo->dwFileVersionLS >> 0 ) & 0xffff)
44-
);
45-
return true;
46-
}
47-
}
48-
}
49-
50-
return false;
25+
wchar_t exePathW[PATH_MAX];
26+
int len = MultiByteToWideChar(CP_UTF8, 0, exePath->chars, (int)exePath->length, exePathW, ARRAY_SIZE(exePathW));
27+
if (len <= 0) return false;
28+
return ffGetFileVersion(exePathW, version);
5129
}
52-
5330
#endif
5431

5532
static bool getExeVersionRaw(FFstrbuf* exe, FFstrbuf* version)
@@ -119,7 +96,7 @@ static bool getShellVersionPwsh(FFstrbuf* exe, FFstrbuf* version)
11996
}
12097

12198
#ifdef _WIN32
122-
if(getFileVersion(exe->chars, version))
99+
if(getFileVersion(exe, version))
123100
{
124101
ffStrbufSubstrBeforeLastC(version, '.');
125102
return true;
@@ -312,7 +289,7 @@ bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, FFstrbuf* exePath,
312289
if(ffStrEqualsIgnCase(exeName, "powershell") || ffStrEqualsIgnCase(exeName, "powershell_ise"))
313290
return getShellVersionWinPowerShell(exe, version);
314291

315-
return getFileVersion(exe->chars, version);
292+
return getFileVersion(exe, version);
316293
#endif
317294

318295
return false;
@@ -706,7 +683,7 @@ static bool getTerminalVersionWindowsTerminal(FFstrbuf* exe, FFstrbuf* version)
706683
return true;
707684
}
708685

709-
return getFileVersion(exe->chars, version);
686+
return getFileVersion(exe, version);
710687
}
711688

712689
static bool getTerminalVersionConEmu(FFstrbuf* exe, FFstrbuf* version)
@@ -716,7 +693,7 @@ static bool getTerminalVersionConEmu(FFstrbuf* exe, FFstrbuf* version)
716693
if(version->length)
717694
return true;
718695

719-
return getFileVersion(exe->chars, version);
696+
return getFileVersion(exe, version);
720697
}
721698

722699
#endif
@@ -875,7 +852,7 @@ bool fftsGetTerminalVersion(FFstrbuf* processName, FF_MAYBE_UNUSED FFstrbuf* exe
875852

876853
#ifdef _WIN32
877854

878-
return getFileVersion(exe->chars, version);
855+
return getFileVersion(exe, version);
879856

880857
#else
881858

src/detection/terminalshell/terminalshell_windows.c

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,13 @@
55
#include "util/mallocHelper.h"
66
#include "util/windows/registry.h"
77
#include "util/windows/unicode.h"
8+
#include "util/windows/version.h"
89
#include "util/stringUtils.h"
910

1011
#include <windows.h>
1112
#include <wchar.h>
1213
#include <tlhelp32.h>
1314

14-
static bool getProductVersion(const wchar_t* filePath, FFstrbuf* version)
15-
{
16-
DWORD handle;
17-
DWORD size = GetFileVersionInfoSizeW(filePath, &handle);
18-
if(size > 0)
19-
{
20-
FF_AUTO_FREE void* versionData = malloc(size);
21-
if(GetFileVersionInfoW(filePath, handle, size, versionData))
22-
{
23-
VS_FIXEDFILEINFO* verInfo;
24-
UINT len;
25-
if(VerQueryValueW(versionData, L"\\", (void**)&verInfo, &len) && len && verInfo->dwSignature == 0xFEEF04BD)
26-
{
27-
ffStrbufAppendF(version, "%u.%u.%u.%u",
28-
(unsigned)(( verInfo->dwProductVersionMS >> 16 ) & 0xffff),
29-
(unsigned)(( verInfo->dwProductVersionMS >> 0 ) & 0xffff),
30-
(unsigned)(( verInfo->dwProductVersionLS >> 16 ) & 0xffff),
31-
(unsigned)(( verInfo->dwProductVersionLS >> 0 ) & 0xffff)
32-
);
33-
return true;
34-
}
35-
}
36-
}
37-
38-
return false;
39-
}
40-
4115
bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, const FFstrbuf* exePath, FFstrbuf* version);
4216

4317
static uint32_t getShellInfo(FFShellResult* result, uint32_t pid)
@@ -113,7 +87,7 @@ static void setShellInfoDetails(FFShellResult* result)
11387
if(wcsncmp(module.szModule, L"clink_dll_", strlen("clink_dll_")) == 0)
11488
{
11589
ffStrbufAppendS(&result->prettyName, " (with Clink ");
116-
getProductVersion(module.szExePath, &result->prettyName);
90+
ffGetFileVersion(module.szExePath, &result->prettyName);
11791
ffStrbufAppendC(&result->prettyName, ')');
11892
break;
11993
}

src/detection/wm/wm_windows.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ extern "C"
33
#include "wm.h"
44
#include "common/io/io.h"
55
#include "detection/terminalshell/terminalshell.h"
6+
#include "util/windows/version.h"
67
}
78

89
#include "util/windows/com.hpp"
@@ -65,7 +66,23 @@ const char* ffDetectWMPlugin(FFstrbuf* pluginName)
6566
return NULL;
6667
}
6768

68-
const char* ffDetectWMVersion(FF_MAYBE_UNUSED const FFstrbuf* wmName, FF_MAYBE_UNUSED FFstrbuf* result, FF_MAYBE_UNUSED FFWMOptions* options)
69+
const char* ffDetectWMVersion(const FFstrbuf* wmName, FFstrbuf* result, FF_MAYBE_UNUSED FFWMOptions* options)
6970
{
71+
if (!wmName)
72+
return "No WM detected";
73+
74+
if (ffStrbufEqualS(wmName, "dwm.exe"))
75+
{
76+
PWSTR pPath = NULL;
77+
if(SUCCEEDED(SHGetKnownFolderPath(FOLDERID_System, KF_FLAG_DEFAULT, NULL, &pPath)))
78+
{
79+
wchar_t fullPath[MAX_PATH];
80+
wcscpy(fullPath, pPath);
81+
wcscat(fullPath, L"\\dwm.exe");
82+
ffGetFileVersion(fullPath, result);
83+
}
84+
CoTaskMemFree(pPath);
85+
return NULL;
86+
}
7087
return "Not supported on this platform";
7188
}

src/util/platform/FFPlatform_windows.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,51 +31,51 @@ static void getExePath(FFPlatform* platform)
3131

3232
static void getHomeDir(FFPlatform* platform)
3333
{
34-
PWSTR pPath;
34+
PWSTR pPath = NULL;
3535
if(SUCCEEDED(SHGetKnownFolderPath(&FOLDERID_Profile, KF_FLAG_DEFAULT, NULL, &pPath)))
3636
{
3737
ffStrbufSetWS(&platform->homeDir, pPath);
3838
ffStrbufReplaceAllC(&platform->homeDir, '\\', '/');
3939
ffStrbufEnsureEndsWithC(&platform->homeDir, '/');
40-
CoTaskMemFree(pPath);
4140
}
4241
else
4342
{
4443
ffStrbufSetS(&platform->homeDir, getenv("USERPROFILE"));
4544
ffStrbufReplaceAllC(&platform->homeDir, '\\', '/');
4645
ffStrbufEnsureEndsWithC(&platform->homeDir, '/');
4746
}
47+
CoTaskMemFree(pPath);
4848
}
4949

5050
static void getCacheDir(FFPlatform* platform)
5151
{
52-
PWSTR pPath;
52+
PWSTR pPath = NULL;
5353
if(SUCCEEDED(SHGetKnownFolderPath(&FOLDERID_LocalAppData, KF_FLAG_DEFAULT, NULL, &pPath)))
5454
{
5555
ffStrbufSetWS(&platform->cacheDir, pPath);
5656
ffStrbufReplaceAllC(&platform->cacheDir, '\\', '/');
5757
ffStrbufEnsureEndsWithC(&platform->cacheDir, '/');
58-
CoTaskMemFree(pPath);
5958
}
6059
else
6160
{
6261
ffStrbufAppend(&platform->cacheDir, &platform->homeDir);
6362
ffStrbufAppendS(&platform->cacheDir, "AppData/Local/");
6463
}
64+
CoTaskMemFree(pPath);
6565
}
6666

6767
static void platformPathAddKnownFolder(FFlist* dirs, REFKNOWNFOLDERID folderId)
6868
{
69-
PWSTR pPath;
69+
PWSTR pPath = NULL;
7070
if(SUCCEEDED(SHGetKnownFolderPath(folderId, 0, NULL, &pPath)))
7171
{
7272
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreateWS(pPath);
7373
ffStrbufReplaceAllC(&buffer, '\\', '/');
7474
ffStrbufEnsureEndsWithC(&buffer, '/');
7575
if (!ffListContains(dirs, &buffer, (void*) ffStrbufEqual))
7676
ffStrbufInitMove((FFstrbuf*) ffListAdd(dirs), &buffer);
77-
CoTaskMemFree(pPath);
7877
}
78+
CoTaskMemFree(pPath);
7979
}
8080

8181
static void platformPathAddEnvSuffix(FFlist* dirs, const char* env, const char* suffix)

src/util/windows/version.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include "util/windows/version.h"
2+
#include "util/mallocHelper.h"
3+
4+
#include <windows.h>
5+
6+
bool ffGetFileVersion(const wchar_t* filePath, FFstrbuf* version)
7+
{
8+
DWORD handle;
9+
DWORD size = GetFileVersionInfoSizeW(filePath, &handle);
10+
if(size > 0)
11+
{
12+
FF_AUTO_FREE void* versionData = malloc(size);
13+
if(GetFileVersionInfoW(filePath, handle, size, versionData))
14+
{
15+
VS_FIXEDFILEINFO* verInfo;
16+
UINT len;
17+
if(VerQueryValueW(versionData, L"\\", (void**)&verInfo, &len) && len && verInfo->dwSignature == 0xFEEF04BD)
18+
{
19+
ffStrbufAppendF(version, "%u.%u.%u.%u",
20+
(unsigned)(( verInfo->dwProductVersionMS >> 16 ) & 0xffff),
21+
(unsigned)(( verInfo->dwProductVersionMS >> 0 ) & 0xffff),
22+
(unsigned)(( verInfo->dwProductVersionLS >> 16 ) & 0xffff),
23+
(unsigned)(( verInfo->dwProductVersionLS >> 0 ) & 0xffff)
24+
);
25+
return true;
26+
}
27+
}
28+
}
29+
30+
return false;
31+
}

src/util/windows/version.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "fastfetch.h"
2+
3+
bool ffGetFileVersion(const wchar_t* filePath, FFstrbuf* version);

0 commit comments

Comments
 (0)