summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2020-02-03 09:16:18 +0100
committerDavid Lönnhager <david.l@mullvad.net>2020-02-03 09:16:18 +0100
commitf353b869ae4133c931e31ff9f83ffd26d41a0f6a (patch)
treec1142c61ee54de1566061548522eed969cab7b46
parent787dd817cca2c66b57f0b4494c701cd994c78513 (diff)
parent7e01878a7a5863a5c6e01b2fe7b0fa0e62a1759a (diff)
downloadmullvadvpn-f353b869ae4133c931e31ff9f83ffd26d41a0f6a.tar.xz
mullvadvpn-f353b869ae4133c931e31ff9f83ffd26d41a0f6a.zip
Merge branch 'driverlogic-proc'
-rwxr-xr-xbuild_windows_modules.sh3
-rw-r--r--dist-assets/windows/installer.nsh28
-rw-r--r--windows/driverlogic/driverlogic.sln34
-rw-r--r--windows/driverlogic/driverlogic.vcxproj (renamed from windows/nsis-plugins/src/driverlogic/driverlogic.vcxproj)85
-rw-r--r--windows/driverlogic/driverlogic.vcxproj.filters17
-rw-r--r--windows/driverlogic/src/driverlogic.cpp (renamed from windows/nsis-plugins/src/driverlogic/driverlogicops.cpp)485
-rw-r--r--windows/driverlogic/src/stdafx.cpp (renamed from windows/nsis-plugins/src/driverlogic/stdafx.cpp)0
-rw-r--r--windows/driverlogic/src/stdafx.h (renamed from windows/nsis-plugins/src/driverlogic/stdafx.h)0
-rw-r--r--windows/driverlogic/src/targetver.h (renamed from windows/nsis-plugins/src/driverlogic/targetver.h)0
-rw-r--r--windows/nsis-plugins/nsis-plugins.sln10
-rw-r--r--windows/nsis-plugins/src/driverlogic/dllmain.cpp11
-rw-r--r--windows/nsis-plugins/src/driverlogic/driverlogic.cpp115
-rw-r--r--windows/nsis-plugins/src/driverlogic/driverlogic.def6
-rw-r--r--windows/nsis-plugins/src/driverlogic/driverlogic.vcxproj.filters17
-rw-r--r--windows/nsis-plugins/src/driverlogic/driverlogicops.h46
15 files changed, 446 insertions, 411 deletions
diff --git a/build_windows_modules.sh b/build_windows_modules.sh
index d7b5c8fc1d..7d429daf26 100755
--- a/build_windows_modules.sh
+++ b/build_windows_modules.sh
@@ -176,6 +176,9 @@ function main
copy_outputs $winnet_root_path "winnet.dll"
copy_outputs $winutil_root_path "winutil.dll"
+ local driverlogic_root_path=${CPP_ROOT_PATH:-"./windows/driverlogic"}
+ build_solution "$driverlogic_root_path" "driverlogic.sln"
+
build_nsis_plugins
}
diff --git a/dist-assets/windows/installer.nsh b/dist-assets/windows/installer.nsh
index 41962c2048..d25ec9c58c 100644
--- a/dist-assets/windows/installer.nsh
+++ b/dist-assets/windows/installer.nsh
@@ -24,10 +24,11 @@
!define MULLVAD_GENERAL_ERROR 0
!define MULLVAD_SUCCESS 1
-# Return codes from driverlogic::RemoveMullvadTap
-!define RMT_GENERAL_ERROR 0
-!define RMT_NO_REMAINING_ADAPTERS 1
-!define RMT_SOME_REMAINING_ADAPTERS 2
+# Return codes from driverlogic
+!define DL_GENERAL_ERROR 0
+!define DL_GENERAL_SUCCESS 1
+!define DL_DELETE_NO_ADAPTERS_REMAIN 2
+!define DL_DELETE_SOME_ADAPTERS_REMAIN 3
# Return codes from tapinstall
!define DEVCON_EXIT_OK 0
@@ -74,6 +75,7 @@
SetOutPath "$TEMP\driver"
+ File "${BUILD_RESOURCES_DIR}\..\windows\driverlogic\bin\x64-Release\driverlogic.exe"
File "${BUILD_RESOURCES_DIR}\binaries\x86_64-pc-windows-msvc\driver\*"
${If} ${AtLeastWin10}
@@ -192,19 +194,19 @@
log::Log "RemoveVanillaTap()"
- driverlogic::RemoveVanillaMullvadTap
+ nsExec::ExecToStack '"$TEMP\driver\driverlogic.exe" remove-vanilla-tap'
Pop $0
Pop $1
- ${If} $0 == ${RMT_GENERAL_ERROR}
+ ${If} $0 == ${DL_GENERAL_ERROR}
StrCpy $R0 "Failed to remove vanilla TAP adapter: $1"
log::Log $R0
Goto RemoveVanillaTap_return
${EndIf}
- ${If} $0 == ${RMT_NO_REMAINING_ADAPTERS}
+ ${If} $0 == ${DL_DELETE_NO_ADAPTERS_REMAIN}
log::Log "Removing vanilla TAP adapter driver since it is no longer in use"
nsExec::ExecToStack '"$TEMP\driver\tapinstall.exe" remove ${DEPRECATED_TAP_HARDWARE_ID}'
@@ -273,8 +275,8 @@
${EndIf}
log::Log "Creating new virtual adapter"
- nsExec::ExecToStack '"$TEMP\driver\tapinstall.exe" install "$TEMP\driver\OemVista.inf" ${TAP_HARDWARE_ID}'
-
+ nsExec::ExecToStack '"$TEMP\driver\driverlogic.exe" install "$TEMP\driver\OemVista.inf"'
+
Pop $0
Pop $1
@@ -285,13 +287,13 @@
Goto InstallDriver_return
${EndIf}
- log::Log "Calling on plugin to identify recently added adapter"
- driverlogic::IdentifyNewAdapter
-
+ log::Log "Identifying recently added adapter"
+ nsExec::ExecToStack '"$TEMP\driver\driverlogic.exe" find-tap'
+
Pop $0
Pop $1
- ${If} $0 != ${MULLVAD_SUCCESS}
+ ${If} $0 != ${DL_GENERAL_SUCCESS}
StrCpy $R0 "Failed to identify new adapter: $1"
log::Log $R0
Goto InstallDriver_return
diff --git a/windows/driverlogic/driverlogic.sln b/windows/driverlogic/driverlogic.sln
new file mode 100644
index 0000000000..71c4e095b2
--- /dev/null
+++ b/windows/driverlogic/driverlogic.sln
@@ -0,0 +1,34 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.29324.140
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "driverlogic", "driverlogic.vcxproj", "{7E04821E-A6EE-4481-8204-6D127E6A8E5E}"
+ ProjectSection(ProjectDependencies) = postProject
+ {B52E2D10-A94A-4605-914A-2DCEF6A757EF} = {B52E2D10-A94A-4605-914A-2DCEF6A757EF}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcommon", "..\windows-libraries\src\libcommon\libcommon.vcxproj", "{B52E2D10-A94A-4605-914A-2DCEF6A757EF}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|x64 = Debug|x64
+ Release|x64 = Release|x64
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {7E04821E-A6EE-4481-8204-6D127E6A8E5E}.Debug|x64.ActiveCfg = Debug|x64
+ {7E04821E-A6EE-4481-8204-6D127E6A8E5E}.Debug|x64.Build.0 = Debug|x64
+ {7E04821E-A6EE-4481-8204-6D127E6A8E5E}.Release|x64.ActiveCfg = Release|x64
+ {7E04821E-A6EE-4481-8204-6D127E6A8E5E}.Release|x64.Build.0 = Release|x64
+ {B52E2D10-A94A-4605-914A-2DCEF6A757EF}.Debug|x64.ActiveCfg = Debug|x64
+ {B52E2D10-A94A-4605-914A-2DCEF6A757EF}.Debug|x64.Build.0 = Debug|x64
+ {B52E2D10-A94A-4605-914A-2DCEF6A757EF}.Release|x64.ActiveCfg = Release|x64
+ {B52E2D10-A94A-4605-914A-2DCEF6A757EF}.Release|x64.Build.0 = Release|x64
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {8CECF4BA-51AE-4EAF-AA3D-AD7B391E8A57}
+ EndGlobalSection
+EndGlobal
diff --git a/windows/nsis-plugins/src/driverlogic/driverlogic.vcxproj b/windows/driverlogic/driverlogic.vcxproj
index 40e9bac4e2..657e58d9eb 100644
--- a/windows/nsis-plugins/src/driverlogic/driverlogic.vcxproj
+++ b/windows/driverlogic/driverlogic.vcxproj
@@ -1,31 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="16.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
- <ProjectConfiguration Include="Debug|Win32">
+ <ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
- <Platform>Win32</Platform>
+ <Platform>x64</Platform>
</ProjectConfiguration>
- <ProjectConfiguration Include="Release|Win32">
+ <ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
- <Platform>Win32</Platform>
+ <Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
- <ProjectGuid>{AABA9AB7-A7D0-4BB5-A1FA-92F566023E0D}</ProjectGuid>
+ <ProjectGuid>{7E04821E-A6EE-4481-8204-6D127E6A8E5E}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>driverlogic</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
- <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
- <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
@@ -36,87 +36,72 @@
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
- <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
- <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)bin\$(Platform)-$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)bin\temp\$(Platform)-$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)bin\$(Platform)-$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)bin\temp\$(Platform)-$(Configuration)\$(ProjectName)\</IntDir>
</PropertyGroup>
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
- <PrecompiledHeader>Use</PrecompiledHeader>
- <WarningLevel>Level3</WarningLevel>
+ <PrecompiledHeader>Create</PrecompiledHeader>
+ <WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
- <PreprocessorDefinitions>WIN32;_DEBUG;DRIVERLOGIC_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
- <AdditionalIncludeDirectories>$(ProjectDir)../../../../dist-assets/binaries/x86_64-pc-windows-msvc/;$(ProjectDir)../../../windows-libraries/src/;$(ProjectDir)../</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>$(ProjectDir)../../../../dist-assets/binaries/x86_64-pc-windows-msvc/;$(ProjectDir)../windows-libraries/src/;$(ProjectDir)../</AdditionalIncludeDirectories>
<LanguageStandard>stdcpplatest</LanguageStandard>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
- <SubSystem>Windows</SubSystem>
+ <SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
- <ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
- <AdditionalLibraryDirectories>$(ProjectDir)../../../../dist-assets/binaries/x86_64-pc-windows-msvc/nsis/;$(SolutionDir)bin\$(Platform)-$(Configuration)\</AdditionalLibraryDirectories>
- <AdditionalDependencies>setupapi.lib;log.lib;libcommon.lib;pluginapi-x86-unicode.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
- <IgnoreSpecificDefaultLibraries>libc.lib</IgnoreSpecificDefaultLibraries>
- <ModuleDefinitionFile>driverlogic.def</ModuleDefinitionFile>
+ <AdditionalDependencies>newdev.lib;setupapi.lib;libcommon.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalLibraryDirectories>$(SolutionDir)bin\$(Platform)-$(Configuration)\</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
- <PrecompiledHeader>Use</PrecompiledHeader>
- <WarningLevel>Level3</WarningLevel>
+ <PrecompiledHeader>Create</PrecompiledHeader>
+ <WarningLevel>Level4</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
- <PreprocessorDefinitions>WIN32;NDEBUG;DRIVERLOGIC_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
- <AdditionalIncludeDirectories>$(ProjectDir)../../../../dist-assets/binaries/x86_64-pc-windows-msvc/;$(ProjectDir)../../../windows-libraries/src/;$(ProjectDir)../</AdditionalIncludeDirectories>
- <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<LanguageStandard>stdcpplatest</LanguageStandard>
+ <AdditionalIncludeDirectories>$(ProjectDir)../../../../dist-assets/binaries/x86_64-pc-windows-msvc/;$(ProjectDir)../windows-libraries/src/;$(ProjectDir)../</AdditionalIncludeDirectories>
+ <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
- <SubSystem>Windows</SubSystem>
+ <SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
- <ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
- <AdditionalLibraryDirectories>$(ProjectDir)../../../../dist-assets/binaries/x86_64-pc-windows-msvc/nsis/;$(SolutionDir)bin\$(Platform)-$(Configuration)\</AdditionalLibraryDirectories>
- <AdditionalDependencies>setupapi.lib;log.lib;libcommon.lib;pluginapi-x86-unicode.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
- <IgnoreSpecificDefaultLibraries>libc.lib</IgnoreSpecificDefaultLibraries>
- <ModuleDefinitionFile>driverlogic.def</ModuleDefinitionFile>
+ <AdditionalDependencies>newdev.lib;setupapi.lib;libcommon.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalLibraryDirectories>$(SolutionDir)bin\$(Platform)-$(Configuration)\</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
- <ClInclude Include="driverlogicops.h" />
- <ClInclude Include="stdafx.h" />
- <ClInclude Include="targetver.h" />
- </ItemGroup>
- <ItemGroup>
- <ClCompile Include="dllmain.cpp" />
- <ClCompile Include="driverlogic.cpp" />
- <ClCompile Include="driverlogicops.cpp" />
- <ClCompile Include="stdafx.cpp">
- <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
- <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
- </ClCompile>
+ <ClCompile Include="src\driverlogic.cpp" />
+ <ClCompile Include="src\stdafx.cpp" />
</ItemGroup>
<ItemGroup>
- <None Include="driverlogic.def" />
+ <ClInclude Include="src\stdafx.h" />
+ <ClInclude Include="src\targetver.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
diff --git a/windows/driverlogic/driverlogic.vcxproj.filters b/windows/driverlogic/driverlogic.vcxproj.filters
new file mode 100644
index 0000000000..ba18d9617c
--- /dev/null
+++ b/windows/driverlogic/driverlogic.vcxproj.filters
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup>
+ <Filter Include="Resource Files">
+ <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
+ <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="src\driverlogic.cpp" />
+ <ClCompile Include="src\stdafx.cpp" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="src\stdafx.h" />
+ <ClInclude Include="src\targetver.h" />
+ </ItemGroup>
+</Project> \ No newline at end of file
diff --git a/windows/nsis-plugins/src/driverlogic/driverlogicops.cpp b/windows/driverlogic/src/driverlogic.cpp
index b837565de1..16704b6c2b 100644
--- a/windows/nsis-plugins/src/driverlogic/driverlogicops.cpp
+++ b/windows/driverlogic/src/driverlogic.cpp
@@ -1,131 +1,129 @@
#include "stdafx.h"
-#include "driverlogicops.h"
-
-#include <libcommon/guid.h>
-#include <libcommon/string.h>
+#include <iostream>
+#include <sstream>
+#include <string>
+#include <optional>
+#include <set>
#include <libcommon/error.h>
+#include <libcommon/guid.h>
#include <libcommon/memory.h>
#include <libcommon/network/nci.h>
-#include <log/log.h>
-
-#include <windows.h>
-
-#include <vector>
-#include <list>
-#include <sstream>
-#include <algorithm>
-
+#include <libcommon/string.h>
#include <setupapi.h>
-#include <devguid.h>
-#include <combaseapi.h>
#include <initguid.h>
+#include <devguid.h>
#include <devpkey.h>
+#include <newdev.h>
+
namespace
{
-const wchar_t TAP_HARDWARE_ID[] = L"tapmullvad0901";
-const wchar_t DEPRECATED_TAP_HARDWARE_ID[] = L"tap0901";
+constexpr wchar_t DEPRECATED_TAP_HARDWARE_ID[] = L"tap0901";
+constexpr wchar_t TAP_HARDWARE_ID[] = L"tapmullvad0901";
+constexpr wchar_t TAP_BASE_ALIAS[] = L"Mullvad";
-template<typename T>
-void LogAdapters(const std::wstring &description, const T &adapters)
+enum ReturnCodes
{
- //
- // Flatten the information so we can log it more easily.
- //
+ GENERAL_ERROR,
+ GENERAL_SUCCESS,
+ DELETE_NO_ADAPTERS_REMAIN,
+ DELETE_SOME_ADAPTERS_REMAIN
+};
- std::vector<std::wstring> details;
+struct NetworkAdapter
+{
+ std::wstring guid;
+ std::wstring name;
+ std::wstring alias;
+ std::wstring deviceInstanceId;
- for (const auto &adapter : adapters)
+ NetworkAdapter(std::wstring guid, std::wstring name, std::wstring alias, std::wstring deviceInstanceId)
+ : guid(guid)
+ , name(name)
+ , alias(alias)
+ , deviceInstanceId(deviceInstanceId)
{
- details.emplace_back(L"Adapter");
-
- details.emplace_back(std::wstring(L" Guid: ").append(adapter.guid));
- details.emplace_back(std::wstring(L" Name: ").append(adapter.name));
- details.emplace_back(std::wstring(L" Alias: ").append(adapter.alias));
}
- PluginLogWithDetails(description, details);
-}
-
-} // anonymous namespace
-
-namespace driverlogic
-{
-
-std::wstring GetNetCfgInstanceId(HDEVINFO devInfo, const SP_DEVINFO_DATA &devInfoData)
-{
- HKEY hNet = SetupDiOpenDevRegKey(
- devInfo,
- const_cast<SP_DEVINFO_DATA *>(&devInfoData),
- DICS_FLAG_GLOBAL,
- 0,
- DIREG_DRV,
- KEY_READ
- );
-
- if (hNet == INVALID_HANDLE_VALUE)
+ bool operator<(const NetworkAdapter &rhs) const
{
- THROW_WINDOWS_ERROR(GetLastError(), "SetupDiOpenDevRegKey");
+ return _wcsicmp(deviceInstanceId.c_str(), rhs.deviceInstanceId.c_str()) < 0;
}
+};
- std::vector<wchar_t> instanceId(MAX_PATH + sizeof(L'\0'));
- DWORD strSize = instanceId.size() * sizeof(wchar_t);
-
- const auto status = RegGetValueW(
- hNet,
- nullptr,
- L"NetCfgInstanceId",
- RRF_RT_REG_SZ,
- nullptr,
- instanceId.data(),
- &strSize
- );
-
- RegCloseKey(hNet);
+void LogAdapters(const std::wstring &description, const std::set<NetworkAdapter> &adapters)
+{
+ std::wcout << description << std::endl;
- if (ERROR_SUCCESS != status)
+ for (const auto &adapter : adapters)
{
- THROW_WINDOWS_ERROR(status, "RegGetValueW");
+ std::wcout << L" Adapter\n"
+ << L" Guid: " << adapter.guid << L'\n'
+ << L" Name: " << adapter.name << L'\n'
+ << L" Alias: " << adapter.alias << L'\n'
+ << L" Device instance ID: " << adapter.deviceInstanceId
+ << std::endl;
}
-
- instanceId[strSize / sizeof(wchar_t)] = L'\0';
-
- return instanceId.data();
}
-std::wstring GetDeviceInstanceId(
+std::optional<std::wstring> GetDeviceRegistryStringProperty(
HDEVINFO devInfo,
- SP_DEVINFO_DATA* devInfoData
+ SP_DEVINFO_DATA *devInfoData,
+ DWORD property
)
{
+ //
+ // Obtain required buffer size
+ //
+
DWORD requiredSize = 0;
- SetupDiGetDeviceInstanceIdW(
+ const auto sizeStatus = SetupDiGetDeviceRegistryPropertyW(
devInfo,
devInfoData,
+ property,
+ nullptr,
nullptr,
0,
&requiredSize
);
- std::vector<wchar_t> deviceInstanceId;
- deviceInstanceId.resize(1 + requiredSize * sizeof(wchar_t));
+ const DWORD lastError = GetLastError();
+ if (FALSE == sizeStatus && ERROR_INSUFFICIENT_BUFFER != lastError)
+ {
+ // ERROR_INVALID_DATA may mean that the property does not exist
+ // TODO: Check if there may be other causes.
+ if (ERROR_INVALID_DATA != lastError)
+ {
+ THROW_WINDOWS_ERROR(lastError, "SetupDiGetDeviceRegistryPropertyW");
+ }
- const auto status = SetupDiGetDeviceInstanceIdW(
+ return std::nullopt;
+ }
+
+ //
+ // Read property
+ //
+
+ std::vector<wchar_t> buffer(requiredSize / sizeof(wchar_t));
+
+ const auto status = SetupDiGetDeviceRegistryPropertyW(
devInfo,
devInfoData,
- &deviceInstanceId[0],
- deviceInstanceId.size(),
+ property,
+ nullptr,
+ reinterpret_cast<PBYTE>(&buffer[0]),
+ requiredSize,
nullptr
);
if (FALSE == status)
{
- THROW_WINDOWS_ERROR(GetLastError(), "SetupDiGetDeviceInstanceIdW() failed");
+ THROW_WINDOWS_ERROR(GetLastError(), "Failed to read device property");
}
- return deviceInstanceId.data();
+ return std::make_optional(buffer.data());
}
std::wstring GetDeviceStringProperty(
@@ -162,8 +160,7 @@ std::wstring GetDeviceStringProperty(
}
}
- std::vector<wchar_t> buffer;
- buffer.resize(1 + requiredSize / sizeof(wchar_t));
+ std::vector<wchar_t> buffer(requiredSize / sizeof(wchar_t));
//
// Read property
@@ -175,7 +172,7 @@ std::wstring GetDeviceStringProperty(
property,
&type,
reinterpret_cast<PBYTE>(&buffer[0]),
- buffer.size() * sizeof(wchar_t),
+ requiredSize,
nullptr,
0
);
@@ -188,64 +185,76 @@ std::wstring GetDeviceStringProperty(
return buffer.data();
}
-std::optional<std::wstring> GetDeviceRegistryStringProperty(
+std::wstring GetDeviceInstanceId(
HDEVINFO devInfo,
- SP_DEVINFO_DATA *devInfoData,
- DWORD property
+ SP_DEVINFO_DATA *devInfoData
)
{
- //
- // Obtain required buffer size
- //
-
DWORD requiredSize = 0;
- const auto sizeStatus = SetupDiGetDeviceRegistryPropertyW(
+ SetupDiGetDeviceInstanceIdW(
devInfo,
devInfoData,
- property,
- nullptr,
nullptr,
0,
&requiredSize
);
- const DWORD lastError = GetLastError();
- if (FALSE == sizeStatus && ERROR_INSUFFICIENT_BUFFER != lastError)
- {
- // ERROR_INVALID_DATA may mean that the property does not exist
- // TODO: Check if there may be other causes.
- if (ERROR_INVALID_DATA != lastError)
- {
- THROW_WINDOWS_ERROR(lastError, "SetupDiGetDeviceRegistryPropertyW");
- }
+ std::vector<wchar_t> deviceInstanceId(1 + requiredSize);
- return std::nullopt;
- }
+ const auto status = SetupDiGetDeviceInstanceIdW(
+ devInfo,
+ devInfoData,
+ &deviceInstanceId[0],
+ requiredSize,
+ nullptr
+ );
- //
- // Read property
- //
+ if (FALSE == status)
+ {
+ THROW_WINDOWS_ERROR(GetLastError(), "SetupDiGetDeviceInstanceIdW");
+ }
- std::vector<wchar_t> buffer;
- buffer.resize(1 + requiredSize / sizeof(wchar_t));
+ return deviceInstanceId.data();
+}
- const auto status = SetupDiGetDeviceRegistryPropertyW(
+std::wstring GetNetCfgInstanceId(HDEVINFO devInfo, const SP_DEVINFO_DATA &devInfoData)
+{
+ HKEY hNet = SetupDiOpenDevRegKey(
devInfo,
- devInfoData,
- property,
+ const_cast<SP_DEVINFO_DATA *>(&devInfoData),
+ DICS_FLAG_GLOBAL,
+ 0,
+ DIREG_DRV,
+ KEY_READ
+ );
+
+ if (hNet == INVALID_HANDLE_VALUE)
+ {
+ THROW_WINDOWS_ERROR(GetLastError(), "SetupDiOpenDevRegKey");
+ }
+
+ std::vector<wchar_t> instanceId(MAX_PATH + 1);
+ DWORD strSize = static_cast<DWORD>(instanceId.size() * sizeof(wchar_t));
+
+ const auto status = RegGetValueW(
+ hNet,
nullptr,
- reinterpret_cast<PBYTE>(&buffer[0]),
- buffer.size() * sizeof(wchar_t),
- nullptr
+ L"NetCfgInstanceId",
+ RRF_RT_REG_SZ,
+ nullptr,
+ instanceId.data(),
+ &strSize
);
- if (FALSE == status)
+ RegCloseKey(hNet);
+
+ if (ERROR_SUCCESS != status)
{
- THROW_WINDOWS_ERROR(GetLastError(), "Failed to read device property");
+ THROW_WINDOWS_ERROR(status, "RegGetValueW");
}
- return { buffer.data() };
+ return instanceId.data();
}
std::set<NetworkAdapter> GetTapAdapters(const std::wstring &tapHardwareId)
@@ -317,28 +326,132 @@ std::set<NetworkAdapter> GetTapAdapters(const std::wstring &tapHardwareId)
GetDeviceInstanceId(devInfo, &devInfoData)
));
}
- catch (const std::exception &e)
+ catch (const std::exception & e)
{
//
// Log exception and skip this adapter
//
- const auto msg =
- std::string("Skipping TAP adapter due to exception caught while iterating: ").append(e.what());
- PluginLog(common::string::ToWide(msg));
+ std::cerr << "Skipping TAP adapter due to exception caught while iterating: "
+ << e.what() << std::endl;
}
}
return adapters;
}
+void CreateTapDevice()
+{
+ GUID classGuid = GUID_DEVCLASS_NET;
+
+ const auto deviceInfoSet = SetupDiCreateDeviceInfoList(&classGuid, 0);
+ if (INVALID_HANDLE_VALUE == deviceInfoSet)
+ {
+ THROW_WINDOWS_ERROR(GetLastError(), "SetupDiCreateDeviceInfoList");
+ }
+
+ common::memory::ScopeDestructor scopeDestructor;
+ scopeDestructor += [&deviceInfoSet]()
+ {
+ SetupDiDestroyDeviceInfoList(deviceInfoSet);
+ };
+
+ SP_DEVINFO_DATA devInfoData;
+ devInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
+
+ auto status = SetupDiCreateDeviceInfoW(
+ deviceInfoSet,
+ L"NET",
+ &classGuid,
+ nullptr,
+ 0,
+ DICD_GENERATE_ID,
+ &devInfoData
+ );
+
+ if (FALSE == status)
+ {
+ THROW_WINDOWS_ERROR(GetLastError(), "SetupDiCreateDeviceInfoW");
+ }
+
+ status = SetupDiSetDeviceRegistryPropertyW(
+ deviceInfoSet,
+ &devInfoData,
+ SPDRP_HARDWAREID,
+ reinterpret_cast<const BYTE *>(TAP_HARDWARE_ID),
+ sizeof(TAP_HARDWARE_ID) - sizeof(L'\0')
+ );
+
+ if (FALSE == status)
+ {
+ THROW_WINDOWS_ERROR(GetLastError(), "SetupDiSetDeviceRegistryPropertyW");
+ }
+
+ //
+ // Create a devnode in the PnP HW tree
+ //
+ status = SetupDiCallClassInstaller(
+ DIF_REGISTERDEVICE,
+ deviceInfoSet,
+ &devInfoData
+ );
+
+ if (FALSE == status)
+ {
+ THROW_WINDOWS_ERROR(GetLastError(), "SetupDiCallClassInstaller");
+ }
+
+ std::wcout << L"Created new TAP adapter successfully" << std::endl;
+}
+
+void UpdateTapDriver(const std::wstring &infPath)
+{
+ std::wcout << L"Attempting to install new driver" << std::endl;
+
+ DWORD installFlags = 0;
+ BOOL rebootRequired = FALSE;
+
+ATTEMPT_UPDATE:
+
+ auto result = UpdateDriverForPlugAndPlayDevicesW(
+ nullptr,
+ TAP_HARDWARE_ID,
+ infPath.c_str(),
+ installFlags,
+ &rebootRequired
+ );
+
+ if (FALSE == result)
+ {
+ const auto lastError = GetLastError();
+
+ if (ERROR_NO_MORE_ITEMS == lastError
+ && (installFlags ^ INSTALLFLAG_FORCE))
+ {
+ std::wcout << L"Driver update failed. Attempting forced install." << std::endl;
+ installFlags |= INSTALLFLAG_FORCE;
+
+ goto ATTEMPT_UPDATE;
+ }
+
+ THROW_WINDOWS_ERROR(lastError, "UpdateDriverForPlugAndPlayDevicesW");
+ }
+
+ //
+ // Driver successfully installed or updated
+ //
+
+ std::wcout << L"TAP driver update complete. Reboot required: "
+ << rebootRequired;
+}
+
std::optional<NetworkAdapter> FindMullvadAdapter(const std::set<NetworkAdapter> &tapAdapters)
{
if (tapAdapters.empty())
{
return std::nullopt;
}
-
+
//
// Look for TAP adapter with alias "Mullvad".
//
@@ -346,20 +459,18 @@ std::optional<NetworkAdapter> FindMullvadAdapter(const std::set<NetworkAdapter>
auto findByAlias = [](const std::set<NetworkAdapter> &adapters, const std::wstring &alias)
{
const auto it = std::find_if(adapters.begin(), adapters.end(), [&alias](const NetworkAdapter &candidate)
- {
- return 0 == _wcsicmp(candidate.alias.c_str(), alias.c_str());
- });
+ {
+ return 0 == _wcsicmp(candidate.alias.c_str(), alias.c_str());
+ });
return it;
};
- static const wchar_t baseAlias[] = L"Mullvad";
-
- const auto mullvadAdapter = findByAlias(tapAdapters, baseAlias);
+ const auto firstMullvadAdapter = findByAlias(tapAdapters, TAP_BASE_ALIAS);
- if (tapAdapters.end() != mullvadAdapter)
+ if (tapAdapters.end() != firstMullvadAdapter)
{
- return { *mullvadAdapter };
+ return { *firstMullvadAdapter };
}
//
@@ -370,7 +481,7 @@ std::optional<NetworkAdapter> FindMullvadAdapter(const std::set<NetworkAdapter>
{
std::wstringstream ss;
- ss << baseAlias << L"-" << i;
+ ss << TAP_BASE_ALIAS << L"-" << i;
const auto alias = ss.str();
@@ -385,7 +496,7 @@ std::optional<NetworkAdapter> FindMullvadAdapter(const std::set<NetworkAdapter>
return std::nullopt;
}
-NetworkAdapter GetAdapter()
+NetworkAdapter FindBrandedTap()
{
std::set<NetworkAdapter> added = GetTapAdapters(TAP_HARDWARE_ID);
@@ -403,7 +514,13 @@ NetworkAdapter GetAdapter()
return *added.begin();
}
-DeletionResult DeleteOldMullvadAdapter()
+enum class DeletionResult
+{
+ NO_REMAINING_TAP_ADAPTERS,
+ SOME_REMAINING_TAP_ADAPTERS
+};
+
+DeletionResult DeleteVanillaMullvadAdapter()
{
auto tapAdapters = GetTapAdapters(DEPRECATED_TAP_HARDWARE_ID);
std::optional<NetworkAdapter> mullvadAdapter = FindMullvadAdapter(tapAdapters);
@@ -439,7 +556,7 @@ DeletionResult DeleteOldMullvadAdapter()
{
SP_DEVINFO_DATA devInfoData = { 0 };
devInfoData.cbSize = sizeof(devInfoData);
-
+
if (FALSE == SetupDiEnumDeviceInfo(devInfo, memberIndex, &devInfoData))
{
const auto lastError = GetLastError();
@@ -470,12 +587,26 @@ DeletionResult DeleteOldMullvadAdapter()
continue;
}
- if (FALSE == SetupDiRemoveDevice(
- devInfo,
- &devInfoData
- ))
+ //
+ // Delete existing device
+ //
+
+ SP_REMOVEDEVICE_PARAMS rmdParams;
+ rmdParams.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);
+ rmdParams.ClassInstallHeader.InstallFunction = DIF_REMOVE;
+ rmdParams.Scope = DI_REMOVEDEVICE_GLOBAL;
+ rmdParams.HwProfile = 0;
+
+ auto status = SetupDiSetClassInstallParamsW(devInfo, &devInfoData, &rmdParams.ClassInstallHeader, sizeof(rmdParams));
+ if (FALSE == status)
+ {
+ THROW_WINDOWS_ERROR(GetLastError(), "SetupDiSetClassInstallParamsW");
+ }
+
+ status = SetupDiCallClassInstaller(DIF_REMOVE, devInfo, &devInfoData);
+ if (FALSE == status)
{
- THROW_WINDOWS_ERROR(GetLastError(), "Error removing Mullvad TAP device");
+ THROW_WINDOWS_ERROR(GetLastError(), "SetupDiCallClassInstaller");
}
}
catch (const std::exception & e)
@@ -484,9 +615,8 @@ DeletionResult DeleteOldMullvadAdapter()
// Log exception and skip this adapter
//
- const auto msg =
- std::string("Skipping TAP adapter due to exception caught while iterating: ").append(e.what());
- PluginLog(common::string::ToWide(msg));
+ std::cerr << "Skipping TAP adapter due to exception caught while iterating: "
+ << e.what();
}
}
@@ -495,4 +625,73 @@ DeletionResult DeleteOldMullvadAdapter()
: DeletionResult::NO_REMAINING_TAP_ADAPTERS;
}
+} // anonymous namespace
+
+int wmain(int argc, const wchar_t * argv[], const wchar_t * [])
+{
+ if (2 > argc)
+ {
+ goto INVALID_ARGUMENTS;
+ }
+
+ try
+ {
+ if (0 == _wcsicmp(argv[1], L"install"))
+ {
+ if (3 != argc)
+ {
+ goto INVALID_ARGUMENTS;
+ }
+
+ CreateTapDevice();
+ UpdateTapDriver(argv[2]);
+ }
+ else if (0 == _wcsicmp(argv[1], L"update"))
+ {
+ if (3 != argc)
+ {
+ goto INVALID_ARGUMENTS;
+ }
+
+ UpdateTapDriver(argv[2]);
+ }
+ else if (0 == _wcsicmp(argv[1], L"remove-vanilla-tap"))
+ {
+ switch (DeleteVanillaMullvadAdapter())
+ {
+ case DeletionResult::NO_REMAINING_TAP_ADAPTERS:
+ std::wcout << L"Removed vanilla Mullvad TAP.";
+ return DELETE_NO_ADAPTERS_REMAIN;
+
+ case DeletionResult::SOME_REMAINING_TAP_ADAPTERS:
+ std::wcout << L"Removed vanilla Mullvad TAP.";
+ return DELETE_SOME_ADAPTERS_REMAIN;
+ }
+ }
+ else if (0 == _wcsicmp(argv[1], L"find-tap"))
+ {
+ const auto tap = FindBrandedTap();
+ std::wcout << tap.alias;
+ }
+ else
+ {
+ goto INVALID_ARGUMENTS;
+ }
+ }
+ catch (const std::exception &e)
+ {
+ std::cerr << e.what();
+ return GENERAL_ERROR;
+ }
+ catch (...)
+ {
+ std::wcerr << L"Unhandled exception.";
+ return GENERAL_ERROR;
+ }
+ return GENERAL_SUCCESS;
+
+INVALID_ARGUMENTS:
+
+ std::wcerr << L"Invalid arguments.";
+ return GENERAL_ERROR;
}
diff --git a/windows/nsis-plugins/src/driverlogic/stdafx.cpp b/windows/driverlogic/src/stdafx.cpp
index 3b6341d106..3b6341d106 100644
--- a/windows/nsis-plugins/src/driverlogic/stdafx.cpp
+++ b/windows/driverlogic/src/stdafx.cpp
diff --git a/windows/nsis-plugins/src/driverlogic/stdafx.h b/windows/driverlogic/src/stdafx.h
index f3a07375c7..f3a07375c7 100644
--- a/windows/nsis-plugins/src/driverlogic/stdafx.h
+++ b/windows/driverlogic/src/stdafx.h
diff --git a/windows/nsis-plugins/src/driverlogic/targetver.h b/windows/driverlogic/src/targetver.h
index ae4a5c032c..ae4a5c032c 100644
--- a/windows/nsis-plugins/src/driverlogic/targetver.h
+++ b/windows/driverlogic/src/targetver.h
diff --git a/windows/nsis-plugins/nsis-plugins.sln b/windows/nsis-plugins/nsis-plugins.sln
index 4518d1f0fe..487b4bebf4 100644
--- a/windows/nsis-plugins/nsis-plugins.sln
+++ b/windows/nsis-plugins/nsis-plugins.sln
@@ -2,12 +2,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29324.140
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "driverlogic", "src\driverlogic\driverlogic.vcxproj", "{AABA9AB7-A7D0-4BB5-A1FA-92F566023E0D}"
- ProjectSection(ProjectDependencies) = postProject
- {B52E2D10-A94A-4605-914A-2DCEF6A757EF} = {B52E2D10-A94A-4605-914A-2DCEF6A757EF}
- {1344152F-2BAD-4198-8E51-31AAC32BFBB2} = {1344152F-2BAD-4198-8E51-31AAC32BFBB2}
- EndProjectSection
-EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cleanup", "src\cleanup\cleanup.vcxproj", "{47B5C1C1-67D7-4544-9037-8E7F44C1E5BD}"
ProjectSection(ProjectDependencies) = postProject
{B52E2D10-A94A-4605-914A-2DCEF6A757EF} = {B52E2D10-A94A-4605-914A-2DCEF6A757EF}
@@ -55,10 +49,6 @@ Global
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {AABA9AB7-A7D0-4BB5-A1FA-92F566023E0D}.Debug|x86.ActiveCfg = Debug|Win32
- {AABA9AB7-A7D0-4BB5-A1FA-92F566023E0D}.Debug|x86.Build.0 = Debug|Win32
- {AABA9AB7-A7D0-4BB5-A1FA-92F566023E0D}.Release|x86.ActiveCfg = Release|Win32
- {AABA9AB7-A7D0-4BB5-A1FA-92F566023E0D}.Release|x86.Build.0 = Release|Win32
{47B5C1C1-67D7-4544-9037-8E7F44C1E5BD}.Debug|x86.ActiveCfg = Debug|Win32
{47B5C1C1-67D7-4544-9037-8E7F44C1E5BD}.Debug|x86.Build.0 = Debug|Win32
{47B5C1C1-67D7-4544-9037-8E7F44C1E5BD}.Release|x86.ActiveCfg = Release|Win32
diff --git a/windows/nsis-plugins/src/driverlogic/dllmain.cpp b/windows/nsis-plugins/src/driverlogic/dllmain.cpp
deleted file mode 100644
index a5a44613dd..0000000000
--- a/windows/nsis-plugins/src/driverlogic/dllmain.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-#include "stdafx.h"
-#include <windows.h>
-
-BOOL APIENTRY DllMain(HMODULE, DWORD reason, LPVOID)
-{
- //
- // Avoid doing work in DllMain since the loader lock is held
- //
-
- return TRUE;
-}
diff --git a/windows/nsis-plugins/src/driverlogic/driverlogic.cpp b/windows/nsis-plugins/src/driverlogic/driverlogic.cpp
deleted file mode 100644
index 6861bbd623..0000000000
--- a/windows/nsis-plugins/src/driverlogic/driverlogic.cpp
+++ /dev/null
@@ -1,115 +0,0 @@
-#include "stdafx.h"
-#include "../error.h"
-#include "driverlogicops.h"
-#include <libcommon/string.h>
-#include <libcommon/error.h>
-#include <libcommon/valuemapper.h>
-#include <windows.h>
-
-// Suppress warnings caused by broken legacy code
-#pragma warning (push)
-#pragma warning (disable: 4005)
-#include <nsis/pluginapi.h>
-#pragma warning (pop)
-
-//
-// RemoveVanillaMullvadTap
-//
-// Deletes the old Mullvad TAP adapter with ID tap0901.
-//
-//
-enum class RemoveVanillaMullvadTapStatus
-{
- GENERAL_ERROR = 0,
- SUCCESS_NO_REMAINING_TAP_ADAPTERS,
- SUCCESS_SOME_REMAINING_TAP_ADAPTERS
-};
-
-void __declspec(dllexport) NSISCALL RemoveVanillaMullvadTap
-(
- HWND hwndParent,
- int string_size,
- LPTSTR variables,
- stack_t **stacktop,
- extra_parameters *extra,
- ...
-)
-{
- EXDLL_INIT();
-
- try
- {
- pushstring(L"");
-
- switch (driverlogic::DeleteOldMullvadAdapter())
- {
- case driverlogic::DeletionResult::NO_REMAINING_TAP_ADAPTERS:
- {
- pushint(RemoveVanillaMullvadTapStatus::SUCCESS_NO_REMAINING_TAP_ADAPTERS);
- break;
- }
-
- case driverlogic::DeletionResult::SOME_REMAINING_TAP_ADAPTERS:
- {
- pushint(RemoveVanillaMullvadTapStatus::SUCCESS_SOME_REMAINING_TAP_ADAPTERS);
- break;
- }
-
- default:
- {
- THROW_ERROR("Unexpected case");
- }
- }
- }
- catch (std::exception &err)
- {
- pushstring(common::string::ToWide(err.what()).c_str());
- pushint(RemoveVanillaMullvadTapStatus::GENERAL_ERROR);
- }
- catch (...)
- {
- pushstring(L"Unspecified error");
- pushint(RemoveVanillaMullvadTapStatus::GENERAL_ERROR);
- }
-}
-
-
-//
-// IdentifyNewAdapter
-//
-// Call this function after installing a TAP adapter.
-//
-// By comparing with the previously captured baseline we're able to
-// identify the new adapter.
-//
-
-void __declspec(dllexport) NSISCALL IdentifyNewAdapter
-(
- HWND hwndParent,
- int string_size,
- LPTSTR variables,
- stack_t **stacktop,
- extra_parameters *extra,
- ...
-)
-{
- EXDLL_INIT();
-
- try
- {
- auto adapter = driverlogic::GetAdapter();
-
- pushstring(adapter.alias.c_str());
- pushint(NsisStatus::SUCCESS);
- }
- catch (std::exception &err)
- {
- pushstring(common::string::ToWide(err.what()).c_str());
- pushint(NsisStatus::GENERAL_ERROR);
- }
- catch (...)
- {
- pushstring(L"Unspecified error");
- pushint(NsisStatus::GENERAL_ERROR);
- }
-}
diff --git a/windows/nsis-plugins/src/driverlogic/driverlogic.def b/windows/nsis-plugins/src/driverlogic/driverlogic.def
deleted file mode 100644
index 78730b5f9b..0000000000
--- a/windows/nsis-plugins/src/driverlogic/driverlogic.def
+++ /dev/null
@@ -1,6 +0,0 @@
-LIBRARY driverlogic
-
-EXPORTS
-
-IdentifyNewAdapter
-RemoveVanillaMullvadTap
diff --git a/windows/nsis-plugins/src/driverlogic/driverlogic.vcxproj.filters b/windows/nsis-plugins/src/driverlogic/driverlogic.vcxproj.filters
deleted file mode 100644
index 2c390fd544..0000000000
--- a/windows/nsis-plugins/src/driverlogic/driverlogic.vcxproj.filters
+++ /dev/null
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <ItemGroup>
- <ClInclude Include="stdafx.h" />
- <ClInclude Include="targetver.h" />
- <ClInclude Include="driverlogicops.h" />
- </ItemGroup>
- <ItemGroup>
- <ClCompile Include="dllmain.cpp" />
- <ClCompile Include="driverlogic.cpp" />
- <ClCompile Include="stdafx.cpp" />
- <ClCompile Include="driverlogicops.cpp" />
- </ItemGroup>
- <ItemGroup>
- <None Include="driverlogic.def" />
- </ItemGroup>
-</Project> \ No newline at end of file
diff --git a/windows/nsis-plugins/src/driverlogic/driverlogicops.h b/windows/nsis-plugins/src/driverlogic/driverlogicops.h
deleted file mode 100644
index c56ff60472..0000000000
--- a/windows/nsis-plugins/src/driverlogic/driverlogicops.h
+++ /dev/null
@@ -1,46 +0,0 @@
-#pragma once
-
-#include <set>
-#include <string>
-#include <optional>
-
-namespace driverlogic
-{
-
-struct NetworkAdapter
-{
- std::wstring guid;
- std::wstring name;
- std::wstring alias;
- std::wstring deviceInstanceId;
-
- NetworkAdapter(std::wstring guid, std::wstring name, std::wstring alias, std::wstring deviceInstanceId)
- : guid(guid)
- , name(name)
- , alias(alias)
- , deviceInstanceId(deviceInstanceId)
- {
- }
-
- bool operator<(const NetworkAdapter &rhs) const
- {
- return _wcsicmp(deviceInstanceId.c_str(), rhs.deviceInstanceId.c_str()) < 0;
- }
-};
-
-//
-// Identify the Mullvad TAP adapter
-//
-NetworkAdapter GetAdapter();
-
-enum class DeletionResult
-{
- NO_REMAINING_TAP_ADAPTERS,
- SOME_REMAINING_TAP_ADAPTERS
-};
-
-DeletionResult DeleteOldMullvadAdapter();
-
-std::optional<NetworkAdapter> FindMullvadAdapter(const std::set<NetworkAdapter> &tapAdapters);
-
-}