# microsoft/krabsetw architecture

> Architecture diagram of the GitHub repository microsoft/krabsetw, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/microsoft/krabsetw
- Repository: https://github.com/microsoft/krabsetw

## Overview

##### Main Components

a) Core Components:
- krabsetw (Native C++ Library)
- Microsoft.O365.Security.Native.ETW (C++/CLI .NET Wrapper, aka "Lobsters")
- ETW System Integration Layer

b) Architectural Layers:
- Client Application Layer
- API Interface Layer
- Event Processing Layer
- ETW Provider Integration Layer
- Windows ETW Infrastructure

**[Client Applications]**
- ↓ ↑
**[.NET API (Lobsters)] ←→ [Native API (krabsetw)]**
- ↓ ↑                     ↓ ↑
**[Event Processing & Filtering System]**
- ↓ ↑
**[ETW Provider Interface]**
- ↓ ↑
**[Windows ETW Infrastructure]**

##### Key Components to Highlight

a) Provider Management:
- User Traces (UserTrace.hpp)
- Kernel Traces (KernelTrace.hpp)
- Raw Providers (RawProvider.hpp)

b) Event Processing:
- Event Filtering System (Filtering/ directory)
- Event Record Processing (EventRecord.hpp)
- Schema Management (schema.hpp)

c) Testing Infrastructure:
- Synthetic Event Generation
- Record Building
- Event Simulation

##### Important Relationships

- Bidirectional flow between native and managed code
- Event flow from providers to consumers
- Filtering pipeline
- Error handling paths
- Testing infrastructure integration

##### Implementation Details

- Support for x64 and ARM64 architectures
- Windows version compatibility (Win7/2008R2+)
- Thread management for blocking operations
- Exception handling boundaries

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client["Client Application Layer"]
        App[Client Applications]
    end

    subgraph API["API Interface Layer"]
        NET[".NET API (Lobsters)"]:::net
        Native["Native API (krabsetw)"]:::native
    end

    subgraph Processing["Event Processing Layer"]
        EventProc["Event Record Processing"]:::eventproc
        Filter["Event Filtering System"]:::filter
        Schema["Schema Management"]:::schema
        TypeConv["Type Conversions"]:::typeconv
        ErrorHandle["Error Handling"]:::error
    end

    subgraph Providers["ETW Provider Integration Layer"]
        UserT["User Traces"]:::user
        KernelT["Kernel Traces"]:::kernel
        RawP["Raw Providers"]:::raw
        KernelP["Kernel Providers"]:::kernelprov
    end

    subgraph Windows["Windows ETW Infrastructure"]
        ETW["ETW System"]
    end

    subgraph Testing["Testing Infrastructure"]
        TestInfra["Test Framework"]:::test
        RecordBuild["Record Builder"]:::recordbuild
    end

    %% Relationships
    App <--> NET
    App <--> Native
    NET <--> Native
    NET --> EventProc
    Native --> EventProc
    EventProc <--> Filter
    EventProc <--> Schema
    EventProc --> TypeConv
    EventProc --> ErrorHandle
    Filter --> UserT
    Filter --> KernelT
    Filter --> RawP
    KernelT --> KernelP
    UserT --> ETW
    KernelT --> ETW
    RawP --> ETW
    TestInfra --> RecordBuild
    RecordBuild --> EventProc

    %% Click Events
    click NET "https://github.com/microsoft/krabsetw/tree/master/Microsoft.O365.Security.Native.ETW/"
    click Native "https://github.com/microsoft/krabsetw/tree/master/krabs/krabs/"
    click UserT "https://github.com/microsoft/krabsetw/blob/master/Microsoft.O365.Security.Native.ETW/UserTrace.hpp"
    click KernelT "https://github.com/microsoft/krabsetw/blob/master/Microsoft.O365.Security.Native.ETW/KernelTrace.hpp"
    click RawP "https://github.com/microsoft/krabsetw/blob/master/Microsoft.O365.Security.Native.ETW/RawProvider.hpp"
    click Filter "https://github.com/microsoft/krabsetw/tree/master/Microsoft.O365.Security.Native.ETW/Filtering/"
    click EventProc "https://github.com/microsoft/krabsetw/blob/master/Microsoft.O365.Security.Native.ETW/EventRecord.hpp"
    click Schema "https://github.com/microsoft/krabsetw/blob/master/krabs/krabs/schema.hpp"
    click TestInfra "https://github.com/microsoft/krabsetw/tree/master/Microsoft.O365.Security.Native.ETW/Testing/"
    click ErrorHandle "https://github.com/microsoft/krabsetw/blob/master/Microsoft.O365.Security.Native.ETW/Errors.hpp"
    click TypeConv "https://github.com/microsoft/krabsetw/blob/master/Microsoft.O365.Security.Native.ETW/Conversions.hpp"
    click KernelP "https://github.com/microsoft/krabsetw/blob/master/krabs/krabs/kernel_providers.hpp"
    click RecordBuild "https://github.com/microsoft/krabsetw/blob/master/krabs/krabs/testing/record_builder.hpp"

    %% Styling
    classDef native fill:#2374ab
    classDef net fill:#2a9d8f
    classDef eventproc fill:#e9c46a
    classDef filter fill:#f4a261
    classDef schema fill:#e76f51
    classDef error fill:#e63946
    classDef user fill:#606c38
    classDef kernel fill:#283618
    classDef raw fill:#dda15e
    classDef test fill:#bc6c25
    classDef recordbuild fill:#dda15e
    classDef typeconv fill:#e9c46a
    classDef kernelprov fill:#283618
```
