1 | /* $Id: tstSupVerify.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * SUP Testcase - Test SUPR3HardenedVerifyPlugIn.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * The contents of this file may alternatively be used under the terms
|
---|
26 | * of the Common Development and Distribution License Version 1.0
|
---|
27 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | * CDDL are applicable instead of those of the GPL.
|
---|
30 | *
|
---|
31 | * You may elect to license modified versions of this file under the
|
---|
32 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | *
|
---|
34 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | */
|
---|
36 |
|
---|
37 |
|
---|
38 | /*********************************************************************************************************************************
|
---|
39 | * Header Files *
|
---|
40 | *********************************************************************************************************************************/
|
---|
41 | #include <VBox/sup.h>
|
---|
42 | #include <iprt/errcore.h>
|
---|
43 |
|
---|
44 | #include <iprt/getopt.h>
|
---|
45 | #include <iprt/initterm.h>
|
---|
46 | #include <iprt/mem.h>
|
---|
47 | #include <iprt/message.h>
|
---|
48 | #include <iprt/path.h>
|
---|
49 | #include <iprt/stream.h>
|
---|
50 |
|
---|
51 |
|
---|
52 | //#define DYNAMIC
|
---|
53 | #ifdef DYNAMIC
|
---|
54 | # include <iprt/win/windows.h>
|
---|
55 |
|
---|
56 | # define DYNAMIC_IMPORTS() \
|
---|
57 | ONE_IMPORT(RTR3InitExe); \
|
---|
58 | ONE_IMPORT(RTMsgInitFailure); \
|
---|
59 | ONE_IMPORT(RTGetOpt); \
|
---|
60 | ONE_IMPORT(RTGetOptInit); \
|
---|
61 | ONE_IMPORT(RTGetOptPrintError); \
|
---|
62 | ONE_IMPORT(RTMsgError); \
|
---|
63 | ONE_IMPORT(RTMsgErrorExit); \
|
---|
64 | ONE_IMPORT(RTMsgInfo); \
|
---|
65 | ONE_IMPORT(RTPrintf); \
|
---|
66 | ONE_IMPORT(SUPR3HardenedVerifyInit); \
|
---|
67 | ONE_IMPORT(SUPR3HardenedVerifyPlugIn)
|
---|
68 |
|
---|
69 | # define ONE_IMPORT(a_fnName) static decltype(a_fnName) *g_pfn##a_fnName
|
---|
70 | DYNAMIC_IMPORTS();
|
---|
71 | # undef ONE_IMPORT
|
---|
72 |
|
---|
73 | static void resolve(void)
|
---|
74 | {
|
---|
75 | HMODULE hmod = LoadLibrary("VBoxRT.dll");
|
---|
76 | DWORD cbWritten = 0;
|
---|
77 |
|
---|
78 | # define ONE_IMPORT(a_fnName) do { \
|
---|
79 | g_pfn##a_fnName = (decltype(a_fnName) *)GetProcAddress(hmod, #a_fnName); \
|
---|
80 | if (!g_pfn##a_fnName) \
|
---|
81 | WriteFile(GetStdHandle(STD_ERROR_HANDLE), RT_STR_TUPLE("Failed to resolve: " #a_fnName "\r\n"), &cbWritten, NULL); \
|
---|
82 | } while (0)
|
---|
83 | DYNAMIC_IMPORTS();
|
---|
84 | # undef ONE_IMPORT
|
---|
85 | }
|
---|
86 |
|
---|
87 | #define RTR3InitExe g_pfnRTR3InitExe
|
---|
88 | #define RTMsgInitFailure g_pfnRTMsgInitFailure
|
---|
89 | #define RTGetOpt g_pfnRTGetOpt
|
---|
90 | #define RTGetOptInit g_pfnRTGetOptInit
|
---|
91 | #define RTGetOptPrintError g_pfnRTGetOptPrintError
|
---|
92 | #define RTMsgError g_pfnRTMsgError
|
---|
93 | #define RTMsgErrorExit g_pfnRTMsgErrorExit
|
---|
94 | #define RTMsgInfo g_pfnRTMsgInfo
|
---|
95 | #define RTPrintf g_pfnRTPrintf
|
---|
96 | #define SUPR3HardenedVerifyInit g_pfnSUPR3HardenedVerifyInit
|
---|
97 | #define SUPR3HardenedVerifyPlugIn g_pfnSUPR3HardenedVerifyPlugIn
|
---|
98 |
|
---|
99 | #endif /* DYNAMIC */
|
---|
100 |
|
---|
101 | int main(int argc, char **argv)
|
---|
102 | {
|
---|
103 | /*
|
---|
104 | * Init.
|
---|
105 | */
|
---|
106 | #ifdef DYNAMIC
|
---|
107 | resolve();
|
---|
108 | #endif
|
---|
109 | int rc = RTR3InitExe(argc, &argv, 0);
|
---|
110 | if (RT_FAILURE(rc))
|
---|
111 | return RTMsgInitFailure(rc);
|
---|
112 | rc = SUPR3HardenedVerifyInit();
|
---|
113 | if (RT_FAILURE(rc))
|
---|
114 | return RTMsgErrorExit(RTEXITCODE_FAILURE, "SUPR3HardenedVerifyInit failed: %Rrc", rc);
|
---|
115 |
|
---|
116 | /*
|
---|
117 | * Process arguments.
|
---|
118 | */
|
---|
119 | static const RTGETOPTDEF s_aOptions[] =
|
---|
120 | {
|
---|
121 | { "--dummy", 'd', RTGETOPT_REQ_NOTHING },
|
---|
122 | };
|
---|
123 |
|
---|
124 | //bool fKeepLoaded = false;
|
---|
125 |
|
---|
126 | int ch;
|
---|
127 | RTGETOPTUNION ValueUnion;
|
---|
128 | RTGETOPTSTATE GetState;
|
---|
129 | RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, 0);
|
---|
130 | while ((ch = RTGetOpt(&GetState, &ValueUnion)))
|
---|
131 | {
|
---|
132 | switch (ch)
|
---|
133 | {
|
---|
134 | case VINF_GETOPT_NOT_OPTION:
|
---|
135 | {
|
---|
136 | RTERRINFOSTATIC ErrInfo;
|
---|
137 | RTErrInfoInitStatic(&ErrInfo);
|
---|
138 | rc = SUPR3HardenedVerifyPlugIn(ValueUnion.psz, &ErrInfo.Core);
|
---|
139 | if (RT_SUCCESS(rc))
|
---|
140 | RTMsgInfo("SUPR3HardenedVerifyPlugIn: %Rrc for '%s'\n", rc, ValueUnion.psz);
|
---|
141 | else
|
---|
142 | RTMsgError("SUPR3HardenedVerifyPlugIn: %Rrc for '%s' ErrInfo: %s\n",
|
---|
143 | rc, ValueUnion.psz, ErrInfo.Core.pszMsg);
|
---|
144 | break;
|
---|
145 | }
|
---|
146 |
|
---|
147 | case 'h':
|
---|
148 | RTPrintf("%s [dll1 [dll2...]]\n", argv[0]);
|
---|
149 | return 1;
|
---|
150 |
|
---|
151 | case 'V':
|
---|
152 | RTPrintf("$Revision: 98103 $\n");
|
---|
153 | return 0;
|
---|
154 |
|
---|
155 | default:
|
---|
156 | return RTGetOptPrintError(ch, &ValueUnion);
|
---|
157 | }
|
---|
158 | }
|
---|
159 |
|
---|
160 | return 0;
|
---|
161 | }
|
---|
162 |
|
---|