feat: Discord's local RPC servers

arRPC (https://github.com/OpenAsar/arrpc)
This commit is contained in:
Elysia
2023-02-21 16:22:51 +07:00
parent 23d59d70ea
commit fbcbe77c14
11 changed files with 841 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
'use strict';
const linux = require('./linux.js');
const win32 = require('./win32.js');
module.exports = { win32, linux };

View 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 };

View 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 };