1 | /* $Id: hardenedmain.cpp 93115 2022-01-01 11:31:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - Hardened main().
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2008-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 |
|
---|
18 | #include <VBox/sup.h>
|
---|
19 |
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * No CRT on windows, so cook our own strcmp.
|
---|
23 | *
|
---|
24 | * @returns See man strcmp.
|
---|
25 | * @param psz1 The first string.
|
---|
26 | * @param psz2 The second string.
|
---|
27 | */
|
---|
28 | static int MyStrCmp(const char *psz1, const char *psz2)
|
---|
29 | {
|
---|
30 | for (;;)
|
---|
31 | {
|
---|
32 | char ch1 = *psz1++;
|
---|
33 | char ch2 = *psz2++;
|
---|
34 | if (ch1 != ch2)
|
---|
35 | return ch1 < ch2 ? -1 : 1;
|
---|
36 | if (!ch1)
|
---|
37 | return 0;
|
---|
38 | }
|
---|
39 | }
|
---|
40 |
|
---|
41 |
|
---|
42 | int main(int argc, char **argv, char **envp)
|
---|
43 | {
|
---|
44 | /*
|
---|
45 | * Do partial option parsing to see if we're starting a VM and how we're
|
---|
46 | * going about that.
|
---|
47 | *
|
---|
48 | * Note! This must must match the corresponding parsing in main.cpp and
|
---|
49 | * UICommon.cpp exactly, otherwise there will be weird error messages.
|
---|
50 | *
|
---|
51 | * Note! ASSUMES that argv is in an ASCII compatible codeset.
|
---|
52 | */
|
---|
53 | unsigned cOptionsLeft = 4;
|
---|
54 | bool fStartVM = false;
|
---|
55 | bool fSeparateProcess = false;
|
---|
56 | bool fExecuteAllInIem = false;
|
---|
57 | bool fDriverless = false;
|
---|
58 | for (int i = 1; i < argc && cOptionsLeft > 0; ++i)
|
---|
59 | {
|
---|
60 | if ( !MyStrCmp(argv[i], "--startvm")
|
---|
61 | || !MyStrCmp(argv[i], "-startvm"))
|
---|
62 | {
|
---|
63 | cOptionsLeft -= fStartVM == false;
|
---|
64 | fStartVM = true;
|
---|
65 | i++;
|
---|
66 | }
|
---|
67 | else if ( !MyStrCmp(argv[i], "--separate")
|
---|
68 | || !MyStrCmp(argv[i], "-separate"))
|
---|
69 | {
|
---|
70 | cOptionsLeft -= fSeparateProcess == false;
|
---|
71 | fSeparateProcess = true;
|
---|
72 | }
|
---|
73 | else if (!MyStrCmp(argv[i], "--execute-all-in-iem"))
|
---|
74 | {
|
---|
75 | cOptionsLeft -= fExecuteAllInIem == false;
|
---|
76 | fExecuteAllInIem = true;
|
---|
77 | }
|
---|
78 | else if (!MyStrCmp(argv[i], "--driverless"))
|
---|
79 | {
|
---|
80 | cOptionsLeft -= fDriverless == false;
|
---|
81 | fDriverless = true;
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|
85 | /*
|
---|
86 | * Convert the command line options to SUPSECMAIN_FLAGS_XXX flags
|
---|
87 | * and call the hardened main code.
|
---|
88 | */
|
---|
89 | uint32_t fFlags = SUPSECMAIN_FLAGS_TRUSTED_ERROR;
|
---|
90 | #ifdef RT_OS_DARWIN
|
---|
91 | fFlags |= SUPSECMAIN_FLAGS_LOC_OSX_HLP_APP;
|
---|
92 | #endif
|
---|
93 | if (!fStartVM || fSeparateProcess)
|
---|
94 | fFlags |= SUPSECMAIN_FLAGS_DONT_OPEN_DEV;
|
---|
95 | else
|
---|
96 | {
|
---|
97 | if (fExecuteAllInIem)
|
---|
98 | fFlags |= SUPSECMAIN_FLAGS_DRIVERLESS_IEM_ALLOWED;
|
---|
99 | #ifdef VBOX_WITH_DRIVERLESS_NEM_FALLBACK
|
---|
100 | else
|
---|
101 | fFlags |= SUPSECMAIN_FLAGS_DRIVERLESS_NEM_FALLBACK;
|
---|
102 | #endif
|
---|
103 | if (fDriverless)
|
---|
104 | fFlags |= SUPSECMAIN_FLAGS_DRIVERLESS;
|
---|
105 | }
|
---|
106 |
|
---|
107 | return SUPR3HardenedMain("VirtualBoxVM", fFlags, argc, argv, envp);
|
---|
108 | }
|
---|
109 |
|
---|