-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathld.ts
36 lines (29 loc) · 1.05 KB
/
ld.ts
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
35
36
// Parse output of ldd and ldconfig
import * as version from './version';
export type Paths = { [path: string]: string };
// Parse output of ldd or ldconfig and return a map of library names to paths
export function parseLdOutput(output: string): Paths {
const libraryList = output.split('\n').filter(ln => ln.includes('=>'));
const result: Paths = {};
libraryList.forEach(s => {
const [name, , libPath] = s.trim().split(' ');
result[name] = libPath;
});
return result;
}
// Parse output of objdump -T and return minimum glibc version required
export function parseObjdumpOutput(output: string): version.Version | null {
const glibcPattern = /\bGLIBC_([0-9.]+)\b/g;
let maxVersion = null;
let match;
do {
match = glibcPattern.exec(output);
if (match) {
const thisVersion = version.parse(match[1]);
if (!maxVersion || version.greater(thisVersion, maxVersion)) {
maxVersion = thisVersion;
}
}
} while (match);
return maxVersion;
}