# rajendra1185/processhacker architecture

> Architecture diagram of the GitHub repository rajendra1185/processhacker, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rajendra1185/processhacker
- Repository: https://github.com/rajendra1185/processhacker

## Overview

##### Project type and purpose
- This is a native Windows desktop application with two main facets:
– A kernel-mode driver component (KSystemInformer) that hooks into low-level system APIs to capture events (process/thread creation, file I/O, registry, networking, etc.).
– A user-mode GUI client (SystemInformer) that presents that data in real time, plus a plugin framework and a wealth of command-line utilities and libraries.
- The README confirms: “A free, powerful, multi-purpose tool to monitor system resources… includes kernel-mode, WOW64 and .NET support.”

##### File structure
Top-level components:
- build/ – build scripts (cmd files), SDK, driver packaging (DDf).
- KSystemInformer/ – kernel driver solution, .sys, .inf and driver source (alloc.c, back_trace.c, alpc.c, comms.c, etc.).
- SystemInformer/ – user-mode GUI solution, .exe and resource files, main UI code, phsvc (service), plugins loader support.
- plugins/ – multiple plugin projects (.vcxproj), each a DLL loaded by the GUI.
- kphlib/, phlib/, phnt/ – shared libraries: kernel/user helper libs, NT API definitions and wrappers used by both driver and GUI.
- tools/ – standalone CLI utilities (.exe) and helper tools (custom build, code generators).
- tools/thirdparty/ – vendor libraries (Capstone, Detours, JSON-C, etc.).

##### README for additional insights
- Describes the two solutions: SystemInformer.sln (GUI + service) and Plugins.sln (all plugins).
- Build instructions point you to build_release.cmd in build/, implying a unified build pipeline.
- Mentions plugin configuration via Options > Plugins.

##### Main components & interactions
a. Kernel Driver (KSystemInformer.sys)
– Hooks low-level APIs via kernel callbacks, ETW, detours-like techniques.
– Writes events to shared channels (ALPC ports or dynamic memory buffers).
– Exposes IOCTL interfaces and ALPC endpoints for control and data retrieval.
b. User-Mode Service/Client (SystemInformer.exe + phsvc)
– phsvc runs as a Windows service for elevated operations (if required).
– GUI (SystemInformer.exe) connects via ALPC/IOCTL to the driver, requests snapshots or real-time streams.
– Uses kphlib and phlib wrappers to talk to the driver and parse NT structures.
c. Plugin Framework
– DLLs placed in plugins/ folder conform to plugin interface headers in plugins/include.
– GUI loads each plugin, calls its exported entry points to gather additional data (disk I/O, network stats, etc.).
d. Supporting Libraries
– phnt: pure header definitions of native NT APIs.
– kphlib: kernel-mode helpers and user-mode stubs for driver communication.
– phlib: UI support, data structures, utility functions shared by GUI and tools.
e. Standalone Tools
– Each under tools/ (CustomBuildTool, CustomSetupTool, CustomSignTool, CustomStartTool, peview, etc.).
– They consume phlib/phnt/capstone/etc. to perform discrete tasks (PE inspection, driver signing, code-gen).
f. Third-party Dependencies
– Compiled into static libs or built as part of the “thirdparty.sln.”
– Capstone (disassembler), Detours (instrumentation), JSON-C, Miniz, PCRE, etc.

##### Architectural patterns & principles
- Layered architecture:
– Kernel layer (driver) <–> communication layer (ALPC/IOCTL) <–> user-mode core <–> plugin modules <–> GUI presentation.
- Plugin pattern: loose coupling, plugins implement exported hooks and rely on core plugin manager.
- Shared library modules (phlib, kphlib) centralize common code.
- Build pipeline (build/*.cmd) orchestrates compilation of driver, GUI, plugins, tools, and third-party.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Kernel Layer
    subgraph "Kernel Layer"
        KernelDriver["Kernel Driver\nKSystemInformer.sys"]:::kernel
    end

    %% Communication Layer
    subgraph "Communication Layer"
        IOCTL["IOCTL Interface"]:::comm
        ALPC["ALPC Port"]:::comm
    end

    %% Core User-Mode
    subgraph "Core User-Mode"
        CoreExe["SystemInformer.exe"]:::core
        Service["phsvc Service"]:::core
    end

    %% Plugin Framework
    subgraph "Plugin Framework"
        PluginMgr["Plugin Manager\nplugman.c"]:::plugin
        PhPlug["phplug.h"]:::plugin
        DotNetTools["DotNetTools.dll"]:::plugin
        ExtNotify["ExtendedNotifications.dll"]:::plugin
        ExtServices["ExtendedServices.dll"]:::plugin
    end

    %% Shared Libraries
    subgraph "Shared Libraries"
        KPHLib["kphlib"]:::lib
        PHLib["phlib"]:::lib
        PHNT["phnt"]:::lib
    end

    %% CLI Tools
    subgraph "CLI Tools"
        CBTool["CustomBuildTool"]:::tool
        CSetup["CustomSetupTool"]:::tool
        PReview["peview"]:::tool
    end

    %% Third-Party Dependencies
    subgraph "Third-Party Dependencies"
        ThirdParty["thirdparty.sln"]:::third
    end

    %% Relationships
    KernelDriver -->|IOCTL/ALPC API| IOCTL
    KernelDriver -->|IOCTL/ALPC API| ALPC
    IOCTL -->|Event Streams| CoreExe
    ALPC -->|Event Streams| CoreExe
    CoreExe -->|Control Commands| KernelDriver
    Service -->|Control Commands| KernelDriver

    CoreExe -->|Load Plugins| PluginMgr
    PluginMgr -->|Plugin Interface| DotNetTools
    PluginMgr -->|Plugin Interface| ExtNotify
    PluginMgr -->|Plugin Interface| ExtServices
    DotNetTools -->|Data Response| CoreExe
    ExtNotify -->|Data Response| CoreExe
    ExtServices -->|Data Response| CoreExe

    CoreExe -->|Uses| KPHLib
    CoreExe -->|Uses| PHLib
    CoreExe -->|Uses| PHNT
    CBTool -->|Uses| PHLib
    CSetup -->|Uses| PHLib
    PReview -->|Uses| PHLib

    ThirdParty -->|Provides| CBTool
    ThirdParty -->|Provides| CSetup
    ThirdParty -->|Provides| PReview
    ThirdParty -->|Provides| KPHLib
    ThirdParty -->|Provides| PHLib

    %% Click Events
    click KernelDriver "https://github.com/rajendra1185/processhacker/tree/master/KSystemInformer/"
    click IOCTL "https://github.com/rajendra1185/processhacker/tree/master/KSystemInformer/include/"
    click ALPC "https://github.com/rajendra1185/processhacker/tree/master/KSystemInformer/include/"
    click CoreExe "https://github.com/rajendra1185/processhacker/blob/master/SystemInformer/SystemInformer.vcxproj"
    click Service "https://github.com/rajendra1185/processhacker/blob/master/SystemInformer/phsvc/svcapiport.c"
    click PluginMgr "https://github.com/rajendra1185/processhacker/blob/master/SystemInformer/plugman.c"
    click PhPlug "https://github.com/rajendra1185/processhacker/blob/master/SystemInformer/include/phplug.h"
    click DotNetTools "https://github.com/rajendra1185/processhacker/blob/master/plugins/DotNetTools/DotNetTools.vcxproj"
    click ExtNotify "https://github.com/rajendra1185/processhacker/blob/master/plugins/ExtendedNotifications/ExtendedNotifications.vcxproj"
    click ExtServices "https://github.com/rajendra1185/processhacker/blob/master/plugins/ExtendedServices/ExtendedServices.vcxproj"
    click KPHLib "https://github.com/rajendra1185/processhacker/tree/master/kphlib/"
    click PHLib "https://github.com/rajendra1185/processhacker/tree/master/phlib/"
    click PHNT "https://github.com/rajendra1185/processhacker/tree/master/phnt/"
    click CBTool "https://github.com/rajendra1185/processhacker/blob/master/tools/CustomBuildTool/CustomBuildTool.csproj"
    click CSetup "https://github.com/rajendra1185/processhacker/blob/master/tools/CustomSetupTool/CustomSetupTool.vcxproj"
    click PReview "https://github.com/rajendra1185/processhacker/blob/master/tools/peview/peview.vcxproj"
    click ThirdParty "https://github.com/rajendra1185/processhacker/blob/master/tools/thirdparty/thirdparty.sln"

    %% Styles
    classDef kernel fill:#ffdddd,stroke:#aa0000,stroke-width:2px
    classDef comm fill:#ffe5cc,stroke:#cc7000,stroke-width:2px
    classDef core fill:#ddffdd,stroke:#00aa00,stroke-width:2px
    classDef plugin fill:#ddeeff,stroke:#0000aa,stroke-width:2px
    classDef lib fill:#f0f0f0,stroke:#888888,stroke-width:1px
    classDef tool fill:#f3e5ff,stroke:#8000aa,stroke-width:2px
    classDef third fill:#eeeeee,stroke:#555555,stroke-width:1px
```
