Skip to content

Commit 0f12a81

Browse files
committed
bit of code improvement and defines for archs
1 parent 778115f commit 0f12a81

3 files changed

Lines changed: 10 additions & 13 deletions

File tree

NoMoreBugCheck/NoMoreBugCheck.vcxproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@
161161
</ItemGroup>
162162
<ItemGroup>
163163
<None Include=".clang-format" />
164-
<None Include="README.md" />
165164
</ItemGroup>
166165
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
167166
<ImportGroup Label="ExtensionTargets">

NoMoreBugCheck/NoMoreBugCheck.vcxproj.filters

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,5 @@
2525
</ItemGroup>
2626
<ItemGroup>
2727
<None Include=".clang-format" />
28-
<None Include="README.md" />
2928
</ItemGroup>
3029
</Project>

NoMoreBugCheck/driver.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <ntddk.h>
22

33
CHAR KeBugCheckExOrignalBytes[14] = {0};
4-
PVOID KeBugCheckExAddress;
4+
ULONG_PTR KeBugCheckExAddress;
55

66
NTSTATUS 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

Comments
 (0)