-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathdumpsig.py
executable file
·76 lines (55 loc) · 1.78 KB
/
dumpsig.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python
from builtins import range
import os
import sys
import nampa
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
def iprint(indent, *args, **kwargs):
kwargs['sep'] = ''
print(" " * indent, *args, **kwargs)
def format_functions(ff):
out = []
for f in ff:
out.append('{}{:04X}:{}'.format('(l)' if f.is_local else '', f.offset, f.name))
return ' '.join(out)
def format_tail_bytes(bb):
out = []
for b in bb:
out.append('({:04X}: {:02X})'.format(b.offset, b.value))
return ' '.join(out)
def format_refs(rr):
out = []
for r in rr:
out.append('(REF {:04X}: {})'.format(r.offset, r.name))
return 'XXX'.join(out)
def print_modules(node, level):
for i, m in enumerate(node.modules):
fmt = '{}. {:02X} {:04X} '
if m.length < 0x10000:
fmt += '{:04X} '
else:
fmt += '{:08X} '
iprint(
level,
fmt.format(i, m.crc_length, m.crc16, m.length),
format_functions(m.public_functions),
' ' + format_tail_bytes(m.tail_bytes) if len(m.tail_bytes) > 0 else '',
' ' + format_refs(m.referenced_functions) if len(m.referenced_functions) > 0 else ''
)
def recurse(node, level):
iprint(level, nampa.pattern2string(node.pattern, node.variant_mask), ':')
if node.is_leaf:
print_modules(node, level + 1)
else:
for child in node.children:
recurse(child, level + 1)
def main(fpath):
sig = nampa.parse_flirt_file(open(fpath, 'rb'))
for child in sig.root.children:
recurse(child, level=0)
if __name__ == '__main__':
if len(sys.argv) != 2:
print("Usage: {} input_file.sig".format(sys.argv[0]))
exit()
main(sys.argv[1])