3
# ***** BEGIN LICENSE BLOCK *****
4
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
6
# The contents of this file are subject to the Mozilla Public License Version
7
# 1.1 (the "License"); you may not use this file except in compliance with
8
# the License. You may obtain a copy of the License at
9
# http://www.mozilla.org/MPL/
11
# Software distributed under the License is distributed on an "AS IS" basis,
12
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13
# for the specific language governing rights and limitations under the
16
# The Original Code is mozilla.org code.
18
# The Initial Developer of the Original Code is
19
# the Mozilla Foundation.
20
# Portions created by the Initial Developer are Copyright (C) 2011
21
# the Initial Developer. All Rights Reserved.
26
# Alternatively, the contents of this file may be used under the terms of
27
# either the GNU General Public License Version 2 or later (the "GPL"), or
28
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29
# in which case the provisions of the GPL or the LGPL are applicable instead
30
# of those above. If you wish to allow use of your version of this file only
31
# under the terms of either the GPL or the LGPL, and not to allow others to
32
# use your version of this file under the terms of the MPL, indicate your
33
# decision by deleting the provisions above and replace them with the notice
34
# and other provisions required by the GPL or the LGPL. If you do not delete
35
# the provisions above, a recipient may use your version of this file under
36
# the terms of any one of the MPL, the GPL or the LGPL.
38
# ***** END LICENSE BLOCK *****
40
# run Microsoft's Binscope tool (http://www.microsoft.com/download/en/details.aspx?id=11910)
41
# against a fresh Windows build. output a 'binscope.log' file with full details
42
# of the run and appropriate strings to integrate with the buildbots
44
# from the docs : "The error code returned when running under the command line is equal
45
# to the number of failures the tool reported plus the number of errors. BinScope will return
46
# 0 only if there are no errors or failures."
48
# the symbol dir should point to the symbol dir hierarchy created
49
# via running make buildsymbols in a windows build's objdir
55
BINSCOPE_OUTPUT_LOGFILE = r".\binscope_xml_output.log"
59
print """usage : autobinscope.by path_to_binary path_to_symbols [log_file_path]"
60
log_file_path is optional, log will be written to .\binscope_xml_output.log by default"""
63
binary_path = sys.argv[1]
64
symbol_path = sys.argv[2]
66
if len(sys.argv) == 4:
67
log_file_path = sys.argv[3]
69
log_file_path = BINSCOPE_OUTPUT_LOGFILE
71
# execute binscope against the binary, using the BINSCOPE environment
72
# variable as the path to binscope.exe
74
binscope_path = os.environ['BINSCOPE']
76
print "BINSCOPE environment variable is not set, can't check DEP/ASLR etc. status."
80
proc = subprocess.Popen([binscope_path, "/target", binary_path,
81
"/output", log_file_path, "/sympath", symbol_path,
82
"/c", "ATLVersionCheck", "/c", "ATLVulnCheck", "/c", "FunctionPointersCheck",
83
"/c", "SharedSectionCheck", "/c", "APTCACheck", "/c", "NXCheck",
84
"/c", "GSCheck", "/c", "GSFunctionSafeBuffersCheck", "/c", "GSFriendlyInitCheck",
85
"/c", "CompilerVersionCheck", "/c", "SafeSEHCheck", "/c", "SNCheck",
86
"/c", "DBCheck"], stdout=subprocess.PIPE)
88
except WindowsError, (errno, strerror):
89
if errno != 2 and errno != 3:
90
print "Unexpected error ! \nError " + str(errno) + " : " + strerror + "\nExiting !\n"
93
print "Could not locate binscope at location : %s\n" % binscope_path
94
print "Binscope wasn't installed or the BINSCOPE env variable wasn't set correctly, skipping this check and exiting..."
99
output = proc.communicate()[0]
101
# is this a PASS or a FAIL ?
102
if proc.returncode != 0:
103
print "TEST-UNEXPECTED-FAIL | autobinscope.py | %s is missing a needed Windows protection, such as /GS or ASLR" % binary_path
105
print "TEST-PASS | autobinscope.py | %s succeeded" % binary_path
3
# This Source Code Form is subject to the terms of the Mozilla Public
4
# License, v. 2.0. If a copy of the MPL was not distributed with this
5
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
# run Microsoft's Binscope tool (http://www.microsoft.com/download/en/details.aspx?id=11910)
8
# against a fresh Windows build. output a 'binscope.log' file with full details
9
# of the run and appropriate strings to integrate with the buildbots
11
# from the docs : "The error code returned when running under the command line is equal
12
# to the number of failures the tool reported plus the number of errors. BinScope will return
13
# 0 only if there are no errors or failures."
15
# the symbol dir should point to the symbol dir hierarchy created
16
# via running make buildsymbols in a windows build's objdir
22
BINSCOPE_OUTPUT_LOGFILE = r".\binscope_xml_output.log"
26
print """usage : autobinscope.by path_to_binary path_to_symbols [log_file_path]"
27
log_file_path is optional, log will be written to .\binscope_xml_output.log by default"""
30
binary_path = sys.argv[1]
31
symbol_path = sys.argv[2]
33
if len(sys.argv) == 4:
34
log_file_path = sys.argv[3]
36
log_file_path = BINSCOPE_OUTPUT_LOGFILE
38
# execute binscope against the binary, using the BINSCOPE environment
39
# variable as the path to binscope.exe
41
binscope_path = os.environ['BINSCOPE']
43
print "BINSCOPE environment variable is not set, can't check DEP/ASLR etc. status."
47
proc = subprocess.Popen([binscope_path, "/target", binary_path,
48
"/output", log_file_path, "/sympath", symbol_path,
49
"/c", "ATLVersionCheck", "/c", "ATLVulnCheck", "/c", "FunctionPointersCheck",
50
"/c", "SharedSectionCheck", "/c", "APTCACheck", "/c", "NXCheck",
51
"/c", "GSCheck", "/c", "GSFunctionSafeBuffersCheck", "/c", "GSFriendlyInitCheck",
52
"/c", "CompilerVersionCheck", "/c", "SafeSEHCheck", "/c", "SNCheck",
53
"/c", "DBCheck"], stdout=subprocess.PIPE)
55
except WindowsError, (errno, strerror):
56
if errno != 2 and errno != 3:
57
print "Unexpected error ! \nError " + str(errno) + " : " + strerror + "\nExiting !\n"
60
print "Could not locate binscope at location : %s\n" % binscope_path
61
print "Binscope wasn't installed or the BINSCOPE env variable wasn't set correctly, skipping this check and exiting..."
66
output = proc.communicate()[0]
68
# is this a PASS or a FAIL ?
69
if proc.returncode != 0:
70
print "Error count: %d" % proc.returncode
71
print "TEST-UNEXPECTED-FAIL | autobinscope.py | %s is missing a needed Windows protection, such as /GS or ASLR" % binary_path
72
logfile = open(log_file_path, "r")
76
print "TEST-PASS | autobinscope.py | %s succeeded" % binary_path