Chromium Code Reviews| Index: chrome/imports/filter_export_list.py |
| diff --git a/chrome/imports/filter_export_list.py b/chrome/imports/filter_export_list.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ed892d33d1832f2bcb9f05aad20969004d7416d1 |
| --- /dev/null |
| +++ b/chrome/imports/filter_export_list.py |
| @@ -0,0 +1,88 @@ |
| +#!/usr/bin/env python |
| +# Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| +# |
| +# A utility scrip to help with maintaining DLL import lists. |
| +import ast |
| +import optparse |
| +import re |
| +import sys |
| + |
| + |
| +_EXPORT_RE = re.compile(""" |
| + ^\s*(?P<ordinal>[0-9]+) # The ordinal field. |
| + \s+(?P<hint>[0-9A-F]+) # The hint field. |
| + \s(?P<rva>........) # The RVA field. |
| + \s+(?P<name>[^ ]+) # And finally the name we're really after. |
| +""", re.VERBOSE) |
| + |
| + |
| +_USAGE = """\ |
| +Usage: %prog [options] [master-file] |
| + |
| +This script filters a list of exports from a DLL, generated from something |
| +like the following command line: |
| + |
| +C:\> dumpbin /exports dllname.dllname |
| + |
| +against a master list of imports built from e.g. |
| + |
| +C:\> dumpbin /exports importlibname.lib |
| + |
| +The point of this is to trim non-public exports from the list, and to |
| +normalize the names to their stdcall-mangled form for the generation of |
| +import libraries. |
| +Note that the export names from the latter incanatation are stdcall-mangled, |
| +e.g. they are suffixed with "@" and the number of argument bytes to the |
| +function. |
| +""" |
| + |
| +def _ReadMasterFile(master_file): |
| + # 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?
|
| + master_exports = ast.literal_eval(open(master_file).read()) |
| + master_mapping = {} |
| + for export in master_exports: |
| + name = export.split('@')[0] |
| + master_mapping[name] = export |
| + |
| + return master_mapping |
| + |
| + |
| +def main(): |
| + parser = optparse.OptionParser(usage=_USAGE) |
| + parser.add_option('-r', '--reverse', |
| + dest='reverse', |
| + action='store_true', |
| + default=False, |
| + help='Reverse the matching, e.g. return the functions ' |
| + 'in the master list that aren\'t in the input.') |
| + |
| + options, args = parser.parse_args() |
| + if len(args) != 1: |
| + parser.error('Must provide a master file.') |
| + return 1 |
| + |
| + master_mapping = _ReadMasterFile(args[0]) |
| + |
| + found_exports = [] |
| + for line in sys.stdin: |
| + match = _EXPORT_RE.match(line) |
| + if match: |
| + export_name = master_mapping.get(match.group('name'), None) |
| + if export_name: |
| + found_exports.append(export_name) |
| + |
| + if options.reverse: |
| + # Reverse the found_exports list. |
| + found_exports = [e for e in (set(master_mapping.values()) - |
| + set(found_exports))] |
| + |
| + # Sort the found exports for tidy output. |
| + found_exports.sort() |
| + for export in found_exports: |
| + 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
|
| + |
| + |
| +if __name__ == '__main__': |
| + sys.exit(main()) |