From 62f21f2fdd7001612dc42336dc03ab1bdf4b7ca0 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sat, 31 Oct 2020 12:34:01 +0100 Subject: [PATCH] api: link to nci.dll at compile time Signed-off-by: Jason A. Donenfeld Signed-off-by: Simon Rozman --- api/api.vcxproj | 9 ++++++--- api/api.vcxproj.filters | 6 +++--- api/entry.c | 4 ---- api/nci.c | 41 ----------------------------------------- api/nci.def | 3 +++ api/nci.h | 13 +++---------- 6 files changed, 15 insertions(+), 61 deletions(-) delete mode 100644 api/nci.c create mode 100644 api/nci.def diff --git a/api/api.vcxproj b/api/api.vcxproj index 0883de8..b93990d 100644 --- a/api/api.vcxproj +++ b/api/api.vcxproj @@ -114,9 +114,12 @@ _M_ARM=7;%(PreprocessorDefinitions) _M_ARM64=1;%(PreprocessorDefinitions) + + lib.exe /def:nci.def /out:"$(IntDir)nci.lib" /machine:$(PlatformTarget) /nologo + - bcrypt.dll;iphlpapi.dll;newdev.dll;version.dll - Bcrypt.lib;Crypt32.lib;Cfgmgr32.lib;Iphlpapi.lib;newdev.lib;ntdll.lib;Setupapi.lib;shlwapi.lib;version.lib;%(AdditionalDependencies) + bcrypt.dll;iphlpapi.dll;nci.dll;newdev.dll;version.dll + Bcrypt.lib;Crypt32.lib;Cfgmgr32.lib;Iphlpapi.lib;$(IntDir)nci.lib;newdev.lib;ntdll.lib;Setupapi.lib;shlwapi.lib;version.lib;%(AdditionalDependencies) exports.def Windows @@ -149,6 +152,7 @@ + @@ -168,7 +172,6 @@ - diff --git a/api/api.vcxproj.filters b/api/api.vcxproj.filters index 90061fb..c1db346 100644 --- a/api/api.vcxproj.filters +++ b/api/api.vcxproj.filters @@ -23,6 +23,9 @@ Source Files + + Source Files + @@ -60,9 +63,6 @@ Source Files - - Source Files - Source Files diff --git a/api/entry.c b/api/entry.c index df24ff9..2232c18 100644 --- a/api/entry.c +++ b/api/entry.c @@ -8,7 +8,6 @@ #include "logger.h" #include "registry.h" #include "namespace.h" -#include "nci.h" #include "wintun.h" #include @@ -84,12 +83,9 @@ DllMain(_In_ HINSTANCE hinstDLL, _In_ DWORD fdwReason, _In_ LPVOID lpvReserved) L"O:SYD:P(A;;GA;;;SY)", SDDL_REVISION_1, &SecurityAttributes.lpSecurityDescriptor, NULL); AdapterInit(); NamespaceInit(); - if (NciInit() != ERROR_SUCCESS) - return FALSE; break; case DLL_PROCESS_DETACH: - NciCleanup(); NamespaceCleanup(); LocalFree(SecurityAttributes.lpSecurityDescriptor); HeapDestroy(ModuleHeap); diff --git a/api/nci.c b/api/nci.c deleted file mode 100644 index e4dea9d..0000000 --- a/api/nci.c +++ /dev/null @@ -1,41 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 - * - * Copyright (C) 2018-2020 WireGuard LLC. All Rights Reserved. - */ - -#include "nci.h" -#include - -static HMODULE NciModule; - -DWORD(WINAPI *NciSetConnectionName)(_In_ const GUID *Guid, _In_z_ const WCHAR *NewName); - -DWORD(WINAPI *NciGetConnectionName) -(_In_ const GUID *Guid, - _Out_z_bytecap_(InDestNameBytes) WCHAR *Name, - _In_ DWORD InDestNameBytes, - _Out_opt_ DWORD *OutDestNameBytes); - -WINTUN_STATUS -NciInit(void) -{ - NciModule = LoadLibraryExW(L"nci.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32); - if (!NciModule) - return GetLastError(); - NciSetConnectionName = - (DWORD(WINAPI *)(const GUID *, const WCHAR *))GetProcAddress(NciModule, "NciSetConnectionName"); - if (!NciSetConnectionName) - return GetLastError(); - NciGetConnectionName = - (DWORD(WINAPI *)(const GUID *, WCHAR *, DWORD, DWORD *))GetProcAddress(NciModule, "NciGetConnectionName"); - if (!NciGetConnectionName) - return GetLastError(); - return ERROR_SUCCESS; -} - -void -NciCleanup(void) -{ - if (NciModule) - FreeLibrary(NciModule); -} diff --git a/api/nci.def b/api/nci.def new file mode 100644 index 0000000..de1b6ea --- /dev/null +++ b/api/nci.def @@ -0,0 +1,3 @@ +EXPORTS + NciGetConnectionName + NciSetConnectionName diff --git a/api/nci.h b/api/nci.h index ef0981f..1346d7a 100644 --- a/api/nci.h +++ b/api/nci.h @@ -5,19 +5,12 @@ #pragma once -#include "wintun.h" #include -extern DWORD(WINAPI *NciSetConnectionName)(_In_ const GUID *Guid, _In_z_ const WCHAR *NewName); +extern DWORD WINAPI NciSetConnectionName(_In_ const GUID *Guid, _In_z_ const WCHAR *NewName); -extern DWORD(WINAPI *NciGetConnectionName)( +extern DWORD WINAPI NciGetConnectionName( _In_ const GUID *Guid, _Out_z_bytecap_(InDestNameBytes) WCHAR *Name, _In_ DWORD InDestNameBytes, - _Out_opt_ DWORD *OutDestNameBytes); - -WINTUN_STATUS -NciInit(void); - -void -NciCleanup(void); + _Out_opt_ DWORD *OutDestNameBytes); \ No newline at end of file