1 | /* $Id: hardenedmain.cpp 82968 2020-02-04 10:35:17Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - Hardened main().
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2008-2020 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 | /* First check whether we're about to start a VM: */
|
---|
45 | bool fStartVM = false;
|
---|
46 | /* In separate process: */
|
---|
47 | bool fSeparateProcess = false;
|
---|
48 | for (int i = 1; i < argc && !(fStartVM && fSeparateProcess); ++i)
|
---|
49 | {
|
---|
50 | /* NOTE: the check here must match the corresponding check for the
|
---|
51 | * options to start a VM in main.cpp and UICommon.cpp exactly,
|
---|
52 | * otherwise there will be weird error messages. */
|
---|
53 | if ( !MyStrCmp(argv[i], "--startvm")
|
---|
54 | || !MyStrCmp(argv[i], "-startvm"))
|
---|
55 | {
|
---|
56 | fStartVM = true;
|
---|
57 | }
|
---|
58 | else if ( !MyStrCmp(argv[i], "--separate")
|
---|
59 | || !MyStrCmp(argv[i], "-separate"))
|
---|
60 | {
|
---|
61 | fSeparateProcess = true;
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
65 | uint32_t fFlags = (fStartVM && !fSeparateProcess) ? 0 : SUPSECMAIN_FLAGS_DONT_OPEN_DEV;
|
---|
66 |
|
---|
67 | return SUPR3HardenedMain("VirtualBoxVM",
|
---|
68 | fFlags | SUPSECMAIN_FLAGS_TRUSTED_ERROR,
|
---|
69 | argc, argv, envp);
|
---|
70 | }
|
---|
71 |
|
---|