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.
Compiler: MSVC 2019+ (C++17) Build System: CMake 3.15+ OS: Windows 10/11 Dependencies: nlohmann/json (header-only, included in common/)
├── 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
-
Open Developer Command Prompt
cd path/to/exe
-
Create Build Directory
mkdir build cd build
-
Generate Visual Studio Solution
cmake .. -G "Visual Studio 17 2022" -A x64
-
Build All Targets
cmake --build . --config Debug
-
Output Files
build/Debug/Client.exe build/Debug/Server.exe build/Debug/StatsUtil.exe
cd build/Debug Server.exe ../../config.json 8080
Arguments:
- config.json : Path to patterns configuration
- 8080 : Port to listen on
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
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 |
+--------------------------------------+
Press Ctrl+C in server console. Server will:
- Stop accepting new connections
- Wait for all worker processes to complete
- Release all resources
- Exit cleanly
- Connects to server via TCP socket
- Sends file content as plain text
- Receives and displays check result
- Uses RAII Socket wrapper
- 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
- 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 |
config.json:
{
"patterns": [
"virus",
"malware",
"trojan",
"backdoor"
]
}
echo Hello clean file > clean.txt Client.exe clean.txt 8080 Expected: OK: File is clean
echo This contains malware and trojan > infected.txt Client.exe infected.txt 8080 Expected: THREAT: malware, trojan
Run multiple clients, then: StatsUtil.exe 8080
Start server, run 2-3 clients, press Ctrl+C Server waits for workers, then exits cleanly