2023-08-17 10:45:50 +02:00
|
|
|
#ifndef DRIVER_H
|
|
|
|
#define DRIVER_H
|
|
|
|
|
|
|
|
#include <Windows.h>
|
|
|
|
|
|
|
|
#include "../threadpool.h"
|
2023-08-22 19:32:25 +02:00
|
|
|
#include "../client.h"
|
2023-08-17 10:45:50 +02:00
|
|
|
|
2023-08-19 04:52:57 +02:00
|
|
|
#define IOCCTL_RUN_NMI_CALLBACKS CTL_CODE(FILE_DEVICE_UNKNOWN, 0x2001, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
|
|
|
#define IOCTL_VALIDATE_DRIVER_OBJECTS CTL_CODE(FILE_DEVICE_UNKNOWN, 0x2002, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
2023-08-20 16:12:04 +02:00
|
|
|
#define IOCTL_MONITOR_CALLBACKS_FOR_REPORTS CTL_CODE(FILE_DEVICE_UNKNOWN, 0x2003, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
|
|
|
#define IOCTL_NOTIFY_DRIVER_ON_PROCESS_LAUNCH CTL_CODE(FILE_DEVICE_UNKNOWN, 0x2004, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
2023-08-20 17:04:53 +02:00
|
|
|
#define IOCTL_HANDLE_REPORTS_IN_CALLBACK_QUEUE CTL_CODE(FILE_DEVICE_UNKNOWN, 0x2005, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
2023-08-21 17:48:34 +02:00
|
|
|
#define IOCTL_PERFORM_VIRTUALIZATION_CHECK CTL_CODE(FILE_DEVICE_UNKNOWN, 0x2006, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
2023-08-22 10:51:52 +02:00
|
|
|
#define IOCTL_ENUMERATE_HANDLE_TABLES CTL_CODE(FILE_DEVICE_UNKNOWN, 0x2007, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
2023-08-22 19:32:25 +02:00
|
|
|
#define IOCTL_RETRIEVE_MODULE_EXECUTABLE_REGIONS CTL_CODE(FILE_DEVICE_UNKNOWN, 0x2008, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
|
|
|
#define IOCTL_REQUEST_TOTAL_MODULE_SIZE CTL_CODE(FILE_DEVICE_UNKNOWN, 0x2009, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
|
|
|
|
2023-08-20 17:04:53 +02:00
|
|
|
|
|
|
|
#define MAX_HANDLE_REPORTS_PER_IRP 10
|
2023-08-19 04:52:57 +02:00
|
|
|
|
2023-08-17 10:45:50 +02:00
|
|
|
namespace kernelmode
|
|
|
|
{
|
|
|
|
class Driver
|
|
|
|
{
|
|
|
|
HANDLE driver_handle;
|
|
|
|
LPCWSTR driver_name;
|
2023-08-22 19:32:25 +02:00
|
|
|
std::shared_ptr<global::Client> report_interface;
|
2023-08-21 06:45:33 +02:00
|
|
|
|
|
|
|
void QueryReportQueue();
|
2023-08-22 19:32:25 +02:00
|
|
|
void RequestTotalModuleSize();
|
2023-08-21 17:48:34 +02:00
|
|
|
|
2023-08-17 10:45:50 +02:00
|
|
|
public:
|
|
|
|
|
2023-08-22 19:32:25 +02:00
|
|
|
Driver(LPCWSTR DriverName, std::shared_ptr<global::Client> ReportInterface );
|
2023-08-19 04:52:57 +02:00
|
|
|
|
|
|
|
void RunNmiCallbacks();
|
|
|
|
void VerifySystemModules();
|
2023-08-21 06:45:33 +02:00
|
|
|
void RunCallbackReportQueue();
|
2023-08-20 16:12:04 +02:00
|
|
|
void NotifyDriverOnProcessLaunch();
|
2023-08-21 17:48:34 +02:00
|
|
|
void DetectSystemVirtualization();
|
2023-08-19 04:52:57 +02:00
|
|
|
void ValidateKPRCBThreads();
|
|
|
|
void CheckDriverHeartbeat();
|
2023-08-22 10:51:52 +02:00
|
|
|
void CheckHandleTableEntries();
|
2023-08-22 19:32:25 +02:00
|
|
|
void RequestModuleExecutableRegions();
|
2023-08-19 04:52:57 +02:00
|
|
|
/* todo: driver integrity check */
|
2023-08-17 10:45:50 +02:00
|
|
|
};
|
2023-08-20 16:12:04 +02:00
|
|
|
|
|
|
|
struct DRIVER_INITIATION_INFORMATION
|
|
|
|
{
|
|
|
|
LONG protected_process_id;
|
|
|
|
};
|
2023-08-21 17:48:34 +02:00
|
|
|
|
|
|
|
struct HYPERVISOR_DETECTION_REPORT
|
|
|
|
{
|
|
|
|
INT aperf_msr_timing_check;
|
|
|
|
INT invd_emulation_check;
|
|
|
|
};
|
2023-08-17 10:45:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|