Skip to content

Commit 35c037e

Browse files
committed
Fail tests more clearly on Linux if ptrace_scope=0 not set
1 parent fcec826 commit 35c037e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/test.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,30 @@ const FIXTURES_BASE = isNode
1818
? path.join(__dirname, 'fixtures')
1919
: process.env.FIXTURES_PATH!;
2020

21+
function checkYamaPtraceScope() {
22+
let result: string;
23+
try {
24+
result = ChildProc.execSync('sysctl kernel.yama.ptrace_scope').toString().trim();
25+
} catch (e) {
26+
console.warn(`Failed to check ptrace_scope value: ${e}`);
27+
return;
28+
}
29+
30+
if (result === 'kernel.yama.ptrace_scope = 0') {
31+
return; // Perfect!
32+
} else if (result === 'kernel.yama.ptrace_scope = 1') {
33+
console.error(
34+
'Yama ptrace scope is set to 1, which will prevent Frida from attaching to processes. ' +
35+
'You can change this by running:\n> sudo sysctl kernel.yama.ptrace_scope=0'
36+
);
37+
process.exit(1);
38+
} else {
39+
console.warn(`Unexpected ptrace_scope value: ${result}`);
40+
}
41+
}
42+
43+
if (isNode && process.platform === 'linux') checkYamaPtraceScope();
44+
2145
describe("Frida-JS", () => {
2246

2347
let fridaClient: FridaSession;

0 commit comments

Comments
 (0)