How hackerhouse-opensource/signtoolex works
Project Overview and Purpose
• This is a specialized tool aimed at modifying the behavior of the native Microsoft “signtool.exe.” It uses the Microsoft Detours library to hijack the signing process in order to “validate” expired code-signing certificates. Essentially, it’s a command-line utility (similar in usage to signtool.exe) that injects a hook (via a DLL module) into the signing workflow.
• The solution consists of two main components: the main executable (SignToolEx) and a dynamic-link library (SignToolExDll) that implements the hooking logic.
Analyzing the File Structure
• The top-level solution file (SignToolEx.sln) encompasses two projects:
– SignToolEx: Contains the source code for the main executable (SignToolEx.cpp and associated VC++ project files). This component is responsible for invoking the sign tool workflow.
– SignToolExDll: Contains the DLL code (dllmain.cpp, framework.h, etc.) that uses detours to perform the hook injection.
• The libs folder includes compiled versions of the Microsoft Detours libraries for both x86 and x64 targets; these are clearly external dependencies.
• The README indicates that the tool needs the hook DLL (named in the README as SignToolExHook.dll, which correlates to the SignToolExDll project contents) and the “signtool.exe” command in the system path.
Identifying the Main Components
• User/CLI Invocation: Represents the operator who runs “SignToolEx.exe” from the command line.
• Main Application (SignToolEx.exe): The entry-point that mimics the interface of signtool.exe while orchestrating the process.
• Hook DLL (SignToolExDll – corresponds to SignToolExHook.dll as mentioned): The DLL that is injected to override or intercept the behavior of the original signtool.exe functions using the Detours library.
• External Component (Original signtool.exe): The legitimate Microsoft signing tool that is being intercepted.
• Detours Library: The external library (provided in the libs folder) that enables the hook installation.
Relationships and Interactions Between Components
• When a user executes “SignToolEx.exe” (via a CLI command), the executable will first verify that the hook DLL (i.e., SignToolExDll) is available in the working directory.
• The main executable loads the DLL, which in turn uses the Detours library functions to intercept calls between the “signtool.exe” process and its signing routine.
• The hooked interactions allow for the modification of certificate validation logic—thereby making expired certificates appear valid (without spoofing Authenticode timestamps).
Important Architectural Patterns/Design Principles
• Modularity and Separation of Concerns: Notice the separation between the main executable and the DLL injection logic. Each is encapsulated as its own VC++ project.
• Dynamic Hooking: The project leverages the Detours library to intercept function calls, emphasizing runtime modification and interception.
• Use of External Libraries: The system relies on pre-built libraries (detours.lib) which are clearly separated in the file tree, showing a dependency management mindset.