From d9f084894e0124e3d98e93906d02430b86b9800a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 10 Jul 2024 22:09:28 +0800 Subject: [PATCH] General: support more module for `--detect-version` --- src/detection/host/host_linux.c | 15 ++++++----- .../terminalshell/terminalshell_windows.c | 27 ++++++++++--------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/detection/host/host_linux.c b/src/detection/host/host_linux.c index e6311f0fd..41b1733b8 100644 --- a/src/detection/host/host_linux.c +++ b/src/detection/host/host_linux.c @@ -78,12 +78,15 @@ const char* ffDetectHost(FFHostResult* host) ffStrbufAppendF(&host->name, " - %s", wslDistroName); ffStrbufAppendS(&host->family, "WSL"); - ffProcessAppendStdOut(&host->version, (char* const[]){ - "wslinfo", - "--wsl-version", - "-n", - NULL, - }); // supported in 2.2.3 and later + if (instance.config.general.detectVersion) + { + ffProcessAppendStdOut(&host->version, (char* const[]){ + "wslinfo", + "--wsl-version", + "-n", + NULL, + }); // supported in 2.2.3 and later + } } } diff --git a/src/detection/terminalshell/terminalshell_windows.c b/src/detection/terminalshell/terminalshell_windows.c index 4470f22bc..4f8e02f57 100644 --- a/src/detection/terminalshell/terminalshell_windows.c +++ b/src/detection/terminalshell/terminalshell_windows.c @@ -99,21 +99,24 @@ static void setShellInfoDetails(FFShellResult* result) { ffStrbufSetS(&result->prettyName, "CMD"); - FF_AUTO_CLOSE_FD HANDLE snapshot = NULL; - while(!(snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, result->pid)) && GetLastError() == ERROR_BAD_LENGTH) {} - - if(snapshot) + if (instance.config.general.detectVersion) { - MODULEENTRY32W module; - module.dwSize = sizeof(module); - for(BOOL success = Module32FirstW(snapshot, &module); success; success = Module32NextW(snapshot, &module)) + FF_AUTO_CLOSE_FD HANDLE snapshot = NULL; + while(!(snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, result->pid)) && GetLastError() == ERROR_BAD_LENGTH) {} + + if(snapshot) { - if(wcsncmp(module.szModule, L"clink_dll_", strlen("clink_dll_")) == 0) + MODULEENTRY32W module; + module.dwSize = sizeof(module); + for(BOOL success = Module32FirstW(snapshot, &module); success; success = Module32NextW(snapshot, &module)) { - ffStrbufAppendS(&result->prettyName, " (with Clink "); - getProductVersion(module.szExePath, &result->prettyName); - ffStrbufAppendC(&result->prettyName, ')'); - break; + if(wcsncmp(module.szModule, L"clink_dll_", strlen("clink_dll_")) == 0) + { + ffStrbufAppendS(&result->prettyName, " (with Clink "); + getProductVersion(module.szExePath, &result->prettyName); + ffStrbufAppendC(&result->prettyName, ')'); + break; + } } } }