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 the Winchecksec tool (https://github.com/trailofbits/winchecksec)
8 # against a given Windows binary.
17 if len(sys
.argv
) != 2:
18 print("""usage : autowinchecksec.by path_to_binary""")
21 binary_path
= sys
.argv
[1]
23 # execute winchecksec against the binary, using the WINCHECKSEC environment
24 # variable as the path to winchecksec.exe
26 winchecksec_path
= buildconfig
.substs
["WINCHECKSEC"]
29 "TEST-UNEXPECTED-FAIL | autowinchecksec.py | WINCHECKSEC environment variable is "
30 "not set, can't check DEP/ASLR etc. status."
34 wine
= buildconfig
.substs
.get("WINE")
35 if wine
and winchecksec_path
.lower().endswith(".exe"):
36 cmd
= [wine
, winchecksec_path
]
38 cmd
= [winchecksec_path
]
41 result
= subprocess
.check_output(cmd
+ ["-j", binary_path
], universal_newlines
=True)
43 except subprocess
.CalledProcessError
as e
:
45 "TEST-UNEXPECTED-FAIL | autowinchecksec.py | Winchecksec returned error code %d:\n%s"
46 % (e
.returncode
, e
.output
)
51 result
= json
.loads(result
)
63 if buildconfig
.substs
["CPU_ARCH"] == "x86":
72 failed
= [c
for c
in checks
if result
.get(c
) is False]
76 "TEST-UNEXPECTED-FAIL | autowinchecksec.py | Winchecksec reported %d error(s) for %s"
77 % (len(failed
), binary_path
)
80 "TEST-UNEXPECTED-FAIL | autowinchecksec.py | The following check(s) failed: %s"
85 print("TEST-PASS | autowinchecksec.py | %s succeeded" % binary_path
)