[11725] | 1 | /* $Id: hardenedmain.cpp 72247 2018-05-17 17:28:18Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
[52722] | 3 | * VBox Qt GUI - Hardened main().
|
---|
[11725] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[69500] | 7 | * Copyright (C) 2008-2017 Oracle Corporation
|
---|
[11725] | 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 |
|
---|
[49892] | 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 |
|
---|
[11725] | 42 | int main(int argc, char **argv, char **envp)
|
---|
| 43 | {
|
---|
[52902] | 44 | /* First check whether we're about to start a VM: */
|
---|
[52894] | 45 | bool fStartVM = false;
|
---|
[52902] | 46 | /* In separate process: */
|
---|
| 47 | bool fSeparateProcess = false;
|
---|
| 48 | for (int i = 1; i < argc && !(fStartVM && fSeparateProcess); ++i)
|
---|
[52894] | 49 | {
|
---|
[24252] | 50 | /* NOTE: the check here must match the corresponding check for the
|
---|
| 51 | * options to start a VM in main.cpp and VBoxGlobal.cpp exactly,
|
---|
| 52 | * otherwise there will be weird error messages. */
|
---|
[49892] | 53 | if ( !MyStrCmp(argv[i], "--startvm")
|
---|
| 54 | || !MyStrCmp(argv[i], "-startvm"))
|
---|
[11725] | 55 | {
|
---|
[52894] | 56 | fStartVM = true;
|
---|
[11725] | 57 | }
|
---|
[52894] | 58 | else if ( !MyStrCmp(argv[i], "--separate")
|
---|
| 59 | || !MyStrCmp(argv[i], "-separate"))
|
---|
| 60 | {
|
---|
[52902] | 61 | fSeparateProcess = true;
|
---|
[52894] | 62 | }
|
---|
| 63 | }
|
---|
[11725] | 64 |
|
---|
[52902] | 65 | uint32_t fFlags = (fStartVM && !fSeparateProcess) ? 0 : SUPSECMAIN_FLAGS_DONT_OPEN_DEV;
|
---|
[52894] | 66 |
|
---|
[72247] | 67 | #ifndef VBOX_GUI_WITH_SHARED_LIBRARY
|
---|
| 68 | # ifdef VBOX_RUNTIME_UI
|
---|
[56817] | 69 | return SUPR3HardenedMain("VirtualBoxVM",
|
---|
| 70 | fFlags | SUPSECMAIN_FLAGS_TRUSTED_ERROR | SUPSECMAIN_FLAGS_OSX_VM_APP,
|
---|
| 71 | argc, argv, envp);
|
---|
[72247] | 72 | # else
|
---|
| 73 | return SUPR3HardenedMain("VirtualBox",
|
---|
| 74 | fFlags | SUPSECMAIN_FLAGS_TRUSTED_ERROR,
|
---|
| 75 | argc, argv, envp);
|
---|
| 76 | # endif
|
---|
[56817] | 77 | #else
|
---|
[72247] | 78 | return SUPR3HardenedMain("VirtualBoxVM",
|
---|
| 79 | fFlags | SUPSECMAIN_FLAGS_TRUSTED_ERROR,
|
---|
| 80 | argc, argv, envp);
|
---|
[56817] | 81 | #endif
|
---|
[11725] | 82 | }
|
---|
| 83 |
|
---|