-
Notifications
You must be signed in to change notification settings - Fork 55
Add sealed ETL denial analysis #699
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
richiemsft
merged 11 commits into
user/saulg/learning-mode-endtoend
from
user/saulg/learning-mode-analyze
Jul 30, 2026
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
46f606d
learning_mode_core: cross-platform denial model + NDJSON emitter
richiemsft 30e249c
Add Windows sealed-ETL denial decoder (PR4 pr4-etl-parse)
richiemsft cfd305d
Add decode-composition tests over real event shapes (pr4-analyze-tests)
richiemsft a0b3a3c
Update decoder terminology for capture modes
richiemsft 51b0415
Update PR4 workspace lockfile
richiemsft 46115be
Harden Learning Mode ETL analysis
richiemsft 564b681
Fix TDH buffer alignment
richiemsft a675adf
Harden denial decoder contracts
richiemsft ca53ed5
Use RFC 7464 terminology
richiemsft 928298c
Enforce canonical denial file paths
richiemsft 6b645d5
Clarify decoder diagnostic boundaries
richiemsft 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
141 changes: 141 additions & 0 deletions
141
src/backends/learning_mode/windows/examples/lm_analyze.rs
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,141 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| //! Decode a sealed learning-mode `.etl` into the captureDenials RFC 7464 | ||
| //! JSON text sequence, or dump its raw ETW events for schema discovery. | ||
| //! | ||
| //! This is a developer diagnostic for inspecting captured traces manually. | ||
| //! End users and SDK agents do not invoke it: the BaseContainer runner seals | ||
| //! and consumes the trace automatically during normal `captureDenials` use. | ||
| //! | ||
| //! Usage: | ||
| //! | ||
| //! ```text | ||
| //! # Emit the DeniedResource JSON text sequence (0x1E-framed) to stdout: | ||
| //! cargo run -p learning_mode_windows --example lm_analyze -- <path-to.etl> --exit-code <code> | ||
| //! | ||
| //! # Dump every decoded event (id + property name/value pairs): | ||
| //! cargo run -p learning_mode_windows --example lm_analyze -- <path-to.etl> --raw | ||
| //! ``` | ||
| //! | ||
| //! Exit codes: `0` = decoded; `2` = wrong platform / bad args; `1` = decode | ||
| //! failed. | ||
|
|
||
| #[cfg(not(target_os = "windows"))] | ||
| fn main() { | ||
| eprintln!("lm_analyze is Windows-only"); | ||
| std::process::exit(2); | ||
| } | ||
|
|
||
| #[cfg(target_os = "windows")] | ||
| fn main() { | ||
| std::process::exit(windows_impl::run()); | ||
| } | ||
|
|
||
| #[cfg(target_os = "windows")] | ||
| mod windows_impl { | ||
| use std::collections::BTreeMap; | ||
| use std::io::Write; | ||
| use std::path::Path; | ||
|
|
||
| use learning_mode_core::{emit, DenialAnalyzer, DenialSummary}; | ||
| use learning_mode_windows::{visit_raw_events, EtlDenialAnalyzer}; | ||
|
|
||
| pub fn run() -> i32 { | ||
| let args: Vec<String> = std::env::args().skip(1).collect(); | ||
| let Some(etl_path) = args.first() else { | ||
| eprintln!("usage: lm_analyze <path-to.etl> [--raw | --exit-code <code>]"); | ||
| return 2; | ||
| }; | ||
| let raw = args.iter().any(|a| a == "--raw"); | ||
| let path = Path::new(etl_path); | ||
|
|
||
| if raw { | ||
| dump_raw(path) | ||
| } else { | ||
| let Some(exit_code) = parse_exit_code(&args) else { | ||
| eprintln!("--exit-code <code> is required unless --raw is used"); | ||
| return 2; | ||
| }; | ||
| emit_json_sequence(path, exit_code) | ||
| } | ||
| } | ||
|
|
||
| fn parse_exit_code(args: &[String]) -> Option<i32> { | ||
| let index = args.iter().position(|arg| arg == "--exit-code")?; | ||
| args.get(index + 1)?.parse().ok() | ||
| } | ||
|
|
||
| /// Decodes denials and writes the RFC 7464 JSON text sequence to stdout. | ||
| fn emit_json_sequence(path: &Path, exit_code: i32) -> i32 { | ||
| let analysis = match EtlDenialAnalyzer.analyze(path) { | ||
| Ok(d) => d, | ||
| Err(e) => { | ||
| eprintln!("analyze failed: {e}"); | ||
| return 1; | ||
| } | ||
| }; | ||
| let summary = DenialSummary::new( | ||
| exit_code, | ||
| analysis.denials.len(), | ||
| analysis.denied_resources_truncated, | ||
| ); | ||
| let stdout = std::io::stdout(); | ||
| let mut handle = stdout.lock(); | ||
| if let Err(e) = emit::write_stream(&mut handle, &analysis.denials, &summary) { | ||
| eprintln!("write failed: {e}"); | ||
| return 1; | ||
| } | ||
| eprintln!( | ||
| "lm_analyze: {} unique denial(s){}", | ||
| analysis.denials.len(), | ||
| if analysis.denied_resources_truncated { | ||
| " (truncated)" | ||
| } else { | ||
| "" | ||
| } | ||
| ); | ||
| 0 | ||
| } | ||
|
|
||
| /// Dumps every decoded event, plus a per-event-id histogram, so the | ||
| /// real provider/ID/field schema can be confirmed against hardware. | ||
| fn dump_raw(path: &Path) -> i32 { | ||
| let mut histogram: BTreeMap<(String, u16), usize> = BTreeMap::new(); | ||
| let stdout = std::io::stdout(); | ||
| let mut out = stdout.lock(); | ||
| let event_count = { | ||
| let mut visitor = |ev: &learning_mode_windows::DecodedEventParts| { | ||
| let provider = format!("{:?}", ev.provider); | ||
| *histogram | ||
| .entry((provider.clone(), ev.event_id)) | ||
| .or_default() += 1; | ||
| let props: Vec<String> = ev.props.iter().map(|(k, v)| format!("{k}={v}")).collect(); | ||
| writeln!( | ||
| out, | ||
| "provider {} event {} | {}", | ||
| provider, | ||
| ev.event_id, | ||
| props.join(" | ") | ||
| ) | ||
| }; | ||
| match visit_raw_events(path, &mut visitor) { | ||
| Ok(count) => count, | ||
| Err(e) => { | ||
| eprintln!("decode failed: {e}"); | ||
| return 1; | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| if writeln!(out, "--- {event_count} event(s) total ---").is_err() { | ||
| return 1; | ||
| } | ||
| for ((provider, id), count) in &histogram { | ||
| if writeln!(out, " provider {provider:?} id {id}: {count}").is_err() { | ||
| return 1; | ||
| } | ||
| } | ||
| 0 | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: is it the developer who is running
cargo run -p learning_mode_windows --example lm_analyze -- <path-to.etl> --exit-code <code>? or lets say GitHub copilot on a user's machine (for my question assume the user has no clue GitHub ;copilot is using MXC and just wants it to perform some workload)?