Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 import re, sys, os, os.path, string
00060
00061 def usage(argv):
00062 sys.stderr.write("%s <lib file> <library name> <version> <def file>\n" %
00063 os.path.basename(argv[0]))
00064
00065 def main(argv):
00066 try:
00067 _, libfile, binname, version, deffile = argv
00068 except ValueError:
00069 usage(argv)
00070 sys.exit(1)
00071
00072 cmd = "DUMPBIN.EXE /SYMBOLS %s" % libfile
00073 print cmd
00074 dumped = os.popen(cmd)
00075
00076 definitions = {}
00077
00078 linere1 = re.compile(r"^[^ ]+ +[^ ]+ +SECT[^ ]+ +[^ ]+ +\(\) +External +\| +(\?[^ ]*)(.*)\n")
00079 linere2 = re.compile(r"^[^ ]+ +[^ ]+ +SECT[^ ]+ +[^ ]+ +External +\| +(\?[^?][^ ]*)(.*)\n")
00080
00081 exclude = re.compile(r"deleting destructor[^(]+\(unsigned int\)|anonymous namespace")
00082
00083 while 1:
00084 line = dumped.readline()
00085 if line == "":
00086 break
00087
00088 match = linere1.search(line) or linere2.search(line)
00089 if match:
00090 symbol = match.group(1)
00091 args = match.group(2)
00092 if exclude.search(args):
00093 continue
00094
00095 definitions[symbol] = None
00096
00097 symbols = definitions.keys()
00098 symbols.sort()
00099
00100 print "Output %d symbols." % len(symbols)
00101
00102 out = open(deffile, "w")
00103 if string.lower(binname[4:]) == ".exe":
00104 out.write("NAME %s\n" % binname)
00105 else:
00106 out.write("LIBRARY %s\n" % binname)
00107 out.write("VERSION %s\n" % version)
00108 out.write("EXPORTS\n")
00109
00110 for s in symbols:
00111 out.write(s + "\n")
00112
00113 out.close()
00114
00115
00116 if __name__ == "__main__":
00117 main(sys.argv)