From 77f7c813f4a80d68e829ac199ae2a1c782fa0921 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 27 May 2023 21:47:36 +0800 Subject: [PATCH] TerminalShell (Windows): print clink version --- .../terminalshell/terminalshell_windows.c | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/detection/terminalshell/terminalshell_windows.c b/src/detection/terminalshell/terminalshell_windows.c index 84c3f6dd2..9af70f8ca 100644 --- a/src/detection/terminalshell/terminalshell_windows.c +++ b/src/detection/terminalshell/terminalshell_windows.c @@ -9,6 +9,33 @@ #include #include +static bool getProductVersion(const wchar_t* filePath, FFstrbuf* version) +{ + DWORD handle; + DWORD size = GetFileVersionInfoSizeW(filePath, &handle); + if(size > 0) + { + FF_AUTO_FREE void* versionData = malloc(size); + if(GetFileVersionInfoW(filePath, handle, size, versionData)) + { + VS_FIXEDFILEINFO* verInfo; + UINT len; + if(VerQueryValueW(versionData, L"\\", (void**)&verInfo, &len) && len && verInfo->dwSignature == 0xFEEF04BD) + { + ffStrbufAppendF(version, "%u.%u.%u.%u", + (unsigned)(( verInfo->dwProductVersionMS >> 16 ) & 0xffff), + (unsigned)(( verInfo->dwProductVersionMS >> 0 ) & 0xffff), + (unsigned)(( verInfo->dwProductVersionLS >> 16 ) & 0xffff), + (unsigned)(( verInfo->dwProductVersionLS >> 0 ) & 0xffff) + ); + return true; + } + } + } + + return false; +} + static bool getProcessInfo(uint32_t pid, uint32_t* ppid, FFstrbuf* pname, FFstrbuf* exe, const char** exeName) { HANDLE hProcess = pid == 0 @@ -150,7 +177,9 @@ static uint32_t getShellInfo(const FFinstance* instance, FFTerminalShellResult* { if(wcsncmp(module.szModule, L"clink_dll_", strlen("clink_dll_")) == 0) { - ffStrbufAppendS(&result->shellPrettyName, "CMD (with Clink)"); + ffStrbufAppendS(&result->shellPrettyName, "CMD (with Clink "); + getProductVersion(module.szExePath, &result->shellPrettyName); + ffStrbufAppendC(&result->shellPrettyName, ')'); break; } }