mirror-ac/driver/driver.c

1125 lines
34 KiB
C
Raw Normal View History

2023-08-17 10:45:50 +02:00
#include "driver.h"
#include "common.h"
#include "ioctl.h"
2023-08-20 16:12:04 +02:00
#include "callbacks.h"
2023-08-21 14:40:40 +02:00
#include "hv.h"
2023-08-28 11:17:38 +02:00
#include "pool.h"
2023-08-29 19:36:58 +02:00
#include "thread.h"
2023-08-31 12:33:26 +02:00
#include "modules.h"
2023-08-22 19:32:25 +02:00
#include "integrity.h"
#include "imports.h"
2024-01-13 22:33:57 +01:00
#include "apc.h"
2023-08-22 19:32:25 +02:00
2023-12-13 05:06:27 +01:00
STATIC
VOID
DriverUnload(_In_ PDRIVER_OBJECT DriverObject);
_Function_class_(DRIVER_INITIALIZE) _IRQL_requires_same_
NTSTATUS
DriverEntry(_In_ PDRIVER_OBJECT DriverObject, _In_ PUNICODE_STRING RegistryPath);
STATIC
NTSTATUS
RegistryPathQueryCallbackRoutine(IN PWSTR ValueName,
IN ULONG ValueType,
IN PVOID ValueData,
IN ULONG ValueLength,
IN PVOID Context,
IN PVOID EntryContext);
2023-10-06 13:08:30 +02:00
2023-10-09 18:27:04 +02:00
STATIC
VOID
DrvUnloadUnregisterObCallbacks();
STATIC
VOID
DrvUnloadFreeConfigStrings();
STATIC
VOID
DrvUnloadFreeSymbolicLink();
STATIC
VOID
DrvUnloadFreeGlobalReportQueue();
STATIC
VOID
DrvUnloadFreeThreadList();
2023-10-10 19:49:17 +02:00
STATIC
VOID
DrvUnloadFreeProcessList();
2023-10-09 18:27:04 +02:00
STATIC
NTSTATUS
DrvLoadEnableNotifyRoutines();
STATIC
NTSTATUS
DrvLoadInitialiseObCbConfig();
STATIC
VOID
DrvLoadInitialiseProcessConfig();
STATIC
NTSTATUS
2023-12-23 19:52:55 +01:00
DrvLoadInitialiseDriverConfig(_In_ PDRIVER_OBJECT DriverObject, _In_ PUNICODE_STRING RegistryPath);
2023-10-09 18:27:04 +02:00
2023-10-06 13:08:30 +02:00
#ifdef ALLOC_PRAGMA
2023-12-13 05:06:27 +01:00
# pragma alloc_text(INIT, DriverEntry)
# pragma alloc_text(PAGE, GetProtectedProcessEProcess)
# pragma alloc_text(PAGE, GetProtectedProcessId)
# pragma alloc_text(PAGE, GetDriverName)
# pragma alloc_text(PAGE, GetDriverPath)
# pragma alloc_text(PAGE, GetDriverRegistryPath)
# pragma alloc_text(PAGE, GetDriverDeviceName)
# pragma alloc_text(PAGE, GetDriverSymbolicLink)
# pragma alloc_text(PAGE, GetDriverConfigSystemInformation)
# pragma alloc_text(PAGE, RegistryPathQueryCallbackRoutine)
# pragma alloc_text(PAGE, TerminateProtectedProcessOnViolation)
# pragma alloc_text(PAGE, ProcCloseDisableObCallbacks)
# pragma alloc_text(PAGE, ProcCloseClearProcessConfiguration)
# pragma alloc_text(PAGE, ProcLoadEnableObCallbacks)
# pragma alloc_text(PAGE, ProcLoadInitialiseProcessConfig)
# pragma alloc_text(PAGE, DrvUnloadUnregisterObCallbacks)
# pragma alloc_text(PAGE, DrvUnloadFreeConfigStrings)
# pragma alloc_text(PAGE, DrvUnloadFreeSymbolicLink)
# pragma alloc_text(PAGE, DrvUnloadFreeGlobalReportQueue)
# pragma alloc_text(PAGE, DrvUnloadFreeThreadList)
# pragma alloc_text(PAGE, DrvLoadEnableNotifyRoutines)
# pragma alloc_text(PAGE, DrvLoadEnableNotifyRoutines)
# pragma alloc_text(PAGE, DrvLoadInitialiseObCbConfig)
2024-01-13 22:33:57 +01:00
// # pragma alloc_text(PAGE, DrvLoadInitialiseReportQueue)
2023-12-13 05:06:27 +01:00
# pragma alloc_text(PAGE, DrvLoadInitialiseProcessConfig)
# pragma alloc_text(PAGE, DrvLoadInitialiseDriverConfig)
# pragma alloc_text(PAGE, ReadProcessInitialisedConfigFlag)
2023-10-06 13:08:30 +02:00
#endif
2024-01-13 22:33:57 +01:00
/*
* This structure can change at anytime based on whether
* the target process to protect is open / closed / changes etc.
*/
typedef struct _PROCESS_CONFIG
{
BOOLEAN initialised;
ULONG um_handle;
PVOID km_handle;
PEPROCESS process;
OB_CALLBACKS_CONFIG callback_info;
UINT16 cookie;
KGUARDED_MUTEX lock;
} PROCESS_CONFIG, *PPROCESS_CONFIG;
2023-09-27 15:10:12 +02:00
typedef struct _DRIVER_CONFIG
{
2023-12-31 15:06:24 +01:00
UNICODE_STRING unicode_driver_name;
ANSI_STRING ansi_driver_name;
UNICODE_STRING device_name;
UNICODE_STRING device_symbolic_link;
UNICODE_STRING driver_path;
UNICODE_STRING registry_path;
SYSTEM_INFORMATION system_information;
PVOID apc_contexts[MAXIMUM_APC_CONTEXTS];
PDRIVER_OBJECT driver_object;
PDEVICE_OBJECT device_object;
volatile BOOLEAN unload_in_progress;
KGUARDED_MUTEX lock;
SYS_MODULE_VAL_CONTEXT sys_val_context;
2024-01-11 10:16:55 +01:00
IRP_QUEUE_HEAD irp_queue;
2024-01-12 06:40:33 +01:00
TIMER_OBJECT timer;
2024-01-13 22:33:57 +01:00
PROCESS_CONFIG process_config;
THREAD_LIST_HEAD thread_list;
DRIVER_LIST_HEAD driver_list;
PROCESS_LIST_HEAD process_list;
REPORT_QUEUE_HEAD report_queue;
2023-12-13 05:06:27 +01:00
} DRIVER_CONFIG, *PDRIVER_CONFIG;
2023-09-27 15:10:12 +02:00
/*
2024-01-13 22:33:57 +01:00
* Rather then getting the driver state from the device object passed to our IOCTL handlers, store a
* pointer to the device extension here and abstract it with getters which can be accessed globally.
* The reason for this is because there isnt a way for us to pass a context structure to some of
* notify routines so I think it's better to do it this way.
*
* Note that the device extension pointer should be encrypted
2023-12-13 05:06:27 +01:00
*/
2024-01-13 22:33:57 +01:00
PDRIVER_CONFIG g_DriverConfig = NULL;
2023-11-18 11:40:22 +01:00
2023-10-06 10:30:14 +02:00
#define POOL_TAG_CONFIG 'conf'
2023-10-09 18:27:04 +02:00
VOID
2024-01-13 22:33:57 +01:00
AcquireDriverConfigLock()
2023-10-08 16:07:49 +02:00
{
2024-01-13 22:33:57 +01:00
ImpKeAcquireGuardedMutex(&g_DriverConfig->lock);
2023-09-25 17:41:38 +02:00
}
2023-09-26 15:32:06 +02:00
VOID
2024-01-13 22:33:57 +01:00
ReleaseDriverConfigLock()
2023-09-26 15:32:06 +02:00
{
2024-01-13 22:33:57 +01:00
ImpKeReleaseGuardedMutex(&g_DriverConfig->lock);
2023-09-26 15:32:06 +02:00
}
2024-01-13 22:33:57 +01:00
PUINT64
GetApcContextArray()
2023-09-26 15:32:06 +02:00
{
2024-01-13 22:33:57 +01:00
return (PUINT64)g_DriverConfig->apc_contexts;
2023-09-27 06:22:14 +02:00
}
2024-01-13 22:33:57 +01:00
BOOLEAN
IsDriverUnloading()
2023-09-27 06:22:14 +02:00
{
2024-01-13 22:33:57 +01:00
return InterlockedExchange(&g_DriverConfig->unload_in_progress,
g_DriverConfig->unload_in_progress);
2023-09-27 06:22:14 +02:00
}
2023-09-26 15:32:06 +02:00
2024-01-08 04:57:07 +01:00
VOID
2024-01-13 22:33:57 +01:00
GetCallbackConfigStructure(_Out_ POB_CALLBACKS_CONFIG* CallbackConfiguration)
2023-09-25 17:41:38 +02:00
{
2024-01-13 22:33:57 +01:00
ImpKeAcquireGuardedMutex(&g_DriverConfig->process_config.lock);
*CallbackConfiguration = &g_DriverConfig->process_config.callback_info;
ImpKeReleaseGuardedMutex(&g_DriverConfig->process_config.lock);
2023-09-25 17:41:38 +02:00
}
2024-01-13 22:33:57 +01:00
LPCSTR
GetDriverName()
2023-09-25 17:41:38 +02:00
{
2024-01-13 22:33:57 +01:00
PAGED_CODE();
return g_DriverConfig->ansi_driver_name.Buffer;
2024-01-08 04:57:07 +01:00
}
2024-01-13 22:33:57 +01:00
PDEVICE_OBJECT
GetDriverDeviceObject()
2024-01-08 04:57:07 +01:00
{
2024-01-13 22:33:57 +01:00
PAGED_CODE();
return g_DriverConfig->device_object;
2023-09-26 12:00:45 +02:00
}
2024-01-13 22:33:57 +01:00
PDRIVER_OBJECT
GetDriverObject()
2023-09-26 12:00:45 +02:00
{
2024-01-13 22:33:57 +01:00
PAGED_CODE();
return g_DriverConfig->driver_object;
2023-09-25 17:41:38 +02:00
}
2024-01-13 22:33:57 +01:00
PIRP_QUEUE_HEAD
GetIrpQueueHead()
2023-08-24 17:10:40 +02:00
{
2024-01-13 22:33:57 +01:00
return &g_DriverConfig->irp_queue;
2023-09-01 14:30:32 +02:00
}
2024-01-13 22:33:57 +01:00
PSYS_MODULE_VAL_CONTEXT
GetSystemModuleValidationContext()
2023-08-20 16:12:04 +02:00
{
2023-12-13 05:06:27 +01:00
PAGED_CODE();
2024-01-13 22:33:57 +01:00
return &g_DriverConfig->sys_val_context;
2023-08-20 16:12:04 +02:00
}
2024-01-13 22:33:57 +01:00
PUNICODE_STRING
GetDriverPath()
2023-12-31 15:06:24 +01:00
{
2024-01-08 04:57:07 +01:00
PAGED_CODE();
2024-01-13 22:33:57 +01:00
return &g_DriverConfig->driver_path;
2023-12-31 15:06:24 +01:00
}
2024-01-13 22:33:57 +01:00
PUNICODE_STRING
GetDriverRegistryPath()
{
2024-01-08 04:57:07 +01:00
PAGED_CODE();
2024-01-13 22:33:57 +01:00
return &g_DriverConfig->registry_path;
}
2024-01-13 22:33:57 +01:00
PUNICODE_STRING
GetDriverDeviceName()
2024-01-11 10:16:55 +01:00
{
2024-01-13 22:33:57 +01:00
PAGED_CODE();
return &g_DriverConfig->device_name;
2024-01-11 10:16:55 +01:00
}
2024-01-13 22:33:57 +01:00
PUNICODE_STRING
GetDriverSymbolicLink()
2024-01-01 17:45:40 +01:00
{
2024-01-08 04:57:07 +01:00
PAGED_CODE();
2024-01-13 22:33:57 +01:00
return &g_DriverConfig->device_symbolic_link;
2024-01-01 17:45:40 +01:00
}
2024-01-13 22:33:57 +01:00
PSYSTEM_INFORMATION
GetDriverConfigSystemInformation()
2023-08-20 16:12:04 +02:00
{
2023-12-13 05:06:27 +01:00
PAGED_CODE();
2024-01-13 22:33:57 +01:00
return &g_DriverConfig->system_information;
2023-08-20 16:12:04 +02:00
}
2024-01-13 22:33:57 +01:00
PREPORT_QUEUE_HEAD
GetDriverReportQueue()
2023-08-20 16:12:04 +02:00
{
2023-12-13 05:06:27 +01:00
PAGED_CODE();
2024-01-13 22:33:57 +01:00
return &g_DriverConfig->report_queue;
2023-08-20 16:12:04 +02:00
}
2024-01-13 22:33:57 +01:00
PTHREAD_LIST_HEAD
GetThreadList()
2023-09-01 14:30:32 +02:00
{
2023-12-13 05:06:27 +01:00
PAGED_CODE();
2024-01-13 22:33:57 +01:00
return &g_DriverConfig->thread_list;
2023-09-01 14:30:32 +02:00
}
2024-01-13 22:33:57 +01:00
PDRIVER_LIST_HEAD
GetDriverList()
2023-09-01 14:30:32 +02:00
{
2023-12-13 05:06:27 +01:00
PAGED_CODE();
2024-01-13 22:33:57 +01:00
return &g_DriverConfig->driver_list;
2023-09-01 14:30:32 +02:00
}
2024-01-13 22:33:57 +01:00
PPROCESS_LIST_HEAD
GetProcessList()
2023-09-07 19:49:36 +02:00
{
2023-12-13 05:06:27 +01:00
PAGED_CODE();
2024-01-13 22:33:57 +01:00
return &g_DriverConfig->process_list;
2023-09-07 19:49:36 +02:00
}
2023-10-09 18:27:04 +02:00
VOID
2023-12-13 05:06:27 +01:00
ReadProcessInitialisedConfigFlag(_Out_ PBOOLEAN Flag)
2023-09-01 18:45:06 +02:00
{
2023-12-13 05:06:27 +01:00
PAGED_CODE();
2024-01-13 22:33:57 +01:00
ImpKeAcquireGuardedMutex(&g_DriverConfig->process_config.lock);
*Flag = g_DriverConfig->process_config.initialised;
ImpKeReleaseGuardedMutex(&g_DriverConfig->process_config.lock);
2023-10-09 18:27:04 +02:00
}
2023-09-01 18:45:06 +02:00
2023-10-09 18:27:04 +02:00
VOID
2023-12-13 05:06:27 +01:00
GetProtectedProcessEProcess(_Out_ PEPROCESS* Process)
2023-10-09 18:27:04 +02:00
{
2023-12-13 05:06:27 +01:00
PAGED_CODE();
2024-01-13 22:33:57 +01:00
ImpKeAcquireGuardedMutex(&g_DriverConfig->process_config.lock);
*Process = g_DriverConfig->process_config.process;
ImpKeReleaseGuardedMutex(&g_DriverConfig->process_config.lock);
2023-10-09 18:27:04 +02:00
}
VOID
2023-12-13 05:06:27 +01:00
GetProtectedProcessId(_Out_ PLONG ProcessId)
2023-10-09 18:27:04 +02:00
{
2023-12-13 05:06:27 +01:00
PAGED_CODE();
2024-01-13 22:33:57 +01:00
ImpKeAcquireGuardedMutex(&g_DriverConfig->process_config.lock);
*ProcessId = g_DriverConfig->process_config.km_handle;
ImpKeReleaseGuardedMutex(&g_DriverConfig->process_config.lock);
2023-10-09 18:27:04 +02:00
}
VOID
ProcCloseDisableObCallbacks()
{
2023-12-13 05:06:27 +01:00
PAGED_CODE();
2024-01-13 22:33:57 +01:00
ImpKeAcquireGuardedMutex(&g_DriverConfig->process_config.callback_info.lock);
2023-10-09 18:27:04 +02:00
2024-01-13 22:33:57 +01:00
if (g_DriverConfig->process_config.callback_info.registration_handle)
2023-12-13 05:06:27 +01:00
{
2024-01-13 22:33:57 +01:00
ImpObUnRegisterCallbacks(
g_DriverConfig->process_config.callback_info.registration_handle);
g_DriverConfig->process_config.callback_info.registration_handle = NULL;
2023-12-13 05:06:27 +01:00
}
2024-01-13 22:33:57 +01:00
ImpKeReleaseGuardedMutex(&g_DriverConfig->process_config.callback_info.lock);
2023-10-09 18:27:04 +02:00
}
2023-10-09 18:27:04 +02:00
VOID
ProcCloseClearProcessConfiguration()
{
2023-12-13 05:06:27 +01:00
PAGED_CODE();
2023-12-23 19:52:55 +01:00
DEBUG_INFO("Protected process closed. Clearing process configuration.");
2024-01-13 22:33:57 +01:00
ImpKeAcquireGuardedMutex(&g_DriverConfig->process_config.lock);
g_DriverConfig->process_config.km_handle = NULL;
g_DriverConfig->process_config.um_handle = NULL;
g_DriverConfig->process_config.process = NULL;
g_DriverConfig->process_config.initialised = FALSE;
ImpKeReleaseGuardedMutex(&g_DriverConfig->process_config.lock);
2023-10-09 18:27:04 +02:00
}
2024-01-13 22:33:57 +01:00
// VOID
// ImageLoadSetProcessId(_In_ HANDLE ProcessId)
//{
// ImpKeAcquireGuardedMutex(&process_config.lock);
// process_config.km_handle = (ULONG)ProcessId;
// ImpKeReleaseGuardedMutex(&process_config.lock);
// }
2023-10-09 18:27:04 +02:00
NTSTATUS
ProcLoadEnableObCallbacks()
{
2023-12-13 05:06:27 +01:00
PAGED_CODE();
2023-10-10 15:52:42 +02:00
2023-12-23 19:52:55 +01:00
NTSTATUS status = STATUS_UNSUCCESSFUL;
DEBUG_VERBOSE("Enabling ObRegisterCallbacks.");
2024-01-13 22:33:57 +01:00
ImpKeAcquireGuardedMutex(&g_DriverConfig->process_config.lock);
2023-10-09 18:27:04 +02:00
2023-12-13 05:06:27 +01:00
OB_CALLBACK_REGISTRATION callback_registration = {0};
OB_OPERATION_REGISTRATION operation_registration = {0};
PCREATE_PROCESS_NOTIFY_ROUTINE_EX notify_routine = {0};
2023-10-09 18:27:04 +02:00
2023-12-13 05:06:27 +01:00
operation_registration.ObjectType = PsProcessType;
2024-01-08 04:57:07 +01:00
operation_registration.Operations |= OB_OPERATION_HANDLE_CREATE;
operation_registration.Operations |= OB_OPERATION_HANDLE_DUPLICATE;
2023-12-13 05:06:27 +01:00
operation_registration.PreOperation = ObPreOpCallbackRoutine;
operation_registration.PostOperation = ObPostOpCallbackRoutine;
2023-10-09 18:27:04 +02:00
2023-12-13 05:06:27 +01:00
callback_registration.Version = OB_FLT_REGISTRATION_VERSION;
callback_registration.OperationRegistration = &operation_registration;
callback_registration.OperationRegistrationCount = 1;
callback_registration.RegistrationContext = NULL;
2023-10-09 18:27:04 +02:00
2024-01-13 22:33:57 +01:00
status = ImpObRegisterCallbacks(
&callback_registration,
&g_DriverConfig->process_config.callback_info.registration_handle);
2023-10-09 18:27:04 +02:00
2023-12-13 05:06:27 +01:00
if (!NT_SUCCESS(status))
2023-12-23 19:52:55 +01:00
DEBUG_ERROR("ObRegisterCallbacks failed with status %x", status);
2023-10-09 18:27:04 +02:00
2024-01-13 22:33:57 +01:00
ImpKeReleaseGuardedMutex(&g_DriverConfig->process_config.lock);
2023-12-13 05:06:27 +01:00
return status;
2023-10-09 18:27:04 +02:00
}
NTSTATUS
2023-12-13 05:06:27 +01:00
ProcLoadInitialiseProcessConfig(_In_ PIRP Irp)
2023-10-09 18:27:04 +02:00
{
2023-12-13 05:06:27 +01:00
PAGED_CODE();
2023-10-10 15:52:42 +02:00
2023-12-23 19:52:55 +01:00
NTSTATUS status = STATUS_UNSUCCESSFUL;
2023-12-13 05:06:27 +01:00
PEPROCESS process = NULL;
PDRIVER_INITIATION_INFORMATION information = NULL;
2023-10-09 18:27:04 +02:00
2023-12-13 05:06:27 +01:00
status = ValidateIrpInputBuffer(Irp, sizeof(DRIVER_INITIATION_INFORMATION));
2023-11-09 08:30:59 +01:00
2023-12-13 05:06:27 +01:00
if (!NT_SUCCESS(status))
{
2023-12-23 19:52:55 +01:00
DEBUG_ERROR("ValidateIrpInputBuffer failed with status %x", status);
2023-12-13 05:06:27 +01:00
return status;
}
2023-11-09 08:30:59 +01:00
2023-12-13 05:06:27 +01:00
information = (PDRIVER_INITIATION_INFORMATION)Irp->AssociatedIrp.SystemBuffer;
2023-10-09 18:27:04 +02:00
2024-01-13 22:33:57 +01:00
ImpKeAcquireGuardedMutex(&g_DriverConfig->process_config.lock);
2023-11-18 11:40:22 +01:00
2024-01-13 22:33:57 +01:00
g_DriverConfig->process_config.um_handle = information->protected_process_id;
2023-11-18 11:40:22 +01:00
2024-01-08 04:57:07 +01:00
/* What if we pass an invalid handle here? not good. */
2024-01-13 22:33:57 +01:00
status = ImpPsLookupProcessByProcessId(g_DriverConfig->process_config.um_handle, &process);
2023-10-09 18:27:04 +02:00
2023-12-13 05:06:27 +01:00
if (!NT_SUCCESS(status))
{
status = STATUS_INVALID_PARAMETER;
goto end;
}
2023-10-09 18:27:04 +02:00
2024-01-13 22:33:57 +01:00
g_DriverConfig->process_config.km_handle = ImpPsGetProcessId(process);
g_DriverConfig->process_config.process = process;
g_DriverConfig->process_config.initialised = TRUE;
2023-10-09 18:27:04 +02:00
2023-11-18 11:40:22 +01:00
end:
2024-01-13 22:33:57 +01:00
ImpKeReleaseGuardedMutex(&g_DriverConfig->process_config.lock);
2023-12-13 05:06:27 +01:00
return status;
2023-10-09 18:27:04 +02:00
}
/*
2023-12-13 05:06:27 +01:00
* The question is, What happens if we attempt to register our callbacks after we
* unregister them but before we free the pool? Hm.. No Good.
*
* Okay to solve this well acquire the driver lock aswell, we could also just
* store the structure in the .data section but i ceebs atm.
*
* This definitely doesn't seem optimal, but it works ...
*/
2023-10-09 18:27:04 +02:00
STATIC
VOID
DrvUnloadUnregisterObCallbacks()
{
2023-12-13 05:06:27 +01:00
PAGED_CODE();
ProcCloseDisableObCallbacks();
2023-10-09 18:27:04 +02:00
}
2023-09-26 12:00:45 +02:00
STATIC
2023-10-05 08:27:17 +02:00
VOID
2023-10-09 18:27:04 +02:00
DrvUnloadFreeConfigStrings()
2023-09-01 18:45:06 +02:00
{
2023-12-13 05:06:27 +01:00
PAGED_CODE();
2023-10-10 15:52:42 +02:00
2024-01-13 22:33:57 +01:00
if (g_DriverConfig->unicode_driver_name.Buffer)
ImpExFreePoolWithTag(g_DriverConfig->unicode_driver_name.Buffer, POOL_TAG_STRINGS);
2023-09-01 18:45:06 +02:00
2024-01-13 22:33:57 +01:00
if (g_DriverConfig->driver_path.Buffer)
ImpExFreePoolWithTag(g_DriverConfig->driver_path.Buffer, POOL_TAG_STRINGS);
2023-09-01 18:45:06 +02:00
2024-01-13 22:33:57 +01:00
if (g_DriverConfig->ansi_driver_name.Buffer)
ImpRtlFreeAnsiString(&g_DriverConfig->ansi_driver_name);
2023-09-01 18:45:06 +02:00
}
2023-10-09 18:27:04 +02:00
STATIC
VOID
DrvUnloadFreeSymbolicLink()
{
2023-12-13 05:06:27 +01:00
PAGED_CODE();
2024-01-13 22:33:57 +01:00
ImpIoDeleteSymbolicLink(&g_DriverConfig->device_symbolic_link);
2023-10-09 18:27:04 +02:00
}
STATIC
VOID
DrvUnloadFreeGlobalReportQueue()
{
2023-12-13 05:06:27 +01:00
PAGED_CODE();
FreeGlobalReportQueueObjects();
2023-10-09 18:27:04 +02:00
}
STATIC
VOID
DrvUnloadFreeThreadList()
{
2023-12-13 05:06:27 +01:00
PAGED_CODE();
CleanupThreadListOnDriverUnload();
2023-10-09 18:27:04 +02:00
}
STATIC
VOID
DrvUnloadFreeDriverList()
{
PAGED_CODE();
CleanupDriverListOnDriverUnload();
}
2024-01-12 06:40:33 +01:00
STATIC
VOID
DrvUnloadFreeTimerObject()
{
PAGED_CODE();
2024-01-13 22:33:57 +01:00
CleanupDriverTimerObjects(&g_DriverConfig->timer);
2024-01-12 06:40:33 +01:00
}
2023-10-10 19:49:17 +02:00
STATIC
VOID
DrvUnloadFreeProcessList()
{
2023-12-13 05:06:27 +01:00
PAGED_CODE();
CleanupProcessListOnDriverUnload();
2023-10-10 19:49:17 +02:00
}
2024-01-02 23:29:23 +01:00
STATIC
VOID
DrvUnloadFreeModuleValidationContext()
{
PAGED_CODE();
2024-01-13 22:33:57 +01:00
CleanupValidationContextOnUnload(&g_DriverConfig->sys_val_context);
2024-01-02 23:29:23 +01:00
}
STATIC
VOID
DrvUnloadFreeImportsStructure()
{
PAGED_CODE();
FreeDriverImportsStructure();
}
2023-10-09 18:27:04 +02:00
STATIC
VOID
2023-12-13 05:06:27 +01:00
DriverUnload(_In_ PDRIVER_OBJECT DriverObject)
2023-10-09 18:27:04 +02:00
{
2023-12-23 19:52:55 +01:00
DEBUG_VERBOSE("Unloading...");
2023-10-09 18:27:04 +02:00
2024-01-13 22:33:57 +01:00
InterlockedExchange(&g_DriverConfig->unload_in_progress, TRUE);
2023-10-09 18:27:04 +02:00
2023-12-13 05:06:27 +01:00
/*
* This blocks the thread dispatching the unload routine, which I don't think is ideal.
* This is the issue with using APCs, we have very little safe control over when they
* complete and thus when we can free them.. For now, thisl do.
*/
while (DrvUnloadFreeAllApcContextStructures() == FALSE)
YieldProcessor();
2023-10-09 18:27:04 +02:00
2024-01-12 06:40:33 +01:00
DrvUnloadFreeTimerObject();
2024-01-02 23:29:23 +01:00
DrvUnloadFreeModuleValidationContext();
2023-12-13 05:06:27 +01:00
DrvUnloadUnregisterObCallbacks();
2024-01-14 05:31:19 +01:00
UnregisterThreadCreateNotifyRoutine();
UnregisterProcessCreateNotifyRoutine();
UnregisterImageLoadNotifyRoutine();
2023-12-13 05:06:27 +01:00
DrvUnloadFreeThreadList();
DrvUnloadFreeProcessList();
DrvUnloadFreeDriverList();
2024-01-14 05:31:19 +01:00
2023-12-13 05:06:27 +01:00
DrvUnloadFreeConfigStrings();
DrvUnloadFreeGlobalReportQueue();
DrvUnloadFreeSymbolicLink();
2024-01-13 22:33:57 +01:00
ImpIoDeleteDevice(DriverObject->DeviceObject);
2024-01-13 22:33:57 +01:00
2023-12-23 19:52:55 +01:00
DEBUG_INFO("Driver successfully unloaded.");
2024-01-08 04:57:07 +01:00
DrvUnloadFreeImportsStructure();
2023-10-09 18:27:04 +02:00
}
2023-09-26 12:00:45 +02:00
STATIC
2023-10-05 08:27:17 +02:00
NTSTATUS
2023-10-09 18:27:04 +02:00
DrvLoadEnableNotifyRoutines()
{
2023-12-13 05:06:27 +01:00
PAGED_CODE();
2023-12-23 19:52:55 +01:00
NTSTATUS status = STATUS_UNSUCCESSFUL;
DEBUG_VERBOSE("Enabling driver wide notify routines.");
2023-12-13 05:06:27 +01:00
status = PsSetLoadImageNotifyRoutine(ImageLoadNotifyRoutineCallback);
2023-12-13 05:06:27 +01:00
if (!NT_SUCCESS(status))
{
DEBUG_ERROR("PsSetLoadImageNotifyRoutine failed with status %x", status);
2023-12-13 05:06:27 +01:00
return status;
}
status = ImpPsSetCreateThreadNotifyRoutine(ThreadCreateNotifyRoutine);
2023-12-13 05:06:27 +01:00
if (!NT_SUCCESS(status))
{
DEBUG_ERROR("PsSetCreateThreadNotifyRoutine failed with status %x", status);
PsRemoveLoadImageNotifyRoutine(ImageLoadNotifyRoutineCallback);
2023-12-13 05:06:27 +01:00
return status;
}
status = ImpPsSetCreateProcessNotifyRoutine(ProcessCreateNotifyRoutine, FALSE);
2023-12-13 05:06:27 +01:00
if (!NT_SUCCESS(status))
{
DEBUG_ERROR("PsSetCreateProcessNotifyRoutine failed with status %x", status);
ImpPsRemoveCreateThreadNotifyRoutine(ThreadCreateNotifyRoutine);
PsRemoveLoadImageNotifyRoutine(ImageLoadNotifyRoutineCallback);
return status;
}
2023-12-13 05:06:27 +01:00
2023-12-23 19:52:55 +01:00
DEBUG_VERBOSE("Successfully enabled driver wide notify routines.");
2023-12-13 05:06:27 +01:00
return status;
2023-10-09 18:27:04 +02:00
}
2024-01-14 05:31:19 +01:00
STATIC
NTSTATUS
DrvLoadSetupDriverLists()
{
PAGED_CODE();
NTSTATUS status = STATUS_UNSUCCESSFUL;
status = InitialiseDriverList();
if (!NT_SUCCESS(status))
{
UnregisterImageLoadNotifyRoutine();
DEBUG_ERROR("InitialiseDriverList failed with status %x", status);
return status;
}
status = InitialiseThreadList();
if (!NT_SUCCESS(status))
{
DEBUG_ERROR("InitialiseThreadList failed with status %x", status);
UnregisterThreadCreateNotifyRoutine();
UnregisterImageLoadNotifyRoutine();
return status;
}
status = InitialiseProcessList();
if (!NT_SUCCESS(status))
{
DEBUG_ERROR("InitialiseProcessList failed with status %x", status);
UnregisterProcessCreateNotifyRoutine();
UnregisterThreadCreateNotifyRoutine();
UnregisterImageLoadNotifyRoutine();
return status;
}
return status;
}
2023-10-09 18:27:04 +02:00
STATIC
NTSTATUS
DrvLoadInitialiseObCbConfig()
{
2023-12-13 05:06:27 +01:00
PAGED_CODE();
2024-01-13 22:33:57 +01:00
ImpKeInitializeGuardedMutex(&g_DriverConfig->process_config.callback_info.lock);
2023-10-09 18:27:04 +02:00
}
STATIC
VOID
2024-01-13 22:33:57 +01:00
DrvLoadInitialiseReportQueue()
2023-10-09 18:27:04 +02:00
{
2023-12-13 05:06:27 +01:00
PAGED_CODE();
2024-01-13 22:33:57 +01:00
InitialiseGlobalReportQueue(&g_DriverConfig->report_queue);
2023-10-09 18:27:04 +02:00
}
STATIC
VOID
DrvLoadInitialiseProcessConfig()
{
2023-12-13 05:06:27 +01:00
PAGED_CODE();
2024-01-13 22:33:57 +01:00
ImpKeInitializeGuardedMutex(&g_DriverConfig->process_config.lock);
}
/*
* Regular routines
*/
VOID
TerminateProtectedProcessOnViolation()
{
PAGED_CODE();
NTSTATUS status = STATUS_UNSUCCESSFUL;
ULONG process_id = 0;
GetProtectedProcessId(&process_id);
if (!process_id)
{
DEBUG_ERROR("Failed to terminate process as process id is null");
return;
}
/* Make sure we pass a km handle to ZwTerminateProcess and NOT a usermode handle. */
status = ZwTerminateProcess(process_id, STATUS_SYSTEM_INTEGRITY_POLICY_VIOLATION);
if (!NT_SUCCESS(status))
{
/*
* We don't want to clear the process config if ZwTerminateProcess fails
* so we can try again.
*/
DEBUG_ERROR("ZwTerminateProcess failed with status %x", status);
return;
}
/* this wont be needed when procloadstuff is implemented */
ProcCloseClearProcessConfiguration();
}
STATIC
NTSTATUS
RegistryPathQueryCallbackRoutine(IN PWSTR ValueName,
IN ULONG ValueType,
IN PVOID ValueData,
IN ULONG ValueLength,
IN PVOID Context,
IN PVOID EntryContext)
{
PAGED_CODE();
UNICODE_STRING value_name = {0};
UNICODE_STRING image_path = RTL_CONSTANT_STRING(L"ImagePath");
UNICODE_STRING display_name = RTL_CONSTANT_STRING(L"DisplayName");
UNICODE_STRING value = {0};
PVOID temp_buffer = NULL;
ImpRtlInitUnicodeString(&value_name, ValueName);
if (ImpRtlCompareUnicodeString(&value_name, &image_path, FALSE) == FALSE)
{
temp_buffer = ImpExAllocatePool2(POOL_FLAG_PAGED, ValueLength, POOL_TAG_STRINGS);
if (!temp_buffer)
return STATUS_MEMORY_NOT_ALLOCATED;
RtlCopyMemory(temp_buffer, ValueData, ValueLength);
g_DriverConfig->driver_path.Buffer = (PWCH)temp_buffer;
g_DriverConfig->driver_path.Length = ValueLength;
g_DriverConfig->driver_path.MaximumLength = ValueLength;
}
if (ImpRtlCompareUnicodeString(&value_name, &display_name, FALSE) == FALSE)
{
temp_buffer =
ImpExAllocatePool2(POOL_FLAG_PAGED, ValueLength + 20, POOL_TAG_STRINGS);
if (!temp_buffer)
return STATUS_MEMORY_NOT_ALLOCATED;
/*
* The registry path driver name does not contain the .sys extension which is
* required for us since when we enumerate the system modules we are comparing the
* entire path including the .sys extension. Hence we add it to the end of the
* buffer here.
*/
RtlCopyMemory(temp_buffer, ValueData, ValueLength);
wcscpy((UINT64)temp_buffer + ValueLength - 2, L".sys");
g_DriverConfig->unicode_driver_name.Buffer = (PWCH)temp_buffer;
g_DriverConfig->unicode_driver_name.Length = ValueLength + 20;
g_DriverConfig->unicode_driver_name.MaximumLength = ValueLength + 20;
}
return STATUS_SUCCESS;
2023-10-09 18:27:04 +02:00
}
/*
* Values returned from CPUID that are equval to the vendor string
*/
#define CPUID_AUTHENTIC_AMD_EBX 0x68747541
#define CPUID_AUTHENTIC_AMD_EDX 0x69746e65
#define CPUID_AUTHENTIC_AMD_ECX 0x444d4163
#define CPUID_GENUINE_INTEL_EBX 0x756e6547
#define CPUID_GENUINE_INTEL_EDX 0x49656e69
#define CPUID_GENUINE_INTEL_ECX 0x6c65746e
2023-12-27 04:35:46 +01:00
#define EBX_REGISTER 1
#define ECX_REGISTER 2
#define EDX_REGISTER 3
2023-10-09 18:27:04 +02:00
STATIC
NTSTATUS
GetSystemProcessorType()
2023-09-01 14:30:32 +02:00
{
UINT32 cpuid[4] = {0};
__cpuid(cpuid, 0);
DEBUG_VERBOSE("Cpuid: EBX: %lx, ECX: %lx, EDX: %lx", cpuid[1], cpuid[2], cpuid[3]);
2023-12-13 05:06:27 +01:00
2023-12-27 04:35:46 +01:00
if (cpuid[EBX_REGISTER] == CPUID_AUTHENTIC_AMD_EBX &&
cpuid[ECX_REGISTER] == CPUID_AUTHENTIC_AMD_ECX &&
cpuid[EDX_REGISTER] == CPUID_AUTHENTIC_AMD_EDX)
{
2024-01-13 22:33:57 +01:00
g_DriverConfig->system_information.processor = GenuineIntel;
return STATUS_SUCCESS;
}
2023-12-27 04:35:46 +01:00
else if (cpuid[EBX_REGISTER] == CPUID_GENUINE_INTEL_EBX &&
cpuid[ECX_REGISTER] == CPUID_GENUINE_INTEL_ECX &&
cpuid[EDX_REGISTER] == CPUID_GENUINE_INTEL_EDX)
{
2024-01-13 22:33:57 +01:00
g_DriverConfig->system_information.processor = AuthenticAmd;
return STATUS_SUCCESS;
}
else
{
2024-01-13 22:33:57 +01:00
g_DriverConfig->system_information.processor = Unknown;
return STATUS_UNSUCCESSFUL;
}
}
/*
* Even though we are technically not meant to be operating when running under a virtualized system,
* it is still useful to test the attainment of system information under a virtualized system for
* testing purposes.
*/
STATIC
NTSTATUS
ParseSmbiosForGivenSystemEnvironment()
{
2023-12-23 19:52:55 +01:00
NTSTATUS status = STATUS_UNSUCCESSFUL;
2023-12-13 05:06:27 +01:00
2024-01-13 22:33:57 +01:00
status = ParseSMBIOSTable(&g_DriverConfig->system_information.vendor,
VENDOR_STRING_MAX_LENGTH,
SmbiosInformation,
SMBIOS_VENDOR_STRING_SUB_INDEX);
if (!NT_SUCCESS(status))
{
DEBUG_ERROR("ParseSMBIOSTable failed with status %x", status);
return status;
}
2024-01-13 22:33:57 +01:00
if (strstr(&g_DriverConfig->system_information.vendor, "VMware, Inc"))
g_DriverConfig->system_information.environment = Vmware;
else if (strstr(&g_DriverConfig->system_information.vendor, "innotek GmbH"))
g_DriverConfig->system_information.environment = VirtualBox;
else
2024-01-13 22:33:57 +01:00
g_DriverConfig->system_information.environment = NativeWindows;
2024-01-13 22:33:57 +01:00
switch (g_DriverConfig->system_information.environment)
{
case NativeWindows:
{
2023-12-27 04:35:46 +01:00
/*
* TODO: double check that amd indexes are the same should be, but should check just
* in case
*/
2024-01-13 22:33:57 +01:00
status = ParseSMBIOSTable(&g_DriverConfig->system_information.motherboard_serial,
MOTHERBOARD_SERIAL_CODE_LENGTH,
VendorSpecificInformation,
SMBIOS_NATIVE_SERIAL_NUMBER_SUB_INDEX);
break;
}
case Vmware:
{
2024-01-13 22:33:57 +01:00
status = ParseSMBIOSTable(&g_DriverConfig->system_information.motherboard_serial,
MOTHERBOARD_SERIAL_CODE_LENGTH,
SystemInformation,
SMBIOS_VMWARE_SERIAL_NUMBER_SUB_INDEX);
break;
}
case VirtualBox:
default: DEBUG_WARNING("Environment type not supported."); return STATUS_NOT_SUPPORTED;
}
if (!NT_SUCCESS(status))
{
2023-12-27 04:35:46 +01:00
DEBUG_ERROR("ParseSMBIOSTable 2 failed with status %x", status);
return status;
}
return status;
}
STATIC
NTSTATUS
DrvLoadGatherSystemEnvironmentSettings()
{
NTSTATUS status = STATUS_UNSUCCESSFUL;
/*
* On Vmware, the APERF_MSR is not emulated hence this will return TRUE.
*/
if (APERFMsrTimingCheck())
2024-01-13 22:33:57 +01:00
g_DriverConfig->system_information.virtualised_environment = TRUE;
2024-01-08 04:57:07 +01:00
2024-01-13 22:33:57 +01:00
status = GetOsVersionInformation(&g_DriverConfig->system_information.os_information);
if (!NT_SUCCESS(status))
{
DEBUG_ERROR("GetOsVersionInformation failed with status %x", status);
return status;
}
2024-01-08 04:57:07 +01:00
status = GetSystemProcessorType();
if (!NT_SUCCESS(status))
{
DEBUG_ERROR("GetSystemProcessorType failed with status %x", status);
return status;
}
2024-01-08 04:57:07 +01:00
status = ParseSmbiosForGivenSystemEnvironment();
if (!NT_SUCCESS(status))
{
DEBUG_ERROR("ParseSmbiosForGivenSystemEnvironment failed with status %x", status);
DrvUnloadFreeConfigStrings();
return status;
}
2024-01-08 04:57:07 +01:00
status =
2024-01-13 22:33:57 +01:00
GetHardDiskDriveSerialNumber(&g_DriverConfig->system_information.drive_0_serial,
sizeof(g_DriverConfig->system_information.drive_0_serial));
if (!NT_SUCCESS(status))
{
DEBUG_ERROR("GetHardDiskDriverSerialNumber failed with status %x", status);
DrvUnloadFreeConfigStrings();
return status;
}
2024-01-08 04:57:07 +01:00
DEBUG_VERBOSE("OS Major Version: %lx, Minor Version: %lx, Build Number: %lx",
2024-01-13 22:33:57 +01:00
g_DriverConfig->system_information.os_information.dwMajorVersion,
g_DriverConfig->system_information.os_information.dwMinorVersion,
g_DriverConfig->system_information.os_information.dwBuildNumber);
DEBUG_VERBOSE("Environment type: %lx", g_DriverConfig->system_information.environment);
DEBUG_VERBOSE("Processor type: %lx", g_DriverConfig->system_information.processor);
DEBUG_VERBOSE("Motherboard serial: %s",
2024-01-13 22:33:57 +01:00
g_DriverConfig->system_information.motherboard_serial);
DEBUG_VERBOSE("Drive 0 serial: %s", g_DriverConfig->system_information.drive_0_serial);
2024-01-08 04:57:07 +01:00
return status;
}
STATIC
NTSTATUS
2023-12-27 04:35:46 +01:00
DrvLoadRetrieveDriverNameFromRegistry(_In_ PUNICODE_STRING RegistryPath)
{
NTSTATUS status = STATUS_UNSUCCESSFUL;
2023-12-13 05:06:27 +01:00
RTL_QUERY_REGISTRY_TABLE query_table[3] = {0};
query_table[0].Flags = RTL_QUERY_REGISTRY_NOEXPAND;
query_table[0].Name = L"ImagePath";
query_table[0].DefaultType = REG_MULTI_SZ;
query_table[0].DefaultLength = 0;
query_table[0].DefaultData = NULL;
query_table[0].EntryContext = NULL;
query_table[0].QueryRoutine = RegistryPathQueryCallbackRoutine;
query_table[1].Flags = RTL_QUERY_REGISTRY_NOEXPAND;
query_table[1].Name = L"DisplayName";
query_table[1].DefaultType = REG_SZ;
query_table[1].DefaultLength = 0;
query_table[1].DefaultData = NULL;
query_table[1].EntryContext = NULL;
query_table[1].QueryRoutine = RegistryPathQueryCallbackRoutine;
status = RtlxQueryRegistryValues(
RTL_REGISTRY_ABSOLUTE, RegistryPath->Buffer, &query_table, NULL, NULL);
if (!NT_SUCCESS(status))
{
DEBUG_ERROR("RtlxQueryRegistryValues failed with status %x", status);
return status;
}
2023-12-27 04:35:46 +01:00
/*
* The registry path contains the name of the driver i.e Driver, but does not contain the
* .sys extension. Lets add it to our stored driver name since we need the .sys extension
* when querying the system modules for our driver.
*/
status = ImpRtlUnicodeStringToAnsiString(
2024-01-13 22:33:57 +01:00
&g_DriverConfig->ansi_driver_name, &g_DriverConfig->unicode_driver_name, TRUE);
2023-12-13 05:06:27 +01:00
if (!NT_SUCCESS(status))
2023-12-23 19:52:55 +01:00
DEBUG_ERROR("RtlUnicodeStringToAnsiString failed with status %x", status);
2024-01-11 10:16:55 +01:00
return status;
2023-12-27 04:35:46 +01:00
}
STATIC
NTSTATUS
DrvLoadInitialiseDriverConfig(_In_ PDRIVER_OBJECT DriverObject, _In_ PUNICODE_STRING RegistryPath)
{
PAGED_CODE();
DEBUG_VERBOSE("Initialising driver configuration");
2024-01-13 22:33:57 +01:00
NTSTATUS status = STATUS_UNSUCCESSFUL;
2023-12-27 04:35:46 +01:00
2024-01-13 22:33:57 +01:00
ImpKeInitializeGuardedMutex(&g_DriverConfig->lock);
2024-01-11 10:16:55 +01:00
IrpQueueInitialise();
2024-01-13 22:33:57 +01:00
g_DriverConfig->unload_in_progress = FALSE;
g_DriverConfig->system_information.virtualised_environment = FALSE;
g_DriverConfig->sys_val_context.active = FALSE;
2023-12-27 04:35:46 +01:00
status = DrvLoadRetrieveDriverNameFromRegistry(RegistryPath);
if (!NT_SUCCESS(status))
{
DEBUG_ERROR("DrvLoadRetrieveDriverNameFromRegistry failed with status %x", status);
2023-12-13 05:06:27 +01:00
DrvUnloadFreeConfigStrings();
return status;
}
status = DrvLoadGatherSystemEnvironmentSettings();
2023-12-13 05:06:27 +01:00
if (!NT_SUCCESS(status))
{
DEBUG_ERROR("GatherSystemEnvironmentSettings failed with status %x", status);
2023-12-13 05:06:27 +01:00
DrvUnloadFreeConfigStrings();
return status;
}
status = DrvLoadInitialiseObCbConfig();
if (!NT_SUCCESS(status))
{
DEBUG_ERROR("AllocateCallbackStructure failed with status %x", status);
DrvUnloadFreeConfigStrings();
return status;
}
2024-01-13 22:33:57 +01:00
status = InitialiseTimerObject(&g_DriverConfig->timer);
2024-01-12 06:40:33 +01:00
if (!NT_SUCCESS(status))
{
DEBUG_ERROR("InitialiseTimerObject failed with status %x", status);
DrvUnloadFreeConfigStrings();
return status;
}
2024-01-13 22:33:57 +01:00
DEBUG_VERBOSE("driver name: %s", g_DriverConfig->ansi_driver_name.Buffer);
2023-12-13 05:06:27 +01:00
return status;
2023-09-01 13:46:31 +02:00
}
2023-10-05 08:27:17 +02:00
NTSTATUS
2023-12-13 05:06:27 +01:00
DriverEntry(_In_ PDRIVER_OBJECT DriverObject, _In_ PUNICODE_STRING RegistryPath)
2023-08-17 10:45:50 +02:00
{
2024-01-13 22:33:57 +01:00
BOOLEAN flag = FALSE;
NTSTATUS status = STATUS_UNSUCCESSFUL;
UNICODE_STRING device_name = RTL_CONSTANT_STRING(L"\\Device\\DonnaAC");
UNICODE_STRING symbolic_link = RTL_CONSTANT_STRING(L"\\??\\DonnaAC");
2024-01-08 04:57:07 +01:00
2024-01-12 06:40:33 +01:00
DriverObject->MajorFunction[IRP_MJ_CREATE] = DeviceCreate;
DriverObject->MajorFunction[IRP_MJ_CLOSE] = DeviceClose;
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = DeviceControl;
DriverObject->DriverUnload = DriverUnload;
2023-12-23 19:52:55 +01:00
DEBUG_VERBOSE("Beginning driver entry routine...");
2023-12-13 05:06:27 +01:00
2024-01-13 22:33:57 +01:00
status = IoCreateDevice(DriverObject,
sizeof(DRIVER_CONFIG),
&device_name,
FILE_DEVICE_UNKNOWN,
FILE_DEVICE_SECURE_OPEN,
FALSE,
&DriverObject->DeviceObject);
2023-12-13 05:06:27 +01:00
if (!NT_SUCCESS(status))
{
DEBUG_ERROR("IoCreateDevice failed with status %x", status);
2024-01-12 06:40:33 +01:00
return status;
2023-12-13 05:06:27 +01:00
}
2024-01-13 22:33:57 +01:00
g_DriverConfig = DriverObject->DeviceObject->DeviceExtension;
g_DriverConfig->driver_object = DriverObject;
g_DriverConfig->device_object = DriverObject->DeviceObject;
RtlCopyUnicodeString(&g_DriverConfig->device_name, &device_name);
RtlCopyUnicodeString(&g_DriverConfig->device_symbolic_link, &symbolic_link);
status = ResolveDynamicImports(DriverObject);
if (!NT_SUCCESS(status))
return status;
2023-12-23 19:52:55 +01:00
2024-01-12 06:40:33 +01:00
status = DrvLoadInitialiseDriverConfig(DriverObject, RegistryPath);
if (!NT_SUCCESS(status))
{
DEBUG_ERROR("InitialiseDriverConfigOnDriverEntry failed with status %x", status);
ImpIoDeleteDevice(DriverObject->DeviceObject);
return status;
}
2024-01-13 22:33:57 +01:00
DrvLoadInitialiseReportQueue();
2024-01-12 06:40:33 +01:00
DrvLoadInitialiseProcessConfig();
2024-01-13 22:33:57 +01:00
status = IoCreateSymbolicLink(&symbolic_link, &device_name);
2023-12-13 05:06:27 +01:00
if (!NT_SUCCESS(status))
{
2023-12-23 19:52:55 +01:00
DEBUG_ERROR("IoCreateSymbolicLink failed with status %x", status);
2023-12-13 05:06:27 +01:00
DrvUnloadFreeConfigStrings();
ImpIoDeleteDevice(DriverObject->DeviceObject);
2023-12-13 05:06:27 +01:00
return STATUS_FAILED_DRIVER_ENTRY;
}
status = DrvLoadEnableNotifyRoutines();
if (!NT_SUCCESS(status))
{
2023-12-23 19:52:55 +01:00
DEBUG_ERROR("EnablenotifyRoutines failed with status %x", status);
2023-12-13 05:06:27 +01:00
DrvUnloadFreeConfigStrings();
2024-01-13 22:33:57 +01:00
ImpIoDeleteSymbolicLink(&g_DriverConfig->device_symbolic_link);
ImpIoDeleteDevice(DriverObject->DeviceObject);
2023-12-13 05:06:27 +01:00
return STATUS_FAILED_DRIVER_ENTRY;
}
2024-01-14 05:31:19 +01:00
status = DrvLoadSetupDriverLists();
if (!NT_SUCCESS(status))
{
DEBUG_ERROR("DrvLoadSetupDriverLists failed with status %x", status);
DrvUnloadFreeConfigStrings();
ImpIoDeleteSymbolicLink(&g_DriverConfig->device_symbolic_link);
ImpIoDeleteDevice(DriverObject->DeviceObject);
}
2023-12-23 19:52:55 +01:00
DEBUG_VERBOSE("Driver Entry Complete.");
2023-12-13 05:06:27 +01:00
return STATUS_SUCCESS;
2023-08-17 10:45:50 +02:00
}