api: make nci.lib work on x86

This is an appalling hack. We need the lib tool to generate a coff lib
with the "undecorate" parameter. And apparently the only way to do this
with the MSVC tools is by making a stub object, and then rewriting the
symbols using the def file. See Q131313 for Microsoft-sanctioned
details.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2020-11-02 11:36:13 +01:00
parent 7f35f0dbab
commit 724508d61f
4 changed files with 19 additions and 5 deletions

View File

@ -121,7 +121,8 @@
<PreprocessorDefinitions Condition="'$(Platform)'=='ARM64'">_M_ARM64=1;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions Condition="'$(Platform)'=='ARM64'">_M_ARM64=1;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ResourceCompile> </ResourceCompile>
<PreLinkEvent> <PreLinkEvent>
<Command>lib.exe /def:nci.def /out:"$(IntDir)nci.lib" /machine:$(PlatformTarget) /nologo</Command> <Command>cl.exe /nologo /DGENERATE_LIB /Ob0 /c /Fo"$(IntDir)nci.obj" /Tc nci.h
lib.exe /def:nci.def /out:"$(IntDir)nci.lib" /machine:$(PlatformTarget) /nologo "$(IntDir)nci.obj"</Command>
</PreLinkEvent> </PreLinkEvent>
<Link> <Link>
<DelayLoadDLLs>bcrypt.dll;iphlpapi.dll;nci.dll;newdev.dll;version.dll</DelayLoadDLLs> <DelayLoadDLLs>bcrypt.dll;iphlpapi.dll;nci.dll;newdev.dll;version.dll</DelayLoadDLLs>
@ -201,4 +202,4 @@
<Target Name="CleanSignTarget"> <Target Name="CleanSignTarget">
<Delete Files="$(IntermediateOutputPath)$(TargetName).sign" /> <Delete Files="$(IntermediateOutputPath)$(TargetName).sign" />
</Target> </Target>
</Project> </Project>

View File

@ -1,3 +1,4 @@
LIBRARY wintun.dll
EXPORTS EXPORTS
WintunAllocateSendPacket WintunAllocateSendPacket
WintunCreateAdapter WintunCreateAdapter

View File

@ -1,3 +1,4 @@
LIBRARY nci.dll
EXPORTS EXPORTS
NciGetConnectionName NciGetConnectionName
NciSetConnectionName NciSetConnectionName

View File

@ -7,10 +7,21 @@
#include <Windows.h> #include <Windows.h>
extern DWORD WINAPI NciSetConnectionName(_In_ const GUID *Guid, _In_z_ const WCHAR *NewName); #ifdef GENERATE_LIB
# define DECLSPEC __declspec(dllexport)
# define STUB { return 0; }
#else
# define DECLSPEC __declspec(dllimport)
# define STUB ;
#endif
extern DWORD WINAPI NciGetConnectionName(
EXTERN_C DECLSPEC DWORD WINAPI
NciSetConnectionName(_In_ const GUID *Guid, _In_z_ const WCHAR *NewName) STUB
EXTERN_C DECLSPEC DWORD WINAPI
NciGetConnectionName(
_In_ const GUID *Guid, _In_ const GUID *Guid,
_Out_z_bytecap_(InDestNameBytes) WCHAR *Name, _Out_z_bytecap_(InDestNameBytes) WCHAR *Name,
_In_ DWORD InDestNameBytes, _In_ DWORD InDestNameBytes,
_Out_opt_ DWORD *OutDestNameBytes); _Out_opt_ DWORD *OutDestNameBytes) STUB