diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-10-31 15:09:47 +0100 |
---|---|---|
committer | Simon Rozman <simon@rozman.si> | 2020-10-31 19:11:56 +0100 |
commit | 6c40f24498d448f3c5b52530835f367306cb0ff7 (patch) | |
tree | 3191d14a860e3134734123708df2fda4f4a8b2a3 /api/rundll32.c | |
parent | api: add missing header for rundll32 mode (diff) | |
download | wintun-6c40f24498d448f3c5b52530835f367306cb0ff7.tar.xz wintun-6c40f24498d448f3c5b52530835f367306cb0ff7.zip |
api: add debugging rundll32 entry point
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'api/rundll32.c')
-rw-r--r-- | api/rundll32.c | 66 |
1 files changed, 52 insertions, 14 deletions
diff --git a/api/rundll32.c b/api/rundll32.c index 2b2f11d..d594723 100644 --- a/api/rundll32.c +++ b/api/rundll32.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 |