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>
|
<CodeAnalysisRuleSet>NativeRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||||
<RunCodeAnalysis>true</RunCodeAnalysis>
|
<RunCodeAnalysis>true</RunCodeAnalysis>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration">
|
||||||
|
<LocalDebuggerCommand>rundll32.exe</LocalDebuggerCommand>
|
||||||
|
<LocalDebuggerCommandArguments>$(OutDir)$(TargetName)$(TargetExt),DoThingsForDebugging</LocalDebuggerCommandArguments>
|
||||||
|
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||||
|
</PropertyGroup>
|
||||||
<ItemDefinitionGroup>
|
<ItemDefinitionGroup>
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
<PreprocessorDefinitions>_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
@ -164,6 +169,7 @@
|
|||||||
<ClInclude Include="ntldr.h" />
|
<ClInclude Include="ntldr.h" />
|
||||||
<ClInclude Include="registry.h" />
|
<ClInclude Include="registry.h" />
|
||||||
<ClInclude Include="resource.h" />
|
<ClInclude Include="resource.h" />
|
||||||
|
<ClInclude Include="session.h" />
|
||||||
<ClInclude Include="wintun.h" />
|
<ClInclude Include="wintun.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -194,4 +200,4 @@
|
|||||||
<Target Name="CleanSignTarget">
|
<Target Name="CleanSignTarget">
|
||||||
<Delete Files="$(IntermediateOutputPath)$(TargetName).sign" />
|
<Delete Files="$(IntermediateOutputPath)$(TargetName).sign" />
|
||||||
</Target>
|
</Target>
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -58,6 +58,9 @@
|
|||||||
<ClInclude Include="entry.h">
|
<ClInclude Include="entry.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="session.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="namespace.c">
|
<ClCompile Include="namespace.c">
|
||||||
|
@ -5,15 +5,23 @@
|
|||||||
|
|
||||||
#include "adapter.h"
|
#include "adapter.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
#include "session.h"
|
||||||
#include "wintun.h"
|
#include "wintun.h"
|
||||||
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <cfgmgr32.h>
|
#include <cfgmgr32.h>
|
||||||
#include <objbase.h>
|
#include <objbase.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
#define EXPORT comment(linker, "/EXPORT:" __FUNCTION__ "=" __FUNCDNAME__)
|
#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
|
static DWORD
|
||||||
WriteFormatted(_In_ DWORD StdHandle, _In_z_ const WCHAR *Template, ...)
|
WriteFormatted(_In_ DWORD StdHandle, _In_z_ const WCHAR *Template, ...)
|
||||||
@ -22,19 +30,18 @@ WriteFormatted(_In_ DWORD StdHandle, _In_z_ const WCHAR *Template, ...)
|
|||||||
DWORD SizeWritten;
|
DWORD SizeWritten;
|
||||||
va_list Arguments;
|
va_list Arguments;
|
||||||
va_start(Arguments, Template);
|
va_start(Arguments, Template);
|
||||||
WriteFile(
|
DWORD Len = sizeof(WCHAR) * FormatMessageW(
|
||||||
GetStdHandle(StdHandle),
|
FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER,
|
||||||
FormattedMessage,
|
Template,
|
||||||
sizeof(WCHAR) * FormatMessageW(
|
0,
|
||||||
FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER,
|
0,
|
||||||
Template,
|
(void *)&FormattedMessage,
|
||||||
0,
|
0,
|
||||||
0,
|
&Arguments);
|
||||||
(void *)&FormattedMessage,
|
if (WriteToConsole)
|
||||||
0,
|
WriteConsoleW(GetStdHandle(StdHandle), FormattedMessage, Len, &SizeWritten, NULL);
|
||||||
&Arguments),
|
else
|
||||||
&SizeWritten,
|
WriteFile(GetStdHandle(StdHandle), FormattedMessage, Len, &SizeWritten, NULL);
|
||||||
NULL);
|
|
||||||
LocalFree(FormattedMessage);
|
LocalFree(FormattedMessage);
|
||||||
va_end(Arguments);
|
va_end(Arguments);
|
||||||
return SizeWritten / sizeof(WCHAR);
|
return SizeWritten / sizeof(WCHAR);
|
||||||
@ -141,4 +148,35 @@ cleanup:
|
|||||||
Done();
|
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
|
#endif
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include "elevate.h"
|
#include "elevate.h"
|
||||||
#include "entry.h"
|
#include "entry.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
#include "session.h"
|
||||||
#include "wintun.h"
|
#include "wintun.h"
|
||||||
#include <Windows.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