1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
#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);
}
}
|