-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlist_messages.py
executable file
·55 lines (43 loc) · 1.46 KB
/
list_messages.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
#!/usr/bin/env python3
import subprocess
import sys
import re
import shutil
def find_objdump():
def try_ex(path):
proc = subprocess.Popen([path, "--v"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout,stderr = proc.communicate()
if str(stdout).find("GNU") > 0:
return True
return False
objd = shutil.which("objdump")
if try_ex(objd):
return objd
objd = shutil.which("gobjdump")
if try_ex(objd):
return objd
return None
def parse_line(line):
pat = r'malt::impl::msg_delivery<(.*?) \((.*?)\)>'
if re.search(pat, line):
match = re.search(pat, line)
return match.group(1), match.group(2).split(', ')
def run_objdump(lib_file):
proc = subprocess.Popen([find_objdump(), "-TC", lib_file], stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=1, universal_newlines=True)
lines = []
for line in iter(proc.stdout.readline, ''):
if (line != '\n'):
lines.append(parse_line(line.replace('\n', '')))
return list(filter(lambda x : not x is None, lines))
def list_messages(lib_file):
return run_objdump(lib_file)
def main():
for (msg, args) in (list_messages(sys.argv[1])):
output = '{}({})'.format(msg, ", ".join(args))
if len(sys.argv) <= 2:
print(output)
else:
with open(sys.argv[2], "a") as out_file:
out_file.write(output + '\n')
if __name__ == "__main__":
main()