Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 # | |
| 6 # A utility scrip to help with maintaining DLL import lists. | |
| 7 import ast | |
| 8 import optparse | |
| 9 import re | |
| 10 import sys | |
| 11 | |
| 12 | |
| 13 _EXPORT_RE = re.compile(""" | |
| 14 ^\s*(?P<ordinal>[0-9]+) # The ordinal field. | |
| 15 \s+(?P<hint>[0-9A-F]+) # The hint field. | |
| 16 \s(?P<rva>........) # The RVA field. | |
| 17 \s+(?P<name>[^ ]+) # And finally the name we're really after. | |
| 18 """, re.VERBOSE) | |
| 19 | |
| 20 | |
| 21 _USAGE = """\ | |
| 22 Usage: %prog [options] [master-file] | |
| 23 | |
| 24 This script filters a list of exports from a DLL, generated from something | |
| 25 like the following command line: | |
| 26 | |
| 27 C:\> dumpbin /exports dllname.dllname | |
| 28 | |
| 29 against a master list of imports built from e.g. | |
| 30 | |
| 31 C:\> dumpbin /exports importlibname.lib | |
| 32 | |
| 33 The point of this is to trim non-public exports from the list, and to | |
| 34 normalize the names to their stdcall-mangled form for the generation of | |
| 35 import libraries. | |
| 36 Note that the export names from the latter incanatation are stdcall-mangled, | |
| 37 e.g. they are suffixed with "@" and the number of argument bytes to the | |
| 38 function. | |
| 39 """ | |
| 40 | |
| 41 def _ReadMasterFile(master_file): | |
| 42 # Slurp the master file. | |
|
cpu_(ooo_6.6-7.5)
2013/02/05 19:28:44
I agree, eval should be renamed to slurp :) Smarta
Sigurður Ásgeirsson
2013/02/05 19:48:51
Yeah .py is disingenious, maybe .data?
| |
| 43 master_exports = ast.literal_eval(open(master_file).read()) | |
| 44 master_mapping = {} | |
| 45 for export in master_exports: | |
| 46 name = export.split('@')[0] | |
| 47 master_mapping[name] = export | |
| 48 | |
| 49 return master_mapping | |
| 50 | |
| 51 | |
| 52 def main(): | |
| 53 parser = optparse.OptionParser(usage=_USAGE) | |
| 54 parser.add_option('-r', '--reverse', | |
| 55 dest='reverse', | |
| 56 action='store_true', | |
| 57 default=False, | |
| 58 help='Reverse the matching, e.g. return the functions ' | |
| 59 'in the master list that aren\'t in the input.') | |
| 60 | |
| 61 options, args = parser.parse_args() | |
| 62 if len(args) != 1: | |
| 63 parser.error('Must provide a master file.') | |
| 64 return 1 | |
| 65 | |
| 66 master_mapping = _ReadMasterFile(args[0]) | |
| 67 | |
| 68 found_exports = [] | |
| 69 for line in sys.stdin: | |
| 70 match = _EXPORT_RE.match(line) | |
| 71 if match: | |
| 72 export_name = master_mapping.get(match.group('name'), None) | |
| 73 if export_name: | |
| 74 found_exports.append(export_name) | |
| 75 | |
| 76 if options.reverse: | |
| 77 # Reverse the found_exports list. | |
| 78 found_exports = [e for e in (set(master_mapping.values()) - | |
| 79 set(found_exports))] | |
| 80 | |
| 81 # Sort the found exports for tidy output. | |
| 82 found_exports.sort() | |
| 83 for export in found_exports: | |
| 84 print export | |
|
cpu_(ooo_6.6-7.5)
2013/02/05 19:28:44
how does the output look like?
Sigurður Ásgeirsson
2013/02/05 19:48:51
The output from this script is just a run of sorte
| |
| 85 | |
| 86 | |
| 87 if __name__ == '__main__': | |
| 88 sys.exit(main()) | |
| OLD | NEW |