Given a dll file location, get all its exported symbols and dump them into the given def file. The .def file will be overwritten
(dll, dfile)
| 222 | return st.split(b'\n') |
| 223 | |
| 224 | def generate_def(dll, dfile): |
| 225 | """Given a dll file location, get all its exported symbols and dump them |
| 226 | into the given def file. |
| 227 | |
| 228 | The .def file will be overwritten""" |
| 229 | dump = dump_table(dll) |
| 230 | for i in range(len(dump)): |
| 231 | if _START.match(dump[i].decode()): |
| 232 | break |
| 233 | else: |
| 234 | raise ValueError("Symbol table not found") |
| 235 | |
| 236 | syms = [] |
| 237 | for j in range(i+1, len(dump)): |
| 238 | m = _TABLE.match(dump[j].decode()) |
| 239 | if m: |
| 240 | syms.append((int(m.group(1).strip()), m.group(2))) |
| 241 | else: |
| 242 | break |
| 243 | |
| 244 | if len(syms) == 0: |
| 245 | log.warn('No symbols found in %s' % dll) |
| 246 | |
| 247 | with open(dfile, 'w') as d: |
| 248 | d.write('LIBRARY %s\n' % os.path.basename(dll)) |
| 249 | d.write(';CODE PRELOAD MOVEABLE DISCARDABLE\n') |
| 250 | d.write(';DATA PRELOAD SINGLE\n') |
| 251 | d.write('\nEXPORTS\n') |
| 252 | for s in syms: |
| 253 | #d.write('@%d %s\n' % (s[0], s[1])) |
| 254 | d.write('%s\n' % s[1]) |
| 255 | |
| 256 | def find_dll(dll_name): |
| 257 |