-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b3dfc4
commit 97efbea
Showing
9 changed files
with
188 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,121 @@ | ||
import * as Natives from './native/index.js'; | ||
import * as Natives from "./native/index.js"; | ||
const Native = Natives[process.platform]; | ||
|
||
const timestamps = {}; | ||
const names = {}; | ||
const pids = {}; | ||
|
||
export default class { | ||
constructor(handlers) { | ||
if (!Native) return; | ||
|
||
this.handlers = handlers; | ||
|
||
this.scan = this.scan.bind(this); | ||
|
||
this.getDB(); | ||
|
||
this.scan(); | ||
setInterval(this.scan, 10000); // every 10 seconds instead of 5 | ||
|
||
console.log("[bunRPC] [Process] Scanner started"); | ||
} | ||
|
||
async getDB() { | ||
if (this.DetectableDB) return this.DetectableDB; | ||
|
||
const data = await fetch("https://discord.com/api/v9/applications/detectable") | ||
|
||
this.DetectableDB = await data.json(); | ||
|
||
return this.DetectableDB; | ||
} | ||
|
||
async scan() { | ||
const processes = await Native.getProcesses(); | ||
const ids = []; | ||
|
||
const DetectableDB = await this.getDB(); | ||
|
||
for (const [pid, _path, args] of processes) { | ||
const path = _path.toLowerCase().replaceAll('\\', '/'); | ||
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()) { | ||
toCompare.push(p.replace('64', '')); | ||
toCompare.push(p.replace('.x64', '')); | ||
toCompare.push(p.replace('x64', '')); | ||
toCompare.push(p.replace('_64', '')); | ||
} | ||
|
||
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 (args && x.arguments) return args.join(" ").indexOf(x.arguments) > -1; | ||
return true; | ||
})) { | ||
names[id] = name; | ||
pids[id] = pid; | ||
|
||
ids.push(id); | ||
if (!timestamps[id]) { | ||
timestamps[id] = Date.now(); | ||
} | ||
|
||
this.handlers.message({ | ||
socketId: id | ||
}, { | ||
cmd: 'SET_ACTIVITY', | ||
args: { | ||
activity: { | ||
application_id: id, | ||
name, | ||
timestamps: { | ||
start: timestamps[id] | ||
} | ||
}, | ||
pid | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
|
||
for (const id in timestamps) { | ||
if (!ids.includes(id)) { | ||
delete timestamps[id]; | ||
|
||
this.handlers.message({ | ||
socketId: id | ||
}, { | ||
cmd: 'SET_ACTIVITY', | ||
args: { | ||
activity: null, | ||
pid: pids[id] | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
constructor(handlers) { | ||
if (!Native) return; | ||
|
||
this.handlers = handlers; | ||
|
||
this.scan = this.scan.bind(this); | ||
|
||
this.getDB(); | ||
|
||
this.scan(); | ||
setInterval(this.scan, 10000); // every 10 seconds instead of 5 | ||
|
||
console.log("[bunRPC] [Process] Scanner started"); | ||
} | ||
|
||
async getDB() { | ||
if (this.DetectableDB) return this.DetectableDB; | ||
|
||
const data = await fetch( | ||
"https://discord.com/api/v9/applications/detectable", | ||
); | ||
|
||
this.DetectableDB = await data.json(); | ||
|
||
return this.DetectableDB; | ||
} | ||
|
||
async scan() { | ||
const processes = await Native.getProcesses(); | ||
const ids = []; | ||
|
||
const DetectableDB = await this.getDB(); | ||
|
||
for (const [pid, _path, args] of processes) { | ||
const path = _path.toLowerCase().replaceAll("\\", "/"); | ||
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()) { | ||
toCompare.push(p.replace("64", "")); | ||
toCompare.push(p.replace(".x64", "")); | ||
toCompare.push(p.replace("x64", "")); | ||
toCompare.push(p.replace("_64", "")); | ||
} | ||
|
||
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 (args && x.arguments) | ||
return args.join(" ").indexOf(x.arguments) > -1; | ||
return true; | ||
}) | ||
) { | ||
names[id] = name; | ||
pids[id] = pid; | ||
|
||
ids.push(id); | ||
if (!timestamps[id]) { | ||
timestamps[id] = Date.now(); | ||
} | ||
|
||
this.handlers.message( | ||
{ | ||
socketId: id, | ||
}, | ||
{ | ||
cmd: "SET_ACTIVITY", | ||
args: { | ||
activity: { | ||
application_id: id, | ||
name, | ||
timestamps: { | ||
start: timestamps[id], | ||
}, | ||
}, | ||
pid, | ||
}, | ||
}, | ||
); | ||
} | ||
} | ||
} | ||
|
||
for (const id in timestamps) { | ||
if (!ids.includes(id)) { | ||
delete timestamps[id]; | ||
|
||
this.handlers.message( | ||
{ | ||
socketId: id, | ||
}, | ||
{ | ||
cmd: "SET_ACTIVITY", | ||
args: { | ||
activity: null, | ||
pid: pids[id], | ||
}, | ||
}, | ||
); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
import { exec } from 'node:child_process'; | ||
import { exec } from "node:child_process"; | ||
|
||
export const getProcesses = () => { | ||
return new Promise((resolve, reject) => { | ||
exec("ps -axo pid,comm", (error, stdout) => { | ||
if (error) { | ||
return reject(error); // Handle errors | ||
} | ||
return new Promise((resolve, reject) => { | ||
exec("ps -axo pid,comm", (error, stdout) => { | ||
if (error) { | ||
return reject(error); // Handle errors | ||
} | ||
|
||
const processes = stdout | ||
.toString() | ||
.split('\n') // Split by new lines | ||
.slice(1) // Skip the header line | ||
.map(line => line.trim().split(/\s+/, 2)) // Split into PID and command | ||
.filter(parts => parts.length === 2) // Ensure both PID and command exist | ||
.map(([pid, command]) => [Number(pid), command]); | ||
const processes = stdout | ||
.toString() | ||
.split("\n") // Split by new lines | ||
.slice(1) // Skip the header line | ||
.map((line) => line.trim().split(/\s+/, 2)) // Split into PID and command | ||
.filter((parts) => parts.length === 2) // Ensure both PID and command exist | ||
.map(([pid, command]) => [Number(pid), command]); | ||
|
||
resolve(processes); | ||
}); | ||
}); | ||
resolve(processes); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export * as darwin from './darwin/index.js'; | ||
export * as linux from './linux/index.js'; | ||
export * as win32 from './win32/index.js'; | ||
export * as darwin from "./darwin/index.js"; | ||
export * as linux from "./linux/index.js"; | ||
export * as win32 from "./win32/index.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
import { readdir } from "node:fs/promises"; | ||
import { file } from "bun" | ||
import { file } from "bun"; | ||
|
||
export const getProcesses = async () => { | ||
const directories = await readdir("/proc"); | ||
const directories = await readdir("/proc"); | ||
|
||
const processPromises = directories | ||
.filter(pid => +pid > 0) // Filter valid PIDs upfront | ||
.map(async (pid) => { | ||
try { | ||
const cmdline = await file(`/proc/${pid}/cmdline`).text(); | ||
const [command, ...args] = cmdline.split("\0"); // Destructure for clarity | ||
return [+pid, command, args]; | ||
} catch { | ||
return null; // Return null on failure | ||
} | ||
}); | ||
const processPromises = directories | ||
.filter((pid) => +pid > 0) // Filter valid PIDs upfront | ||
.map(async (pid) => { | ||
try { | ||
const cmdline = await file(`/proc/${pid}/cmdline`).text(); | ||
const [command, ...args] = cmdline.split("\0"); // Destructure for clarity | ||
return [+pid, command, args]; | ||
} catch { | ||
return null; // Return null on failure | ||
} | ||
}); | ||
|
||
const processes = await Promise.all(processPromises); | ||
return processes.filter(Boolean); // Filter out null entries | ||
const processes = await Promise.all(processPromises); | ||
return processes.filter(Boolean); // Filter out null entries | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,23 @@ | ||
import { exec } from 'node:child_process'; | ||
import { exec } from "node:child_process"; | ||
|
||
export const getProcesses = () => { | ||
return new Promise((resolve) => { | ||
exec("wmic process get ProcessID,ExecutablePath /format:csv", (error, output) => { | ||
return new Promise((resolve) => { | ||
exec( | ||
"wmic process get ProcessID,ExecutablePath /format:csv", | ||
(error, output) => { | ||
const processes = output | ||
.toString() | ||
.split("\r\n") // Split by new lines | ||
.slice(2) // Remove headers | ||
.map((line) => line.trim().split(",").reverse()) // Split, reverse, and trim | ||
.filter((parsed) => parsed[1]) // Filter out invalid paths | ||
.map(([executablePath, processId]) => [ | ||
Number(processId) || processId, | ||
executablePath, | ||
]); // Parse IDs | ||
|
||
const processes = output | ||
.toString() | ||
.split('\r\n') // Split by new lines | ||
.slice(2) // Remove headers | ||
.map(line => line.trim().split(',').reverse()) // Split, reverse, and trim | ||
.filter(parsed => parsed[1]) // Filter out invalid paths | ||
.map(([executablePath, processId]) => [Number(processId) || processId, executablePath]); // Parse IDs | ||
|
||
resolve(processes); | ||
}); | ||
}); | ||
resolve(processes); | ||
}, | ||
); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.