@@ -11,6 +11,32 @@ const DetectableDB = JSON.parse(fs.readFileSync(join(__dirname, 'detectable.json
1111import * as Natives from './native/index.js' ;
1212const Native = Natives [ process . platform ] ;
1313
14+ function basename ( str ) {
15+ return str . substr ( str . lastIndexOf ( '/' ) + 1 ) ;
16+ }
17+
18+ // https://stackoverflow.com/a/56641259
19+ /**
20+ * Replaces all occurrences of words in a sentence with new words.
21+ * @function
22+ * @param {string } sentence - The sentence to modify.
23+ * @param {Object } wordsToReplace - An object containing words to be replaced as the keys and their replacements as the values.
24+ * @returns {string } - The modified sentence.
25+ */
26+ function replaceAll ( sentence , wordsToReplace ) {
27+ return Object . keys ( wordsToReplace ) . reduce (
28+ ( f , s , i ) =>
29+ `${ f } ` . replace ( new RegExp ( s , 'ig' ) , wordsToReplace [ s ] ) ,
30+ sentence
31+ )
32+ }
33+
34+ const bitness_suffixes = {
35+ '.x64' : '' ,
36+ '_64' : '' ,
37+ 'x64' : '' ,
38+ '64' : '' ,
39+ }
1440
1541const timestamps = { } , names = { } , pids = { } ;
1642export default class ProcessServer {
@@ -35,24 +61,22 @@ export default class ProcessServer {
3561 // log(`got processed in ${(performance.now() - startTime).toFixed(2)}ms`);
3662
3763 for ( const [ pid , _path , args , _cwdPath = '' ] of processes ) {
64+ if ( _path . length < 1 ) continue ;
3865 const path = _path . toLowerCase ( ) . replaceAll ( '\\' , '/' ) ;
3966 const cwdPath = _cwdPath . toLowerCase ( ) . replaceAll ( '\\' , '/' ) ;
4067 const toCompare = [ ] ;
41- const splitPath = path . split ( '/' ) ;
42- for ( let i = 1 ; i < splitPath . length || i == 1 ; i ++ ) {
43- toCompare . push ( splitPath . slice ( - i ) . join ( '/' ) ) ;
44- }
4568
46- for ( const p of toCompare . slice ( ) ) { // add more possible tweaked paths for less false negatives
47- toCompare . push ( p . replace ( '64' , '' ) ) ; // remove 64bit identifiers-ish
48- toCompare . push ( p . replace ( '.x64' , '' ) ) ;
49- toCompare . push ( p . replace ( 'x64' , '' ) ) ;
50- toCompare . push ( p . replace ( '_64' , '' ) ) ;
69+ let newPath = basename ( path ) ;
70+ if ( path . includes ( ' --' ) ) {
71+ newPath = path . split ( ' --' ) [ 0 ] ;
5172 }
73+ toCompare . push ( newPath ) ;
74+ replaceAll ( toCompare , bitness_suffixes ) ;
5275
5376 for ( const { executables, id, name } of DetectableDB ) {
5477 if ( executables ?. some ( x => {
5578 if ( x . is_launcher ) return false ;
79+ if ( toCompare . some ( y => y . includes ( '.exe' ) && ( x . name . includes ( 'game/' + y ) || x . name . includes ( 'games/' + y ) ) ) ) return true ;
5680 if ( x . name [ 0 ] === '>' ? x . name . substring ( 1 ) !== toCompare [ 0 ] : ! toCompare . some ( y => x . name === y || `${ cwdPath } /${ y } ` . includes ( `/${ x . name } ` ) ) ) return false ;
5781 if ( args && x . arguments ) return args . join ( " " ) . indexOf ( x . arguments ) > - 1 ;
5882 return true ;
0 commit comments