-
Notifications
You must be signed in to change notification settings - Fork 0
/
strace-parser.js
34 lines (32 loc) · 1.25 KB
/
strace-parser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// listeners: socket, connect, open, read
const parseOutput = (_lines, listeners = {}) => {
const lines = _lines.split('\n');
for (lineIndex in lines) {
const _line = lines[lineIndex];
if (_line.startsWith('open(')) {
const openTarget = [..._line.matchAll(/open\("(\S*)"/g)][0][1];
listeners['open'] && listeners['open'](_line);
} else if (_line.startsWith('read(')) {
const readTarget = [..._line.matchAll(/read\((\d+),\s*([\S\s]*),\s*(\d+)/g)];
const bytesRead = readTarget[0][3];
const fileDescriptor = readTarget[0][1];
listeners['open'] && listeners['open'](_line);
} else {
if (!_line.startsWith('clock_gettime(') && !_line.startsWith('close(') && !_line.startsWith('futex(')) {
if (_line.startsWith('getsockopt(') || _line.startsWith('setsockopt(')) {
listeners['socket'] && listeners['socket'](_line);
} else if (_line.startsWith('getsockname(') || _line.startsWith('socket(')) {
listeners['socket'] && listeners['socket'](_line);
} else if (_line.startsWith('connect(')) {
const connectTarget = [..._line.matchAll(/inet_addr\("(\S*)"\)/g)][0][1];
listeners['connect'] && listeners['connect'](_line);
} else {
// console.log(_line);
}
}
}
}
};
module.exports = {
parseOutput
}