Skip to content

Commit 38ac339

Browse files
committed
WM: support WindowBlinds detection
1 parent b4777fe commit 38ac339

File tree

4 files changed

+79
-6
lines changed

4 files changed

+79
-6
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ elseif(WIN32)
641641
src/detection/users/users_windows.c
642642
src/detection/wallpaper/wallpaper_windows.c
643643
src/detection/wifi/wifi_windows.c
644-
src/detection/wm/wm_nosupport.c
644+
src/detection/wm/wm_windows.cpp
645645
src/detection/de/de_nosupport.c
646646
src/detection/wmtheme/wmtheme_windows.c
647647
src/util/windows/getline.c

src/detection/terminalshell/terminalshell_windows.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ static uint32_t getShellInfo(FFTerminalShellResult* result, uint32_t pid)
130130
{
131131
ffStrbufClear(&result->shellPrettyName);
132132

133-
HANDLE snapshot;
133+
FF_AUTO_CLOSE_FD HANDLE snapshot = NULL;
134134
while(!(snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pid)) && GetLastError() == ERROR_BAD_LENGTH) {}
135135

136136
if(snapshot)
@@ -147,7 +147,6 @@ static uint32_t getShellInfo(FFTerminalShellResult* result, uint32_t pid)
147147
break;
148148
}
149149
}
150-
CloseHandle(snapshot);
151150
}
152151
if(result->shellPrettyName.length == 0)
153152
ffStrbufAppendS(&result->shellPrettyName, "Command Prompt");

src/detection/wm/wm_windows.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
extern "C"
2+
{
3+
#include "wm.h"
4+
#include "common/io/io.h"
5+
#include "detection/terminalshell/terminalshell.h"
6+
}
7+
8+
#include "util/windows/com.hpp"
9+
10+
#include <utility>
11+
#include <windows.h>
12+
#include <tlhelp32.h>
13+
#include <shlobj.h>
14+
#include <Propkey.h>
15+
16+
template <typename Fn>
17+
struct on_scope_exit {
18+
on_scope_exit(Fn &&fn): _fn(std::move(fn)) {}
19+
~on_scope_exit() { this->_fn(); }
20+
21+
private:
22+
Fn _fn;
23+
};
24+
25+
extern "C"
26+
const char* ffDetectWMPlugin(FFstrbuf* pluginName)
27+
{
28+
DWORD pid = ffDetectTerminalShell()->terminalPid; // Whatever GUI program
29+
if (pid == 0) return "Unable to find a GUI program";
30+
31+
FF_AUTO_CLOSE_FD HANDLE snapshot = NULL;
32+
while(!(snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pid)) && GetLastError() == ERROR_BAD_LENGTH) {}
33+
34+
if(!snapshot)
35+
return "CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pid) failed";
36+
37+
if (ffInitCom())
38+
return "ffInitCom() failed";
39+
40+
MODULEENTRY32W module;
41+
module.dwSize = sizeof(module);
42+
for(BOOL success = Module32FirstW(snapshot, &module); success; success = Module32NextW(snapshot, &module))
43+
{
44+
if(wcscmp(module.szModule, L"wbhelp64.dll") == 0 || wcscmp(module.szModule, L"wbhelp.dll") == 0)
45+
{
46+
IShellItem2* shellItem = NULL;
47+
if (FAILED(SHCreateItemFromParsingName(module.szExePath, NULL, IID_IShellItem2, (void**) &shellItem)))
48+
continue;
49+
50+
on_scope_exit destroyShellItem([=] { shellItem->Release(); });
51+
52+
wchar_t* desc = NULL;
53+
if (FAILED(shellItem->GetString(PKEY_FileDescription, &desc)))
54+
continue;
55+
56+
on_scope_exit destroyDesc([=] { CoTaskMemFree(desc); });
57+
58+
if (wcscmp(desc, L"WindowBlinds Helper DLL") == 0)
59+
{
60+
ffStrbufSetStatic(pluginName, "WindowBlinds");
61+
break;
62+
}
63+
}
64+
}
65+
return NULL;
66+
}

src/modules/wm/wm.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "modules/wm/wm.h"
66
#include "util/stringUtils.h"
77

8-
#define FF_WM_NUM_FORMAT_ARGS 3
8+
#define FF_WM_NUM_FORMAT_ARGS 4
99

1010
void ffPrintWM(FFWMOptions* options)
1111
{
@@ -48,7 +48,8 @@ void ffPrintWM(FFWMOptions* options)
4848
ffPrintFormat(FF_WM_MODULE_NAME, 0, &options->moduleArgs, FF_WM_NUM_FORMAT_ARGS, (FFformatarg[]){
4949
{FF_FORMAT_ARG_TYPE_STRBUF, &result->wmProcessName},
5050
{FF_FORMAT_ARG_TYPE_STRBUF, &result->wmPrettyName},
51-
{FF_FORMAT_ARG_TYPE_STRBUF, &result->wmProtocolName}
51+
{FF_FORMAT_ARG_TYPE_STRBUF, &result->wmProtocolName},
52+
{FF_FORMAT_ARG_TYPE_STRBUF, &pluginName},
5253
});
5354
}
5455
}
@@ -112,18 +113,25 @@ void ffGenerateWMJsonResult(FF_MAYBE_UNUSED FFWMOptions* options, yyjson_mut_doc
112113
yyjson_mut_obj_add_str(doc, module, "error", "No WM found");
113114
return;
114115
}
116+
117+
FF_STRBUF_AUTO_DESTROY pluginName = ffStrbufCreate();
118+
if(options->detectPlugin)
119+
ffDetectWMPlugin(&pluginName);
120+
115121
yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
116122
yyjson_mut_obj_add_strbuf(doc, obj, "processName", &result->wmProcessName);
117123
yyjson_mut_obj_add_strbuf(doc, obj, "prettyName", &result->wmPrettyName);
118124
yyjson_mut_obj_add_strbuf(doc, obj, "protocolName", &result->wmProtocolName);
125+
yyjson_mut_obj_add_strbuf(doc, obj, "pluginName", &pluginName);
119126
}
120127

121128
void ffPrintWMHelpFormat(void)
122129
{
123130
ffPrintModuleFormatHelp(FF_WM_MODULE_NAME, "{2} ({3})", FF_WM_NUM_FORMAT_ARGS, (const char* []) {
124131
"WM process name",
125132
"WM pretty name",
126-
"WM protocol name"
133+
"WM protocol name",
134+
"WM plugin name"
127135
});
128136
}
129137

0 commit comments

Comments
 (0)