Download src/sensor.rs from Sahek/jay-squad-sec: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/datasets/Sahek/jay-squad-sec/resolve/main/src/sensor.rs
- Command line
-
hf download hf://datasets/Sahek/jay-squad-sec/src/sensor.rs
-
curl -L -o sensor.rs https://huggingface.co/datasets/Sahek/jay-squad-sec/resolve/main/src/sensor.rs
1.1 kB
| //! Mock sensor: a scripted stand-in for the kernel adapters. | |
| //! | |
| //! Real builds replace this with eBPF ringbuffer readers (Linux) or | |
| //! ETW/WFP consumers (Windows) that emit the same normalized `Event`s. | |
| use crate::event::{Event, EventKind}; | |
| use crate::rtid::Rtid; | |
| pub struct ScriptedSensor { | |
| script: Vec<(u64, Rtid, EventKind, String)>, | |
| cursor: usize, | |
| } | |
| impl ScriptedSensor { | |
| pub fn new(mut script: Vec<(u64, Rtid, EventKind, String)>) -> Self { | |
| script.sort_by_key(|s| s.0); | |
| Self { script, cursor: 0 } | |
| } | |
| /// Emit every scripted event whose time has arrived. | |
| pub fn poll(&mut self, now_ms: u64) -> Vec<Event> { | |
| let mut out = Vec::new(); | |
| while self.cursor < self.script.len() && self.script[self.cursor].0 <= now_ms { | |
| let (at_ms, rtid, kind, detail) = self.script[self.cursor].clone(); | |
| out.push(Event { rtid, kind, at_ms, detail }); | |
| self.cursor += 1; | |
| } | |
| out | |
| } | |
| pub fn exhausted(&self) -> bool { | |
| self.cursor >= self.script.len() | |
| } | |
| } | |