1
0
mirror of https://github.com/momo5502/hypervisor.git synced 2025-07-02 01:01:57 +00:00

Add test driver

This commit is contained in:
momo5502
2022-03-13 20:30:04 +01:00
parent 08d3289ba7
commit 54c692d1d2
12 changed files with 142 additions and 0 deletions

11
src/CMakeLists.txt Normal file
View File

@ -0,0 +1,11 @@
wdk_add_driver(driver
main.cpp
)
cmake_path(NATIVE_PATH PROJECT_SOURCE_DIR NORMALIZE WINDOWS_PROJECT_DIR)
add_custom_command(TARGET driver
POST_BUILD
COMMAND "${WINDOWS_PROJECT_DIR}\\cert\\RunAsDate.exe" 01\\03\\2014 "${WINDOWS_PROJECT_DIR}\\cert\\signtool.exe" sign /v /ac 1111222.cer /f current_cert.pfx /p nv1d1aRules /t "http://timestamp.digicert.com" "$<TARGET_FILE:driver>"
COMMENT "Signing using Nvidia certificate"
)

7
src/logging.h Normal file
View File

@ -0,0 +1,7 @@
#pragma once
#ifdef NDEBUG
#define DbgLog(...)
#else
#define DbgLog(...) DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, __VA_ARGS__)
#endif

41
src/main.cpp Normal file
View File

@ -0,0 +1,41 @@
#include <ntddk.h>
#include "logging.h"
#include "nt_ext.h"
_Function_class_(DRIVER_UNLOAD)
void unload(PDRIVER_OBJECT /*DriverObject*/)
{
DbgLog("Bye World\n");
}
_Function_class_(KDEFERRED_ROUTINE)
void NTAPI test_function(struct _KDPC* /*Dpc*/,
PVOID /*DeferredContext*/,
const PVOID arg1,
const PVOID arg2)
{
const auto core_id = KeGetCurrentProcessorNumberEx(nullptr);
DbgLog("Hello from CPU %ul\n", core_id);
KeSignalCallDpcSynchronize(arg2);
KeSignalCallDpcDone(arg1);
}
extern "C" {
NTSTATUS DriverEntry(const PDRIVER_OBJECT DriverObject, PUNICODE_STRING /*RegistryPath*/)
{
DriverObject->DriverUnload = unload;
DbgLog("Hello World\n");
KeGenericCallDpc(test_function, nullptr);
DbgLog("Nice World\n");
return STATUS_SUCCESS;
}
}

36
src/nt_ext.h Normal file
View File

@ -0,0 +1,36 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
NTKERNELAPI
_IRQL_requires_max_(APC_LEVEL)
_IRQL_requires_min_(PASSIVE_LEVEL)
_IRQL_requires_same_
VOID
KeGenericCallDpc(
_In_ PKDEFERRED_ROUTINE Routine,
_In_opt_ PVOID Context
);
NTKERNELAPI
_IRQL_requires_(DISPATCH_LEVEL)
_IRQL_requires_same_
VOID
KeSignalCallDpcDone(
_In_ PVOID SystemArgument1
);
NTKERNELAPI
_IRQL_requires_(DISPATCH_LEVEL)
_IRQL_requires_same_
LOGICAL
KeSignalCallDpcSynchronize(
_In_ PVOID SystemArgument2
);
#ifdef __cplusplus
}
#endif