Add missing TraceLoggingRegister calls (VT ONLY) (#16467)

17cc109 and e9de646 both made the same mistake: When cleaning up our
telemetry code they also removed the calls to `TraceLoggingRegister`
which also broke regular tracing. Windows Defender in particular uses
the "CookedRead" event to monitor for malicious shell commands.

This doesn't fix it the "right way", because destructors of statics
aren't executed when DLLs are unloaded. But I felt like that this is
fine because we have way more statics than that in conhost land,
all of which have the same kind of issue.

(cherry picked from commit a65d5f321f)
Service-Card-Id: 91337330
Service-Version: 1.19
This commit is contained in:
Leonard Hecker
2023-12-16 00:29:09 +01:00
committed by Dustin L. Howett
parent 48a6d92255
commit 5575187b26

View File

@@ -7,6 +7,7 @@
using namespace Microsoft::Console::VirtualTerminal;
#pragma warning(push)
#pragma warning(disable : 26426) // Global initializer calls a non-constexpr function '...' (i.22).)
#pragma warning(disable : 26447) // The function is declared 'noexcept' but calls function '_tlgWrapBinary<wchar_t>()' which may throw exceptions
#pragma warning(disable : 26477) // Use 'nullptr' rather than 0 or NULL
@@ -15,6 +16,13 @@ TRACELOGGING_DEFINE_PROVIDER(g_hConsoleVirtTermParserEventTraceProvider,
// {c9ba2a84-d3ca-5e19-2bd6-776a0910cb9d}
(0xc9ba2a84, 0xd3ca, 0x5e19, 0x2b, 0xd6, 0x77, 0x6a, 0x09, 0x10, 0xcb, 0x9d));
static const auto cleanup = []() noexcept {
TraceLoggingRegister(g_hConsoleVirtTermParserEventTraceProvider);
return wil::scope_exit([]() noexcept {
TraceLoggingUnregister(g_hConsoleVirtTermParserEventTraceProvider);
});
}();
void ParserTracing::TraceStateChange(_In_z_ const wchar_t* name) const noexcept
{
TraceLoggingWrite(g_hConsoleVirtTermParserEventTraceProvider,