From d5a60d0650c459d7e072ae7fd4a8dbdbe203fdf1 Mon Sep 17 00:00:00 2001 From: oxygen <304914289@qq.com> Date: Mon, 12 Aug 2024 17:12:08 +0800 Subject: [PATCH 1/2] Fix the BUG that functions in intrin.h cannot be used even if it is introduced --- cmake/FindWdk.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/FindWdk.cmake b/cmake/FindWdk.cmake index 6987305..7f634f4 100644 --- a/cmake/FindWdk.cmake +++ b/cmake/FindWdk.cmake @@ -96,6 +96,7 @@ set(WDK_COMPILE_FLAGS "/kernel" # create kernel mode binary "/FIwarning.h" # disable warnings in WDK headers "/FI${WDK_ADDITIONAL_FLAGS_FILE}" # include file to disable RTC + "/Oi" # enable intrinsic functions so that you can use functions like _disable or _enable ) set(WDK_COMPILE_DEFINITIONS "WINNT=1") From 0c10d54a84eb33e226c9077740d5aa0306062e89 Mon Sep 17 00:00:00 2001 From: oxygen <304914289@qq.com> Date: Tue, 13 Aug 2024 09:50:52 +0800 Subject: [PATCH 2/2] add demonstrate --- samples/CMakeLists.txt | 3 ++- samples/WdmIntrinsicFunctions/CMakeLists.txt | 4 ++++ samples/WdmIntrinsicFunctions/Main.cpp | 25 ++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 samples/WdmIntrinsicFunctions/CMakeLists.txt create mode 100644 samples/WdmIntrinsicFunctions/Main.cpp diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 59d3978..18bd37a 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -16,4 +16,5 @@ add_subdirectory(MinifilterCppDriver) add_subdirectory(WdmCppDriver) add_subdirectory(WdmCppLib) add_subdirectory(WdmDriver) -add_subdirectory(WdmLib) \ No newline at end of file +add_subdirectory(WdmLib) +add_subdirectory(WdmIntrinsicFunctions) \ No newline at end of file diff --git a/samples/WdmIntrinsicFunctions/CMakeLists.txt b/samples/WdmIntrinsicFunctions/CMakeLists.txt new file mode 100644 index 0000000..efb9854 --- /dev/null +++ b/samples/WdmIntrinsicFunctions/CMakeLists.txt @@ -0,0 +1,4 @@ +wdk_add_driver(WdmIntrinsicFunctions + Main.cpp + ) +target_link_libraries(WdmIntrinsicFunctions WdmCppLib) \ No newline at end of file diff --git a/samples/WdmIntrinsicFunctions/Main.cpp b/samples/WdmIntrinsicFunctions/Main.cpp new file mode 100644 index 0000000..eddc05c --- /dev/null +++ b/samples/WdmIntrinsicFunctions/Main.cpp @@ -0,0 +1,25 @@ +#include +#include + +DRIVER_UNLOAD driverUnload; +VOID driverUnload(_In_ PDRIVER_OBJECT driverObject) +{ + UNREFERENCED_PARAMETER(driverObject); + + DbgPrint("Driver unloaded\n"); +} + +EXTERN_C NTSTATUS DriverEntry(_In_ PDRIVER_OBJECT driverObject, _In_ PUNICODE_STRING registryPath) +{ + UNREFERENCED_PARAMETER(registryPath); + + DbgPrint("Driver loaded\n"); + + _disable(); //use intrinsic function + ULONG64 cr3 = __readcr3(); //use intrinsic function + _enable(); //use intrinsic function + + DbgPrint("CR3: %p\n", cr3); + driverObject->DriverUnload = driverUnload; + return STATUS_SUCCESS; +} \ No newline at end of file