Files
reverse-engineering-anything/scripts/lib/ownership-ps-trace.mjs
T
morluto f7706a199c fix(verify): recognize the ownership ps inventory from the process owner's arguments (#11291)
* fix(verify): recognize the ownership ps inventory from the process owner's arguments

* fix(verify): match the recorded-crash ps inventory against REA's fixed ps locations
2026-11-16 00:01:18 +08:00

25 lines
878 B
JavaScript

import {
LINUX_SYSTEM_PS_LOCATIONS,
PROCESS_INVENTORY_PS_ARGUMENTS,
} from "../../dist/process/systemPs.js";
/** The fixed Linux `ps` locations REA selects for ownership inventory. */
export const ownershipPsExecutables = new Set(LINUX_SYSTEM_PS_LOCATIONS);
/**
* Whether an strace `execve` line is REA's process-ownership `ps` inventory
* run from one of `executables`. REA spawns the selected path, so it is also
* argv[0]; the arguments come from the process owner, not a copy.
*/
export const isOwnershipPsExecution = (
line,
executables = ownershipPsExecutables,
) => {
const match = /^execve\("([^"]+)", (\[[^\]]*\])/u.exec(line);
if (match === null || !executables.has(match[1])) return false;
const argv = [match[1], ...PROCESS_INVENTORY_PS_ARGUMENTS];
return (
match[2] === `[${argv.map((value) => JSON.stringify(value)).join(", ")}]`
);
};