feat: Discord's local RPC servers
arRPC (https://github.com/OpenAsar/arrpc)
This commit is contained in:
5
src/util/arRPC/process/native/index.js
Normal file
5
src/util/arRPC/process/native/index.js
Normal file
@@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const linux = require('./linux.js');
|
||||
const win32 = require('./win32.js');
|
||||
module.exports = { win32, linux };
|
||||
37
src/util/arRPC/process/native/linux.js
Normal file
37
src/util/arRPC/process/native/linux.js
Normal file
@@ -0,0 +1,37 @@
|
||||
'use strict';
|
||||
|
||||
const { exec } = require('child_process');
|
||||
const { readlink } = require('fs/promises');
|
||||
|
||||
const getProcesses = () =>
|
||||
new Promise(res =>
|
||||
exec(`ps a -o "%p;%c;%a"`, async (e, out) => {
|
||||
res(
|
||||
(
|
||||
await Promise.all(
|
||||
out
|
||||
.toString()
|
||||
.split('\n')
|
||||
.slice(1, -1)
|
||||
|
||||
.map(async x => {
|
||||
const split = x.trim().split(';');
|
||||
// If (split.length === 1) return;
|
||||
|
||||
const pid = parseInt(split[0].trim());
|
||||
/* Unused
|
||||
const cmd = split[1].trim();
|
||||
const argv = split.slice(2).join(';').trim();
|
||||
*/
|
||||
|
||||
const path = await readlink(`/proc/${pid}/exe`).catch(() => {}); // Read path from /proc/{pid}/exe symlink
|
||||
|
||||
return [pid, path];
|
||||
}),
|
||||
)
|
||||
).filter(x => x && x[1]),
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
module.exports = { getProcesses };
|
||||
25
src/util/arRPC/process/native/win32.js
Normal file
25
src/util/arRPC/process/native/win32.js
Normal file
@@ -0,0 +1,25 @@
|
||||
'use strict';
|
||||
|
||||
const { exec } = require('child_process');
|
||||
|
||||
const getProcesses = () =>
|
||||
new Promise(res =>
|
||||
exec(`wmic process get ProcessID,ExecutablePath /format:csv`, (e, out) => {
|
||||
res(
|
||||
out
|
||||
.toString()
|
||||
.split('\r\n')
|
||||
.slice(2)
|
||||
|
||||
.map(x => {
|
||||
// eslint-disable-next-line newline-per-chained-call
|
||||
const parsed = x.trim().split(',').slice(1).reverse();
|
||||
parsed[0] = parseInt(parsed[0]) || parsed[0]; // Pid to int
|
||||
return parsed;
|
||||
})
|
||||
.filter(x => x[1]),
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
module.exports = { getProcesses };
|
||||
Reference in New Issue
Block a user