2 # Simple script to convert the output from 'nm' to a C style header
3 # file with defined offsets.
5 # Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
7 # This file may be distributed under the terms of the GNU GPLv3 license.
13 print "Usage:\n %s <output file>" % (sys.argv[0],)
17 if len(sys.argv) != 2:
19 # Find symbols (that are valid)
21 lines = sys.stdin.readlines()
23 addr, type, sym = line.split()
25 # Only interested in global symbols in text segment
28 if c not in string.letters + string.digits + '_':
31 syms.append((sym, addr))
35 if c not in string.letters + string.digits + '_':
40 f = open(sys.argv[1], 'wb')
42 #ifndef __OFFSET_AUTO_H__%s
43 #define __OFFSET_AUTO_H__%s
44 // Auto generated file - please see defsyms.py.
45 // This file contains symbol offsets of a compiled binary.
47 """ % (guardstr, guardstr))
48 for sym, addr in syms:
49 f.write("#define OFFSET_%s 0x%s\n" % (sym, addr))
51 #endif // __OFFSET_AUTO_H__%s
54 if __name__ == '__main__':