From 06adf7ddaeafc3cb8ec52cd6d3fe5e31e2171a16 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Fri, 15 Jul 2016 13:14:33 +0200 Subject: [PATCH] EventMonitor replaced with Windows-based application (work in progress...) --- .gitmodules | 3 + EventMonitor/App.cpp | 86 + EventMonitor/App.h | 61 + EventMonitor/EventMonitor.props | 4 +- EventMonitor/EventMonitor.vcxproj | 18 +- EventMonitor/EventMonitor.vcxproj.filters | 39 +- EventMonitor/Frame.cpp | 86 + EventMonitor/Frame.h | 63 + EventMonitor/LogPanel.cpp | 81 + EventMonitor/LogPanel.h | 60 + EventMonitor/Main.cpp | 1080 +-- EventMonitor/README.md | 9 - EventMonitor/StdAfx.h | 28 +- EventMonitor/locale/EventMonitor.pot | 47 + EventMonitor/wxEventMonitor_UI.cpp | 72 + EventMonitor/wxEventMonitor_UI.fbp | 449 + EventMonitor/wxEventMonitor_UI.h | 78 + VS10Solution.sln | 11 + include/xgettext.targets | 66 + include/xgettext.xml | 84 + lib/WinStd | 2 +- lib/wxExtend | 1 + output/locale/.gitignore | 1 + output/locale/de_DE/wxstd.mo | Bin 0 -> 145908 bytes output/locale/de_DE/wxstd.po | 9107 +++++++++++++++++++ output/locale/ru_RU/wxstd.mo | Bin 0 -> 154076 bytes output/locale/ru_RU/wxstd.po | 8885 +++++++++++++++++++ output/locale/sl_SI/wxstd.mo | Bin 0 -> 129140 bytes output/locale/sl_SI/wxstd.po | 9822 +++++++++++++++++++++ 29 files changed, 29675 insertions(+), 568 deletions(-) create mode 100644 EventMonitor/App.cpp create mode 100644 EventMonitor/App.h create mode 100644 EventMonitor/Frame.cpp create mode 100644 EventMonitor/Frame.h create mode 100644 EventMonitor/LogPanel.cpp create mode 100644 EventMonitor/LogPanel.h delete mode 100644 EventMonitor/README.md create mode 100644 EventMonitor/locale/EventMonitor.pot create mode 100644 EventMonitor/wxEventMonitor_UI.cpp create mode 100644 EventMonitor/wxEventMonitor_UI.fbp create mode 100644 EventMonitor/wxEventMonitor_UI.h create mode 100644 include/xgettext.targets create mode 100644 include/xgettext.xml create mode 160000 lib/wxExtend create mode 100644 output/locale/.gitignore create mode 100644 output/locale/de_DE/wxstd.mo create mode 100644 output/locale/de_DE/wxstd.po create mode 100644 output/locale/ru_RU/wxstd.mo create mode 100644 output/locale/ru_RU/wxstd.po create mode 100644 output/locale/sl_SI/wxstd.mo create mode 100644 output/locale/sl_SI/wxstd.po diff --git a/.gitmodules b/.gitmodules index d3795a4..076a32b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "lib/WinStd"] path = lib/WinStd url = https://github.com/Amebis/WinStd.git +[submodule "lib/wxExtend"] + path = lib/wxExtend + url = https://github.com/Amebis/wxExtend.git diff --git a/EventMonitor/App.cpp b/EventMonitor/App.cpp new file mode 100644 index 0000000..596981c --- /dev/null +++ b/EventMonitor/App.cpp @@ -0,0 +1,86 @@ +/* + Copyright 2015-2016 Amebis + Copyright 2016 GANT + + This file is part of GANTLink. + + GANTLink is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + GANTLink is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GANTLink. If not, see . +*/ + +#include "stdafx.h" +#if defined(__WXMSW__) +#pragma comment(lib, "msi.lib") +#endif + + +////////////////////////////////////////////////////////////////////////// +// wxEventMonitorApp +////////////////////////////////////////////////////////////////////////// + +wxIMPLEMENT_APP(wxEventMonitorApp); + + +wxEventMonitorApp::wxEventMonitorApp() : wxApp() +{ +} + + +bool wxEventMonitorApp::OnInit() +{ +#if defined(__WXMSW__) + // To compensate migration to non-advertised shortcut, do the Microsoft Installer's feature completeness check manually. + // If execution got this far in the first place (EXE and dependent DLLs are present and loadable). + // Furthermore, this increments program usage counter. + if (::MsiQueryFeatureState(_T(PRODUCT_VERSION_GUID), _T("featEventMonitor")) != INSTALLSTATE_UNKNOWN) + ::MsiUseFeature(_T(PRODUCT_VERSION_GUID), _T("featEventMonitor")); +#endif + + wxConfigBase *cfgPrev = wxConfigBase::Set(new wxConfig(wxT("EventMonitor"), wxT(PRODUCT_NAME_STR))); + if (cfgPrev) wxDELETE(cfgPrev); + + if (!wxApp::OnInit()) + return false; + + // Set desired locale. + wxLanguage language = (wxLanguage)wxConfigBase::Get()->Read(wxT("Language"), wxLANGUAGE_DEFAULT); + if (wxLocale::IsAvailable(language)) { + wxString sPath; + if (wxConfigBase::Get()->Read(wxT("LocalizationRepositoryPath"), &sPath)) + m_locale.AddCatalogLookupPathPrefix(sPath); + if (m_locale.Init(language)) { + wxVERIFY(m_locale.AddCatalog(wxT("wxExtend") wxT(wxExtendVersion))); + wxVERIFY(m_locale.AddCatalog(wxT("EventMonitor"))); + } + } + +#ifdef __WXMSW__ + // Find EventMonitor window if already running. + HWND okno = ::FindWindow(_T("wxWindowNR"), _("Event Monitor")); + if (okno) { + if (::IsIconic(okno)) + ::SendMessage(okno, WM_SYSCOMMAND, SC_RESTORE, 0); + ::SetActiveWindow(okno); + ::SetForegroundWindow(okno); + + // Not an error condition actually; Just nothing else to do... + return false; + } +#endif + + m_mainWnd = new wxEventMonitorFrame(); + wxPersistentRegisterAndRestore(m_mainWnd); + m_mainWnd->Show(); + + return true; +} diff --git a/EventMonitor/App.h b/EventMonitor/App.h new file mode 100644 index 0000000..9c88010 --- /dev/null +++ b/EventMonitor/App.h @@ -0,0 +1,61 @@ +/* + Copyright 2015-2016 Amebis + Copyright 2016 GANT + + This file is part of GANTLink. + + GANTLink is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + GANTLink is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GANTLink. If not, see . +*/ + +/// +/// EventMonitor application +/// +class wxEventMonitorApp; + +#pragma once + +#include "Frame.h" + +#include +#include +#include + + +class wxEventMonitorApp : public wxApp +{ +public: + wxEventMonitorApp(); + + /// + /// Called when application initializes. + /// + /// \returns + /// - \c true if initialization succeeded + /// - \c false otherwise + /// + virtual bool OnInit(); + + /// + /// Called when application uninitializes. + /// + /// \returns Result code to return to OS + /// + //virtual int OnExit(); + +public: + wxEventMonitorFrame *m_mainWnd; ///< Main window + wxLocale m_locale; ///< Current locale +}; + +wxDECLARE_APP(wxEventMonitorApp); diff --git a/EventMonitor/EventMonitor.props b/EventMonitor/EventMonitor.props index 0c85d22..4c26039 100644 --- a/EventMonitor/EventMonitor.props +++ b/EventMonitor/EventMonitor.props @@ -7,11 +7,9 @@ - ..\lib\Events\build\temp\Events.$(Platform).$(Configuration).$(PlatformToolset);..\lib\WinStd\include;%(AdditionalIncludeDirectories) - _CONSOLE;%(PreprocessorDefinitions) + ..\lib\Events\build\temp\Events.$(Platform).$(Configuration).$(PlatformToolset);..\lib\WinStd\include;..\lib\wxExtend\include;%(AdditionalIncludeDirectories) - Console RequireAdministrator diff --git a/EventMonitor/EventMonitor.vcxproj b/EventMonitor/EventMonitor.vcxproj index 8a1fc3d..205d4bf 100644 --- a/EventMonitor/EventMonitor.vcxproj +++ b/EventMonitor/EventMonitor.vcxproj @@ -86,12 +86,16 @@ + + + + - - - + + + Create @@ -99,6 +103,7 @@ Create Create + @@ -107,6 +112,13 @@ {47399d91-7eb9-41de-b521-514ba5db0c43} + + {d3e29951-d9f5-486d-a167-20ae8e90b1fa} + + + + + diff --git a/EventMonitor/EventMonitor.vcxproj.filters b/EventMonitor/EventMonitor.vcxproj.filters index c2bbbec..a3d41a1 100644 --- a/EventMonitor/EventMonitor.vcxproj.filters +++ b/EventMonitor/EventMonitor.vcxproj.filters @@ -13,6 +13,10 @@ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + {e43059ae-37ac-4b28-84fb-18d1b3972b30} + po;pot + @@ -23,9 +27,18 @@ Header Files - - - + + Header Files + + + Header Files + + + Header Files + + + Header Files + @@ -34,5 +47,25 @@ Source Files + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Resource Files + + + Resource Files\Localization + \ No newline at end of file diff --git a/EventMonitor/Frame.cpp b/EventMonitor/Frame.cpp new file mode 100644 index 0000000..7aa47b2 --- /dev/null +++ b/EventMonitor/Frame.cpp @@ -0,0 +1,86 @@ +/* + Copyright 2015-2016 Amebis + Copyright 2016 GANT + + This file is part of GANTLink. + + GANTLink is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + GANTLink is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GANTLink. If not, see . +*/ + +#include "StdAfx.h" + + +////////////////////////////////////////////////////////////////////////// +// wxEventMonitorFrame +////////////////////////////////////////////////////////////////////////// + +wxBEGIN_EVENT_TABLE(wxEventMonitorFrame, wxEventMonitorFrameBase) + EVT_MENU(wxID_EXIT, wxEventMonitorFrame::OnExit) +wxEND_EVENT_TABLE() + + +wxEventMonitorFrame::wxEventMonitorFrame() : wxEventMonitorFrameBase(NULL) +{ +// // Load main window icons. +//#ifdef __WINDOWS__ +// wxIcon icon_small(wxT("00_EventMonitor.ico"), wxBITMAP_TYPE_ICO_RESOURCE, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON)); +// wxIconBundle icons; +// icons.AddIcon(icon_small); +// icons.AddIcon(wxIcon(wxT("00_EventMonitor.ico"), wxBITMAP_TYPE_ICO_RESOURCE, ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON))); +// SetIcons(icons); +//#else +// wxIcon icon_small(wxICON(00_EventMonitor.ico)); +// SetIcon(icon_small); +//#endif + + // Restore persistent state of wxAuiManager manually, since m_mgr is not on the heap. + wxPersistentAuiManager(&m_mgr).Restore(); +} + + +void wxEventMonitorFrame::OnExit(wxCommandEvent& /*event*/) +{ + Close(); +} + + +////////////////////////////////////////////////////////////////////////// +// wxPersistentEventMonitorFrame +////////////////////////////////////////////////////////////////////////// + +wxPersistentEventMonitorFrame::wxPersistentEventMonitorFrame(wxEventMonitorFrame *wnd) : wxPersistentTLW(wnd) +{ +} + + +void wxPersistentEventMonitorFrame::Save() const +{ + const wxEventMonitorFrame * const wnd = static_cast(GetWindow()); + + wxPersistentEventMonitorLogPanel(wnd->m_panel).Save(); + + wxPersistentTLW::Save(); +} + + +bool wxPersistentEventMonitorFrame::Restore() +{ + const bool r = wxPersistentTLW::Restore(); + + wxEventMonitorFrame * const wnd = static_cast(GetWindow()); + + wxPersistentEventMonitorLogPanel(wnd->m_panel).Restore(); + + return r; +} diff --git a/EventMonitor/Frame.h b/EventMonitor/Frame.h new file mode 100644 index 0000000..d4f662a --- /dev/null +++ b/EventMonitor/Frame.h @@ -0,0 +1,63 @@ +/* + Copyright 2015-2016 Amebis + Copyright 2016 GANT + + This file is part of GANTLink. + + GANTLink is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + GANTLink is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GANTLink. If not, see . +*/ + +/// +/// EventMonitor main frame +/// +class wxEventMonitorFrame; + +/// +/// Supports saving/restoring wxEventMonitorFrame GUI state +/// +class wxPersistentEventMonitorFrame; + +#pragma once; + +#include "wxEventMonitor_UI.h" +#include + + +class wxEventMonitorFrame : public wxEventMonitorFrameBase +{ +public: + wxEventMonitorFrame(); + + friend class wxPersistentEventMonitorFrame; + +protected: + void OnExit(wxCommandEvent& event); + wxDECLARE_EVENT_TABLE(); +}; + + +class wxPersistentEventMonitorFrame : public wxPersistentTLW +{ +public: + wxPersistentEventMonitorFrame(wxEventMonitorFrame *wnd); + + virtual void Save() const; + virtual bool Restore(); +}; + + +inline wxPersistentObject *wxCreatePersistentObject(wxEventMonitorFrame *wnd) +{ + return new wxPersistentEventMonitorFrame(wnd); +} diff --git a/EventMonitor/LogPanel.cpp b/EventMonitor/LogPanel.cpp new file mode 100644 index 0000000..0d7cdab --- /dev/null +++ b/EventMonitor/LogPanel.cpp @@ -0,0 +1,81 @@ +/* + Copyright 2015-2016 Amebis + Copyright 2016 GANT + + This file is part of GANTLink. + + GANTLink is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + GANTLink is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GANTLink. If not, see . +*/ + +#include "StdAfx.h" + + +////////////////////////////////////////////////////////////////////////// +// wxEventMonitorLogPanel +////////////////////////////////////////////////////////////////////////// + +wxEventMonitorLogPanel::wxEventMonitorLogPanel(wxWindow* parent) : wxEventMonitorLogPanelBase(parent) +{ + m_log->AppendColumn(_("Time")); + m_log->AppendColumn(_("Source")); + + // Set focus. + m_log->SetFocus(); +} + + +////////////////////////////////////////////////////////////////////////// +// wxPersistentEventMonitorLogPanel +////////////////////////////////////////////////////////////////////////// + +wxPersistentEventMonitorLogPanel::wxPersistentEventMonitorLogPanel(wxEventMonitorLogPanel *wnd) : wxPersistentWindow(wnd) +{ +} + + +wxString wxPersistentEventMonitorLogPanel::GetKind() const +{ + return wxT(wxPERSIST_TLW_KIND); +} + + +void wxPersistentEventMonitorLogPanel::Save() const +{ + //const wxEventMonitorLogPanel * const wnd = static_cast(GetWindow()); + + //SaveValue(wxT("splitDecomposed"), wnd->m_splitterDecomposed->GetSashPosition()); + //SaveValue(wxT("splitComposed" ), wnd->m_splitterComposed ->GetSashPosition()); +} + + +bool wxPersistentEventMonitorLogPanel::Restore() +{ + //wxEventMonitorLogPanel * const wnd = static_cast(GetWindow()); + + //int sashVal; + + //if (RestoreValue(wxT("splitDecomposed"), &sashVal)) { + // // wxFormBuilder sets initial splitter stash in idle event handler after GUI settles. Overriding our loaded value. Disconnect it's idle event handler. + // wnd->m_splitterDecomposed->Disconnect( wxEVT_IDLE, wxIdleEventHandler( wxEventMonitorLogPanelBase::m_splitterDecomposedOnIdle ), NULL, wnd ); + // wnd->m_splitterDecomposed->SetSashPosition(sashVal); + //} + + //if (RestoreValue(wxT("splitComposed"), &sashVal)) { + // // wxFormBuilder sets initial splitter stash in idle event handler after GUI settles. Overriding our loaded value. Disconnect it's idle event handler. + // wnd->m_splitterComposed->Disconnect( wxEVT_IDLE, wxIdleEventHandler( wxEventMonitorLogPanelBase::m_splitterComposedOnIdle ), NULL, wnd ); + // wnd->m_splitterComposed->SetSashPosition(sashVal); + //} + + return true; +} diff --git a/EventMonitor/LogPanel.h b/EventMonitor/LogPanel.h new file mode 100644 index 0000000..108223d --- /dev/null +++ b/EventMonitor/LogPanel.h @@ -0,0 +1,60 @@ +/* + Copyright 2015-2016 Amebis + Copyright 2016 GANT + + This file is part of GANTLink. + + GANTLink is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + GANTLink is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GANTLink. If not, see . +*/ + +/// +/// EventMonitor trace log panel +/// +class wxEventMonitorLogPanel; + +/// +/// Supports saving/restoring wxEventMonitorLogPanel state +/// +class wxPersistentEventMonitorLogPanel; + +#pragma once + +#include "wxEventMonitor_UI.h" +#include + + +class wxEventMonitorLogPanel : public wxEventMonitorLogPanelBase +{ +public: + wxEventMonitorLogPanel(wxWindow* parent); + + friend class wxPersistentEventMonitorLogPanel; // Allow saving/restoring window state. +}; + + +class wxPersistentEventMonitorLogPanel : public wxPersistentWindow +{ +public: + wxPersistentEventMonitorLogPanel(wxEventMonitorLogPanel *wnd); + + virtual wxString GetKind() const; + virtual void Save() const; + virtual bool Restore(); +}; + + +inline wxPersistentObject *wxCreatePersistentObject(wxEventMonitorLogPanel *wnd) +{ + return new wxPersistentEventMonitorLogPanel(wnd); +} diff --git a/EventMonitor/Main.cpp b/EventMonitor/Main.cpp index 319f1b5..6dc9d55 100644 --- a/EventMonitor/Main.cpp +++ b/EventMonitor/Main.cpp @@ -20,543 +20,543 @@ #include "StdAfx.h" -#pragma comment(lib, "tdh.lib") -#pragma comment(lib, "Ws2_32.lib") - -using namespace std; -using namespace winstd; - -static vector g_traces; - - -static BOOL WINAPI ConsoleHandler(_In_ DWORD dwCtrlType) -{ - switch(dwCtrlType) { - case CTRL_C_EVENT: - case CTRL_BREAK_EVENT: - case CTRL_CLOSE_EVENT: - case CTRL_LOGOFF_EVENT: - case CTRL_SHUTDOWN_EVENT: - for (vector::const_iterator trace = g_traces.cbegin(), trace_end = g_traces.cend(); trace != trace_end; ++trace) - CloseTrace(*trace); - } - return TRUE; -} - - -static tstring MapToString(_In_ const EVENT_MAP_INFO *pMapInfo, _In_ LPCBYTE pData) -{ - if ( (pMapInfo->Flag & EVENTMAP_INFO_FLAG_MANIFEST_VALUEMAP) || - ((pMapInfo->Flag & EVENTMAP_INFO_FLAG_WBEM_VALUEMAP ) && (pMapInfo->Flag & ~EVENTMAP_INFO_FLAG_WBEM_VALUEMAP) != EVENTMAP_INFO_FLAG_WBEM_FLAG)) - { - if ((pMapInfo->Flag & EVENTMAP_INFO_FLAG_WBEM_NO_MAP) == EVENTMAP_INFO_FLAG_WBEM_NO_MAP) - return tstring_printf(_T("%ls"), (PBYTE)pMapInfo + pMapInfo->MapEntryArray[*(PULONG)pData].OutputOffset); - else { - for (ULONG i = 0; ; i++) { - if (i >= pMapInfo->EntryCount) - return tstring_printf(_T("%lu"), *(PULONG)pData); - else if (pMapInfo->MapEntryArray[i].Value == *(PULONG)pData) - return tstring_printf(_T("%ls"), (PBYTE)pMapInfo + pMapInfo->MapEntryArray[i].OutputOffset); - } - } - } else if ( - (pMapInfo->Flag & EVENTMAP_INFO_FLAG_MANIFEST_BITMAP) || - (pMapInfo->Flag & EVENTMAP_INFO_FLAG_WBEM_BITMAP ) || - ((pMapInfo->Flag & EVENTMAP_INFO_FLAG_WBEM_VALUEMAP ) && (pMapInfo->Flag & ~EVENTMAP_INFO_FLAG_WBEM_VALUEMAP) == EVENTMAP_INFO_FLAG_WBEM_FLAG)) - { - tstring out; - - if (pMapInfo->Flag & EVENTMAP_INFO_FLAG_WBEM_NO_MAP) { - for (ULONG i = 0; i < pMapInfo->EntryCount; i++) - if (*(PULONG)pData & (1 << i)) - out.append(tstring_printf(out.empty() ? _T("%ls") : _T(" | %ls"), (PBYTE)pMapInfo + pMapInfo->MapEntryArray[i].OutputOffset)); - } else { - for (ULONG i = 0; i < pMapInfo->EntryCount; i++) - if ((pMapInfo->MapEntryArray[i].Value & *(PULONG)pData) == pMapInfo->MapEntryArray[i].Value) - out.append(tstring_printf(out.empty() ? _T("%ls") : _T(" | %ls"), (PBYTE)pMapInfo + pMapInfo->MapEntryArray[i].OutputOffset)); - } - - return out.empty() ? tstring_printf(_T("%lu"), *(PULONG)pData) : out; - } - - return _T(""); -} - - -static tstring DataToString(_In_ USHORT InType, _In_ USHORT OutType, _In_count_(nDataSize) LPCBYTE pData, _In_ SIZE_T nDataSize, _In_ const EVENT_MAP_INFO *pMapInfo, _In_ BYTE nPtrSize) -{ - assert(pData || !nDataSize); - - switch (InType) { - case TDH_INTYPE_UNICODESTRING: - case TDH_INTYPE_NONNULLTERMINATEDSTRING: - case TDH_INTYPE_UNICODECHAR: - return tstring_printf(_T("%.*ls"), nDataSize/sizeof(WCHAR), pData); - - case TDH_INTYPE_ANSISTRING: - case TDH_INTYPE_NONNULLTERMINATEDANSISTRING: - case TDH_INTYPE_ANSICHAR: { - // Convert strings from ANSI code page, all others (JSON, XML etc.) from UTF-8 - wstring str; - MultiByteToWideChar(OutType == TDH_OUTTYPE_STRING ? CP_ACP : CP_UTF8, 0, (LPCSTR)pData, (int)nDataSize, str); - return tstring_printf(_T("%ls"), str.c_str()); - } - - case TDH_INTYPE_COUNTEDSTRING: - return DataToString(TDH_INTYPE_NONNULLTERMINATEDSTRING, OutType, (LPCBYTE)((PUSHORT)pData + 1), *(PUSHORT)pData, pMapInfo, nPtrSize); - - case TDH_INTYPE_COUNTEDANSISTRING: - return DataToString(TDH_INTYPE_NONNULLTERMINATEDANSISTRING, OutType, (LPCBYTE)((PUSHORT)pData + 1), *(PUSHORT)pData, pMapInfo, nPtrSize); - - case TDH_INTYPE_REVERSEDCOUNTEDSTRING: - return DataToString(TDH_INTYPE_NONNULLTERMINATEDSTRING, OutType, (LPCBYTE)((PUSHORT)pData + 1), MAKEWORD(HIBYTE(*(PUSHORT)pData), LOBYTE(*(PUSHORT)pData)), pMapInfo, nPtrSize); - - case TDH_INTYPE_REVERSEDCOUNTEDANSISTRING: - return DataToString(TDH_INTYPE_NONNULLTERMINATEDANSISTRING, OutType, (LPCBYTE)((PUSHORT)pData + 1), MAKEWORD(HIBYTE(*(PUSHORT)pData), LOBYTE(*(PUSHORT)pData)), pMapInfo, nPtrSize); - - case TDH_INTYPE_INT8: - assert(nDataSize >= sizeof(CHAR)); - switch (OutType) { - case TDH_OUTTYPE_STRING: return DataToString(TDH_INTYPE_ANSICHAR, TDH_OUTTYPE_NULL, pData, nDataSize, pMapInfo, nPtrSize); - default : return tstring_printf(_T("%hd"), *(PCHAR)pData); - } - - case TDH_INTYPE_UINT8: - assert(nDataSize >= sizeof(BYTE)); - switch (OutType) { - case TDH_OUTTYPE_STRING : return DataToString(TDH_INTYPE_ANSICHAR, TDH_OUTTYPE_NULL, pData, nDataSize, pMapInfo, nPtrSize); - case TDH_OUTTYPE_HEXINT8: return tstring_printf(_T("0x%x"), *(PBYTE)pData); - default : return tstring_printf(_T("%hu" ), *(PBYTE)pData); - } - - case TDH_INTYPE_INT16: - assert(nDataSize >= sizeof(SHORT)); - return tstring_printf(_T("%hd"), *(PSHORT)pData); - - case TDH_INTYPE_UINT16: - assert(nDataSize >= sizeof(USHORT)); - switch (OutType) { - case TDH_OUTTYPE_PORT : return tstring_printf(_T("%hu" ), ntohs(*(PUSHORT)pData)); - case TDH_OUTTYPE_HEXINT16: return tstring_printf(_T("0x%x"), *(PUSHORT)pData ); - case TDH_OUTTYPE_STRING : return tstring_printf(_T("%lc" ), *(PUSHORT)pData ); - default : return tstring_printf(_T("%hu" ), *(PUSHORT)pData ); - } - - case TDH_INTYPE_INT32: - assert(nDataSize >= sizeof(LONG)); - switch (OutType) { - case TDH_OUTTYPE_HRESULT: return tstring_printf(_T("0x%x"), *(PLONG)pData); - default : return tstring_printf(_T("%ld" ), *(PLONG)pData); - } - - case TDH_INTYPE_UINT32: - assert(nDataSize >= sizeof(ULONG)); - switch (OutType) { - case TDH_OUTTYPE_HRESULT : - case TDH_OUTTYPE_WIN32ERROR: - case TDH_OUTTYPE_NTSTATUS : - case TDH_OUTTYPE_HEXINT32 : return tstring_printf(_T("0x%x" ), *(PULONG)pData); - case TDH_OUTTYPE_IPV4 : return tstring_printf(_T("%d.%d.%d.%d"), (*(PULONG)pData >> 0) & 0xff, (*(PULONG)pData >> 8) & 0xff, (*(PULONG)pData >> 16) & 0xff, (*(PULONG)pData >> 24) & 0xff); - default: return pMapInfo ? MapToString(pMapInfo, pData) : tstring_printf(_T("%lu"), *(PULONG)pData); - } - - case TDH_INTYPE_HEXINT32: - return DataToString(TDH_INTYPE_UINT32, TDH_OUTTYPE_HEXINT32, pData, nDataSize, pMapInfo, nPtrSize); - - case TDH_INTYPE_INT64: - assert(nDataSize >= sizeof(LONGLONG)); - return tstring_printf(_T("%I64d"), *(PLONGLONG)pData); - - case TDH_INTYPE_UINT64: - assert(nDataSize >= sizeof(ULONGLONG)); - switch (OutType) { - case TDH_OUTTYPE_HEXINT64: return tstring_printf(_T("0x%I64x"), *(PULONGLONG)pData); - default : return tstring_printf(_T("%I64u" ), *(PULONGLONG)pData); - } - - case TDH_INTYPE_HEXINT64: - return DataToString(TDH_INTYPE_UINT64, TDH_OUTTYPE_HEXINT64, pData, nDataSize, pMapInfo, nPtrSize); - - case TDH_INTYPE_FLOAT: - assert(nDataSize >= sizeof(FLOAT)); - return tstring_printf(_T("%f"), *(PFLOAT)pData); - - case TDH_INTYPE_DOUBLE: - assert(nDataSize >= sizeof(DOUBLE)); - return tstring_printf(_T("%I64f"), *(DOUBLE*)pData); - - case TDH_INTYPE_BOOLEAN: - assert(nDataSize >= sizeof(ULONG)); // Yes, boolean is really 32-bit. - return *(PULONG)pData ? _T("true") : _T("false"); - - case TDH_INTYPE_BINARY: - switch (OutType) { - case TDH_OUTTYPE_IPV6: { - auto RtlIpv6AddressToString = (LPTSTR(NTAPI*)(const IN6_ADDR*, LPTSTR))GetProcAddress(GetModuleHandle(_T("ntdll.dll")), -#ifdef _UNICODE - "RtlIpv6AddressToStringW" -#else - "RtlIpv6AddressToStringA" -#endif - ); - if (RtlIpv6AddressToString) { - TCHAR szIPv6Addr[47]; - RtlIpv6AddressToString((IN6_ADDR*)pData, szIPv6Addr); - return tstring_printf(_T("%s"), szIPv6Addr); - } else - return _T(""); - } - default: { - tstring out; - for (SIZE_T i = 0; i < nDataSize; i++) - out.append(tstring_printf(i ? _T(" %02x") : _T("%02x"), pData[i])); - return out; - }} - - case TDH_INTYPE_HEXDUMP: - return DataToString(TDH_INTYPE_BINARY, TDH_OUTTYPE_NULL, pData, nDataSize, pMapInfo, nPtrSize); - - case TDH_INTYPE_GUID: { - assert(nDataSize >= sizeof(GUID)); - WCHAR szGuid[39]; - StringFromGUID2(*(GUID*)pData, szGuid, _countof(szGuid)); - return tstring_printf(_T("%ls"), szGuid); - } - - case TDH_INTYPE_POINTER: - assert(nDataSize >= nPtrSize); - switch (nPtrSize) { - case sizeof(ULONG ): return tstring_printf(_T("0x%08x" ), *(PULONG )pData); - case sizeof(ULONGLONG): return tstring_printf(_T("0x%016I64x"), *(PULONGLONG)pData); - default: // Unsupported pointer size. - assert(0); - return _T(""); - } - - case TDH_INTYPE_SIZET: - assert(nDataSize >= nPtrSize); - switch (nPtrSize) { - case sizeof(ULONG ): return tstring_printf(_T("%u" ), *(PULONG )pData); - case sizeof(ULONGLONG): return tstring_printf(_T("%I64u"), *(PULONGLONG)pData); - default: // Unsupported size_t size. - assert(0); - return _T(""); - } - - case TDH_INTYPE_FILETIME: { - assert(nDataSize >= sizeof(FILETIME)); - SYSTEMTIME st, st_local; - FileTimeToSystemTime((PFILETIME)pData, &st); - SystemTimeToTzSpecificLocalTime(NULL, &st, &st_local); - return DataToString(TDH_INTYPE_SYSTEMTIME, OutType, (LPCBYTE)&st_local, sizeof(st_local), pMapInfo, nPtrSize); - } - - case TDH_INTYPE_SYSTEMTIME: - assert(nDataSize >= sizeof(SYSTEMTIME)); - switch (OutType) { - case TDH_OUTTYPE_CULTURE_INSENSITIVE_DATETIME: return tstring_printf(_T("%04d-%02d-%02d %02d:%02d:%02d.%03u"), ((PSYSTEMTIME)pData)->wYear, ((PSYSTEMTIME)pData)->wMonth, ((PSYSTEMTIME)pData)->wDay, ((PSYSTEMTIME)pData)->wHour, ((PSYSTEMTIME)pData)->wMinute, ((PSYSTEMTIME)pData)->wSecond, ((PSYSTEMTIME)pData)->wMilliseconds); - default: { - tstring out; - return GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, (PSYSTEMTIME)pData, NULL, out) ? out : tstring(_T("