This guide provides detailed instructions for installing WinKernelLite, building and running examples, and integrating it into your projects.
WinKernelLite is a static library that provides Windows kernel API compatibility for user-mode testing:
- Requires compilation and linking of the static library
- Provides compiled implementations of kernel-mode APIs
- Installation includes both headers and compiled library
- Can be used as a CMake subdirectory or installed package
Before installing WinKernelLite, ensure your system meets the following requirements:
- Windows operating system (supports both 32-bit and 64-bit versions)
- CMake 3.29 or higher
- Note: The project officially requires CMake 3.29. If you have an earlier version:
- You can download CMake from the official website
- Alternatively, you can modify the first line of CMakeLists.txt to use an earlier version (e.g.,
cmake_minimum_required(VERSION 3.20)). Most functionality should work with CMake 3.20+, but this is not officially tested or supported
- Note: The project officially requires CMake 3.29. If you have an earlier version:
- Visual Studio 2019 or later with C/C++ development tools
- Git (optional, for cloning the repository)
There are two ways to install and use WinKernelLite:
- Build and install from source
- Use as a CMake subdirectory
git clone https://github.com/TorinKS/WinKernelLite.git
cd WinKernelLitemkdir build
cd buildcmake ..Note about CMake Version: If you encounter errors related to the CMake version, you may need to either:
- Update to CMake 3.29 or higher
- Modify the first line of CMakeLists.txt to reduce the required version
Example modification in CMakeLists.txt:
# Original line # cmake_minimum_required(VERSION 3.29) # Modified line for older CMake versions cmake_minimum_required(VERSION 3.20)
Configure with specific options:
# Example: Build with examples but don't install them
cmake .. -DBUILD_EXAMPLES=ON -DINSTALL_EXAMPLES=OFFcmake --build . --config ReleaseThis will install the library to the default installation directory (C:\Program Files\WinKernelLite).
cmake --build . --target installFor a custom installation directory:
cmake .. -DCMAKE_INSTALL_PREFIX="C:/Custom/Install/Path"
cmake --build . --target installYou can include WinKernelLite directly in your CMake project without installing it.
Place the WinKernelLite source folder inside your project or reference it as a Git submodule:
git submodule add https://github.com/TorinKS/WinKernelLite.git external/WinKernelLite
git submodule update --init --recursiveYour project structure should look like:
your-project/
├── CMakeLists.txt
├── src/
│ └── main.cpp
└── external/
└── WinKernelLite/
└── CMakeLists.txt
In your top-level CMakeLists.txt, do the following:
cmake_minimum_required(VERSION 3.15)
project(YourProject)
# Your executable/library
add_executable(YourExecutable src/main.cpp)
# Add WinKernelLite subdirectory
add_subdirectory(external/WinKernelLite)
# Link the library
target_link_libraries(YourExecutable PRIVATE WinKernelLite::WinKernelLite)Note: WinKernelLite defines an exported target called WinKernelLite::WinKernelLite which you can link to in your project.
When using WinKernelLite as a submodule, you can include the headers like this:
#include <WinKernelLite/KernelHeap.h>
#include <WinKernelLite/LinkedList.h>
#include <WinKernelLite/UnicodeString.h>After configuring with CMake, check that the include directories and symbols from WinKernelLite are found and used properly by your target.
WinKernelLite includes an example that demonstrates how to use the library:
This example demonstrates linked list operations and device management:
cd examples\DevicesList
.\build_and_run.batBy default, the example is built but not installed to Program Files:
- The example is always built in the build directory:
build/bin/examples - You can choose whether to install it using the
INSTALL_EXAMPLESoption
cmake -B build -DINSTALL_EXAMPLES=OFF
cmake --build build --target installcmake -B build -DINSTALL_EXAMPLES=ON
cmake --build build --target installThe recommended way to use WinKernelLite is with CMake's package discovery:
cmake_minimum_required(VERSION 3.15)
project(YourProject)
# Find WinKernelLite package
find_package(WinKernelLite REQUIRED)
# Create your executable
add_executable(your_target main.cpp)
# Link with WinKernelLite
target_link_libraries(your_target PRIVATE WinKernelLite::WinKernelLite)This automatically handles include paths and library configuration.
If not using CMake, you can manually configure Visual Studio:
- Add the include directory:
- Project Properties -> C/C++ -> General -> Additional Include Directories
- Add
C:\Program Files\WinKernelLite\include
#include <WinKernelLite/KernelHeap.h>
#include <WinKernelLite/LinkedList.h>
#include <WinKernelLite/UnicodeString.h>#include <WinKernelLite/KernelHeap.h>
#include <stdio.h>
int main() {
// Initialize memory tracking
InitializeMemoryTracking();
// Allocate memory
PVOID buffer = ExAllocatePool(PagedPool, 1024);
if (!buffer) {
printf("Memory allocation failed\n");
return 1;
}
// Use the buffer...
// Free the memory
ExFreePool(buffer);
// Check for memory leaks
ReportMemoryLeaks();
return 0;
}#include <WinKernelLite/KernelHeap.h>
#include <WinKernelLite/LinkedList.h>
#include <stdio.h>
typedef struct _MY_ITEM {
LIST_ENTRY ListEntry;
int Data;
} MY_ITEM, *PMY_ITEM;
int main() {
InitializeMemoryTracking();
LIST_ENTRY listHead;
InitializeListHead(&listHead);
// Add items to list
for (int i = 0; i < 5; i++) {
PMY_ITEM item = ExAllocatePool(PagedPool, sizeof(MY_ITEM));
if (!item) continue;
item->Data = i;
InsertTailList(&listHead, &item->ListEntry);
}
// Display items
PLIST_ENTRY entry = listHead.Flink;
while (entry != &listHead) {
PMY_ITEM item = CONTAINING_RECORD(entry, MY_ITEM, ListEntry);
printf("Item: %d\n", item->Data);
entry = entry->Flink;
}
// Clean up
while (!IsListEmpty(&listHead)) {
PLIST_ENTRY entry = RemoveHeadList(&listHead);
PMY_ITEM item = CONTAINING_RECORD(entry, MY_ITEM, ListEntry);
ExFreePool(item);
}
ReportMemoryLeaks();
return 0;
}If CMake cannot find WinKernelLite, ensure you have:
- Built the library first:
cmake --build build - Set the correct CMake prefix path when building examples:
cmake .. -DCMAKE_PREFIX_PATH="../build"
For installed libraries, you may need to specify the path:
set(WinKernelLite_DIR "C:/Program Files/WinKernelLite/lib/cmake/WinKernelLite")
find_package(WinKernelLite REQUIRED)If header files cannot be found:
- Check that you're using the correct CMake approach with
find_package() - Verify that you're including files with the correct path:
#include <WinKernelLite/KernelHeap.h>
- If using manual setup, check that the include directory is correctly set
The example now uses the modern CMake approach. If the example fails to build:
- Ensure the main project is built first:
cmake --build build - Navigate to the example directory and run its build script
If you encounter problems not covered in this guide:
- Check the GitHub Issues page for similar problems
- Create a new issue with details about your problem
- Include your system information, CMake version, and compiler version