update arRPC

This commit is contained in:
smartfrigde 2024-04-29 18:06:05 +02:00
parent a532cb9a72
commit 362a116e6a
5 changed files with 10621 additions and 82477 deletions

View file

@ -1,7 +1,7 @@
const rgb = (r, g, b, msg) => `\x1b[38;2;${r};${g};${b}m${msg}\x1b[0m`;
const log = (...args) => console.log(`[${rgb(88, 101, 242, "arRPC")}]`, ...args);
log("arRPC v3.3.1 ArmCord");
log("arRPC v3.4.0 ArmCord");
const RPCServer = require("./server.js");
const {mainWindow} = require("../../../ts-out/window.js");

File diff suppressed because it is too large Load diff

View file

@ -24,15 +24,19 @@ class ProcessServer {
}
async scan() {
const startTime = performance.now();
// const startTime = performance.now();
const processes = await Native.getProcesses();
const ids = [];
// log(`got processed in ${(performance.now() - startTime).toFixed(2)}ms`);
for (const [pid, _path] of processes) {
for (const [pid, _path, args] of processes) {
const path = _path.toLowerCase().replaceAll("\\", "/");
const toCompare = [path.split("/").pop(), path.split("/").slice(-2).join("/")];
const toCompare = [];
const splitPath = path.split("/");
for (let i = 1; i < splitPath.length; i++) {
toCompare.push(splitPath.slice(-i).join("/"));
}
for (const p of toCompare.slice()) {
// add more possible tweaked paths for less false negatives
@ -42,7 +46,19 @@ class ProcessServer {
}
for (const {executables, id, name} of DetectableDB) {
if (executables?.some((x) => !x.isLauncher && toCompare.some((y) => x.name === y))) {
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 (args && x.arguments) return args.join(" ").indexOf(x.arguments) > -1;
return true;
})
) {
names[id] = name;
pids[id] = pid;
@ -50,26 +66,27 @@ class ProcessServer {
if (!timestamps[id]) {
log("detected game!", name);
timestamps[id] = Date.now();
this.handlers.message(
{
socketId: id
},
{
cmd: "SET_ACTIVITY",
args: {
activity: {
application_id: id,
name,
timestamps: {
start: timestamps[id]
}
},
pid
}
}
);
}
// Resending this on evry scan is intentional, so that in the case that arRPC scans processes before Discord, existing activities will be sent
this.handlers.message(
{
socketId: id
},
{
cmd: "SET_ACTIVITY",
args: {
activity: {
application_id: id,
name,
timestamps: {
start: timestamps[id]
}
},
pid
}
}
);
}
}
}

View file

@ -9,7 +9,7 @@ const getProcesses = async () =>
(pid) =>
+pid > 0 &&
readFile(`/proc/${pid}/cmdline`, "utf8").then(
(path) => [+pid, path.replaceAll("0", "")],
(path) => [+pid, path.split("\0")[0], path.split("\0").slice(1)],
() => 0
)
)

View file

@ -34,28 +34,28 @@ class RPCServer extends EventEmitter {
onConnection(socket) {
socket.send({
cmd: "DISPATCH",
evt: "READY",
nonce: "initial-ready",
data: {
v: 1,
// needed otherwise some stuff errors out parsing json strictly
config: {
cdn_host: "cdn.discordapp.com",
api_endpoint: "//discord.com/api",
environment: "production"
},
user: {
// mock user data using arRPC app/bot
id: "1045800378228281345",
username: "arRPC",
discriminator: "0000",
username: "arrpc",
discriminator: "0",
global_name: "arRPC",
avatar: "cfefa4d9839fb4bdf030f91c2a13e95c",
avatar_decoration_data: null,
bot: false,
flags: 0,
premium_type: 0
},
config: {
api_endpoint: "//discord.com/api",
cdn_host: "cdn.discordapp.com",
environment: "production"
}
}
},
evt: "READY",
nonce: null
});
socket.socketId = socketId++;
@ -130,7 +130,12 @@ class RPCServer extends EventEmitter {
socket.send?.({
cmd,
data: null,
data: {
...activity,
name: "",
application_id: socket.clientId,
type: 0
},
evt: null,
nonce
});