|
7 | 7 | #include "threadhidefromdbg.h"
|
8 | 8 |
|
9 | 9 | static UNICODE_STRING DeviceName;
|
| 10 | +static wchar_t DeviceNameBuffer[256]; |
10 | 11 | static UNICODE_STRING Win32Device;
|
| 12 | +static wchar_t Win32DeviceBuffer[256]; |
11 | 13 |
|
12 | 14 | static void DriverUnload(IN PDRIVER_OBJECT DriverObject)
|
13 | 15 | {
|
@@ -65,9 +67,44 @@ static NTSTATUS DriverWrite(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
|
65 | 67 | return RetStatus;
|
66 | 68 | }
|
67 | 69 |
|
68 |
| -extern "C" NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath) |
| 70 | +extern "C" NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath) |
69 | 71 | {
|
70 |
| - UNREFERENCED_PARAMETER(RegistryPath); |
| 72 | + // Initialize name buffers |
| 73 | + RtlInitEmptyUnicodeString(&DeviceName, DeviceNameBuffer, sizeof(DeviceNameBuffer)); |
| 74 | + RtlAppendUnicodeToString(&DeviceName, L"\\Device\\"); |
| 75 | + RtlInitEmptyUnicodeString(&Win32Device, Win32DeviceBuffer, sizeof(Win32DeviceBuffer)); |
| 76 | + RtlAppendUnicodeToString(&Win32Device, L"\\DosDevices\\"); |
| 77 | + |
| 78 | + // Derive the device name and symbolic link from the registry path |
| 79 | + UNICODE_STRING DriverName = {}; |
| 80 | + if (RegistryPath != NULL && RegistryPath->Buffer != NULL) |
| 81 | + { |
| 82 | + for (int i = 0; i < RegistryPath->Length / sizeof(WCHAR); i++) |
| 83 | + { |
| 84 | + auto index = RegistryPath->Length / sizeof(WCHAR) - i - 1; |
| 85 | + if (RegistryPath->Buffer[index] == L'\\') |
| 86 | + { |
| 87 | + index++; // skip the backslash |
| 88 | + DriverName.Buffer = RegistryPath->Buffer + index; |
| 89 | + DriverName.Length = (USHORT)(RegistryPath->Length - index * sizeof(WCHAR)); |
| 90 | + DriverName.MaximumLength = DriverName.Length; |
| 91 | + break; |
| 92 | + } |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + // Fall back to default driver name |
| 97 | + if (DriverName.Length == 0) |
| 98 | + { |
| 99 | + RtlInitUnicodeString(&DriverName, L"TitanHide"); |
| 100 | + } |
| 101 | + |
| 102 | + // Use the driver name |
| 103 | + RtlAppendUnicodeStringToString(&DeviceName, &DriverName); |
| 104 | + RtlAppendUnicodeStringToString(&Win32Device, &DriverName); |
| 105 | + InitLog(&DriverName); |
| 106 | + Log("[TITANHIDE] DriverName: %.*ws\r\n", DriverName.Length / sizeof(WCHAR), DriverName.Buffer); |
| 107 | + |
71 | 108 | PDEVICE_OBJECT DeviceObject = NULL;
|
72 | 109 | NTSTATUS status;
|
73 | 110 |
|
@@ -103,8 +140,6 @@ extern "C" NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRI
|
103 | 140 | }
|
104 | 141 |
|
105 | 142 | //create io device
|
106 |
| - RtlInitUnicodeString(&DeviceName, L"\\Device\\TitanHide"); |
107 |
| - RtlInitUnicodeString(&Win32Device, L"\\DosDevices\\TitanHide"); |
108 | 143 | status = IoCreateDevice(DriverObject,
|
109 | 144 | 0,
|
110 | 145 | &DeviceName,
|
|
0 commit comments