2023-08-19 04:52:57 +02:00
|
|
|
#ifndef MODULES_H
|
|
|
|
#define MODULES_H
|
|
|
|
|
|
|
|
#include <ntifs.h>
|
|
|
|
#include <intrin.h>
|
2023-09-25 17:41:38 +02:00
|
|
|
|
2023-08-22 19:32:25 +02:00
|
|
|
#include "common.h"
|
2023-09-25 17:41:38 +02:00
|
|
|
#include "queue.h"
|
2023-08-19 04:52:57 +02:00
|
|
|
|
2023-08-28 17:00:52 +02:00
|
|
|
typedef struct NMI_CALLBACK_FAILURE
|
|
|
|
{
|
2023-12-13 05:06:27 +01:00
|
|
|
INT report_code;
|
|
|
|
INT were_nmis_disabled;
|
|
|
|
UINT64 kthread_address;
|
|
|
|
UINT64 invalid_rip;
|
2023-08-28 17:00:52 +02:00
|
|
|
|
2023-12-13 05:06:27 +01:00
|
|
|
} NMI_CALLBACK_FAILURE, *PNMI_CALLBACK_FAILURE;
|
2023-08-28 17:00:52 +02:00
|
|
|
|
2023-12-29 17:20:32 +01:00
|
|
|
#define APC_STACKWALK_BUFFER_SIZE 4096
|
|
|
|
|
|
|
|
typedef struct _DPC_STACKWALK_REPORT
|
|
|
|
{
|
|
|
|
UINT32 report_code;
|
|
|
|
UINT64 kthread_address;
|
|
|
|
UINT64 invalid_rip;
|
|
|
|
CHAR driver[APC_STACKWALK_BUFFER_SIZE];
|
|
|
|
|
|
|
|
} DPC_STACKWALK_REPORT, *PDPC_STACKWALK_REPORT;
|
|
|
|
|
2023-08-19 04:52:57 +02:00
|
|
|
typedef struct _MODULE_VALIDATION_FAILURE
|
|
|
|
{
|
2023-12-13 05:06:27 +01:00
|
|
|
INT report_code;
|
|
|
|
INT report_type;
|
|
|
|
UINT64 driver_base_address;
|
|
|
|
UINT64 driver_size;
|
|
|
|
CHAR driver_name[128];
|
2023-08-19 04:52:57 +02:00
|
|
|
|
2023-12-13 05:06:27 +01:00
|
|
|
} MODULE_VALIDATION_FAILURE, *PMODULE_VALIDATION_FAILURE;
|
2023-08-19 04:52:57 +02:00
|
|
|
|
2023-09-28 15:56:07 +02:00
|
|
|
typedef struct _APC_STACKWALK_REPORT
|
|
|
|
{
|
2023-12-13 05:06:27 +01:00
|
|
|
INT report_code;
|
|
|
|
UINT64 kthread_address;
|
|
|
|
UINT64 invalid_rip;
|
|
|
|
CHAR driver[APC_STACKWALK_BUFFER_SIZE];
|
2023-09-28 15:56:07 +02:00
|
|
|
|
2023-12-13 05:06:27 +01:00
|
|
|
} APC_STACKWALK_REPORT, *PAPC_STACKWALK_REPORT;
|
2023-09-28 15:56:07 +02:00
|
|
|
|
2023-09-28 18:10:01 +02:00
|
|
|
typedef struct _APC_OPERATION_ID
|
|
|
|
{
|
2023-12-13 05:06:27 +01:00
|
|
|
int operation_id;
|
2023-09-28 18:10:01 +02:00
|
|
|
|
2023-12-13 05:06:27 +01:00
|
|
|
} APC_OPERATION_ID, *PAPC_OPERATION_ID;
|
2023-09-28 18:10:01 +02:00
|
|
|
|
2023-08-19 04:52:57 +02:00
|
|
|
/* system modules information */
|
|
|
|
|
|
|
|
typedef struct _SYSTEM_MODULES
|
|
|
|
{
|
2023-12-13 05:06:27 +01:00
|
|
|
PVOID address;
|
|
|
|
INT module_count;
|
2023-08-19 04:52:57 +02:00
|
|
|
|
2023-12-13 05:06:27 +01:00
|
|
|
} SYSTEM_MODULES, *PSYSTEM_MODULES;
|
2023-08-19 04:52:57 +02:00
|
|
|
|
2023-09-25 17:41:38 +02:00
|
|
|
#define APC_CONTEXT_ID_STACKWALK 0x1
|
|
|
|
|
|
|
|
typedef struct _APC_CONTEXT_HEADER
|
|
|
|
{
|
2023-12-13 05:06:27 +01:00
|
|
|
LONG context_id;
|
|
|
|
volatile INT count;
|
|
|
|
volatile INT allocation_in_progress;
|
2023-09-25 17:41:38 +02:00
|
|
|
|
2023-12-13 05:06:27 +01:00
|
|
|
} APC_CONTEXT_HEADER, *PAPC_CONTEXT_HEADER;
|
2023-09-26 12:00:45 +02:00
|
|
|
|
|
|
|
typedef struct _APC_STACKWALK_CONTEXT
|
|
|
|
{
|
2023-12-13 05:06:27 +01:00
|
|
|
APC_CONTEXT_HEADER header;
|
|
|
|
PSYSTEM_MODULES modules;
|
2023-09-26 12:00:45 +02:00
|
|
|
|
2023-12-13 05:06:27 +01:00
|
|
|
} APC_STACKWALK_CONTEXT, *PAPC_STACKWALK_CONTEXT;
|
2023-09-25 17:41:38 +02:00
|
|
|
|
2023-10-05 08:27:17 +02:00
|
|
|
NTSTATUS
|
2023-12-13 05:06:27 +01:00
|
|
|
GetSystemModuleInformation(_Out_ PSYSTEM_MODULES ModuleInformation);
|
2023-08-19 04:52:57 +02:00
|
|
|
|
2023-10-05 08:27:17 +02:00
|
|
|
NTSTATUS
|
2023-12-13 05:06:27 +01:00
|
|
|
HandleValidateDriversIOCTL(_Inout_ PIRP Irp);
|
2023-08-19 04:52:57 +02:00
|
|
|
|
2023-10-05 08:27:17 +02:00
|
|
|
PRTL_MODULE_EXTENDED_INFO
|
2023-12-13 05:06:27 +01:00
|
|
|
FindSystemModuleByName(_In_ LPCSTR ModuleName, _In_ PSYSTEM_MODULES SystemModules);
|
2023-08-22 19:32:25 +02:00
|
|
|
|
2023-10-05 08:27:17 +02:00
|
|
|
NTSTATUS
|
2023-12-13 05:06:27 +01:00
|
|
|
HandleNmiIOCTL(_Inout_ PIRP Irp);
|
2023-09-02 15:47:15 +02:00
|
|
|
|
2023-09-26 15:32:06 +02:00
|
|
|
BOOLEAN
|
2023-12-13 05:06:27 +01:00
|
|
|
FreeApcContextStructure(_Inout_ PAPC_CONTEXT_HEADER Context);
|
2023-09-25 17:41:38 +02:00
|
|
|
|
2023-10-05 08:27:17 +02:00
|
|
|
NTSTATUS
|
2023-09-27 06:22:14 +02:00
|
|
|
ValidateThreadsViaKernelApc();
|
2023-09-24 13:13:20 +02:00
|
|
|
|
2023-09-26 15:32:06 +02:00
|
|
|
VOID
|
2023-12-13 05:06:27 +01:00
|
|
|
FreeApcStackwalkApcContextInformation(_Inout_ PAPC_STACKWALK_CONTEXT Context);
|
2023-10-07 17:37:47 +02:00
|
|
|
|
|
|
|
NTSTATUS
|
2023-12-13 05:06:27 +01:00
|
|
|
IsInstructionPointerInInvalidRegion(_In_ UINT64 RIP,
|
|
|
|
_In_ PSYSTEM_MODULES SystemModules,
|
|
|
|
_Out_ PBOOLEAN Result);
|
2023-10-07 17:37:47 +02:00
|
|
|
|
|
|
|
BOOLEAN
|
2023-12-13 05:06:27 +01:00
|
|
|
FlipKThreadMiscFlagsFlag(_In_ PKTHREAD Thread, _In_ ULONG FlagIndex, _In_ BOOLEAN NewValue);
|
2023-09-26 12:00:45 +02:00
|
|
|
|
2023-10-30 12:57:24 +01:00
|
|
|
NTSTATUS
|
2023-12-29 17:20:32 +01:00
|
|
|
DispatchStackwalkToEachCpuViaDpc();
|
2023-10-30 12:57:24 +01:00
|
|
|
|
2023-08-19 04:52:57 +02:00
|
|
|
#endif
|