-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfilefilter.py
57 lines (37 loc) · 1.36 KB
/
filefilter.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
import re
import sys
import os
import sets
def is_file(file):
if file is None:
return false
return os.path.isfile(file)
def extract_path(pattern, line, group_nr):
match = pattern.search(line)
path = None
if match:
file = match.group(group_nr)
if is_file(file) and re.compile('\.so').search(file):
path = file
return path
def main():
if len(sys.argv) < 2:
print "usage: filefilter <(strace|ldd) output...>"
exit(1)
strace_pattern = re.compile('(openat|open|stat|execve)\([^"]*"([^"]+)"')
ldd_pattern = re.compile('(/.*) \(0x\w+\)$')
for arg_file in sys.argv[1:]:
output_file = open(arg_file, "r")
path_set = sets.Set()
for line in output_file:
path = extract_path(strace_pattern, line, 2)
if path is not None:
path_set.add(path)
path = extract_path(ldd_pattern, line, 1)
if path is not None:
path_set.add(path)
for path in path_set:
print path
if __name__ == "__main__":
main()