11#include <ntddk.h>
22
33CHAR KeBugCheckExOrignalBytes [14 ] = {0 };
4- PVOID KeBugCheckExAddress ;
4+ ULONG_PTR KeBugCheckExAddress ;
55
66NTSTATUS Overwrite (PVOID Address , PVOID Data , ULONG Size ) {
77 PHYSICAL_ADDRESS PhysAddress = MmGetPhysicalAddress (Address );
@@ -47,10 +47,7 @@ NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject,
4747
4848 DriverObject -> DriverUnload = DriverUnload ;
4949
50- UNICODE_STRING FunctionName ;
51- RtlInitUnicodeString (& FunctionName , L"KeBugCheckEx" );
52- KeBugCheckExAddress = MmGetSystemRoutineAddress (& FunctionName );
53-
50+ KeBugCheckExAddress = (ULONG_PTR )KeBugCheckEx ;
5451
5552 DbgPrint ("[*] Hello World\n" );
5653 DbgPrint ("[*] KeBugCheckEx located at 0x%llx\n" , KeBugCheckExAddress );
@@ -68,17 +65,16 @@ NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject,
6865 DbgPrint ("[*] KeBugCheckExOrignalBytes[%d]: 0x%x\n" , i ,
6966 KeBugCheckExOrignalBytes [i ] & 0xff );
7067
68+ #if defined(_M_X64 )
7169 CHAR Patch [] = {
7270 0x49 , 0xba , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , // mov r10, address
7371 0x41 , 0xff , 0xe2 // jmp r10
7472 };
7573
76- ULONG_PTR KeHookedBugCheckEx_Address = (ULONG_PTR )KeHookedBugCheckEx ;
77- CHAR * KeHookedBugCheckEx_Address_Bytes = (CHAR * )& KeHookedBugCheckEx_Address ;
74+ ULONG_PTR KeHookedBugCheckExAddress = (ULONG_PTR )KeHookedBugCheckEx ;
75+ CHAR * KeHookedBugCheckExAddressBytes = (CHAR * )& KeHookedBugCheckExAddress ;
7876
79- for (INT i = 0 ; i < sizeof (ULONG_PTR ); i ++ ) {
80- Patch [2 + i ] = KeHookedBugCheckEx_Address_Bytes [i ];
81- }
77+ RtlCopyMemory (& Patch [2 ], KeHookedBugCheckExAddressBytes , sizeof (ULONG_PTR ));
8278
8379 NTSTATUS Status = Overwrite (KeBugCheckExAddress , (PVOID )Patch , sizeof (Patch ));
8480
@@ -88,7 +84,10 @@ NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject,
8884 }
8985
9086 DbgPrint ("[+] Successfully overwrote KeBugCheckEx\n" );
91-
87+ #else
88+ DbgPrint ("[!] Unknown architecture" );
89+ return STATUS_FAILED_DRIVER_ENTRY ;
90+ #endif
9291
9392 CHAR Temp [14 ] = {0 };
9493 RtlCopyMemory (Temp , KeBugCheckExAddress , 14 );
0 commit comments