# ultrasound123d/winsockpacketeditor architecture

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

- Interactive diagram: https://gitdiagram.com/ultrasound123d/winsockpacketeditor
- Repository: https://github.com/ultrasound123d/winsockpacketeditor

## Overview

##### Project type and purpose
- This is a Windows desktop application (“Winsock Packet Editor” or WPE x64) built with C#/.NET Framework 4.8.
- Its purpose is to intercept, inspect, modify, and replay WinSock network packets from target processes. It supports two modes: in-process injection (via EasyHook) and an external SOCKS proxy.

##### File structure
Top-level solution:
- WinSockPacketEditor.sln – Visual Studio solution.
- Two projects:
– WPELibrary (class library + WinForms UI + EasyHook services)
– WinsockPacketEditor (WinForms UI “host” + injection launcher + Web-based UI)
- Each project has:
– x86 and x64 folders containing compiled hook services (EasyHook32Svc.exe, EasyHook64Svc.exe).
– Lib/NativeMethods for P/Invoke wrappers around WinSock and Windows APIs.
– Web and WebAPI folders for built-in HTTP UI and REST controllers.
– UserControl and multiple Form *.cs files for UI screens (proxy, filters, packet views, robots).
– app.config, packages.config, .csproj for .NET build and dependencies.

##### Readme insights
- Core technologies: C#/.NET Framework 4.8, EasyHook for injection, multi-threading, message queue.
- Deployment: ClickOnce auto-update, online/offline modes.
- Architecture: two modes of interception, advanced filters, programmable robots, REST/WebUI for remote control.

##### Main components
a. Client UI (WinForms)
– Packet Editor Form
– Injector Form
– Filter, Compare, Send, Robot configuration Forms
– Process list Form
b. Interceptor Services (x86 & x64)
– EasyHook32Svc.exe / EasyHook64Svc.exe
– DLL hook handlers (WinSockHook.cs)
– Message queue buffer
c. Application Core (WPELibrary/WinsockPacketEditor)
– Injection Manager (select target, call EasyHook API)
– Proxy Mode Manager (embedded SOCKS5 server, port mapping)
– Packet Processing Engine (Socket_*.cs classes)
– Robot Engine (Socket_Robot.cs + triggers)
– Filter Engine (Socket_FilterInfo.cs)
– WebAPI Controllers (CCProxy_Controller, ProxyAccount_Controller, etc.)
– Local Configuration Store (app.config, Resources.resx, settings persistence)
d. External Dependencies
– Target Processes (games, browsers, emulators)
– WinSock APIs (Kernel32, WS2_32, User32)
– .NET runtime
– Network / SOCKS upstream servers
– ClickOnce update server

##### Relationships and data flows
- UI ↔ Core: user actions (inject, start proxy, apply filters) invoke Core services via in-process calls.
- Core ↔ Interceptor Services:
- Injection mode: Core uses EasyHook to inject hook DLL into target → hook DLL intercepts WinSock calls → sends raw packets back via IPC or memory-mapped queue.
- Proxy mode: Core hosts a local SOCKS server → target process traffic routed through this server → Core inspects/modifies packets.
- Interceptor Services → Core: intercepted packets flow into the Message Queue → Core dispatches to UI, Filter Engine, Robot Engine, and WebAPI.
- Core → WebAPI / Web UI: local HTTP server exposes REST endpoints → Web UI (HTML/JS files) communicates via AJAX to display packet logs and controls.
- Core → Persistence: configuration and logs saved to resources or local files on change.

##### Architectural patterns and design principles
- Layered architecture (UI layer, Application/Core layer, Hook/Service layer, Infrastructure).
- Plugin-style injection via EasyHook (decoupling host and hook code).
- Asynchronous message queue for packet buffering (producer/consumer).
- MVC-like controllers for WebAPI.
- Multi-threading for non-blocking packet processing.

##### Essential architectural elements to capture
- Dual-mode interception entry points (Injection vs. SOCKS proxy).
- EasyHook service processes running out-of-process.
- Central message queue buffering.
- UI forms and WebUI as distinct presentation channels.
- Packet Processing Engine, Filter Engine, Robot Engine as sub-modules within Core.
- Persistence and auto-update mechanism.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% UI Layer
    subgraph "UI Layer"
        direction TB
        Injector_Form["Injector Form"]:::ui
        ProcessList_Form["Process List Form"]:::ui
        Proxy_Form["Proxy Mode Form"]:::ui
        ModeSelection_Form["Mode Selection Form"]:::ui
        PacketEditor_Form["Packet Editor Form"]:::ui
        FilterForm["Filter Configuration Form"]:::ui
        CompareForm["Compare Form"]:::ui
        SendForm["Send Packet Form"]:::ui
        RobotForm["Robot Configuration Form"]:::ui
        subgraph "Web UI"
            WebUI_HTML["index.html & Static Assets"]:::ui
        end
    end

    %% Core Layer
    subgraph "Core/Application Layer"
        direction TB
        InjectionManager["Injection Manager\n(Program.cs)"]:::core
        ProxyModeManager["Proxy Mode Manager"]:::core
        PacketProcessingEngine["Packet Processing Engine"]:::core
        RobotEngine["Robot Engine"]:::core
        FilterEngine["Filter Engine"]:::core
        MessageQueue["Message Queue & Buffer"]:::core
        WebAPIControllers["WebAPI Controllers\n(REST Services)"]:::core
        Persistence["Configuration & Persistence"]:::core
        DLLHookHandler["DLL Hook Handler\n(WinSockHook.cs)"]:::core
    end

    %% Hook/Service Layer
    subgraph "Hook/Service Layer"
        direction TB
        Easy32SvcHost["EasyHook32Svc.exe\n(host copy)"]:::hook
        Easy64SvcHost["EasyHook64Svc.exe\n(host copy)"]:::hook
        Easy32SvcLib["EasyHook32Svc.exe"]:::hook
        Easy64SvcLib["EasyHook64Svc.exe"]:::hook
    end

    %% External Dependencies
    subgraph "External / Infrastructure"
        direction TB
        TargetProcesses["Target Processes"]:::infra
        WinSockAPIs["WinSock & Native APIs"]:::infra
        DotNetRuntime[".NET Runtime"]:::infra
        NetworkServers["SOCKS Upstream Servers"]:::infra
        UpdateServer["ClickOnce Update Server"]:::infra
    end

    %% Relationships
    Injector_Form -->|"user actions"| InjectionManager
    ProcessList_Form -->|select target| InjectionManager
    ModeSelection_Form -->|select mode| ProxyModeManager
    Proxy_Form -->|start proxy| ProxyModeManager
    PacketEditor_Form -->|view/edit packets| PacketProcessingEngine
    FilterForm -->|apply filters| FilterEngine
    CompareForm -->|compare packets| PacketProcessingEngine
    SendForm -->|send packet| PacketProcessingEngine
    RobotForm -->|configure robots| RobotEngine

    InjectionManager -->|"Inject() call"| Easy32SvcHost
    InjectionManager -->|"Inject() call"| Easy64SvcHost
    Easy32SvcHost --> DLLHookHandler
    Easy64SvcHost --> DLLHookHandler
    DLLHookHandler -->|produce packets| MessageQueue

    ProxyModeManager -->|bind socket| NetworkServers
    NetworkServers -->|route traffic| ProxyModeManager
    ProxyModeManager -->|produce packets| MessageQueue

    MessageQueue -->|dispatch packets| PacketProcessingEngine
    MessageQueue -->|dispatch packets| FilterEngine
    MessageQueue -->|dispatch packets| RobotEngine
    MessageQueue -->|dispatch packets| WebAPIControllers

    WebAPIControllers -->|REST calls| WebUI_HTML

    InjectionManager -->|read/write| Persistence
    ProxyModeManager -->|read/write| Persistence
    PacketProcessingEngine -->|read/write| Persistence
    FilterEngine -->|read/write| Persistence
    RobotEngine -->|read/write| Persistence

    TargetProcesses -->|loaded via injection| Easy32SvcHost
    TargetProcesses -->|loaded via injection| Easy64SvcHost
    WinSockAPIs -->|P/Invoke calls| DLLHookHandler
    DotNetRuntime -->|hosts| InjectionManager
    DotNetRuntime -->|hosts| ProxyModeManager

    UpdateServer -->|updates| InjectionManager

    %% Click Events - UI
    click Injector_Form "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WinsockPacketEditor/Injector_Form.cs"
    click ProcessList_Form "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WinsockPacketEditor/ProcessList_Form.cs"
    click Proxy_Form "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WinsockPacketEditor/SocketProxy_Form.cs"
    click ModeSelection_Form "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WinsockPacketEditor/SystemMode_Form.cs"
    click PacketEditor_Form "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WPELibrary/Socket_Form.cs"
    click FilterForm "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WPELibrary/Socket_FilterForm.cs"
    click CompareForm "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WPELibrary/Socket_CompareForm.cs"
    click SendForm "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WPELibrary/Socket_SendForm.cs"
    click RobotForm "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WPELibrary/Socket_RobotForm.cs"
    click WebUI_HTML "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WinsockPacketEditor/Web/index.html"

    %% Click Events - Hook Services
    click Easy32SvcLib "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WPELibrary/EasyHook32Svc.exe"
    click Easy64SvcLib "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WPELibrary/EasyHook64Svc.exe"
    click Easy32SvcHost "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WinsockPacketEditor/EasyHook32Svc.exe"
    click Easy64SvcHost "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WinsockPacketEditor/EasyHook64Svc.exe"

    %% Click Events - Core Components
    click DLLHookHandler "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WPELibrary/Lib/WinSockHook.cs"
    click MessageQueue "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WPELibrary/Lib/Socket_Cache.cs"
    click MessageQueue "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WPELibrary/Lib/Socket_Operation.cs"
    click InjectionManager "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WinsockPacketEditor/Lib/Program.cs"
    click ProxyModeManager "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WPELibrary/Lib/Socket_ProxyTCP.cs"
    click ProxyModeManager "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WPELibrary/Lib/Socket_ProxyUDP.cs"
    click PacketProcessingEngine "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WPELibrary/Lib/Socket_BitInfo.cs"
    click PacketProcessingEngine "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WPELibrary/Lib/Socket_PacketInfo.cs"
    click PacketProcessingEngine "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WPELibrary/Lib/Socket_LogInfo.cs"
    click PacketProcessingEngine "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WPELibrary/Lib/Socket_SendInfo.cs"
    click RobotEngine "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WPELibrary/Lib/Socket_Robot.cs"
    click RobotEngine "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WPELibrary/Lib/Socket_RobotInfo.cs"
    click FilterEngine "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WPELibrary/Lib/Socket_FilterInfo.cs"
    click WebAPIControllers "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WPELibrary/Lib/WebAPI/CCProxy_Controller.cs"
    click WebAPIControllers "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WPELibrary/Lib/WebAPI/ProxyAccount_Controller.cs"
    click WebAPIControllers "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WPELibrary/Lib/WebAPI/ProxyInfo_Controller.cs"
    click WebAPIControllers "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WPELibrary/Lib/WebAPI/SocketInfo_Controller.cs"
    click WebAPIControllers "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WPELibrary/Lib/WebAPI/SystemInfo_Controller.cs"
    click WebAPIControllers "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WPELibrary/Lib/WebAPI/Socket_Web.cs"
    click Persistence "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WPELibrary/app.config"
    click Persistence "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WPELibrary/Properties/Resources.resx"
    click Persistence "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WinsockPacketEditor/app.config"
    click Persistence "https://github.com/ultrasound123d/winsockpacketeditor/blob/master/WinsockPacketEditor/Properties/Resources.resx"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef core fill:#90EE90,stroke:#333,stroke-width:1px
    classDef hook fill:#FFA500,stroke:#333,stroke-width:1px
    classDef infra fill:#D3D3D3,stroke:#333,stroke-width:1px
```
