A Windows NT API hooking framework that allows monitoring and intercepting NT system calls in target processes. Built with C++ and CMake.
HookNt enables you to intercept and monitor NT system calls by hooking functions in the Windows NT API. The framework uses a function-based architecture with separation of concerns.
- Process creation and DLL injection
- NT function hooking with trampoline support
- Parameter logging for hooked functions
- CMake-based build system
- Support for multiple NT functions
srcn/
├── CMakeLists.txt # Main CMake configuration
├── build.bat # Windows build script
├── src/
│ ├── include/ # Public headers
│ │ ├── common.h # Shared definitions and types
│ │ ├── hook_manager.h # Hook management interface
│ │ ├── process_manager.h # Process management interface
│ │ ├── memory_utils.h # Memory utility functions
│ │ ├── ntdlln.h # DLL exports and NT function declarations
│ │ ├── module_resolver.h # Module resolution interface
│ │ ├── function_resolver.h # Function resolution interface
│ │ └── logger.h # Logging interface
│ ├── hooknt/ # Main executable
│ │ ├── main.cpp # Application entry point
│ │ ├── process_manager.cpp
│ │ ├── hook_manager.cpp
│ │ └── memory_utils.cpp
│ └── ntdlln/ # Hook DLL
│ ├── dllmain.cpp # DLL entry point
│ ├── ntdlln.cpp # NT function hooks
│ ├── module_resolver.cpp
│ ├── function_resolver.cpp
│ └── logger.cpp
└── libs/distorm/ # DiStorm integration
cd srcn
.\build.batThis will generate:
hooknt.exe- Main executablentdlln.dll- Hook DLL
hookNt.exe <target_program> <nt_function1> <nt_function2> ...Example:
# Hook file operations in the test.exe process
hookNt.exe test.exe NtWriteFile NtCreateFile NtReadFileOutput will show:
- Process creation and injection status
- Function hooking details
- Parameters and return values of hooked functions
- Process Creation: Creates target process suspended
- DLL Injection: Uses reflective DLL injection
- Function Resolution: Locates NT functions in both DLLs
- Trampoline Creation: Preserves original functionality
- Function Patching: Redirects calls to hooks
- Process Resumption: Resumes with hooks active
sequenceDiagram
participant User
participant HookNt as hooknt.exe
participant Target as Target Process
participant NTDLL as ntdll.dll
participant NTDLLN as ntdlln.dll
User->>HookNt: Launch with target process & functions
HookNt->>Target: Create suspended process
HookNt->>Target: Inject ntdlln.dll
loop For each function to hook
HookNt->>NTDLL: Locate original NT function
HookNt->>NTDLLN: Locate -N hook function
HookNt->>NTDLLN: Locate trampoline variable
HookNt->>Target: Allocate trampoline memory
HookNt->>NTDLLN: Save trampoline address
HookNt->>NTDLL: Patch to jump to -N function
end
HookNt->>Target: Resume process
Note over Target,NTDLLN: When NT function called:
Target->>NTDLL: Call NT function
NTDLL->>NTDLLN: Jump to -N function
NTDLLN->>NTDLLN: Log parameters
NTDLLN->>NTDLL: Call via trampoline
NTDLL->>NTDLLN: Return result
NTDLLN->>NTDLLN: Log result
NTDLLN->>Target: Return to caller
- Process Manager: Handles process creation, DLL injection, and memory management
- Hook Manager: Manages function hooking, patching, and trampoline creation
- Memory Utils: Provides custom memory functions
- Module Resolver: Implements PEB-based module resolution
- Function Resolver: Handles export table parsing
- Logger: Provides logging functionality
- Architecture: x64 Windows
- Jump Technique: push+ret for 64-bit absolute jumps
- String Operations: Custom implementations
- Calling Convention: NTAPI for all NT functions
- Memory Safety: Proper allocation/cleanup
- Build System: CMake
Currently, only the following functions are supported:
NtCreateFileNtReadFileNtWriteFile
But you can easily add new functions by following these steps:
-
Add trampoline variable:
extern "C" NTDLLN_API PVOID NtNewFunctionTrampoline = nullptr;
-
Implement hook:
extern "C" NTDLLN_API NTSTATUS NTAPI NtNewFunctionN(...) { printfN("\n[*] NtNewFunction\n"); // Log parameters typedef NTSTATUS(NTAPI* NtNewFunction_proc)(...); NtNewFunction_proc trampoline = (NtNewFunction_proc)NtNewFunctionTrampoline; return trampoline(...); }
-
Add declaration to ntdlln.h
-
Rebuild
- Visual Studio 2019+ (with C++)
- CMake 3.20+
- Windows SDK
Educational and research purposes. Use responsibly and in accordance with applicable laws.

