VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/testcase/tstSupVerify.cpp@ 93931

Last change on this file since 93931 was 93115, checked in by vboxsync, 3 years ago

scm --update-copyright-year

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette