How ribshark/safediscshim works
Project type and purpose
• SafeDiscShim is a native Windows compatibility shim—a small DLL that injects into SafeDisc-protected game processes and intercepts calls that would normally go to the blacklisted secdrv.sys driver. It simulates the driver’s responses in user-mode so the game can start without requiring the real driver.
File structure
• installer/
– installer.iss (Inno Setup script)
– license.rtf
• src/
– CMakeLists.txt (build orchestration, vcpkg integration via vcpkg.json)
– dllmain.cpp (DLL entry point, initialization)
– hooks.cpp/.h (API-hooking logic)
– secdrv_ioctl.cpp/.h (mapping of IOCTL codes to emulated responses)
– process.cpp/.h (process-related helpers, injection points)
– logging.cpp/.h (log subsystem, governed by SAFEDISCSHIM_LOGLEVEL)
– pch.cpp/.h (precompiled headers)
– version.h.in (versioning stub)
Extract insights from the README
• No kernel drivers are installed; all “driver” behavior is emulated in user-mode.
• The tool leverages Windows API hooking to catch CreateFile/DeviceIoControl requests destined for “\\.\SecDrv”.
• Logs are emitted next to the game executable, toggleable via an environment variable.
a. Main components:
• Game Executable (process)
• SafeDiscShim DLL
– Hook Engine (initializes and installs detours)
– IOCTL Handler (secdrv_ioctl module)
– Process Helper (process module)
– Logging Subsystem
• Windows API / OS Kernel Interfaces
• Installer (Inno Setup)
b. Relationships & data flows:
1. Installer installs the DLL and any manifest/AppInit settings into the game folder.
2. Windows Loader starts the Game Executable; AppInit or similar mechanism loads SafeDiscShim.dll at process startup.
3. DllMain invokes the Hook Engine, which attaches detours to:
– CreateFileW targeting “\\.\SecDrv”
– DeviceIoControl for secdrv IOCTL codes
4. When the game issues a DeviceIoControl to “\\.\SecDrv”:
– Control flow is intercepted by the IOCTL Handler
– Handler returns a crafted response buffer that mimics the real driver
5. Logging subsystem captures each intercepted call/result and writes to disk if enabled
c. Architectural patterns & principles:
– Modular separation: hooks vs. IOCTL vs. logging vs. process logic
– Dependency management via vcpkg and CMake
– Inno Setup for packaging, keeping installer code separate from shim code
d. Key technologies/frameworks:
– C++17 (or later) on Windows
– Windows API Detours/inline hooking
– CMake + vcpkg for build & dependencies
– Inno Setup (installer.iss)