Skip to content

Commit b96d8ad

Browse files
committed
Terminal (Linux): adds kmscon version detection support
1 parent 52970e2 commit b96d8ad

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

src/detection/terminalshell/terminalshell.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,36 @@ FF_A_UNUSED static bool getTerminalVersionWeston(FF_A_UNUSED FFstrbuf* exe, FFst
503503
return version->length > 0;
504504
}
505505

506+
FF_A_UNUSED static bool extractKmsconVersion(const char* str, FF_A_UNUSED uint32_t len, void* userdata) {
507+
if (!ffStrStartsWith(str, "v")) {
508+
return true;
509+
}
510+
int count = 0;
511+
sscanf(str, "v%*d.%*d.%*d%n", &count);
512+
if (count == 0) {
513+
return true;
514+
}
515+
ffStrbufSetNS((FFstrbuf*) userdata, (uint32_t) count - 1, str + 1);
516+
return false;
517+
}
518+
519+
FF_A_UNUSED static bool getTerminalVersionKmscon(FFstrbuf* exe, FFstrbuf* version) {
520+
if (ffIsAbsolutePath(exe->chars)) {
521+
ffBinaryExtractStrings(exe->chars, extractKmsconVersion, version, (uint32_t) strlen("v0.0.0"));
522+
if (version->length) {
523+
return true;
524+
}
525+
}
526+
527+
if (!getExeVersionRaw(exe, version)) {
528+
return false;
529+
}
530+
531+
// kmscon version v10.0.0
532+
ffStrbufSubstrAfterLastC(version, ' ');
533+
return version->length > 0;
534+
}
535+
506536
static bool getTerminalVersionContour(FFstrbuf* exe, FFstrbuf* version) {
507537
const char* env = getenv("TERMINAL_VERSION_STRING");
508538
if (env) {
@@ -840,6 +870,14 @@ bool fftsGetTerminalVersion(FFstrbuf* processName, FF_A_UNUSED FFstrbuf* exe, FF
840870

841871
#endif
842872

873+
#ifdef __linux__
874+
875+
if (ffStrbufIgnCaseEqualS(processName, "kmscon")) {
876+
return getTerminalVersionKmscon(exe, version);
877+
}
878+
879+
#endif
880+
843881
#ifdef _WIN32
844882

845883
if (ffStrbufIgnCaseEqualS(processName, "WindowsTerminal.exe")) {

0 commit comments

Comments
 (0)