1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/build/win32/autobinscope.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,76 @@ 1.4 +#!/usr/bin/env python 1.5 + 1.6 +# This Source Code Form is subject to the terms of the Mozilla Public 1.7 +# License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 +# file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.9 + 1.10 +# run Microsoft's Binscope tool (http://www.microsoft.com/download/en/details.aspx?id=11910) 1.11 +# against a fresh Windows build. output a 'binscope.log' file with full details 1.12 +# of the run and appropriate strings to integrate with the buildbots 1.13 + 1.14 +# from the docs : "The error code returned when running under the command line is equal 1.15 +# to the number of failures the tool reported plus the number of errors. BinScope will return 1.16 +# 0 only if there are no errors or failures." 1.17 + 1.18 +# the symbol dir should point to the symbol dir hierarchy created 1.19 +# via running make buildsymbols in a windows build's objdir 1.20 + 1.21 +import sys 1.22 +import subprocess 1.23 +import os 1.24 + 1.25 +BINSCOPE_OUTPUT_LOGFILE = r".\binscope_xml_output.log" 1.26 + 1.27 +# usage 1.28 +if len(sys.argv) < 3: 1.29 + print """usage : autobinscope.by path_to_binary path_to_symbols [log_file_path]" 1.30 + log_file_path is optional, log will be written to .\binscope_xml_output.log by default""" 1.31 + sys.exit(0) 1.32 + 1.33 +binary_path = sys.argv[1] 1.34 +symbol_path = sys.argv[2] 1.35 + 1.36 +if len(sys.argv) == 4: 1.37 + log_file_path = sys.argv[3] 1.38 +else: 1.39 + log_file_path = BINSCOPE_OUTPUT_LOGFILE 1.40 + 1.41 +# execute binscope against the binary, using the BINSCOPE environment 1.42 +# variable as the path to binscope.exe 1.43 +try: 1.44 + binscope_path = os.environ['BINSCOPE'] 1.45 +except KeyError: 1.46 + print "BINSCOPE environment variable is not set, can't check DEP/ASLR etc. status." 1.47 + sys.exit(0) 1.48 + 1.49 +try: 1.50 + proc = subprocess.Popen([binscope_path, "/target", binary_path, 1.51 + "/output", log_file_path, "/sympath", symbol_path, 1.52 + "/c", "ATLVersionCheck", "/c", "ATLVulnCheck", "/c", "FunctionPointersCheck", 1.53 + "/c", "SharedSectionCheck", "/c", "APTCACheck", "/c", "NXCheck", 1.54 + "/c", "GSCheck", "/c", "GSFunctionSafeBuffersCheck", "/c", "GSFriendlyInitCheck", 1.55 + "/c", "CompilerVersionCheck", "/c", "SafeSEHCheck", "/c", "SNCheck", 1.56 + "/c", "DBCheck"], stdout=subprocess.PIPE) 1.57 + 1.58 +except WindowsError, (errno, strerror): 1.59 + if errno != 2 and errno != 3: 1.60 + print "Unexpected error ! \nError " + str(errno) + " : " + strerror + "\nExiting !\n" 1.61 + sys.exit(0) 1.62 + else: 1.63 + print "Could not locate binscope at location : %s\n" % binscope_path 1.64 + print "Binscope wasn't installed or the BINSCOPE env variable wasn't set correctly, skipping this check and exiting..." 1.65 + sys.exit(0) 1.66 + 1.67 +proc.wait() 1.68 + 1.69 +output = proc.communicate()[0] 1.70 + 1.71 +# is this a PASS or a FAIL ? 1.72 +if proc.returncode != 0: 1.73 + print "Error count: %d" % proc.returncode 1.74 + print "TEST-UNEXPECTED-FAIL | autobinscope.py | %s is missing a needed Windows protection, such as /GS or ASLR" % binary_path 1.75 + logfile = open(log_file_path, "r") 1.76 + for line in logfile: 1.77 + print(line), 1.78 +else: 1.79 + print "TEST-PASS | autobinscope.py | %s succeeded" % binary_path