Skip to content

Commit 784a7a9

Browse files
committed
DE (Linux): adds Trinity version detection support
1 parent 8331242 commit 784a7a9

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

src/detection/de/de_linux.c

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
#include "common/parsing.h"
77
#include "common/properties.h"
88
#include "common/processing.h"
9+
#include "util/binary.h"
10+
#include "util/path.h"
911
#include "detection/displayserver/displayserver.h"
10-
#include "util/stringUtils.h"
1112

1213
#include <ctype.h>
1314
#ifdef __FreeBSD__
@@ -195,6 +196,45 @@ static void getUnity(FFstrbuf* result, FF_MAYBE_UNUSED FFDEOptions* options)
195196
ffStrbufSubstrBeforeFirstC(result, '"');
196197
}
197198

199+
static bool extractTdeVersion(const char* line, uint32_t len, void *userdata)
200+
{
201+
int count = 0;
202+
sscanf(line, "R%*d.%*d.%*d%n", &count);
203+
if (count == 0) return true;
204+
205+
ffStrbufSetNS((FFstrbuf*) userdata, len, line);
206+
return false;
207+
}
208+
209+
static const char* getTrinity(FFstrbuf* result, FFDEOptions* options)
210+
{
211+
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate();
212+
const char* error = ffFindExecutableInPath("tde-config", &path);
213+
if (error) return "Failed to find tde-config path";
214+
215+
ffStrbufSubstrBeforeLastC(&path, '/');
216+
ffStrbufAppendS(&path, "/../lib/libtdecore.so");
217+
218+
if (ffBinaryExtractStrings(path.chars, extractTdeVersion, result, strlen("R0.0.0")) == NULL)
219+
return NULL;
220+
221+
if (options->slowVersionDetection)
222+
{
223+
ffStrbufClear(&path);
224+
ffProcessAppendStdOut(&path, (char* const[]){
225+
"tde-config",
226+
"--version",
227+
NULL
228+
});
229+
230+
ffParsePropLines(path.chars , "TDE: ", result);
231+
return NULL;
232+
}
233+
234+
return "All methods failed";
235+
}
236+
237+
198238
const char* ffDetectDEVersion(const FFstrbuf* deName, FFstrbuf* result, FFDEOptions* options)
199239
{
200240
if (!instance.config.general.detectVersion) return "Disabled by config";
@@ -215,6 +255,8 @@ const char* ffDetectDEVersion(const FFstrbuf* deName, FFstrbuf* result, FFDEOpti
215255
getBudgie(result, options);
216256
else if (ffStrbufEqualS(deName, FF_DE_PRETTY_UNITY))
217257
getUnity(result, options);
258+
else if (ffStrbufEqualS(deName, "trinity"))
259+
getTrinity(result, options);
218260
else
219261
return "Unsupported DE";
220262
return NULL;

0 commit comments

Comments
 (0)