1 | @echo off
|
---|
2 | rem $Id: UnpackBlessedDrivers.cmd 72047 2018-04-27 00:07:20Z vboxsync $
|
---|
3 | rem rem @file
|
---|
4 | rem Windows NT batch script for unpacking drivers after being signed.
|
---|
5 | rem
|
---|
6 |
|
---|
7 | rem
|
---|
8 | rem Copyright (C) 2018 Oracle Corporation
|
---|
9 | rem
|
---|
10 | rem This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | rem available from http://www.virtualbox.org. This file is free software;
|
---|
12 | rem you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | rem General Public License (GPL) as published by the Free Software
|
---|
14 | rem Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | rem VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | rem hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | rem
|
---|
18 |
|
---|
19 |
|
---|
20 | setlocal ENABLEEXTENSIONS
|
---|
21 | setlocal
|
---|
22 |
|
---|
23 | rem
|
---|
24 | rem Globals and Check for environment variables we need.
|
---|
25 | rem
|
---|
26 | if ".%KBUILD_DEVTOOLS%" == "." (echo KBUILD_DEVTOOLS is not set & goto end_failed)
|
---|
27 | set _MY_DRIVER_BASE_NAMES=VBoxDrv VBoxNetAdp6 VBoxNetLwf VBoxUSB VBoxUSBMon
|
---|
28 | set _MY_DRIVER_BASE_NAMES=VBoxDrv VBoxNetAdp6 VBoxNetLwf VBoxUSB VBoxUSBMon
|
---|
29 | set _MY_UNZIP=%KBUILD_DEVTOOLS%\win.x86\bin\unzip.exe
|
---|
30 | if not exist "%_MY_UNZIP%" (echo "%_MY_UNZIP%" does not exist & goto end_failed)
|
---|
31 |
|
---|
32 | rem
|
---|
33 | rem Parse arguments.
|
---|
34 | rem
|
---|
35 | set _MY_OPT_BINDIR=..\bin
|
---|
36 | set _MY_OPT_INPUT=
|
---|
37 | set _MY_OPT_SIGN_CAT=1
|
---|
38 |
|
---|
39 | :argument_loop
|
---|
40 | if ".%1" == "." goto no_more_arguments
|
---|
41 |
|
---|
42 | if ".%1" == ".-h" goto opt_h
|
---|
43 | if ".%1" == ".-?" goto opt_h
|
---|
44 | if ".%1" == "./h" goto opt_h
|
---|
45 | if ".%1" == "./H" goto opt_h
|
---|
46 | if ".%1" == "./?" goto opt_h
|
---|
47 | if ".%1" == ".-help" goto opt_h
|
---|
48 | if ".%1" == ".--help" goto opt_h
|
---|
49 |
|
---|
50 | if ".%1" == ".-b" goto opt_b
|
---|
51 | if ".%1" == ".--bindir" goto opt_b
|
---|
52 | if ".%1" == ".-i" goto opt_i
|
---|
53 | if ".%1" == ".--input" goto opt_i
|
---|
54 | if ".%1" == ".-n" goto opt_n
|
---|
55 | if ".%1" == ".--no-sign-cat" goto opt_n
|
---|
56 | echo syntax error: Unknown option: %1
|
---|
57 | echo Try --help to list valid options.
|
---|
58 | goto end_failed
|
---|
59 |
|
---|
60 | :argument_loop_next_with_value
|
---|
61 | shift
|
---|
62 | shift
|
---|
63 | goto argument_loop
|
---|
64 |
|
---|
65 | :opt_b
|
---|
66 | if ".%~2" == "." goto syntax_error_missing_value
|
---|
67 | set _MY_OPT_BINDIR=%~2
|
---|
68 | goto argument_loop_next_with_value
|
---|
69 |
|
---|
70 | :opt_h
|
---|
71 | echo This script unpacks the zip-file containing the blessed driver files from
|
---|
72 | echo Microsoft, replacing original files in the bin directory. The catalog files
|
---|
73 | echo will be signed again and the Microsoft signature merged with ours.
|
---|
74 | echo .
|
---|
75 | echo Usage: UnpackBlessedDrivers.cmd [-b bindir] [-n/--no-sign-cat] -i input.zip
|
---|
76 | echo .
|
---|
77 | echo Warning! This script should normally be invoked from the repack directory
|
---|
78 | goto end_failed
|
---|
79 |
|
---|
80 | :opt_i
|
---|
81 | if ".%~2" == "." goto syntax_error_missing_value
|
---|
82 | set _MY_OPT_INPUT=%~2
|
---|
83 | goto argument_loop_next_with_value
|
---|
84 |
|
---|
85 | :opt_n
|
---|
86 | set _MY_OPT_SIGN_CAT=0
|
---|
87 | shift
|
---|
88 | goto argument_loop
|
---|
89 |
|
---|
90 | :syntax_error_missing_value
|
---|
91 | echo syntax error: missing or empty option value after %1
|
---|
92 | goto end_failed
|
---|
93 |
|
---|
94 | :error_bindir_does_not_exist
|
---|
95 | echo syntax error: Specified BIN directory does not exist: "%_MY_OPT_BINDIR%"
|
---|
96 | goto end_failed
|
---|
97 |
|
---|
98 | :error_input_not_found
|
---|
99 | echo error: Input file does not exist: "%_MY_OPT_INPUT%"
|
---|
100 | goto end_failed
|
---|
101 |
|
---|
102 | :no_more_arguments
|
---|
103 | rem validate specified options
|
---|
104 | if not exist "%_MY_OPT_BINDIR%" goto error_bindir_does_not_exist
|
---|
105 |
|
---|
106 | rem figure defaults here: if ".%_MY_OPT_INPUT%" == "." if exist "%_MY_OPT_BINDIR%\x86" set _MY_OPT_INPUT=VBoxDrivers-amd64.cab
|
---|
107 | rem figure defaults here: if ".%_MY_OPT_INPUT%" == "." set _MY_OPT_INPUT=VBoxDrivers-x86.cab
|
---|
108 | if not exist "%_MY_OPT_INPUT%" goto error_input_not_found
|
---|
109 |
|
---|
110 | rem
|
---|
111 | rem Unpack the stuff.
|
---|
112 | rem We ignore error level 1 here as that is what unzip returns on warning (slashes).
|
---|
113 | rem
|
---|
114 | "%_MY_UNZIP%" -o -j "%_MY_OPT_INPUT%" -d "%_MY_OPT_BINDIR%" && goto unzip_okay
|
---|
115 | if NOT ERRORLEVEL 1 goto end_failed
|
---|
116 | :unzip_okay
|
---|
117 |
|
---|
118 | rem
|
---|
119 | rem Verify it against the PreW10 catalog files we saved.
|
---|
120 | rem
|
---|
121 | set _MY_SIGNTOOL=%KBUILD_DEVTOOLS%\win.x86\sdk\v8.1\bin\x86\signtool.exe
|
---|
122 | if not exist "%_MY_SIGNTOOL%" set _MY_SIGNTOOL=%KBUILD_DEVTOOLS%\win.x86\selfsign\r3\signtool.exe
|
---|
123 |
|
---|
124 | for %%d in (%_MY_DRIVER_BASE_NAMES%) do (
|
---|
125 | @echo * Verifying %%d against %%d.cat...
|
---|
126 | "%_MY_SIGNTOOL%" verify /kp /c "%_MY_OPT_BINDIR%\%%d.cat" "%_MY_OPT_BINDIR%\%%d.inf" || goto end_failed
|
---|
127 | "%_MY_SIGNTOOL%" verify /kp /c "%_MY_OPT_BINDIR%\%%d.cat" "%_MY_OPT_BINDIR%\%%d.sys" || goto end_failed
|
---|
128 | @echo * Verifying %%d against %%d-PreW10.cat...
|
---|
129 | "%_MY_SIGNTOOL%" verify /kp /c "%_MY_OPT_BINDIR%\%%d-PreW10.cat" "%_MY_OPT_BINDIR%\%%d.inf" || goto end_failed
|
---|
130 | "%_MY_SIGNTOOL%" verify /kp /c "%_MY_OPT_BINDIR%\%%d-PreW10.cat" "%_MY_OPT_BINDIR%\%%d.sys" || goto end_failed
|
---|
131 | )
|
---|
132 |
|
---|
133 |
|
---|
134 | rem
|
---|
135 | rem Modify the catalog signatures.
|
---|
136 | rem
|
---|
137 | for %%d in (%_MY_DRIVER_BASE_NAMES%) do (
|
---|
138 | copy /y "%_MY_OPT_BINDIR%\%%d.cat" "%_MY_OPT_BINDIR%\%%d.cat.ms" || goto end_failed
|
---|
139 | call sign-dual.cmd "%_MY_OPT_BINDIR%\%%d.cat" || goto end_failed
|
---|
140 | "%_MY_OPT_BINDIR%\tools\RTSignTool.exe" add-nested-exe-signature -v "%_MY_OPT_BINDIR%\%%d.cat" "%_MY_OPT_BINDIR%\%%d.cat.ms" || goto end_failed
|
---|
141 | )
|
---|
142 |
|
---|
143 | goto end
|
---|
144 |
|
---|
145 | :end_failed
|
---|
146 | @echo failed (%ERRORLEVEL%)
|
---|
147 | @endlocal
|
---|
148 | @endlocal
|
---|
149 | @exit /b 1
|
---|
150 |
|
---|
151 | :end
|
---|
152 | @endlocal
|
---|
153 | @endlocal
|
---|
154 |
|
---|