From e7ce66710dc74b8a085e9c0fb99511ecbaa4f93b Mon Sep 17 00:00:00 2001 From: "caitkp@chromium.org" Date: Thu, 16 Jan 2014 15:46:33 +0000 Subject: [PATCH] 1. Make sure chrome_elf.dll imports nothing besides kernel32, advapi32, and some msvc libs (DEBUG builds) 2. Add gyp action and test to ensure chrome_elf.dll is always the first entry in chrome.exe's import table. Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=242834 Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=243048 Review URL: https://codereview.chromium.org/109483003 git-svn-id: http://src.chromium.org/svn/trunk/src/build@245197 4ff67af0-8c30-449e-8e8b-ad334ec8d88c --- win/reorder-imports.py | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 win/reorder-imports.py diff --git a/win/reorder-imports.py b/win/reorder-imports.py new file mode 100755 index 000000000..d320b51e9 --- /dev/null +++ b/win/reorder-imports.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python +# Copyright 2014 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. + +import glob +import optparse +import os +import shutil +import subprocess +import sys + +def reorder_imports(input_dir, output_dir): + """Run swapimports.exe on the initial chrome.exe, and write to the output + directory. Also copy over any related files that might be needed + (pdbs, manifests etc.). + """ + input_image = '--input-image=%s' % (os.path.join(input_dir, 'chrome.exe')) + output_image = '--output-image=%s' % (os.path.join(output_dir, 'chrome.exe')) + + swap_exe = os.path.join( + __file__, + '..\\..\\..\\third_party\\syzygy\\binaries\\exe\\swapimport.exe') + subprocess.call( + [swap_exe, input_image, output_image, '--overwrite', 'chrome_elf.dll']) + + for fname in glob.iglob(os.path.join(input_dir, 'chrome.exe.*')): + shutil.copy(fname, os.path.join(output_dir, os.path.basename(fname))) + return 0 + + +def main(argv): + usage = 'reorder_imports.py -i -o ' + parser = optparse.OptionParser(usage=usage) + parser.add_option('-i', '--input', help='reorder chrome.exe in DIR', + metavar='DIR') + parser.add_option('-o', '--output', help='write new chrome.exe to DIR', + metavar='DIR') + opts, args = parser.parse_args() + + if not opts.input or not opts.output: + parser.error('Please provide and input and output directory') + return reorder_imports(opts.input, opts.output) + +if __name__ == "__main__": + sys.exit(main(sys.argv[1:]))