api: add debugging rundll32 entry point
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
f6d8b694eb
commit
6c40f24498
@ -100,6 +100,11 @@
|
||||
<CodeAnalysisRuleSet>NativeRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<RunCodeAnalysis>true</RunCodeAnalysis>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration">
|
||||
<LocalDebuggerCommand>rundll32.exe</LocalDebuggerCommand>
|
||||
<LocalDebuggerCommandArguments>$(OutDir)$(TargetName)$(TargetExt),DoThingsForDebugging</LocalDebuggerCommandArguments>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
@ -164,6 +169,7 @@
|
||||
<ClInclude Include="ntldr.h" />
|
||||
<ClInclude Include="registry.h" />
|
||||
<ClInclude Include="resource.h" />
|
||||
<ClInclude Include="session.h" />
|
||||
<ClInclude Include="wintun.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@ -194,4 +200,4 @@
|
||||
<Target Name="CleanSignTarget">
|
||||
<Delete Files="$(IntermediateOutputPath)$(TargetName).sign" />
|
||||
</Target>
|
||||
</Project>
|
||||
</Project>
|
||||
|
@ -58,6 +58,9 @@
|
||||
<ClInclude Include="entry.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="session.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="namespace.c">
|
||||
|
@ -5,15 +5,23 @@
|
||||
|
||||
#include "adapter.h"
|
||||
#include "logger.h"
|
||||
#include "session.h"
|
||||
#include "wintun.h"
|
||||
|
||||
#include <Windows.h>
|
||||
#include <cfgmgr32.h>
|
||||
#include <objbase.h>
|
||||
#include <assert.h>
|
||||
|
||||
#define EXPORT comment(linker, "/EXPORT:" __FUNCTION__ "=" __FUNCDNAME__)
|
||||
|
||||
#ifdef ACCEPT_WOW64
|
||||
#if defined(ACCEPT_WOW64) || defined(_DEBUG)
|
||||
|
||||
static
|
||||
#ifndef _DEBUG
|
||||
const
|
||||
#endif
|
||||
BOOL WriteToConsole = FALSE;
|
||||
|
||||
static DWORD
|
||||
WriteFormatted(_In_ DWORD StdHandle, _In_z_ const WCHAR *Template, ...)
|
||||
@ -22,19 +30,18 @@ WriteFormatted(_In_ DWORD StdHandle, _In_z_ const WCHAR *Template, ...)
|
||||
DWORD SizeWritten;
|
||||
va_list Arguments;
|
||||
va_start(Arguments, Template);
|
||||
WriteFile(
|
||||
GetStdHandle(StdHandle),
|
||||
FormattedMessage,
|
||||
sizeof(WCHAR) * FormatMessageW(
|
||||
FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER,
|
||||
Template,
|
||||
0,
|
||||
0,
|
||||
(void *)&FormattedMessage,
|
||||
0,
|
||||
&Arguments),
|
||||
&SizeWritten,
|
||||
NULL);
|
||||
DWORD Len = sizeof(WCHAR) * FormatMessageW(
|
||||
FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER,
|
||||
Template,
|
||||
0,
|
||||
0,
|
||||
(void *)&FormattedMessage,
|
||||
0,
|
||||
&Arguments);
|
||||
if (WriteToConsole)
|
||||
WriteConsoleW(GetStdHandle(StdHandle), FormattedMessage, Len, &SizeWritten, NULL);
|
||||
else
|
||||
WriteFile(GetStdHandle(StdHandle), FormattedMessage, Len, &SizeWritten, NULL);
|
||||
LocalFree(FormattedMessage);
|
||||
va_end(Arguments);
|
||||
return SizeWritten / sizeof(WCHAR);
|
||||
@ -141,4 +148,35 @@ cleanup:
|
||||
Done();
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
VOID __stdcall DoThingsForDebugging(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow)
|
||||
{
|
||||
# pragma EXPORT
|
||||
UNREFERENCED_PARAMETER(hwnd);
|
||||
UNREFERENCED_PARAMETER(hinst);
|
||||
UNREFERENCED_PARAMETER(lpszCmdLine);
|
||||
UNREFERENCED_PARAMETER(nCmdShow);
|
||||
|
||||
AllocConsole();
|
||||
WriteToConsole = TRUE;
|
||||
Init();
|
||||
GUID TestGuid = {
|
||||
0xdeadbabe,
|
||||
0xcafe,
|
||||
0xbeef,
|
||||
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }
|
||||
};
|
||||
WINTUN_ADAPTER *Adapter;
|
||||
BOOL RebootRequired = FALSE;
|
||||
assert(WintunCreateAdapter(L"Wintun", L"Test", &TestGuid, &Adapter, &RebootRequired) == ERROR_SUCCESS);
|
||||
assert(!RebootRequired);
|
||||
TUN_SESSION *Session;
|
||||
HANDLE ReadWait;
|
||||
assert(WintunStartSession(Adapter, WINTUN_MIN_RING_CAPACITY, &Session, &ReadWait) == ERROR_SUCCESS);
|
||||
WintunEndSession(Session);
|
||||
assert(WintunDeleteAdapter(Adapter, TRUE, &RebootRequired) == ERROR_SUCCESS);
|
||||
assert(!RebootRequired);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "elevate.h"
|
||||
#include "entry.h"
|
||||
#include "logger.h"
|
||||
#include "session.h"
|
||||
#include "wintun.h"
|
||||
#include <Windows.h>
|
||||
|
||||
|
54
api/session.h
Normal file
54
api/session.h
Normal file
@ -0,0 +1,54 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0
|
||||
*
|
||||
* Copyright (C) 2018-2020 WireGuard LLC. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "wintun.h"
|
||||
#include <Windows.h>
|
||||
|
||||
typedef struct _TUN_SESSION TUN_SESSION;
|
||||
|
||||
/**
|
||||
* @copydoc WINTUN_START_SESSION_FUNC
|
||||
*/
|
||||
WINTUN_STATUS WINAPI
|
||||
WintunStartSession(
|
||||
_In_ const WINTUN_ADAPTER *Adapter,
|
||||
_In_ DWORD Capacity,
|
||||
_Out_ TUN_SESSION **Session,
|
||||
_Out_ HANDLE *ReadWait);
|
||||
|
||||
/**
|
||||
* @copydoc WINTUN_END_SESSION_FUNC
|
||||
*/
|
||||
void WINAPI
|
||||
WintunEndSession(_In_ TUN_SESSION *Session);
|
||||
|
||||
/**
|
||||
* @copydoc WINTUN_RECEIVE_PACKET_FUNC
|
||||
*/
|
||||
WINTUN_STATUS WINAPI
|
||||
WintunReceivePacket(_In_ TUN_SESSION *Session, _Out_bytecapcount_(*PacketSize) BYTE **Packet, _Out_ DWORD *PacketSize);
|
||||
|
||||
/**
|
||||
* @copydoc WINTUN_RECEIVE_RELEASE_FUNC
|
||||
*/
|
||||
void WINAPI
|
||||
WintunReceiveRelease(_In_ TUN_SESSION *Session, _In_ const BYTE *Packet);
|
||||
|
||||
/**
|
||||
* @copydoc WINTUN_ALLOCATE_SEND_PACKET
|
||||
*/
|
||||
WINTUN_STATUS WINAPI
|
||||
WintunAllocateSendPacket(
|
||||
_In_ TUN_SESSION *Session,
|
||||
_In_ DWORD PacketSize,
|
||||
_Out_bytecapcount_(PacketSize) BYTE **Packet);
|
||||
|
||||
/**
|
||||
* @copydoc WINTUN_SEND_PACKET
|
||||
*/
|
||||
void WINAPI
|
||||
WintunSendPacket(_In_ TUN_SESSION *Session, _In_ const BYTE *Packet);
|
Loading…
Reference in New Issue
Block a user