Back to index

enigmail  1.4.3
autobinscope.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 # ***** BEGIN LICENSE BLOCK *****
00004 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005 #
00006 # The contents of this file are subject to the Mozilla Public License Version
00007 # 1.1 (the "License"); you may not use this file except in compliance with
00008 # the License. You may obtain a copy of the License at
00009 # http://www.mozilla.org/MPL/
00010 #
00011 # Software distributed under the License is distributed on an "AS IS" basis,
00012 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013 # for the specific language governing rights and limitations under the
00014 # License.
00015 #
00016 # The Original Code is mozilla.org code.
00017 #
00018 # The Initial Developer of the Original Code is
00019 # the Mozilla Foundation.
00020 # Portions created by the Initial Developer are Copyright (C) 2011
00021 # the Initial Developer. All Rights Reserved.
00022 #
00023 # Contributor(s):
00024 #   imelven@mozilla.com
00025 #
00026 # Alternatively, the contents of this file may be used under the terms of
00027 # either the GNU General Public License Version 2 or later (the "GPL"), or
00028 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029 # in which case the provisions of the GPL or the LGPL are applicable instead
00030 # of those above. If you wish to allow use of your version of this file only
00031 # under the terms of either the GPL or the LGPL, and not to allow others to
00032 # use your version of this file under the terms of the MPL, indicate your
00033 # decision by deleting the provisions above and replace them with the notice
00034 # and other provisions required by the GPL or the LGPL. If you do not delete
00035 # the provisions above, a recipient may use your version of this file under
00036 # the terms of any one of the MPL, the GPL or the LGPL.
00037 #
00038 # ***** END LICENSE BLOCK *****
00039 
00040 # run Microsoft's Binscope tool (http://www.microsoft.com/download/en/details.aspx?id=11910)
00041 # against a fresh Windows build. output a 'binscope.log' file with full details
00042 # of the run and appropriate strings to integrate with the buildbots
00043 
00044 # from the docs : "The error code returned when running under the command line is equal 
00045 # to the number of failures the tool reported plus the number of errors. BinScope will return 
00046 # 0 only if there are no errors or failures."
00047 
00048 # the symbol dir should point to the symbol dir hierarchy created
00049 # via running make buildsymbols in a windows build's objdir
00050 
00051 import sys
00052 import subprocess
00053 import os
00054 
00055 BINSCOPE_OUTPUT_LOGFILE = r".\binscope_xml_output.log"
00056 
00057 # usage
00058 if len(sys.argv) < 3:
00059   print """usage : autobinscope.by path_to_binary path_to_symbols [log_file_path]"
00060               log_file_path is optional, log will be written to .\binscope_xml_output.log by default"""
00061   sys.exit(0)
00062 
00063 binary_path = sys.argv[1]
00064 symbol_path = sys.argv[2]
00065 
00066 if len(sys.argv) == 4:
00067   log_file_path = sys.argv[3]
00068 else:
00069   log_file_path = BINSCOPE_OUTPUT_LOGFILE
00070   
00071 # execute binscope against the binary, using the BINSCOPE environment
00072 # variable as the path to binscope.exe
00073 try:
00074   binscope_path = os.environ['BINSCOPE']
00075 except KeyError:
00076   print "BINSCOPE environment variable is not set, can't check DEP/ASLR etc. status."
00077   sys.exit(0)
00078   
00079 try:    
00080   proc = subprocess.Popen([binscope_path, "/target", binary_path,
00081     "/output", log_file_path, "/sympath", symbol_path,
00082     "/c", "ATLVersionCheck", "/c", "ATLVulnCheck", "/c", "FunctionPointersCheck",
00083     "/c", "SharedSectionCheck", "/c", "APTCACheck", "/c", "NXCheck",
00084     "/c", "GSCheck", "/c", "GSFunctionSafeBuffersCheck", "/c", "GSFriendlyInitCheck",
00085     "/c", "CompilerVersionCheck", "/c", "SafeSEHCheck", "/c", "SNCheck",
00086     "/c", "DBCheck"], stdout=subprocess.PIPE)
00087 
00088 except WindowsError, (errno, strerror): 
00089   if errno != 2 and errno != 3:
00090     print "Unexpected error ! \nError " + str(errno) + " : " + strerror + "\nExiting !\n"
00091     sys.exit(0)
00092   else:
00093     print "Could not locate binscope at location : %s\n" % binscope_path
00094     print "Binscope wasn't installed or the BINSCOPE env variable wasn't set correctly, skipping this check and exiting..."
00095     sys.exit(0)
00096 
00097 proc.wait()
00098 
00099 output = proc.communicate()[0]
00100 
00101 # is this a PASS or a FAIL ? 
00102 if proc.returncode != 0:
00103   print "TEST-UNEXPECTED-FAIL | autobinscope.py | %s is missing a needed Windows protection, such as /GS or ASLR" % binary_path
00104 else:
00105   print "TEST-PASS | autobinscope.py | %s succeeded" % binary_path
00106 
00107 
00108