Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TCP IPC File Scanner

A C++ client-server file scanner that detects configured text patterns in files. The server handles each client in a separate worker process and stores statistics using Windows IPC mechanisms.

REQUIREMENTS

Compiler: MSVC 2019+ (C++17) Build System: CMake 3.15+ OS: Windows 10/11 Dependencies: nlohmann/json (header-only, included in common/)

PROJECT STRUCTURE


├── CMakeLists.txt
├── README.md
├── config.json
├── common/
│   └── json.hpp
└── src/
    ├── Client/
    │   ├── main.cpp
    │   ├── client.cpp
    │   ├── client.h
    │   ├── socket.cpp
    │   └── socket.h
    ├── Server/
    │   ├── main.cpp
    │   ├── server.cpp
    │   ├── server.h
    │   └── worker.cpp
    └── StatsUtil/
        └── stats_util.cpp

BUILD INSTRUCTIONS

  1. Open Developer Command Prompt

    cd path/to/exe

  2. Create Build Directory

    mkdir build cd build

  3. Generate Visual Studio Solution

    cmake .. -G "Visual Studio 17 2022" -A x64

  4. Build All Targets

    cmake --build . --config Debug

  5. Output Files

    build/Debug/Client.exe build/Debug/Server.exe build/Debug/StatsUtil.exe

USAGE

1. START SERVER

cd build/Debug Server.exe ../../config.json 8080

Arguments:

  • config.json : Path to patterns configuration
  • 8080 : Port to listen on

2. SEND FILE FOR CHECK (CLIENT)

Client.exe test.txt 8080

Arguments:

  • test.txt : Path to file to check
  • 8080 : Server port

Example Output: Connected to 127.0.0.1:8080 File sent: test.txt Server response: THREAT: malware, trojan

3. VIEW STATISTICS (STATSUTIL)

StatsUtil.exe 8080

Arguments:

  • 8080 : Server port (optional, default: 8080)

Example Output:

	+--------------------------------------+
	|            STATISTICS                |
	+--------------------------------------+
	| Files checked:                    5  |
	| Threats found:                    3  |
	| Detected patterns:                   |
	|   malware        :                2  |
	|   trojan         :                1  |
	+--------------------------------------+

4. GRACEFUL SHUTDOWN

Press Ctrl+C in server console. Server will:

  • Stop accepting new connections
  • Wait for all worker processes to complete
  • Release all resources
  • Exit cleanly

ARCHITECTURE

CLIENT:

  • Connects to server via TCP socket
  • Sends file content as plain text
  • Receives and displays check result
  • Uses RAII Socket wrapper

SERVER:

  • Listens on specified TCP port
  • Creates separate process for each client (CreateProcess + socket inheritance)
  • Loads patterns from JSON config
  • Checks file for all matching patterns (not just first)
  • Maintains shared statistics via Shared Memory + Mutex
  • Provides statistics via Named Pipe (IPC)
  • Handles Ctrl+C for graceful shutdown

STATSUTIL:

  • Connects via Named Pipe (\.\pipe\IPCStats_(port))
  • Requests current statistics
  • Displays formatted output
  • Exits after displaying

IPC MECHANISMS:

| Mechanism      | Purpose                        |
|----------------|--------------------------------|
| TCP Socket     | Client <-> Server              |
| Shared Memory  | Server <-> Workers (stats)     |
| Named Mutex    | Statistics synchronization     |
| Named Pipe     | Server <-> StatsUtil           |

CONFIGURATION FILE

config.json:


{
  "patterns": [
    "virus",
    "malware",
    "trojan",
    "backdoor"
  ]
}

TESTING

1. CLEAN FILE

echo Hello clean file > clean.txt Client.exe clean.txt 8080 Expected: OK: File is clean

2. INFECTED FILE

echo This contains malware and trojan > infected.txt Client.exe infected.txt 8080 Expected: THREAT: malware, trojan

3. STATISTICS

Run multiple clients, then: StatsUtil.exe 8080

4. GRACEFUL SHUTDOWN

Start server, run 2-3 clients, press Ctrl+C Server waits for workers, then exits cleanly

About

C++ TCP server/client file scanner with worker processes and IPC-based statistics.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages