-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathscript.py
31 lines (23 loc) · 811 Bytes
/
script.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
import argparse
import collections
from pwn import *
from pycparser import *
from pycparser import parse_file
import pprint
from funcparser import ExtractAllFuncDecls
p = argparse.ArgumentParser(description='''
Parse a header file into Python to extract the function signatures
''')
p.add_argument('file')
p.add_argument('-v','--verbose',action='store_true')
args = p.parse_args()
ast = parse_file(args.file)
Functions = ExtractAllFuncDecls(ast, verbose=args.verbose)
print "Parsed %i functions" % len(Functions)
with open('functions.py','wt+') as f:
f.write('''
import collections
Function = collections.namedtuple('Function', ('type', 'derefcnt', 'name', 'args'))
Argument = collections.namedtuple('Argument', ('type', 'derefcnt', 'name'))
functions = %s
'''.lstrip() % pprint.pformat(Functions))