diff --git a/EAPMethods/build/Common.props b/EAPMethods/build/Common.props index c2a4d0a..992a7e5 100644 --- a/EAPMethods/build/Common.props +++ b/EAPMethods/build/Common.props @@ -8,8 +8,11 @@ - ..\include;..\..\lib\WinStd\include;%(AdditionalIncludeDirectories) + $(IntDir);..\include;..\..\lib\WinStd\include;%(AdditionalIncludeDirectories) + + $(IntDir);%(AdditionalIncludeDirectories) + \ No newline at end of file diff --git a/EAPMethods/build/EAPTTLS.props b/EAPMethods/build/EAPTTLS.props index 809659b..e2974e7 100644 --- a/EAPMethods/build/EAPTTLS.props +++ b/EAPMethods/build/EAPTTLS.props @@ -7,6 +7,9 @@ + + EAPMETHOD_TYPE=21;%(PreprocessorDefinitions) + \ No newline at end of file diff --git a/EAPMethods/build/EAPTTLS.rc b/EAPMethods/build/EAPTTLS.rc index 0e00fce..45ddcc5 100644 Binary files a/EAPMethods/build/EAPTTLS.rc and b/EAPMethods/build/EAPTTLS.rc differ diff --git a/EAPMethods/build/EAPTTLS.vcxproj b/EAPMethods/build/EAPTTLS.vcxproj index 1320714..496f275 100644 --- a/EAPMethods/build/EAPTTLS.vcxproj +++ b/EAPMethods/build/EAPTTLS.vcxproj @@ -98,6 +98,23 @@ {47399d91-7eb9-41de-b521-514ba5db0c43} + + + Document + mc.exe "%(Identity)" -u -b -z "EAPMethodETW" -e "h" -h "$(IntDir)." -r "$(IntDir)." + mc.exe "%(Identity)" -u -b -z "EAPMethodETW" -e "h" -h "$(IntDir)." -r "$(IntDir)." + mc.exe "%(Identity)" -u -b -z "EAPMethodETW" -e "h" -h "$(IntDir)." -r "$(IntDir)." + mc.exe "%(Identity)" -u -b -z "EAPMethodETW" -e "h" -h "$(IntDir)." -r "$(IntDir)." + Compiling manifest... + Compiling manifest... + Compiling manifest... + Compiling manifest... + $(IntDir)EAPMethodETW.h;$(IntDir)EAPMethodETW.rc;$(IntDir)EAPMethodETW_MSG00001.bin;$(IntDir)EAPMethodETWTEMP.BIN;%(Outputs) + $(IntDir)EAPMethodETW.h;$(IntDir)EAPMethodETW.rc;$(IntDir)EAPMethodETW_MSG00001.bin;$(IntDir)EAPMethodETWTEMP.BIN;%(Outputs) + $(IntDir)EAPMethodETW.h;$(IntDir)EAPMethodETW.rc;$(IntDir)EAPMethodETW_MSG00001.bin;$(IntDir)EAPMethodETWTEMP.BIN;%(Outputs) + $(IntDir)EAPMethodETW.h;$(IntDir)EAPMethodETW.rc;$(IntDir)EAPMethodETW_MSG00001.bin;$(IntDir)EAPMethodETWTEMP.BIN;%(Outputs) + + diff --git a/EAPMethods/build/EAPTTLS.vcxproj.filters b/EAPMethods/build/EAPTTLS.vcxproj.filters index 1c80dcd..ac58632 100644 --- a/EAPMethods/build/EAPTTLS.vcxproj.filters +++ b/EAPMethods/build/EAPTTLS.vcxproj.filters @@ -32,4 +32,9 @@ Resource Files + + + Resource Files + + \ No newline at end of file diff --git a/EAPMethods/include/StdAfx.h b/EAPMethods/include/StdAfx.h index 512c1d4..773bd73 100644 --- a/EAPMethods/include/StdAfx.h +++ b/EAPMethods/include/StdAfx.h @@ -20,6 +20,12 @@ #pragma once +#include #include +#include + +#include #include + +#include diff --git a/EAPMethods/res/EAPMethod.man b/EAPMethods/res/EAPMethod.man new file mode 100644 index 0000000..5e9f56e Binary files /dev/null and b/EAPMethods/res/EAPMethod.man differ diff --git a/EAPMethods/src/Main.cpp b/EAPMethods/src/Main.cpp index 78512d4..2c3943b 100644 --- a/EAPMethods/src/Main.cpp +++ b/EAPMethods/src/Main.cpp @@ -20,15 +20,161 @@ #include +using namespace std; +using namespace winstd; + + +#define ETW_FN_VOID event_fn_auto < &EAPMETHOD_TRACE_EVT_FN_CALL, &EAPMETHOD_TRACE_EVT_FN_RETURN > _event_auto(*g_ep, __FUNCTION__) +#define ETW_FN_DWORD(res) event_fn_auto_ret _event_auto(*g_ep, __FUNCTION__, res) +#define ETW_FN_HRESULT(res) event_fn_auto_ret _event_auto(*g_ep, __FUNCTION__, res) + + +event_provider *g_ep = NULL; + + +// event_fn_auto actually and winstd::event_auto_res<> do not need an assignment operator actually, so the C4512 warning is safely ignored. +#pragma warning(push) +#pragma warning(disable: 4512) + +/// +/// Helper class to write an event on entry/exit of scope. +/// +/// It writes one string event at creation and another at destruction. +/// +template +class event_fn_auto +{ +public: + inline event_fn_auto(_In_ event_provider &ep, _In_z_ LPCSTR pszFnName) : m_ep(ep) + { + EventDataDescCreate(&m_fn_name, pszFnName, (ULONG)(strlen(pszFnName) + 1)*sizeof(*pszFnName)); + m_ep.write(event_cons, 1, &m_fn_name); + } + + inline ~event_fn_auto() + { + m_ep.write(event_dest, 1, &m_fn_name); + } + +protected: + event_provider &m_ep; ///< Reference to event provider in use + EVENT_DATA_DESCRIPTOR m_fn_name; ///< Function name +}; + + +/// +/// Helper template to write an event on entry/exit of scope with one parameter (typically result). +/// +/// It writes one string event at creation and another at destruction, with allowing one sprintf type parameter for string event at destruction. +/// +template +class event_fn_auto_ret +{ +public: + inline event_fn_auto_ret(_In_ event_provider &ep, _In_z_ LPCSTR pszFnName, T &result) : m_ep(ep), m_result(result) + { + EventDataDescCreate(m_desc + 0, pszFnName, (ULONG)(strlen(pszFnName) + 1)*sizeof(*pszFnName)); + m_ep.write(event_cons, 1, m_desc); + } + + inline ~event_fn_auto_ret() + { + EventDataDescCreate(m_desc + 1, &m_result, sizeof(T)); + m_ep.write(event_dest, 2, m_desc); + } + +protected: + event_provider &m_ep; ///< Reference to event provider in use + T &m_result; ///< Function result + EVENT_DATA_DESCRIPTOR m_desc[2]; ///< Function name and return value +}; + +#pragma warning(pop) + + BOOL WINAPI DllMain(_In_ HINSTANCE hinstDLL, _In_ DWORD fdwReason, _In_ LPVOID lpvReserved) { + UNREFERENCED_PARAMETER(hinstDLL); UNREFERENCED_PARAMETER(lpvReserved); if (fdwReason == DLL_PROCESS_ATTACH) { - winstd::tstring filename; - GetModuleFileName(hinstDLL, filename); + g_ep = new event_provider(); + assert(g_ep); + g_ep->create(&EAPMETHOD_TRACE_EVENT_PROVIDER); + g_ep->write(&EAPMETHOD_TRACE_EVT_MODULE_LOAD, EAPMETHOD_TYPE); + } else if (fdwReason == DLL_PROCESS_DETACH) { + assert(g_ep); + g_ep->write(&EAPMETHOD_TRACE_EVT_MODULE_UNLOAD, EAPMETHOD_TYPE); + delete g_ep; + + assert(!_CrtDumpMemoryLeaks()); } return TRUE; } + + +//#pragma comment(linker, "/EXPORT:DllRegisterServer,PRIVATE") +//#pragma comment(linker, "/EXPORT:DllUnregisterServer,PRIVATE") + + +extern "C" +{ + ///// + ///// Registers the EAP method. + ///// + //HRESULT STDAPICALLTYPE DllRegisterServer() + //{ + // HRESULT hr = S_OK; + // ETW_FN_HRESULT(hr); + + // return hr; + //} + + + ///// + ///// Unregisters the EAP method. + ///// + //HRESULT STDAPICALLTYPE DllUnregisterServer() + //{ + // HRESULT hr = S_OK; + // ETW_FN_HRESULT(hr); + + // return hr; + //} + + + /// + /// Releases all memory associated with an opaque user interface context data buffer. + /// + /// \sa [EapPeerFreeMemory function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363606.aspx) + /// + __declspec(dllexport) VOID WINAPI EapPeerFreeMemory(_In_ void *pUIContextData) + { + ETW_FN_VOID; + + if (pUIContextData) { + // Since we do security here and some of the BLOBs contain credentials, sanitize every memory block before freeing. + HANDLE hHeap = GetProcessHeap(); + SecureZeroMemory(pUIContextData, HeapSize(hHeap, 0, pUIContextData)); + HeapFree(hHeap, 0, pUIContextData); + } + } + + + /// + /// Releases error-specific memory allocated by the EAP peer method. + /// + /// \sa [EapPeerFreeErrorMemory function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363605.aspx) + /// + __declspec(dllexport) VOID WINAPI EapPeerFreeErrorMemory(_In_ EAP_ERROR *ppEapError) + { + ETW_FN_VOID; + + if (ppEapError) { + // pRootCauseString and pRepairString always trail the ppEapError to reduce number of (de)allocations. + HeapFree(GetProcessHeap(), 0, ppEapError); + } + } +}; diff --git a/lib/WinStd b/lib/WinStd index f6029b2..9be7e7e 160000 --- a/lib/WinStd +++ b/lib/WinStd @@ -1 +1 @@ -Subproject commit f6029b2f04f52ae2b692980cb4d5734031568d91 +Subproject commit 9be7e7eafb62f815155a9635764ce7770a5daa25