From 24ee87720ea43785783d28b69d3492cfa0b2fb2e 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:18 +0800 Subject: [PATCH] TerminalShell: code refactoring --- src/detection/terminalshell/terminalshell.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/detection/terminalshell/terminalshell.c b/src/detection/terminalshell/terminalshell.c index 940002dda..3117f6cb5 100644 --- a/src/detection/terminalshell/terminalshell.c +++ b/src/detection/terminalshell/terminalshell.c @@ -5,6 +5,8 @@ #ifdef _WIN32 +#include "util/mallocHelper.h" + #include static bool getFileVersion(const char* exePath, FFstrbuf* version) @@ -13,7 +15,7 @@ static bool getFileVersion(const char* exePath, FFstrbuf* version) DWORD size = GetFileVersionInfoSizeA(exePath, &handle); if(size > 0) { - void* versionData = malloc(size); + FF_AUTO_FREE void* versionData = malloc(size); if(GetFileVersionInfoA(exePath, handle, size, versionData)) { VS_FIXEDFILEINFO* verInfo; @@ -26,11 +28,9 @@ static bool getFileVersion(const char* exePath, FFstrbuf* version) (unsigned)(( verInfo->dwFileVersionLS >> 16 ) & 0xffff), (unsigned)(( verInfo->dwFileVersionLS >> 0 ) & 0xffff) ); - free(versionData); return true; } } - free(versionData); } return false; @@ -195,11 +195,7 @@ FF_MAYBE_UNUSED static bool getTerminalVersionKonsole(FFstrbuf* exe, FFstrbuf* v FF_MAYBE_UNUSED static bool getTerminalVersionFoot(FFstrbuf* exe, FFstrbuf* version) { - if(ffProcessAppendStdOut(version, (char* const[]){ - exe->chars, - "--version", - NULL - })) return false; + if(!getExeVersionRaw(exe, version)) return false; //foot version: 1.13.1 -pgo +ime -graphemes -assertions ffStrbufSubstrAfterFirstS(version, "version: "); @@ -279,11 +275,7 @@ bool fftsGetTerminalVersion(FFstrbuf* processName, FF_MAYBE_UNUSED FFstrbuf* exe if(ffStrbufIgnCaseEqualS(processName, "kitty")) return getExeVersionGeneral(exe, version); //kitty 0.21.2 created by Kovid Goyal - if (ffStrbufIgnCaseEqualS(processName, "Tabby") && !ffProcessAppendStdOut(version, (char* const[]){ - exe->chars, - "--version", - NULL - })) + if (ffStrbufIgnCaseEqualS(processName, "Tabby") && getExeVersionRaw(exe, version)) return true; #endif