From 8f977ee581f19675b23580bfc731d4b02545011b Mon Sep 17 00:00:00 2001 From: Justsnoopy30 Date: Sat, 18 May 2024 16:18:56 -0500 Subject: [PATCH 1/2] process: improve linux game detection Some games are listed in the discord game database with their parent directories but their launched processes on linux don't always have this included in cmdline. This fixes that by checking processes with their working directories as well. For example, this will now detect DOOM Eternal running through proton. --- src/process/index.js | 7 ++++--- src/process/native/linux.js | 10 ++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/process/index.js b/src/process/index.js index 97ea651..b2e27ef 100644 --- a/src/process/index.js +++ b/src/process/index.js @@ -34,11 +34,12 @@ export default class ProcessServer { // log(`got processed in ${(performance.now() - startTime).toFixed(2)}ms`); - for (const [ pid, _path, args ] of processes) { + for (const [ pid, _path, args, _cwdPath = '' ] of processes) { const path = _path.toLowerCase().replaceAll('\\', '/'); + const cwdPath = _cwdPath.toLowerCase().replaceAll('\\', '/'); const toCompare = []; const splitPath = path.split('/'); - for (let i = 1; i < splitPath.length; i++) { + for (let i = 1; i < splitPath.length || i == 1; i++) { toCompare.push(splitPath.slice(-i).join('/')); } @@ -51,7 +52,7 @@ export default class ProcessServer { for (const { executables, id, name } of DetectableDB) { if (executables?.some(x => { if (x.is_launcher) return false; - if (x.name[0] === '>' ? x.name.substring(1) !== toCompare[0] : !toCompare.some(y => x.name === y)) return false; + if (x.name[0] === '>' ? x.name.substring(1) !== toCompare[0] : !toCompare.some(y => x.name === y || `${cwdPath}/${y}`.includes(x.name))) return false; if (args && x.arguments) return args.join(" ").indexOf(x.arguments) > -1; return true; })) { diff --git a/src/process/native/linux.js b/src/process/native/linux.js index ed45681..0dc7f4d 100644 --- a/src/process/native/linux.js +++ b/src/process/native/linux.js @@ -1,8 +1,14 @@ -import { readdir, readFile } from "fs/promises"; +import { readdir, readFile, readlink } from "fs/promises"; export const getProcesses = async () => (await Promise.all( (await readdir("/proc")).map(pid => (+pid > 0) && readFile(`/proc/${pid}/cmdline`, 'utf8') - .then(path => [+pid, path.split("\0")[0], path.split("\0").slice(1)], () => 0) + .then(async path => { + let cwdPath; + try { + cwdPath = await readlink(`/proc/${pid}/cwd`); + } catch (err) {}; + return [+pid, path.split("\0")[0], path.split("\0").slice(1), cwdPath] + }, () => 0) ) )).filter(x => x); \ No newline at end of file From c29adc0db4e23f8a767a008bfef36ef253a436f3 Mon Sep 17 00:00:00 2001 From: Justsnoopy30 Date: Thu, 23 May 2024 14:58:15 -0500 Subject: [PATCH 2/2] process: small fix for false positives --- src/process/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/process/index.js b/src/process/index.js index b2e27ef..9ef779b 100644 --- a/src/process/index.js +++ b/src/process/index.js @@ -52,7 +52,7 @@ export default class ProcessServer { for (const { executables, id, name } of DetectableDB) { if (executables?.some(x => { if (x.is_launcher) return false; - if (x.name[0] === '>' ? x.name.substring(1) !== toCompare[0] : !toCompare.some(y => x.name === y || `${cwdPath}/${y}`.includes(x.name))) return false; + if (x.name[0] === '>' ? x.name.substring(1) !== toCompare[0] : !toCompare.some(y => x.name === y || `${cwdPath}/${y}`.includes(`/${x.name}`))) return false; if (args && x.arguments) return args.join(" ").indexOf(x.arguments) > -1; return true; })) {