From 784a7a92c82a0f676b0cb500a6e5b68718c88983 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Thu, 21 Aug 2025 18:19:23 +0800 Subject: [PATCH] DE (Linux): adds Trinity version detection support --- src/detection/de/de_linux.c | 44 ++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/detection/de/de_linux.c b/src/detection/de/de_linux.c index 2f3570e19..5913c66c9 100644 --- a/src/detection/de/de_linux.c +++ b/src/detection/de/de_linux.c @@ -6,8 +6,9 @@ #include "common/parsing.h" #include "common/properties.h" #include "common/processing.h" +#include "util/binary.h" +#include "util/path.h" #include "detection/displayserver/displayserver.h" -#include "util/stringUtils.h" #include #ifdef __FreeBSD__ @@ -195,6 +196,45 @@ static void getUnity(FFstrbuf* result, FF_MAYBE_UNUSED FFDEOptions* options) ffStrbufSubstrBeforeFirstC(result, '"'); } +static bool extractTdeVersion(const char* line, uint32_t len, void *userdata) +{ + int count = 0; + sscanf(line, "R%*d.%*d.%*d%n", &count); + if (count == 0) return true; + + ffStrbufSetNS((FFstrbuf*) userdata, len, line); + return false; +} + +static const char* getTrinity(FFstrbuf* result, FFDEOptions* options) +{ + FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate(); + const char* error = ffFindExecutableInPath("tde-config", &path); + if (error) return "Failed to find tde-config path"; + + ffStrbufSubstrBeforeLastC(&path, '/'); + ffStrbufAppendS(&path, "/../lib/libtdecore.so"); + + if (ffBinaryExtractStrings(path.chars, extractTdeVersion, result, strlen("R0.0.0")) == NULL) + return NULL; + + if (options->slowVersionDetection) + { + ffStrbufClear(&path); + ffProcessAppendStdOut(&path, (char* const[]){ + "tde-config", + "--version", + NULL + }); + + ffParsePropLines(path.chars , "TDE: ", result); + return NULL; + } + + return "All methods failed"; +} + + const char* ffDetectDEVersion(const FFstrbuf* deName, FFstrbuf* result, FFDEOptions* options) { if (!instance.config.general.detectVersion) return "Disabled by config"; @@ -215,6 +255,8 @@ const char* ffDetectDEVersion(const FFstrbuf* deName, FFstrbuf* result, FFDEOpti getBudgie(result, options); else if (ffStrbufEqualS(deName, FF_DE_PRETTY_UNITY)) getUnity(result, options); + else if (ffStrbufEqualS(deName, "trinity")) + getTrinity(result, options); else return "Unsupported DE"; return NULL;