diff options
Diffstat (limited to 'src/VBox/Additions/common/VBoxGuest/win')
4 files changed, 423 insertions, 0 deletions
diff --git a/src/VBox/Additions/common/VBoxGuest/win/Makefile.kup b/src/VBox/Additions/common/VBoxGuest/win/Makefile.kup new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/src/VBox/Additions/common/VBoxGuest/win/Makefile.kup diff --git a/src/VBox/Additions/common/VBoxGuest/win/VBoxGuest.inf b/src/VBox/Additions/common/VBoxGuest/win/VBoxGuest.inf new file mode 100644 index 00000000..c8dca3f8 --- /dev/null +++ b/src/VBox/Additions/common/VBoxGuest/win/VBoxGuest.inf @@ -0,0 +1,92 @@ +; $Id: VBoxGuest.inf $ +;; @file +; INF file for installing the VirtualBox Windows guest driver. +; + +; +; Copyright (C) 2006-2019 Oracle Corporation +; +; This file is part of VirtualBox Open Source Edition (OSE), as +; available from http://www.virtualbox.org. This file is free software; +; you can redistribute it and/or modify it under the terms of the GNU +; General Public License (GPL) as published by the Free Software +; Foundation, in version 2 as it comes in the "COPYING" file of the +; VirtualBox OSE distribution. VirtualBox OSE is distributed in the +; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. +; +; The contents of this file may alternatively be used under the terms +; of the Common Development and Distribution License Version 1.0 +; (CDDL) only, as it comes in the "COPYING.CDDL" file of the +; VirtualBox OSE distribution, in which case the provisions of the +; CDDL are applicable instead of those of the GPL. +; +; You may elect to license modified versions of this file under the +; terms and conditions of either the GPL or the CDDL or both. +; + +[Version] +Signature="$WINDOWS NT$" +Provider=%ORACLE% +ClassGuid={4D36E97D-E325-11CE-BFC1-08002BE10318} +Class=System +DriverPackageType=PlugAndPlay +;edit-DriverVer=08/26/2008,2.00.0000 +;cat CatalogFile=VBoxGuest.cat + +[SourceDisksNames] +1 = %VBoxGuest.MediaDesc% +2 = %VBoxControl.MediaDesc% +3 = %VBoxTray.MediaDesc% + +[SourceDisksFiles] +VBoxGuest.sys = 1 +VBoxControl.exe = 2 +VBoxTray.exe = 3 + +[DestinationDirs] +DefaultDestDir = 12 ; drivers +VBoxTray_CopyFiles = 11 ; system32 + +[Manufacturer] +;x86 %ORACLE%=VBoxGuest +;amd64 %ORACLE%=VBoxGuest, NTamd64 + +;x86 [VBoxGuest] +;amd64 [VBoxGuest.NTamd64] +%VBoxGuest.DeviceDesc%=VBoxGuest_Install,PCI\VEN_80ee&DEV_cafe + +[VBoxGuest_Install] +CopyFiles = VBoxGuest_CopyFiles, VBoxTray_CopyFiles +AddReg = VBoxTray_Add_Reg + +[VBoxGuest_CopyFiles] +VBoxGuest.sys + +[VBoxTray_CopyFiles] +VBoxTray.exe +VBoxControl.exe + +[VBoxGuest_Install.Services] +AddService = VBoxGuest, 0x00000002, VBoxGuest_ServiceInstallSection +DelService = VBoxTray, 0x00000004 + +[VBoxGuest_ServiceInstallSection] +DisplayName = %VBoxGuest_svcdesc% +ServiceType = 0x00000001 ; kernel driver +StartType = 0x00000000 ; boot start +ErrorControl = 0x00000001 ; normal error handling +LoadOrderGroup = Base +ServiceBinary = %12%\VBoxGuest.sys + +[VBoxTray_Add_Reg] +HKLM, SOFTWARE\Microsoft\Windows\CurrentVersion\Run, VBoxTray, 0x00000000, %11%\VBoxTray.exe + +[ClassInstall32] +; This should fix the error 0xe0000101 (The required section was not found in the INF). + +[Strings] +ORACLE = "Oracle Corporation" +VBoxGuest.DeviceDesc = "VirtualBox Device" +VBoxGuest_svcdesc = "VirtualBox Guest Driver" +VBoxTray_svcdesc = "VirtualBox Guest Tray" + diff --git a/src/VBox/Additions/common/VBoxGuest/win/VBoxGuest.rc b/src/VBox/Additions/common/VBoxGuest/win/VBoxGuest.rc new file mode 100644 index 00000000..abbe33b0 --- /dev/null +++ b/src/VBox/Additions/common/VBoxGuest/win/VBoxGuest.rc @@ -0,0 +1,62 @@ +/* $Id: VBoxGuest.rc $ */ +/** @file + * VBoxGuest - Resource file containing version info and icon. + */ + +/* + * Copyright (C) 2006-2019 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL) only, as it comes in the "COPYING.CDDL" file of the + * VirtualBox OSE distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + */ + +#include <windows.h> +#include <VBox/version.h> + +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +VS_VERSION_INFO VERSIONINFO + FILEVERSION VBOX_RC_FILE_VERSION + PRODUCTVERSION VBOX_RC_FILE_VERSION + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK + FILEFLAGS VBOX_RC_FILE_FLAGS + FILEOS VBOX_RC_FILE_OS + FILETYPE VBOX_RC_TYPE_DLL + FILESUBTYPE VFT2_UNKNOWN +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "FileDescription", "VirtualBox Guest Driver\0" + VALUE "InternalName", "VBoxGuest\0" + VALUE "OriginalFilename", "VBoxGuest.sys\0" + VALUE "CompanyName", VBOX_RC_COMPANY_NAME + VALUE "FileVersion", VBOX_RC_FILE_VERSION_STR + VALUE "LegalCopyright", VBOX_RC_LEGAL_COPYRIGHT + VALUE "ProductName", VBOX_RC_PRODUCT_NAME_GA_STR + VALUE "ProductVersion", VBOX_RC_PRODUCT_VERSION_STR + VBOX_RC_MORE_STRINGS + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END + +// #include <VBoxGuestMsg.rc> diff --git a/src/VBox/Additions/common/VBoxGuest/win/VBoxGuestInst.cpp b/src/VBox/Additions/common/VBoxGuest/win/VBoxGuestInst.cpp new file mode 100644 index 00000000..5b680edb --- /dev/null +++ b/src/VBox/Additions/common/VBoxGuest/win/VBoxGuestInst.cpp @@ -0,0 +1,269 @@ +/* $Id: VBoxGuestInst.cpp $ */ +/** @file + * Small tool to (un)install the VBoxGuest device driver. + */ + +/* + * Copyright (C) 2006-2019 Oracle Corporation + * + * This file is part of VirtualBox Open Source Edition (OSE), as + * available from http://www.virtualbox.org. This file is free software; + * you can redistribute it and/or modify it under the terms of the GNU + * General Public License (GPL) as published by the Free Software + * Foundation, in version 2 as it comes in the "COPYING" file of the + * VirtualBox OSE distribution. VirtualBox OSE is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL) only, as it comes in the "COPYING.CDDL" file of the + * VirtualBox OSE distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + */ + + +/********************************************************************************************************************************* +* Header Files * +*********************************************************************************************************************************/ +#include <iprt/win/windows.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <VBox/VBoxGuest.h> /* for VBOXGUEST_SERVICE_NAME */ +#include <iprt/err.h> + + +//#define TESTMODE + + + +static int installDriver(bool fStartIt) +{ + /* + * Assume it didn't exist, so we'll create the service. + */ + SC_HANDLE hSMgrCreate = OpenSCManager(NULL, NULL, SERVICE_CHANGE_CONFIG); + if (!hSMgrCreate) + { + printf("OpenSCManager(,,create) failed rc=%d\n", GetLastError()); + return -1; + } + + const char *pszSlashName = "\\VBoxGuest.sys"; + char szDriver[MAX_PATH * 2]; + GetCurrentDirectory(MAX_PATH, szDriver); + strcat(szDriver, pszSlashName); + if (GetFileAttributesA(szDriver) == INVALID_FILE_ATTRIBUTES) + { + GetSystemDirectory(szDriver, sizeof(szDriver)); + strcat(strcat(szDriver, "\\drivers"), pszSlashName); + + /* Try FAT name abbreviation. */ + if (GetFileAttributesA(szDriver) == INVALID_FILE_ATTRIBUTES) + { + pszSlashName = "\\VBoxGst.sys"; + GetCurrentDirectory(MAX_PATH, szDriver); + strcat(szDriver, pszSlashName); + if (GetFileAttributesA(szDriver) == INVALID_FILE_ATTRIBUTES) + { + GetSystemDirectory(szDriver, sizeof(szDriver)); + strcat(strcat(szDriver, "\\drivers"), pszSlashName); + + } + } + } + + SC_HANDLE hService = CreateService(hSMgrCreate, + VBOXGUEST_SERVICE_NAME, + "VBoxGuest Support Driver", + SERVICE_QUERY_STATUS | (fStartIt ? SERVICE_START : 0), + SERVICE_KERNEL_DRIVER, + SERVICE_BOOT_START, + SERVICE_ERROR_NORMAL, + szDriver, + "System", + NULL, NULL, NULL, NULL); + if (hService) + { + printf("Successfully created service '%s' for driver '%s'.\n", VBOXGUEST_SERVICE_NAME, szDriver); + if (fStartIt) + { + if (StartService(hService, 0, NULL)) + printf("successfully started driver '%s'\n", szDriver); + else + printf("StartService failed: %d\n", GetLastError()); + } + CloseServiceHandle(hService); + } + else + printf("CreateService failed! lasterr=%d (szDriver=%s)\n", GetLastError(), szDriver); + CloseServiceHandle(hSMgrCreate); + return hService ? 0 : -1; +} + +static int uninstallDriver(void) +{ + int rc = -1; + SC_HANDLE hSMgr = OpenSCManager(NULL, NULL, SERVICE_CHANGE_CONFIG); + if (!hSMgr) + { + printf("OpenSCManager(,,delete) failed rc=%d\n", GetLastError()); + return -1; + } + SC_HANDLE hService = OpenService(hSMgr, VBOXGUEST_SERVICE_NAME, SERVICE_STOP | SERVICE_QUERY_STATUS | DELETE); + if (hService) + { + /* + * Try stop it if it's running. + */ + SERVICE_STATUS Status = { 0, 0, 0, 0, 0, 0, 0 }; + QueryServiceStatus(hService, &Status); + if (Status.dwCurrentState == SERVICE_STOPPED) + rc = VINF_SUCCESS; + else if (ControlService(hService, SERVICE_CONTROL_STOP, &Status)) + { + int iWait = 100; + while (Status.dwCurrentState == SERVICE_STOP_PENDING && iWait-- > 0) + { + Sleep(100); + QueryServiceStatus(hService, &Status); + } + if (Status.dwCurrentState == SERVICE_STOPPED) + rc = VINF_SUCCESS; + else + { + printf("Failed to stop service. status=%d (%#x)\n", Status.dwCurrentState, Status.dwCurrentState); + rc = VERR_GENERAL_FAILURE; + } + } + else + { + DWORD dwErr = GetLastError(); + if ( Status.dwCurrentState == SERVICE_STOP_PENDING + && dwErr == ERROR_SERVICE_CANNOT_ACCEPT_CTRL) + rc = VERR_RESOURCE_BUSY; /* better than VERR_GENERAL_FAILURE */ + else + { + printf("ControlService failed with dwErr=%u. status=%d (%#x)\n", + dwErr, Status.dwCurrentState, Status.dwCurrentState); + rc = -1; + } + } + + /* + * Delete the service. + */ + if (RT_SUCCESS(rc)) + { + if (DeleteService(hService)) + rc = 0; + else + { + printf("DeleteService failed lasterr=%d\n", GetLastError()); + rc = -1; + } + } + CloseServiceHandle(hService); + } + else if (GetLastError() == ERROR_SERVICE_DOES_NOT_EXIST) + rc = 0; + else + printf("OpenService failed lasterr=%d\n", GetLastError()); + CloseServiceHandle(hSMgr); + return rc; +} + +#ifdef TESTMODE + +static HANDLE openDriver(void) +{ + HANDLE hDevice; + + hDevice = CreateFile(VBOXGUEST_DEVICE_NAME, // Win2k+: VBOXGUEST_DEVICE_NAME_GLOBAL + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); + if (hDevice == INVALID_HANDLE_VALUE) + { + printf("CreateFile did not work. GetLastError() 0x%x\n", GetLastError()); + } + return hDevice; +} + +static int closeDriver(HANDLE hDevice) +{ + CloseHandle(hDevice); + return 0; +} + +static int performTest(void) +{ + int rc = 0; + + HANDLE hDevice = openDriver(); + + if (hDevice != INVALID_HANDLE_VALUE) + closeDriver(hDevice); + else + printf("openDriver failed!\n"); + + return rc; +} + +#endif /* TESTMODE */ + +static int usage(char *programName) +{ + printf("error, syntax: %s [install|uninstall]\n", programName); + return 1; +} + +int main(int argc, char **argv) +{ + bool installMode; +#ifdef TESTMODE + bool testMode = false; +#endif + + if (argc != 2) + return usage(argv[0]); + + if (strcmp(argv[1], "install") == 0) + installMode = true; + else if (strcmp(argv[1], "uninstall") == 0) + installMode = false; +#ifdef TESTMODE + else if (strcmp(argv[1], "test") == 0) + testMode = true; +#endif + else + return usage(argv[0]); + + + int rc; +#ifdef TESTMODE + if (testMode) + rc = performTest(); + else +#endif + if (installMode) + rc = installDriver(true); + else + rc = uninstallDriver(); + + if (rc == 0) + printf("operation completed successfully!\n"); + else + printf("error: operation failed with status code %d\n", rc); + + return rc; +} + |