summaryrefslogtreecommitdiffstats
path: root/src/VBox/HostDrivers/VBoxNetFlt/win/tools
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-06 03:01:46 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-06 03:01:46 +0000
commitf8fe689a81f906d1b91bb3220acde2a4ecb14c5b (patch)
tree26484e9d7e2c67806c2d1760196ff01aaa858e8c /src/VBox/HostDrivers/VBoxNetFlt/win/tools
parentInitial commit. (diff)
downloadvirtualbox-upstream.tar.xz
virtualbox-upstream.zip
Adding upstream version 6.0.4-dfsg.upstream/6.0.4-dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/VBox/HostDrivers/VBoxNetFlt/win/tools')
-rw-r--r--src/VBox/HostDrivers/VBoxNetFlt/win/tools/Makefile.kup0
-rw-r--r--src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetAdpInstall.cpp292
-rw-r--r--src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetAdpUninstall.cpp89
-rw-r--r--src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetFltInstall.cpp183
-rw-r--r--src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetFltUninstall.cpp113
-rw-r--r--src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetLwfInstall.cpp167
-rw-r--r--src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetLwfUninstall.cpp110
7 files changed, 954 insertions, 0 deletions
diff --git a/src/VBox/HostDrivers/VBoxNetFlt/win/tools/Makefile.kup b/src/VBox/HostDrivers/VBoxNetFlt/win/tools/Makefile.kup
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/src/VBox/HostDrivers/VBoxNetFlt/win/tools/Makefile.kup
diff --git a/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetAdpInstall.cpp b/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetAdpInstall.cpp
new file mode 100644
index 00000000..3731dd18
--- /dev/null
+++ b/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetAdpInstall.cpp
@@ -0,0 +1,292 @@
+/* $Id: VBoxNetAdpInstall.cpp $ */
+/** @file
+ * NetAdpInstall - VBoxNetAdp installer command line tool.
+ */
+
+/*
+ * Copyright (C) 2009-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 <VBox/VBoxNetCfg-win.h>
+#include <VBox/VBoxDrvCfg-win.h>
+#include <stdio.h>
+#include <devguid.h>
+
+#define VBOX_NETADP_APP_NAME L"NetAdpInstall"
+
+#define VBOX_NETADP_HWID L"sun_VBoxNetAdp"
+#ifdef NDIS60
+#define VBOX_NETADP_INF L"VBoxNetAdp6.inf"
+#else /* !NDIS60 */
+#define VBOX_NETADP_INF L"VBoxNetAdp.inf"
+#endif /* !NDIS60 */
+
+static VOID winNetCfgLogger(LPCSTR szString)
+{
+ printf("%s\n", szString);
+}
+
+static int VBoxNetAdpInstall(void)
+{
+ VBoxNetCfgWinSetLogging(winNetCfgLogger);
+
+ HRESULT hr = CoInitialize(NULL);
+ if (SUCCEEDED(hr))
+ {
+ wprintf(L"adding host-only interface..\n");
+
+ DWORD dwErr = ERROR_SUCCESS;
+ WCHAR MpInf[MAX_PATH];
+
+ if (!GetFullPathNameW(VBOX_NETADP_INF, sizeof(MpInf)/sizeof(MpInf[0]), MpInf, NULL))
+ dwErr = GetLastError();
+
+ if (dwErr == ERROR_SUCCESS)
+ {
+ INetCfg *pnc;
+ LPWSTR lpszLockedBy = NULL;
+ hr = VBoxNetCfgWinQueryINetCfg(&pnc, TRUE, VBOX_NETADP_APP_NAME, 10000, &lpszLockedBy);
+ if (hr == S_OK)
+ {
+
+ hr = VBoxNetCfgWinNetAdpInstall(pnc, MpInf);
+
+ if (hr == S_OK)
+ {
+ wprintf(L"installed successfully\n");
+ }
+ else
+ {
+ wprintf(L"error installing VBoxNetAdp (0x%x)\n", hr);
+ }
+
+ VBoxNetCfgWinReleaseINetCfg(pnc, TRUE);
+ }
+ else
+ wprintf(L"VBoxNetCfgWinQueryINetCfg failed: hr = 0x%x\n", hr);
+ /*
+ hr = VBoxDrvCfgInfInstall(MpInf);
+ if (FAILED(hr))
+ printf("VBoxDrvCfgInfInstall failed %#x\n", hr);
+
+ GUID guid;
+ BSTR name, errMsg;
+
+ hr = VBoxNetCfgWinCreateHostOnlyNetworkInterface (MpInf, true, &guid, &name, &errMsg);
+ if (SUCCEEDED(hr))
+ {
+ ULONG ip, mask;
+ hr = VBoxNetCfgWinGenHostOnlyNetworkNetworkIp(&ip, &mask);
+ if (SUCCEEDED(hr))
+ {
+ // ip returned by VBoxNetCfgWinGenHostOnlyNetworkNetworkIp is a network ip,
+ // i.e. 192.168.xxx.0, assign 192.168.xxx.1 for the hostonly adapter
+ ip = ip | (1 << 24);
+ hr = VBoxNetCfgWinEnableStaticIpConfig(&guid, ip, mask);
+ if (SUCCEEDED(hr))
+ {
+ printf("installation successful\n");
+ }
+ else
+ printf("VBoxNetCfgWinEnableStaticIpConfig failed: hr = 0x%x\n", hr);
+ }
+ else
+ printf("VBoxNetCfgWinGenHostOnlyNetworkNetworkIp failed: hr = 0x%x\n", hr);
+ }
+ else
+ printf("VBoxNetCfgWinCreateHostOnlyNetworkInterface failed: hr = 0x%x\n", hr);
+ */
+ }
+ else
+ {
+ wprintf(L"GetFullPathNameW failed: winEr = %d\n", dwErr);
+ hr = HRESULT_FROM_WIN32(dwErr);
+
+ }
+ CoUninitialize();
+ }
+ else
+ wprintf(L"Error initializing COM (0x%x)\n", hr);
+
+ VBoxNetCfgWinSetLogging(NULL);
+
+ return SUCCEEDED(hr) ? 0 : 1;
+}
+
+static int VBoxNetAdpUninstall(void)
+{
+ VBoxNetCfgWinSetLogging(winNetCfgLogger);
+
+ printf("uninstalling all host-only interfaces..\n");
+
+ HRESULT hr = CoInitialize(NULL);
+ if (SUCCEEDED(hr))
+ {
+ hr = VBoxNetCfgWinRemoveAllNetDevicesOfId(VBOX_NETADP_HWID);
+ if (SUCCEEDED(hr))
+ {
+ hr = VBoxDrvCfgInfUninstallAllSetupDi(&GUID_DEVCLASS_NET, L"Net", VBOX_NETADP_HWID, 0/* could be SUOI_FORCEDELETE */);
+ if (SUCCEEDED(hr))
+ {
+ printf("uninstallation successful\n");
+ }
+ else
+ printf("uninstalled successfully, but failed to remove infs\n");
+ }
+ else
+ printf("uninstall failed, hr = 0x%x\n", hr);
+ CoUninitialize();
+ }
+ else
+ printf("Error initializing COM (0x%x)\n", hr);
+
+ VBoxNetCfgWinSetLogging(NULL);
+
+ return SUCCEEDED(hr) ? 0 : 1;
+}
+
+static int VBoxNetAdpUpdate(void)
+{
+ VBoxNetCfgWinSetLogging(winNetCfgLogger);
+
+ printf("uninstalling all host-only interfaces..\n");
+
+ HRESULT hr = CoInitialize(NULL);
+ if (SUCCEEDED(hr))
+ {
+ BOOL fRebootRequired = FALSE;
+ /*
+ * Before we can update the driver for existing adapters we need to remove
+ * all old driver packages from the driver cache. Otherwise we may end up
+ * with both NDIS5 and NDIS6 versions of VBoxNetAdp in the cache which
+ * will cause all sorts of trouble.
+ */
+ VBoxDrvCfgInfUninstallAllF(L"Net", VBOX_NETADP_HWID, SUOI_FORCEDELETE);
+ hr = VBoxNetCfgWinUpdateHostOnlyNetworkInterface(VBOX_NETADP_INF, &fRebootRequired, VBOX_NETADP_HWID);
+ if (SUCCEEDED(hr))
+ {
+ if (fRebootRequired)
+ printf("!!REBOOT REQUIRED!!\n");
+ printf("updated successfully\n");
+ }
+ else
+ printf("update failed, hr = 0x%x\n", hr);
+
+ CoUninitialize();
+ }
+ else
+ printf("Error initializing COM (0x%x)\n", hr);
+
+ VBoxNetCfgWinSetLogging(NULL);
+
+ return SUCCEEDED(hr) ? 0 : 1;
+}
+
+static int VBoxNetAdpDisable(void)
+{
+ VBoxNetCfgWinSetLogging(winNetCfgLogger);
+
+ printf("disabling all host-only interfaces..\n");
+
+ HRESULT hr = CoInitialize(NULL);
+ if (SUCCEEDED(hr))
+ {
+ hr = VBoxNetCfgWinPropChangeAllNetDevicesOfId(VBOX_NETADP_HWID, VBOXNECTFGWINPROPCHANGE_TYPE_DISABLE);
+ if (SUCCEEDED(hr))
+ {
+ printf("disabling successful\n");
+ }
+ else
+ printf("disable failed, hr = 0x%x\n", hr);
+
+ CoUninitialize();
+ }
+ else
+ printf("Error initializing COM (0x%x)\n", hr);
+
+ VBoxNetCfgWinSetLogging(NULL);
+
+ return SUCCEEDED(hr) ? 0 : 1;
+}
+
+static int VBoxNetAdpEnable(void)
+{
+ VBoxNetCfgWinSetLogging(winNetCfgLogger);
+
+ printf("enabling all host-only interfaces..\n");
+
+ HRESULT hr = CoInitialize(NULL);
+ if (SUCCEEDED(hr))
+ {
+ hr = VBoxNetCfgWinPropChangeAllNetDevicesOfId(VBOX_NETADP_HWID, VBOXNECTFGWINPROPCHANGE_TYPE_ENABLE);
+ if (SUCCEEDED(hr))
+ {
+ printf("enabling successful\n");
+ }
+ else
+ printf("enabling failed, hr = 0x%x\n", hr);
+
+ CoUninitialize();
+ }
+ else
+ printf("Error initializing COM (0x%x)\n", hr);
+
+ VBoxNetCfgWinSetLogging(NULL);
+
+ return SUCCEEDED(hr) ? 0 : 1;
+}
+
+static void printUsage(void)
+{
+ printf("host-only network adapter configuration tool\n"
+ " Usage: VBoxNetAdpInstall [cmd]\n"
+ " cmd can be one of the following values:\n"
+ " i - install a new host-only interface (default command)\n"
+ " u - uninstall all host-only interfaces\n"
+ " a - update the host-only driver\n"
+ " d - disable all host-only interfaces\n"
+ " e - enable all host-only interfaces\n"
+ " h - print this message\n");
+}
+
+int __cdecl main(int argc, char **argv)
+{
+ if (argc < 2)
+ return VBoxNetAdpInstall();
+ if (argc > 2)
+ {
+ printUsage();
+ return 1;
+ }
+
+ if (!strcmp(argv[1], "i"))
+ return VBoxNetAdpInstall();
+ if (!strcmp(argv[1], "u"))
+ return VBoxNetAdpUninstall();
+ if (!strcmp(argv[1], "a"))
+ return VBoxNetAdpUpdate();
+ if (!strcmp(argv[1], "d"))
+ return VBoxNetAdpDisable();
+ if (!strcmp(argv[1], "e"))
+ return VBoxNetAdpEnable();
+
+ printUsage();
+ return !strcmp(argv[1], "h");
+}
diff --git a/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetAdpUninstall.cpp b/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetAdpUninstall.cpp
new file mode 100644
index 00000000..7eed8fd3
--- /dev/null
+++ b/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetAdpUninstall.cpp
@@ -0,0 +1,89 @@
+/* $Id: VBoxNetAdpUninstall.cpp $ */
+/** @file
+ * NetAdpUninstall - VBoxNetAdp uninstaller command line tool
+ */
+
+/*
+ * Copyright (C) 2009-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 <VBox/VBoxNetCfg-win.h>
+#include <VBox/VBoxDrvCfg-win.h>
+#include <stdio.h>
+
+#include <devguid.h>
+
+#ifdef NDIS60
+#define VBOX_NETADP_HWID L"sun_VBoxNetAdp6"
+#else /* !NDIS60 */
+#define VBOX_NETADP_HWID L"sun_VBoxNetAdp"
+#endif /* !NDIS60 */
+
+static VOID winNetCfgLogger (LPCSTR szString)
+{
+ printf("%s", szString);
+}
+
+static int VBoxNetAdpUninstall()
+{
+ int r = 1;
+ VBoxNetCfgWinSetLogging(winNetCfgLogger);
+
+ printf("uninstalling all Host-Only interfaces..\n");
+
+ HRESULT hr = CoInitialize(NULL);
+ if (hr == S_OK)
+ {
+ hr = VBoxNetCfgWinRemoveAllNetDevicesOfId(VBOX_NETADP_HWID);
+ if (hr == S_OK)
+ {
+ hr = VBoxDrvCfgInfUninstallAllSetupDi(&GUID_DEVCLASS_NET, L"Net", VBOX_NETADP_HWID, 0/* could be SUOI_FORCEDELETE */);
+ if (hr == S_OK)
+ {
+ printf("uninstalled successfully\n");
+ }
+ else
+ {
+ printf("uninstalled successfully, but failed to remove infs\n");
+ }
+ r = 0;
+ }
+ else
+ {
+ printf("uninstall failed, hr = 0x%x\n", hr);
+ }
+
+ CoUninitialize();
+ }
+ else
+ {
+ wprintf(L"Error initializing COM (0x%x)\n", hr);
+ }
+
+ VBoxNetCfgWinSetLogging(NULL);
+
+ return r;
+}
+
+int __cdecl main(int argc, char **argv)
+{
+ RT_NOREF2(argc, argv);
+ return VBoxNetAdpUninstall();
+}
diff --git a/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetFltInstall.cpp b/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetFltInstall.cpp
new file mode 100644
index 00000000..f6fbe3d5
--- /dev/null
+++ b/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetFltInstall.cpp
@@ -0,0 +1,183 @@
+/* $Id: VBoxNetFltInstall.cpp $ */
+/** @file
+ * NetFltInstall - VBoxNetFlt installer command line tool
+ */
+
+/*
+ * Copyright (C) 2008-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 <VBox/VBoxNetCfg-win.h>
+#include <devguid.h>
+#include <stdio.h>
+
+#define NETFLT_ID L"sun_VBoxNetFlt"
+#define VBOX_NETCFG_APP_NAME L"NetFltInstall"
+#define VBOX_NETFLT_PT_INF L".\\VBoxNetFlt.inf"
+#define VBOX_NETFLT_MP_INF L".\\VBoxNetFltM.inf"
+#define VBOX_NETFLT_RETRIES 10
+
+
+static VOID winNetCfgLogger (LPCSTR szString)
+{
+ printf("%s", szString);
+}
+
+/** Wrapper around GetfullPathNameW that will try an alternative INF location.
+ *
+ * The default location is the current directory. If not found there, the
+ * alternative location is the executable directory. If not found there either,
+ * the first alternative is present to the caller.
+ */
+static DWORD MyGetfullPathNameW(LPCWSTR pwszName, size_t cchFull, LPWSTR pwszFull)
+{
+ LPWSTR pwszFilePart;
+ DWORD dwSize = GetFullPathNameW(pwszName, (DWORD)cchFull, pwszFull, &pwszFilePart);
+ if (dwSize <= 0)
+ return dwSize;
+
+ /* if it doesn't exist, see if the file exists in the same directory as the executable. */
+ if (GetFileAttributesW(pwszFull) == INVALID_FILE_ATTRIBUTES)
+ {
+ WCHAR wsz[512];
+ DWORD cch = GetModuleFileNameW(GetModuleHandle(NULL), &wsz[0], sizeof(wsz) / sizeof(wsz[0]));
+ if (cch > 0)
+ {
+ while (cch > 0 && wsz[cch - 1] != '/' && wsz[cch - 1] != '\\' && wsz[cch - 1] != ':')
+ cch--;
+ unsigned i = 0;
+ while (cch < sizeof(wsz) / sizeof(wsz[0]))
+ {
+ wsz[cch] = pwszFilePart[i++];
+ if (!wsz[cch])
+ {
+ dwSize = GetFullPathNameW(wsz, (DWORD)cchFull, pwszFull, NULL);
+ if (dwSize > 0 && GetFileAttributesW(pwszFull) != INVALID_FILE_ATTRIBUTES)
+ return dwSize;
+ break;
+ }
+ cch++;
+ }
+ }
+ }
+
+ /* fallback */
+ return GetFullPathNameW(pwszName, (DWORD)cchFull, pwszFull, NULL);
+}
+
+static int VBoxNetFltInstall()
+{
+ WCHAR PtInf[MAX_PATH];
+ WCHAR MpInf[MAX_PATH];
+ INetCfg *pnc;
+ LPWSTR lpszLockedBy = NULL;
+ int r = 1;
+
+ VBoxNetCfgWinSetLogging(winNetCfgLogger);
+
+ HRESULT hr = CoInitialize(NULL);
+ if (hr == S_OK)
+ {
+ int i = 0;
+ do
+ {
+ hr = VBoxNetCfgWinQueryINetCfg(&pnc, TRUE, VBOX_NETCFG_APP_NAME, 10000, &lpszLockedBy);
+ if (hr == S_OK)
+ {
+ DWORD dwSize;
+ dwSize = MyGetfullPathNameW(VBOX_NETFLT_PT_INF, sizeof(PtInf)/sizeof(PtInf[0]), PtInf);
+ if (dwSize > 0)
+ {
+ /** @todo add size check for (sizeof(PtInf)/sizeof(PtInf[0])) == dwSize (string length in sizeof(PtInf[0])) */
+
+ dwSize = MyGetfullPathNameW(VBOX_NETFLT_MP_INF, sizeof(MpInf)/sizeof(MpInf[0]), MpInf);
+ if (dwSize > 0)
+ {
+ /** @todo add size check for (sizeof(MpInf)/sizeof(MpInf[0])) == dwSize (string length in sizeof(MpInf[0])) */
+
+ LPCWSTR aInfs[] = {PtInf, MpInf};
+ hr = VBoxNetCfgWinNetFltInstall(pnc, aInfs, 2);
+ if (hr == S_OK)
+ {
+ wprintf(L"installed successfully\n");
+ r = 0;
+ }
+ else
+ {
+ wprintf(L"error installing VBoxNetFlt (0x%x)\n", hr);
+ }
+ }
+ else
+ {
+ hr = HRESULT_FROM_WIN32(GetLastError());
+ wprintf(L"error getting full inf path for VBoxNetFltM.inf (0x%x)\n", hr);
+ }
+ }
+ else
+ {
+ hr = HRESULT_FROM_WIN32(GetLastError());
+ wprintf(L"error getting full inf path for VBoxNetFlt.inf (0x%x)\n", hr);
+ }
+
+
+ VBoxNetCfgWinReleaseINetCfg(pnc, TRUE);
+ break;
+ }
+ else if (hr == NETCFG_E_NO_WRITE_LOCK && lpszLockedBy)
+ {
+ if (i < VBOX_NETFLT_RETRIES && !wcscmp(lpszLockedBy, L"6to4svc.dll"))
+ {
+ wprintf(L"6to4svc.dll is holding the lock, retrying %d out of %d\n", ++i, VBOX_NETFLT_RETRIES);
+ CoTaskMemFree(lpszLockedBy);
+ }
+ else
+ {
+ wprintf(L"Error: write lock is owned by another application (%s), close the application and retry installing\n", lpszLockedBy);
+ r = 1;
+ CoTaskMemFree(lpszLockedBy);
+ break;
+ }
+ }
+ else
+ {
+ wprintf(L"Error getting the INetCfg interface (0x%x)\n", hr);
+ r = 1;
+ break;
+ }
+ } while (true);
+
+ CoUninitialize();
+ }
+ else
+ {
+ wprintf(L"Error initializing COM (0x%x)\n", hr);
+ r = 1;
+ }
+
+ VBoxNetCfgWinSetLogging(NULL);
+
+ return r;
+}
+
+int __cdecl main(int argc, char **argv)
+{
+ RT_NOREF2(argc, argv);
+ return VBoxNetFltInstall();
+}
diff --git a/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetFltUninstall.cpp b/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetFltUninstall.cpp
new file mode 100644
index 00000000..a1860d04
--- /dev/null
+++ b/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetFltUninstall.cpp
@@ -0,0 +1,113 @@
+/* $Id: VBoxNetFltUninstall.cpp $ */
+/** @file
+ * NetFltUninstall - VBoxNetFlt uninstaller command line tool
+ */
+
+/*
+ * Copyright (C) 2008-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 <VBox/VBoxNetCfg-win.h>
+#include <stdio.h>
+
+#define NETFLT_ID L"sun_VBoxNetFlt"
+#define VBOX_NETCFG_APP_NAME L"NetFltUninstall"
+#define VBOX_NETFLT_PT_INF L".\\VBoxNetFlt.inf"
+#define VBOX_NETFLT_MP_INF L".\\VBoxNetFltM.inf"
+#define VBOX_NETFLT_RETRIES 10
+
+static VOID winNetCfgLogger (LPCSTR szString)
+{
+ printf("%s", szString);
+}
+
+static int VBoxNetFltUninstall()
+{
+ INetCfg *pnc;
+ LPWSTR lpszLockedBy = NULL;
+ int r;
+
+ VBoxNetCfgWinSetLogging(winNetCfgLogger);
+
+ HRESULT hr = CoInitialize(NULL);
+ if (hr == S_OK)
+ {
+ int i = 0;
+ do
+ {
+ hr = VBoxNetCfgWinQueryINetCfg(&pnc, TRUE, VBOX_NETCFG_APP_NAME, 10000, &lpszLockedBy);
+ if (hr == S_OK)
+ {
+ hr = VBoxNetCfgWinNetFltUninstall(pnc);
+ if (hr != S_OK && hr != S_FALSE)
+ {
+ wprintf(L"error uninstalling VBoxNetFlt (0x%x)\n", hr);
+ r = 1;
+ }
+ else
+ {
+ wprintf(L"uninstalled successfully\n");
+ r = 0;
+ }
+
+ VBoxNetCfgWinReleaseINetCfg(pnc, TRUE);
+ break;
+ }
+ else if (hr == NETCFG_E_NO_WRITE_LOCK && lpszLockedBy)
+ {
+ if (i < VBOX_NETFLT_RETRIES && !wcscmp(lpszLockedBy, L"6to4svc.dll"))
+ {
+ wprintf(L"6to4svc.dll is holding the lock, retrying %d out of %d\n", ++i, VBOX_NETFLT_RETRIES);
+ CoTaskMemFree(lpszLockedBy);
+ }
+ else
+ {
+ wprintf(L"Error: write lock is owned by another application (%s), close the application and retry uninstalling\n", lpszLockedBy);
+ r = 1;
+ CoTaskMemFree(lpszLockedBy);
+ break;
+ }
+ }
+ else
+ {
+ wprintf(L"Error getting the INetCfg interface (0x%x)\n", hr);
+ r = 1;
+ break;
+ }
+ } while (true);
+
+ CoUninitialize();
+ }
+ else
+ {
+ wprintf(L"Error initializing COM (0x%x)\n", hr);
+ r = 1;
+ }
+
+ VBoxNetCfgWinSetLogging(NULL);
+
+ return r;
+}
+
+int __cdecl main(int argc, char **argv)
+{
+ RT_NOREF2(argc, argv);
+ return VBoxNetFltUninstall();
+}
diff --git a/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetLwfInstall.cpp b/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetLwfInstall.cpp
new file mode 100644
index 00000000..89eeda07
--- /dev/null
+++ b/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetLwfInstall.cpp
@@ -0,0 +1,167 @@
+/* $Id: VBoxNetLwfInstall.cpp $ */
+/** @file
+ * NetLwfInstall - VBoxNetLwf installer command line tool
+ */
+
+/*
+ * Copyright (C) 2014-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 <VBox/VBoxNetCfg-win.h>
+#include <devguid.h>
+#include <stdio.h>
+
+#define VBOX_NETCFG_APP_NAME L"NetLwfInstall"
+#define VBOX_NETLWF_INF L".\\VBoxNetLwf.inf"
+#define VBOX_NETLWF_RETRIES 10
+
+
+static VOID winNetCfgLogger (LPCSTR szString)
+{
+ printf("%s", szString);
+}
+
+/** Wrapper around GetfullPathNameW that will try an alternative INF location.
+ *
+ * The default location is the current directory. If not found there, the
+ * alternative location is the executable directory. If not found there either,
+ * the first alternative is present to the caller.
+ */
+static DWORD MyGetfullPathNameW(LPCWSTR pwszName, size_t cchFull, LPWSTR pwszFull)
+{
+ LPWSTR pwszFilePart;
+ DWORD dwSize = GetFullPathNameW(pwszName, (DWORD)cchFull, pwszFull, &pwszFilePart);
+ if (dwSize <= 0)
+ return dwSize;
+
+ /* if it doesn't exist, see if the file exists in the same directory as the executable. */
+ if (GetFileAttributesW(pwszFull) == INVALID_FILE_ATTRIBUTES)
+ {
+ WCHAR wsz[512];
+ DWORD cch = GetModuleFileNameW(GetModuleHandle(NULL), &wsz[0], sizeof(wsz) / sizeof(wsz[0]));
+ if (cch > 0)
+ {
+ while (cch > 0 && wsz[cch - 1] != '/' && wsz[cch - 1] != '\\' && wsz[cch - 1] != ':')
+ cch--;
+ unsigned i = 0;
+ while (cch < sizeof(wsz) / sizeof(wsz[0]))
+ {
+ wsz[cch] = pwszFilePart[i++];
+ if (!wsz[cch])
+ {
+ dwSize = GetFullPathNameW(wsz, (DWORD)cchFull, pwszFull, NULL);
+ if (dwSize > 0 && GetFileAttributesW(pwszFull) != INVALID_FILE_ATTRIBUTES)
+ return dwSize;
+ break;
+ }
+ cch++;
+ }
+ }
+ }
+
+ /* fallback */
+ return GetFullPathNameW(pwszName, (DWORD)cchFull, pwszFull, NULL);
+}
+
+static int VBoxNetLwfInstall()
+{
+ WCHAR Inf[MAX_PATH];
+ INetCfg *pnc;
+ LPWSTR lpszLockedBy = NULL;
+ int r = 1;
+
+ VBoxNetCfgWinSetLogging(winNetCfgLogger);
+
+ HRESULT hr = CoInitialize(NULL);
+ if (hr == S_OK)
+ {
+ int i = 0;
+ do
+ {
+ hr = VBoxNetCfgWinQueryINetCfg(&pnc, TRUE, VBOX_NETCFG_APP_NAME, 10000, &lpszLockedBy);
+ if (hr == S_OK)
+ {
+ DWORD dwSize;
+ dwSize = MyGetfullPathNameW(VBOX_NETLWF_INF, sizeof(Inf)/sizeof(Inf[0]), Inf);
+ if (dwSize > 0)
+ {
+ /** @todo add size check for (sizeof(Inf)/sizeof(Inf[0])) == dwSize (string length in sizeof(Inf[0])) */
+ hr = VBoxNetCfgWinNetLwfInstall(pnc, Inf);
+ if (hr == S_OK)
+ {
+ wprintf(L"installed successfully\n");
+ r = 0;
+ }
+ else
+ {
+ wprintf(L"error installing VBoxNetLwf (0x%x)\n", hr);
+ }
+ }
+ else
+ {
+ hr = HRESULT_FROM_WIN32(GetLastError());
+ wprintf(L"error getting full inf path for VBoxNetLwf.inf (0x%x)\n", hr);
+ }
+
+
+ VBoxNetCfgWinReleaseINetCfg(pnc, TRUE);
+ break;
+ }
+ else if (hr == NETCFG_E_NO_WRITE_LOCK && lpszLockedBy)
+ {
+ if (i < VBOX_NETLWF_RETRIES && !wcscmp(lpszLockedBy, L"6to4svc.dll"))
+ {
+ wprintf(L"6to4svc.dll is holding the lock, retrying %d out of %d\n", ++i, VBOX_NETLWF_RETRIES);
+ CoTaskMemFree(lpszLockedBy);
+ }
+ else
+ {
+ wprintf(L"Error: write lock is owned by another application (%s), close the application and retry installing\n", lpszLockedBy);
+ r = 1;
+ CoTaskMemFree(lpszLockedBy);
+ break;
+ }
+ }
+ else
+ {
+ wprintf(L"Error getting the INetCfg interface (0x%x)\n", hr);
+ r = 1;
+ break;
+ }
+ } while (true);
+
+ CoUninitialize();
+ }
+ else
+ {
+ wprintf(L"Error initializing COM (0x%x)\n", hr);
+ r = 1;
+ }
+
+ VBoxNetCfgWinSetLogging(NULL);
+
+ return r;
+}
+
+int __cdecl main(int argc, char **argv)
+{
+ RT_NOREF2(argc, argv);
+ return VBoxNetLwfInstall();
+}
diff --git a/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetLwfUninstall.cpp b/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetLwfUninstall.cpp
new file mode 100644
index 00000000..b757289f
--- /dev/null
+++ b/src/VBox/HostDrivers/VBoxNetFlt/win/tools/VBoxNetLwfUninstall.cpp
@@ -0,0 +1,110 @@
+/* $Id: VBoxNetLwfUninstall.cpp $ */
+/** @file
+ * NetLwfUninstall - VBoxNetLwf uninstaller command line tool
+ */
+
+/*
+ * Copyright (C) 2014-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 <VBox/VBoxNetCfg-win.h>
+#include <stdio.h>
+
+#define VBOX_NETCFG_APP_NAME L"NetLwfUninstall"
+#define VBOX_NETLWF_RETRIES 10
+
+static VOID winNetCfgLogger (LPCSTR szString)
+{
+ printf("%s", szString);
+}
+
+static int VBoxNetLwfUninstall()
+{
+ INetCfg *pnc;
+ LPWSTR lpszLockedBy = NULL;
+ int r;
+
+ VBoxNetCfgWinSetLogging(winNetCfgLogger);
+
+ HRESULT hr = CoInitialize(NULL);
+ if (hr == S_OK)
+ {
+ int i = 0;
+ do
+ {
+ hr = VBoxNetCfgWinQueryINetCfg(&pnc, TRUE, VBOX_NETCFG_APP_NAME, 10000, &lpszLockedBy);
+ if (hr == S_OK)
+ {
+ hr = VBoxNetCfgWinNetLwfUninstall(pnc);
+ if (hr != S_OK)
+ {
+ wprintf(L"error uninstalling VBoxNetLwf (0x%x)\n", hr);
+ r = 1;
+ }
+ else
+ {
+ wprintf(L"uninstalled successfully\n");
+ r = 0;
+ }
+
+ VBoxNetCfgWinReleaseINetCfg(pnc, TRUE);
+ break;
+ }
+ else if (hr == NETCFG_E_NO_WRITE_LOCK && lpszLockedBy)
+ {
+ if (i < VBOX_NETLWF_RETRIES && !wcscmp(lpszLockedBy, L"6to4svc.dll"))
+ {
+ wprintf(L"6to4svc.dll is holding the lock, retrying %d out of %d\n", ++i, VBOX_NETLWF_RETRIES);
+ CoTaskMemFree(lpszLockedBy);
+ }
+ else
+ {
+ wprintf(L"Error: write lock is owned by another application (%s), close the application and retry uninstalling\n", lpszLockedBy);
+ r = 1;
+ CoTaskMemFree(lpszLockedBy);
+ break;
+ }
+ }
+ else
+ {
+ wprintf(L"Error getting the INetCfg interface (0x%x)\n", hr);
+ r = 1;
+ break;
+ }
+ } while (true);
+
+ CoUninitialize();
+ }
+ else
+ {
+ wprintf(L"Error initializing COM (0x%x)\n", hr);
+ r = 1;
+ }
+
+ VBoxNetCfgWinSetLogging(NULL);
+
+ return r;
+}
+
+int __cdecl main(int argc, char **argv)
+{
+ RT_NOREF2(argc, argv);
+ return VBoxNetLwfUninstall();
+}