Skip to content

Create LogMonitorAPI and replace ETW EventRecord Callback - #2

Draft
iankingori wants to merge 2 commits into
mainfrom
hack/library
Draft

iankingori wants to merge 2 commits into
mainfrom
hack/library

Conversation

@iankingori

Copy link
Copy Markdown
Owner

No description provided.

Comment thread LogMonitor/src/LogMonitor/LogMonitorAPI.cpp Fixed
@iankingori
iankingori marked this pull request as draft June 20, 2025 07:08
Comment on lines +60 to +75
switch (source->Type)
{
case LogSourceType::ETW:
{
std::shared_ptr<SourceETW> sourceETW =
std::reinterpret_pointer_cast<SourceETW>(source);
InitializeEtwMonitor(
sourceETW,
etwProviders);
break;
}
default:
logWriter.TraceWarning(
L"Log source type not supported for monitoring");
break;
}

Check notice

Code scanning / CodeQL

No trivial switch statements

This switch statement should either handle more cases, or be rewritten as an if statement.

Copilot Autofix

AI about 1 year ago

To fix the issue, the switch statement should be replaced with an if/else structure. This involves:

  1. Replacing the switch statement with an if condition for the LogSourceType::ETW case.
  2. Adding an else block to handle the default case.
  3. Ensuring the functionality remains unchanged.

The changes will be made in the StartMonitors function, specifically in the block starting at line 60.


Suggested changeset 1
LogMonitor/src/LogMonitor/LogMonitorAPI.cpp

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/LogMonitor/src/LogMonitor/LogMonitorAPI.cpp b/LogMonitor/src/LogMonitor/LogMonitorAPI.cpp
--- a/LogMonitor/src/LogMonitor/LogMonitorAPI.cpp
+++ b/LogMonitor/src/LogMonitor/LogMonitorAPI.cpp
@@ -59,18 +59,15 @@
     {
-        switch (source->Type)
-        {
-        case LogSourceType::ETW:
-        {
-            std::shared_ptr<SourceETW> sourceETW =
-                std::reinterpret_pointer_cast<SourceETW>(source);
-            InitializeEtwMonitor(
-                sourceETW,
-                etwProviders);
-            break;
-        }
-        default:
-            logWriter.TraceWarning(
-                L"Log source type not supported for monitoring");
-            break;
-        }
+        if (source->Type == LogSourceType::ETW)
+        {
+            std::shared_ptr<SourceETW> sourceETW =
+                std::reinterpret_pointer_cast<SourceETW>(source);
+            InitializeEtwMonitor(
+                sourceETW,
+                etwProviders);
+        }
+        else
+        {
+            logWriter.TraceWarning(
+                L"Log source type not supported for monitoring");
+        }
     }
EOF
@@ -59,18 +59,15 @@
{
switch (source->Type)
{
case LogSourceType::ETW:
{
std::shared_ptr<SourceETW> sourceETW =
std::reinterpret_pointer_cast<SourceETW>(source);
InitializeEtwMonitor(
sourceETW,
etwProviders);
break;
}
default:
logWriter.TraceWarning(
L"Log source type not supported for monitoring");
break;
}
if (source->Type == LogSourceType::ETW)
{
std::shared_ptr<SourceETW> sourceETW =
std::reinterpret_pointer_cast<SourceETW>(source);
InitializeEtwMonitor(
sourceETW,
etwProviders);
}
else
{
logWriter.TraceWarning(
L"Log source type not supported for monitoring");
}
}
Copilot is powered by AI and may make mistakes. Always verify output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants