-
Notifications
You must be signed in to change notification settings - Fork 167
Add process_start_key() to read ProcessStartKey from extended data #271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Kyle Reed (kylereedmsft)
merged 4 commits into
master
from
users/suvenka/processStartKey
Mar 9, 2026
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
676d948
Add process_start_key() to read ProcessStartKey from extended data
a16f78a
Fix CI build: pin .NET SDK to 8.0.x via global.json
a6d38ba
Address PR review: null checks and parameter lifetime fix
dab7f9e
Add unit tests for process_start_key extended data
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| // This example demonstrates reading the ProcessStartKey from ETW extended data items. | ||
| // The ProcessStartKey uniquely identifies a process instance across a boot session | ||
| // (unlike PID which can be recycled). | ||
|
|
||
| using System; | ||
| using System.Security.Principal; | ||
| using System.Threading; | ||
| using Microsoft.O365.Security.ETW; | ||
|
|
||
| namespace ManagedExamples | ||
| { | ||
| public static class UserTrace008_ProcessStartKey | ||
| { | ||
| public static void Start() | ||
| { | ||
| if (!(new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator))) | ||
| { | ||
| Console.WriteLine("Microsoft-Windows-Kernel-Process provider requires Administrator privileges."); | ||
| return; | ||
| } | ||
|
|
||
| var trace = new UserTrace("UserTrace008_ProcessStartKey"); | ||
| var provider = new Provider("Microsoft-Windows-Kernel-Process"); | ||
| provider.Any = 0x10; // WINEVENT_KEYWORD_PROCESS | ||
| provider.TraceFlags |= TraceFlags.IncludeProcessStartKey; | ||
|
|
||
| int eventCount = 0; | ||
| int eventsWithKey = 0; | ||
| const int maxEvents = 10; | ||
|
|
||
| // Listen for ProcessStart (1) and ProcessStop (2) | ||
| var filter = new EventFilter(Filter.EventIdIs(1).Or(Filter.EventIdIs(2))); | ||
| filter.OnEvent += (record) => | ||
| { | ||
| var pid = record.GetUInt32("ProcessID"); | ||
| string imageName; | ||
| try { imageName = record.GetUnicodeString("ImageName"); } | ||
| catch { try { imageName = record.GetAnsiString("ImageName"); } catch { imageName = "<unknown>"; } } | ||
|
|
||
| ulong processStartKey = 0; | ||
| bool hasKey = record.TryGetProcessStartKey(out processStartKey); | ||
|
|
||
| if (hasKey && processStartKey != 0) | ||
| Interlocked.Increment(ref eventsWithKey); | ||
|
|
||
| int count = Interlocked.Increment(ref eventCount); | ||
|
|
||
| Console.WriteLine($"[{record.TaskName}] PID={pid} ImageName={imageName} " + | ||
| $"HasProcessStartKey={hasKey} ProcessStartKey=0x{processStartKey:X}"); | ||
|
|
||
| if (count >= maxEvents) | ||
| { | ||
| Console.WriteLine($"\nReceived {count} events, {eventsWithKey} had a non-zero ProcessStartKey."); | ||
| if (eventsWithKey > 0) | ||
| Console.WriteLine("PASS: ProcessStartKey is being populated in extended data."); | ||
| else | ||
| Console.WriteLine("FAIL: No events had a ProcessStartKey set."); | ||
| trace.Stop(); | ||
| } | ||
| }; | ||
|
|
||
| provider.AddFilter(filter); | ||
| trace.Enable(provider); | ||
|
|
||
| Console.WriteLine("Listening for process start/stop events (will stop after 10 events)..."); | ||
| Console.WriteLine("Tip: Start or stop some processes to generate events.\n"); | ||
| trace.Start(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "sdk": { | ||
| "version": "8.0.100", | ||
| "rollForward": "latestFeature" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.