1 | @echo off
|
---|
2 | rem $Id: UnpackBlessedDrivers.cmd 106061 2024-09-16 14:03:52Z 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-2024 Oracle and/or its affiliates.
|
---|
9 | rem
|
---|
10 | rem This file is part of VirtualBox base platform packages, as
|
---|
11 | rem available from https://www.virtualbox.org.
|
---|
12 | rem
|
---|
13 | rem This program is free software; you can redistribute it and/or
|
---|
14 | rem modify it under the terms of the GNU General Public License
|
---|
15 | rem as published by the Free Software Foundation, in version 3 of the
|
---|
16 | rem License.
|
---|
17 | rem
|
---|
18 | rem This program is distributed in the hope that it will be useful, but
|
---|
19 | rem WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
20 | rem MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
21 | rem General Public License for more details.
|
---|
22 | rem
|
---|
23 | rem You should have received a copy of the GNU General Public License
|
---|
24 | rem along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
25 | rem
|
---|
26 | rem SPDX-License-Identifier: GPL-3.0-only
|
---|
27 | rem
|
---|
28 |
|
---|
29 |
|
---|
30 | setlocal ENABLEEXTENSIONS
|
---|
31 | setlocal
|
---|
32 |
|
---|
33 | rem
|
---|
34 | rem Globals and Check for environment variables we need.
|
---|
35 | rem
|
---|
36 | if ".%KBUILD_DEVTOOLS%" == "." (echo KBUILD_DEVTOOLS is not set & goto end_failed)
|
---|
37 | set _MY_DRIVER_BASE_NAMES=VBoxSup VBoxNetAdp6 VBoxNetLwf VBoxUSB VBoxUSBMon
|
---|
38 | set _MY_GUEST_ADDITIONS_DRIVER_BASE_NAMES=VBoxVideo VBoxWddm VBoxGuest VBoxMouse
|
---|
39 | set _MY_UNZIP=%KBUILD_DEVTOOLS%\win.x86\bin\unzip.exe
|
---|
40 | if not exist "%_MY_UNZIP%" (echo "%_MY_UNZIP%" does not exist & goto end_failed)
|
---|
41 |
|
---|
42 | rem
|
---|
43 | rem Parse arguments.
|
---|
44 | rem
|
---|
45 | set _MY_OPT_BINDIR=..\bin
|
---|
46 | set _MY_OPT_INPUT=
|
---|
47 | set _MY_OPT_SIGN_CAT=1
|
---|
48 | set _MY_OPT_SIGN_VERIFY=1
|
---|
49 |
|
---|
50 | :argument_loop
|
---|
51 | if ".%1" == "." goto no_more_arguments
|
---|
52 |
|
---|
53 | if ".%1" == ".-h" goto opt_h
|
---|
54 | if ".%1" == ".-?" goto opt_h
|
---|
55 | if ".%1" == "./h" goto opt_h
|
---|
56 | if ".%1" == "./H" goto opt_h
|
---|
57 | if ".%1" == "./?" goto opt_h
|
---|
58 | if ".%1" == ".-help" goto opt_h
|
---|
59 | if ".%1" == ".--help" goto opt_h
|
---|
60 |
|
---|
61 | if ".%1" == ".-b" goto opt_b
|
---|
62 | if ".%1" == ".--bindir" goto opt_b
|
---|
63 | if ".%1" == ".-i" goto opt_i
|
---|
64 | if ".%1" == ".--input" goto opt_i
|
---|
65 | if ".%1" == ".-n" goto opt_n
|
---|
66 | if ".%1" == ".--no-sign-cat" goto opt_n
|
---|
67 | if ".%1" == ".-v" goto opt_v
|
---|
68 | if ".%1" == ".--no-sign-verify" goto opt_v
|
---|
69 | if ".%1" == ".--guest-additions" goto opt_ga
|
---|
70 |
|
---|
71 | echo syntax error: Unknown option: %1
|
---|
72 | echo Try --help to list valid options.
|
---|
73 | goto end_failed
|
---|
74 |
|
---|
75 | :argument_loop_next_with_value
|
---|
76 | shift
|
---|
77 | shift
|
---|
78 | goto argument_loop
|
---|
79 |
|
---|
80 | :opt_b
|
---|
81 | if ".%~2" == "." goto syntax_error_missing_value
|
---|
82 | set _MY_OPT_BINDIR=%~2
|
---|
83 | goto argument_loop_next_with_value
|
---|
84 |
|
---|
85 | :opt_h
|
---|
86 | echo This script unpacks the zip-file containing the blessed driver files from
|
---|
87 | echo Microsoft, replacing original files in the bin directory. The catalog files
|
---|
88 | echo will be signed again and the Microsoft signature merged with ours.
|
---|
89 | echo .
|
---|
90 | echo Usage: UnpackBlessedDrivers.cmd [-b bindir] [-n/--no-sign-cat] [-v/--no-sign-verify] -i input.zip
|
---|
91 | echo .
|
---|
92 | echo Warning! This script should normally be invoked from the repack directory
|
---|
93 | goto end_failed
|
---|
94 |
|
---|
95 | :opt_i
|
---|
96 | if ".%~2" == "." goto syntax_error_missing_value
|
---|
97 | set _MY_OPT_INPUT=%~2
|
---|
98 | goto argument_loop_next_with_value
|
---|
99 |
|
---|
100 | :opt_n
|
---|
101 | set _MY_OPT_SIGN_CAT=0
|
---|
102 | shift
|
---|
103 | goto argument_loop
|
---|
104 |
|
---|
105 | :opt_v
|
---|
106 | set _MY_OPT_SIGN_VERIFY=0
|
---|
107 | shift
|
---|
108 | goto argument_loop
|
---|
109 |
|
---|
110 | :opt_ga
|
---|
111 | set _MY_DRIVER_BASE_NAMES=%_MY_GUEST_ADDITIONS_DRIVER_BASE_NAMES%
|
---|
112 | shift
|
---|
113 | goto argument_loop
|
---|
114 |
|
---|
115 | :syntax_error_missing_value
|
---|
116 | echo syntax error: missing or empty option value after %1
|
---|
117 | goto end_failed
|
---|
118 |
|
---|
119 | :error_bindir_does_not_exist
|
---|
120 | echo syntax error: Specified BIN directory does not exist: "%_MY_OPT_BINDIR%"
|
---|
121 | goto end_failed
|
---|
122 |
|
---|
123 | :error_input_not_found
|
---|
124 | echo error: Input file does not exist: "%_MY_OPT_INPUT%"
|
---|
125 | goto end_failed
|
---|
126 |
|
---|
127 | :no_more_arguments
|
---|
128 | rem validate specified options
|
---|
129 | if not exist "%_MY_OPT_BINDIR%" goto error_bindir_does_not_exist
|
---|
130 |
|
---|
131 | rem figure defaults here: if ".%_MY_OPT_INPUT%" == "." if exist "%_MY_OPT_BINDIR%\x86" set _MY_OPT_INPUT=VBoxDrivers-amd64.cab
|
---|
132 | rem figure defaults here: if ".%_MY_OPT_INPUT%" == "." set _MY_OPT_INPUT=VBoxDrivers-x86.cab
|
---|
133 | if not exist "%_MY_OPT_INPUT%" goto error_input_not_found
|
---|
134 |
|
---|
135 | rem
|
---|
136 | rem Unpack the stuff.
|
---|
137 | rem We ignore error level 1 here as that is what unzip returns on warning (slashes).
|
---|
138 | rem
|
---|
139 | "%_MY_UNZIP%" -o -j "%_MY_OPT_INPUT%" -d "%_MY_OPT_BINDIR%" && goto unzip_okay
|
---|
140 | if NOT ERRORLEVEL 1 goto end_failed
|
---|
141 | :unzip_okay
|
---|
142 |
|
---|
143 | if ".%_MY_OPT_SIGN_VERIFY%" == ".0" goto no_sign_verify
|
---|
144 | rem
|
---|
145 | rem Verify it against the PreW10 catalog files we saved.
|
---|
146 | rem
|
---|
147 | set _MY_SIGNTOOL=%KBUILD_DEVTOOLS%\win.x86\sdk\v8.1\bin\x86\signtool.exe
|
---|
148 | if not exist "%_MY_SIGNTOOL%" set _MY_SIGNTOOL=%KBUILD_DEVTOOLS%\win.x86\selfsign\r3\signtool.exe
|
---|
149 |
|
---|
150 | for %%d in (%_MY_DRIVER_BASE_NAMES%) do (
|
---|
151 | @echo * Verifying %%d against %%d.cat...
|
---|
152 | "%_MY_SIGNTOOL%" verify /kp /c "%_MY_OPT_BINDIR%\%%d.cat" "%_MY_OPT_BINDIR%\%%d.inf" || goto end_failed
|
---|
153 | "%_MY_SIGNTOOL%" verify /kp /c "%_MY_OPT_BINDIR%\%%d.cat" "%_MY_OPT_BINDIR%\%%d.sys" || goto end_failed
|
---|
154 | rem The following is disabled because signtool.exe does not accept these
|
---|
155 | rem signatures because it fails to look at the timestamp. Eventually should
|
---|
156 | rem replace this by doing out own signature verification in RTSignTool.
|
---|
157 | rem @echo * Verifying %%d against %%d-PreW10.cat...
|
---|
158 | rem "%_MY_SIGNTOOL%" verify /kp /c "%_MY_OPT_BINDIR%\%%d-PreW10.cat" "%_MY_OPT_BINDIR%\%%d.inf" || goto end_failed
|
---|
159 | rem "%_MY_SIGNTOOL%" verify /kp /c "%_MY_OPT_BINDIR%\%%d-PreW10.cat" "%_MY_OPT_BINDIR%\%%d.sys" || goto end_failed
|
---|
160 | )
|
---|
161 | :no_sign_verify
|
---|
162 |
|
---|
163 | rem
|
---|
164 | rem Modify the catalog signatures.
|
---|
165 | rem
|
---|
166 | if "%_MY_OPT_SIGN_CAT%" == "0" goto no_sign_cat
|
---|
167 | set PATH=%PATH%;%_MY_OPT_BINDIR%
|
---|
168 | for %%d in (%_MY_DRIVER_BASE_NAMES%) do (
|
---|
169 | copy /y "%_MY_OPT_BINDIR%\%%d.cat" "%_MY_OPT_BINDIR%\%%d.cat.ms" || goto end_failed
|
---|
170 | call sign-dual.cmd "%_MY_OPT_BINDIR%\%%d.cat" || goto end_failed
|
---|
171 | "%_MY_OPT_BINDIR%\tools\RTSignTool.exe" add-nested-cat-signature -v "%_MY_OPT_BINDIR%\%%d.cat" "%_MY_OPT_BINDIR%\%%d.cat.ms" || goto end_failed
|
---|
172 | )
|
---|
173 | :no_sign_cat
|
---|
174 | goto end
|
---|
175 |
|
---|
176 | :end_failed
|
---|
177 | @echo failed (%ERRORLEVEL%)
|
---|
178 | @endlocal
|
---|
179 | @endlocal
|
---|
180 | @exit /b 1
|
---|
181 |
|
---|
182 | :end
|
---|
183 | @endlocal
|
---|
184 | @endlocal
|
---|
185 |
|
---|