Panoptes 1.0.0
Endpoint Detection and Response
Loading...
Searching...
No Matches
event_queue.cpp File Reference
#include "event_queue.h"

Go to the source code of this file.

Classes

struct  _PANO_EVENT_NODE

Macros

#define PANO_EVENT_POOL_TAG   'vEoP'
#define PANO_CONSUMER_MARK   ((PVOID)(ULONG_PTR)0x50414E4F)

Typedefs

typedef struct _PANO_EVENT_NODE PANO_EVENT_NODE
typedef struct _PANO_EVENT_NODE * PPANO_EVENT_NODE

Functions

 _IRQL_raises_ (DISPATCH_LEVEL) _Acquires_lock_(g_IrpLock) static VOID CsqAcquireLock(PIO_CSQ Csq
 _Releases_lock_ (g_IrpLock) static VOID CsqReleaseLock(PIO_CSQ Csq
NTSTATUS EventQueueInit ()
 Initializes the event queue. Call once from DriverEntry before any producer can run and before the device is exposed.
void EventQueueCleanup ()
 Cancels every pending GET_EVENT request and frees all buffered events. Call from the unload path after all producers have been stopped.
BOOLEAN EventQueueReceiveRequest (PIRP Irp, NTSTATUS *Status)
 Queues a GET_EVENT request. Call from the IOCTL dispatch routine. On success the IRP is either completed immediately (an event was waiting) or marked pending and parked in the cancel-safe queue; in both cases the dispatch routine must return the value written to *Status and must not touch the IRP again.
BOOLEAN EventQueueIsConsumerProcess (UINT64 ProcessId)
 Checks whether a process is the one reading events (the service). The filter does not report that process's own file activity: its log writes, database and scans would otherwise each produce more events for it to read, and it discards them anyway. Tracks the process of the handle that most recently became a consumer. Safe at any IRQL <= DISPATCH_LEVEL.
void EventQueueCleanupFile (PFILE_OBJECT FileObject)
 Handles IRP_MJ_CLEANUP for a handle to the device: cancels the GET_EVENT requests still parked for it and, if it was the last consumer, drops the buffered events. Call from the IRP_MJ_CLEANUP dispatch routine.
NTSTATUS PanoReportEvent (PANO_EVENT_TYPE Type, const void *Payload, UINT32 PayloadSize)
NTSTATUS PanoReportFileEvent (PANO_EVENT_TYPE Type, UINT64 ProcessId, UINT64 ThreadId, INT64 FileOffset, UINT32 Length, UINT32 Flags, const WCHAR *FileName, UINT32 NameLength)
NTSTATUS PanoReportFileModifiedEvent (UINT64 ProcessId, UINT64 ThreadId, UINT64 Writes, UINT64 Bytes, INT64 FirstWriteTime, UINT32 Flags, const WCHAR *FileName, UINT32 NameLength)
NTSTATUS PanoReportRenameEvent (UINT64 ProcessId, UINT64 ThreadId, UINT32 Flags, const WCHAR *SourceName, UINT32 SourceNameLength, const WCHAR *DestinationName, UINT32 DestinationNameLength)
NTSTATUS PanoReportProcessEvent (PANO_EVENT_TYPE Type, UINT64 ProcessId, UINT64 ParentProcessId, UINT64 CreatingProcessId, UINT64 CreatingThreadId, const WCHAR *ImageName, UINT32 ImageNameLength, const WCHAR *CommandLine, UINT32 CommandLineLength)
NTSTATUS PanoReportRegistryEvent (PANO_EVENT_TYPE Type, UINT64 ProcessId, UINT64 ThreadId, UINT32 Flags, UINT32 Detail, UINT32 DataSize, const WCHAR *KeyName, UINT32 KeyNameLength, const WCHAR *SecondName, UINT32 SecondNameLength, const void *Data, UINT32 DataLength)

Variables

PKIRQL Irql

Macro Definition Documentation

◆ PANO_CONSUMER_MARK

#define PANO_CONSUMER_MARK   ((PVOID)(ULONG_PTR)0x50414E4F)

Definition at line 31 of file event_queue.cpp.

Referenced by EventQueueCleanupFile(), and EventQueueReceiveRequest().

◆ PANO_EVENT_POOL_TAG

#define PANO_EVENT_POOL_TAG   'vEoP'

Definition at line 3 of file event_queue.cpp.

Referenced by EventQueueCleanup(), and EventQueueCleanupFile().

Typedef Documentation

◆ PANO_EVENT_NODE

◆ PPANO_EVENT_NODE

Function Documentation

◆ _IRQL_raises_()

_IRQL_raises_ ( DISPATCH_LEVEL )

◆ _Releases_lock_()

_Releases_lock_ ( g_IrpLock )

References Irql.

◆ EventQueueCleanup()

void EventQueueCleanup ( )

Cancels every pending GET_EVENT request and frees all buffered events. Call from the unload path after all producers have been stopped.

Definition at line 202 of file event_queue.cpp.

203{
204 // Cancel every parked request.
205 PIRP irp;
206 while ((irp = IoCsqRemoveNextIrp(&g_Csq, NULL)) != NULL) {
207 irp->IoStatus.Status = STATUS_CANCELLED;
208 irp->IoStatus.Information = 0;
209 IoCompleteRequest(irp, IO_NO_INCREMENT);
210 }
211
212 // Drop every buffered event.
213 PPANO_EVENT_NODE node;
214 while ((node = DequeueEvent()) != NULL) {
215 ExFreePoolWithTag(node, PANO_EVENT_POOL_TAG);
216 }
217}
struct _PANO_EVENT_NODE * PPANO_EVENT_NODE
#define PANO_EVENT_POOL_TAG

References PANO_EVENT_POOL_TAG.

Referenced by DriverEntry(), and UnloadPanoptes().

◆ EventQueueCleanupFile()

void EventQueueCleanupFile ( PFILE_OBJECT FileObject)

Handles IRP_MJ_CLEANUP for a handle to the device: cancels the GET_EVENT requests still parked for it and, if it was the last consumer, drops the buffered events. Call from the IRP_MJ_CLEANUP dispatch routine.

Parameters
FileObjectThe file object being cleaned up.

Definition at line 277 of file event_queue.cpp.

278{
279 // Complete the requests this handle still has parked. A process that is exiting
280 // has had them cancelled already, but one that just closes its handle has not
281 PIRP irp;
282 while ((irp = IoCsqRemoveNextIrp(&g_Csq, FileObject)) != NULL) {
283 irp->IoStatus.Status = STATUS_CANCELLED;
284 irp->IoStatus.Information = 0;
285 IoCompleteRequest(irp, IO_NO_INCREMENT);
286 }
287
288 // Called for both IRP_MJ_CLEANUP and IRP_MJ_CLOSE; only the first unmarks the
289 // handle. IRP_MJ_CLOSE covers a GET_EVENT request that was still being
290 // dispatched when IRP_MJ_CLEANUP arrived and marked the handle afterwards
291 if (InterlockedCompareExchangePointer(&FileObject->FsContext, NULL, PANO_CONSUMER_MARK) != PANO_CONSUMER_MARK) {
292 return;
293 }
294
295 // Stop exempting this handle's process, unless a newer consumer has replaced it
296 InterlockedCompareExchange64(&g_ConsumerProcessId, 0, (LONG64)(ULONG_PTR)FileObject->FsContext2);
297 FileObject->FsContext2 = NULL;
298
299 if (InterlockedDecrement(&g_Consumers) != 0) {
300 return;
301 }
302
303 // No consumer is left. What is buffered would only reach the next service as
304 // stale events, so it is dropped and counted
305 KIRQL irql;
306 LIST_ENTRY dropped;
307 InitializeListHead(&dropped);
308 LONG count = 0;
309
310 KeAcquireSpinLock(&g_EventLock, &irql);
311 while (!IsListEmpty(&g_EventList)) {
312 InsertTailList(&dropped, RemoveHeadList(&g_EventList));
313 count++;
314 }
315 g_EventCount = 0;
316 KeReleaseSpinLock(&g_EventLock, irql);
317
318 while (!IsListEmpty(&dropped)) {
319 PPANO_EVENT_NODE node = CONTAINING_RECORD(RemoveHeadList(&dropped), PANO_EVENT_NODE, ListEntry);
320 ExFreePoolWithTag(node, PANO_EVENT_POOL_TAG);
321 }
322 InterlockedAdd(&g_DroppedNoConsumer, count);
323}
struct _PANO_EVENT_NODE PANO_EVENT_NODE
#define PANO_CONSUMER_MARK

References PANO_CONSUMER_MARK, and PANO_EVENT_POOL_TAG.

◆ EventQueueInit()

NTSTATUS EventQueueInit ( )

Initializes the event queue. Call once from DriverEntry before any producer can run and before the device is exposed.

Definition at line 181 of file event_queue.cpp.

182{
183 InitializeListHead(&g_IrpList);
184 InitializeListHead(&g_EventList);
185 KeInitializeSpinLock(&g_IrpLock);
186 KeInitializeSpinLock(&g_EventLock);
187 g_EventCount = 0;
188 g_Dropped = 0;
189 g_Consumers = 0;
190 g_DroppedNoConsumer = 0;
191
192 return IoCsqInitialize(
193 &g_Csq,
194 CsqInsertIrp,
195 CsqRemoveIrp,
196 CsqPeekNextIrp,
197 CsqAcquireLock,
198 CsqReleaseLock,
199 CsqCompleteCanceledIrp);
200}

Referenced by DriverEntry().

◆ EventQueueIsConsumerProcess()

BOOLEAN EventQueueIsConsumerProcess ( UINT64 ProcessId)

Checks whether a process is the one reading events (the service). The filter does not report that process's own file activity: its log writes, database and scans would otherwise each produce more events for it to read, and it discards them anyway. Tracks the process of the handle that most recently became a consumer. Safe at any IRQL <= DISPATCH_LEVEL.

Definition at line 270 of file event_queue.cpp.

271{
272 // An aligned 64-bit read is atomic on x64
273 LONG64 consumer = g_ConsumerProcessId;
274 return consumer != 0 && (UINT64)consumer == ProcessId;
275}

◆ EventQueueReceiveRequest()

BOOLEAN EventQueueReceiveRequest ( PIRP Irp,
NTSTATUS * Status )

Queues a GET_EVENT request. Call from the IOCTL dispatch routine. On success the IRP is either completed immediately (an event was waiting) or marked pending and parked in the cancel-safe queue; in both cases the dispatch routine must return the value written to *Status and must not touch the IRP again.

Parameters
IrpThe IOCTL_PANOPTES_GET_EVENT request (METHOD_BUFFERED).
StatusReceives the status the dispatch routine should return.
Returns
TRUE if the queue took ownership of the IRP, FALSE if the caller must complete it with *Status (e.g. the output buffer was too small).

Definition at line 219 of file event_queue.cpp.

220{
221 PIO_STACK_LOCATION irpSp = IoGetCurrentIrpStackLocation(Irp);
222
223 // Every buffered event is <= PANO_MAX_EVENT_SIZE, so a request that can hold
224 // that much can hold any event and the copy at delivery never truncates.
225 if (irpSp->Parameters.DeviceIoControl.OutputBufferLength < PANO_MAX_EVENT_SIZE) {
226 *Status = STATUS_BUFFER_TOO_SMALL;
227 return FALSE;
228 }
229
230 // The handle's first request makes it a consumer, and events start being kept
231 if (InterlockedCompareExchangePointer(&irpSp->FileObject->FsContext, PANO_CONSUMER_MARK, NULL) == NULL) {
232 // The device has no drivers above it, so the request is dispatched in the context of
233 // the thread that sent it
234 LONG64 processId = (LONG64)(ULONG_PTR)PsGetCurrentProcessId();
235 irpSp->FileObject->FsContext2 = (PVOID)(ULONG_PTR)processId;
236 InterlockedExchange64(&g_ConsumerProcessId, processId);
237 InterlockedIncrement(&g_Consumers);
238 }
239
240 // Fast path: an event is already waiting.
241 PPANO_EVENT_NODE node = DequeueEvent();
242 if (node != NULL) {
243 DeliverEventToIrp(Irp, node);
244 *Status = STATUS_SUCCESS;
245 return TRUE;
246 }
247
248 // Park the request. IoCsqInsertIrp marks it pending for us.
249 IoCsqInsertIrp(&g_Csq, Irp, NULL);
250
251 // An event may have been buffered after our DequeueEvent and before the
252 // insert, while no request was parked to receive it. Drain it now so the
253 // request does not stall behind an event that already arrived.
254 node = DequeueEvent();
255 if (node != NULL) {
256 PIRP waiter = IoCsqRemoveNextIrp(&g_Csq, NULL);
257 if (waiter != NULL) {
258 DeliverEventToIrp(waiter, node);
259 }
260 else {
261 // Our request was already taken (by a producer); put the event back.
262 RequeueEventFront(node);
263 }
264 }
265
266 *Status = STATUS_PENDING;
267 return TRUE;
268}
#define PANO_MAX_EVENT_SIZE
The output buffer size the service passes with IOCTL_PANOPTES_GET_EVENT. The driver never returns an ...
Definition pano_events.h:59

References PANO_CONSUMER_MARK, and PANO_MAX_EVENT_SIZE.

◆ PanoReportEvent()

NTSTATUS PanoReportEvent ( PANO_EVENT_TYPE Type,
const void * Payload,
UINT32 PayloadSize )

Definition at line 398 of file event_queue.cpp.

399{
400 void* dest;
401 PPANO_EVENT_NODE node = AllocEventNode(Type, PayloadSize, &dest);
402 if (node == NULL) {
403 return STATUS_INSUFFICIENT_RESOURCES;
404 }
405
406 if (PayloadSize != 0) {
407 RtlCopyMemory(dest, Payload, PayloadSize);
408 }
409
410 SubmitEventNode(node);
411 return STATUS_SUCCESS;
412}

◆ PanoReportFileEvent()

NTSTATUS PanoReportFileEvent ( PANO_EVENT_TYPE Type,
UINT64 ProcessId,
UINT64 ThreadId,
INT64 FileOffset,
UINT32 Length,
UINT32 Flags,
const WCHAR * FileName,
UINT32 NameLength )

Definition at line 414 of file event_queue.cpp.

423{
424 if (FileName == NULL) {
425 NameLength = 0;
426 }
427 if (NameLength > PANO_MAX_FILE_NAME_LENGTH) {
428 NameLength = (UINT32)PANO_MAX_FILE_NAME_LENGTH;
430 }
431
432 UINT32 payloadSize = (UINT32)FIELD_OFFSET(PANO_FILE_EVENT_DATA, FileName) + NameLength * (UINT32)sizeof(WCHAR);
433
434 // Assemble straight into the pooled node to avoid a large kernel-stack copy.
435 void* dest;
436 PPANO_EVENT_NODE node = AllocEventNode(Type, payloadSize, &dest);
437 if (node == NULL) {
438 return STATUS_INSUFFICIENT_RESOURCES;
439 }
440
442 data->ProcessId = ProcessId;
443 data->ThreadId = ThreadId;
444 data->FileOffset = FileOffset;
445 data->Length = Length;
446 data->Flags = Flags;
447 data->NameLength = NameLength;
448 if (NameLength != 0) {
449 RtlCopyMemory(data->FileName, FileName, NameLength * sizeof(WCHAR));
450 }
451
452 SubmitEventNode(node);
453 return STATUS_SUCCESS;
454}
struct _PANO_FILE_EVENT_DATA * PPANO_FILE_EVENT_DATA
#define PANO_FLAG_NAME_TRUNCATED
struct _PANO_FILE_EVENT_DATA PANO_FILE_EVENT_DATA
The data for file, named pipe and mailslot events.
#define PANO_MAX_FILE_NAME_LENGTH
The maximum number of WCHARs in PANO_FILE_EVENT_DATA::FileName so that the whole response fits in PAN...
UINT32 Length
Length of the write, PANO_EVENT_FILE_WRITE only.
UINT32 NameLength
Length of FileName in WCHARs. FileName is not null terminated.
UINT32 Flags
PANO_FLAG_* values.
INT64 FileOffset
Offset of the write, PANO_EVENT_FILE_WRITE only.

References _PANO_FILE_EVENT_DATA::FileName, _PANO_FILE_EVENT_DATA::FileOffset, _PANO_FILE_EVENT_DATA::Flags, _PANO_FILE_EVENT_DATA::Length, _PANO_FILE_EVENT_DATA::NameLength, PANO_FLAG_NAME_TRUNCATED, PANO_MAX_FILE_NAME_LENGTH, _PANO_FILE_EVENT_DATA::ProcessId, and _PANO_FILE_EVENT_DATA::ThreadId.

◆ PanoReportFileModifiedEvent()

NTSTATUS PanoReportFileModifiedEvent ( UINT64 ProcessId,
UINT64 ThreadId,
UINT64 Writes,
UINT64 Bytes,
INT64 FirstWriteTime,
UINT32 Flags,
const WCHAR * FileName,
UINT32 NameLength )

Definition at line 456 of file event_queue.cpp.

465{
466 if (FileName == NULL) {
467 NameLength = 0;
468 }
469 if (NameLength > PANO_MAX_MODIFIED_FILE_NAME_LENGTH) {
470 NameLength = (UINT32)PANO_MAX_MODIFIED_FILE_NAME_LENGTH;
472 }
473
474 UINT32 payloadSize = (UINT32)FIELD_OFFSET(PANO_FILE_MODIFIED_EVENT_DATA, FileName) + NameLength * (UINT32)sizeof(WCHAR);
475
476 void* dest;
477 PPANO_EVENT_NODE node = AllocEventNode(PANO_EVENT_FILE_MODIFIED, payloadSize, &dest);
478 if (node == NULL) {
479 return STATUS_INSUFFICIENT_RESOURCES;
480 }
481
483 data->ProcessId = ProcessId;
484 data->ThreadId = ThreadId;
485 data->Writes = Writes;
486 data->Bytes = Bytes;
487 data->FirstWriteTime = FirstWriteTime;
488 data->Flags = Flags;
489 data->NameLength = NameLength;
490 if (NameLength != 0) {
491 RtlCopyMemory(data->FileName, FileName, NameLength * sizeof(WCHAR));
492 }
493
494 SubmitEventNode(node);
495 return STATUS_SUCCESS;
496}
#define PANO_MAX_MODIFIED_FILE_NAME_LENGTH
The maximum number of WCHARs in PANO_FILE_MODIFIED_EVENT_DATA::FileName so that the whole response fi...
@ PANO_EVENT_FILE_MODIFIED
A handle that wrote to a file was closed (a PANO_FILE_MODIFIED_EVENT_DATA). One event covers every wr...
Definition pano_events.h:94
struct _PANO_FILE_MODIFIED_EVENT_DATA * PPANO_FILE_MODIFIED_EVENT_DATA
struct _PANO_FILE_MODIFIED_EVENT_DATA PANO_FILE_MODIFIED_EVENT_DATA
The data for PANO_EVENT_FILE_MODIFIED.
UINT64 ProcessId
The process and thread of the most recent write.
UINT32 NameLength
Length of FileName in WCHARs. FileName is not null terminated. It is the file's name when the event w...
INT64 FirstWriteTime
When the first of those writes happened, in FILETIME units (UTC).
UINT32 Flags
PANO_FLAG_* values.
UINT64 Bytes
Bytes written by those writes.
UINT64 Writes
Number of writes through the handle covered by this event.

References _PANO_FILE_MODIFIED_EVENT_DATA::Bytes, _PANO_FILE_MODIFIED_EVENT_DATA::FileName, _PANO_FILE_MODIFIED_EVENT_DATA::FirstWriteTime, _PANO_FILE_MODIFIED_EVENT_DATA::Flags, _PANO_FILE_MODIFIED_EVENT_DATA::NameLength, PANO_EVENT_FILE_MODIFIED, PANO_FLAG_NAME_TRUNCATED, PANO_MAX_MODIFIED_FILE_NAME_LENGTH, _PANO_FILE_MODIFIED_EVENT_DATA::ProcessId, _PANO_FILE_MODIFIED_EVENT_DATA::ThreadId, and _PANO_FILE_MODIFIED_EVENT_DATA::Writes.

◆ PanoReportProcessEvent()

NTSTATUS PanoReportProcessEvent ( PANO_EVENT_TYPE Type,
UINT64 ProcessId,
UINT64 ParentProcessId,
UINT64 CreatingProcessId,
UINT64 CreatingThreadId,
const WCHAR * ImageName,
UINT32 ImageNameLength,
const WCHAR * CommandLine,
UINT32 CommandLineLength )

Definition at line 575 of file event_queue.cpp.

585{
586 UINT32 flags = 0;
587 if (ImageName == NULL) {
588 ImageNameLength = 0;
589 }
590 if (CommandLine == NULL) {
591 CommandLineLength = 0;
592 }
593
594 BOOLEAN imageCut, commandLineCut;
595 FitTwoStrings(&ImageNameLength, &CommandLineLength, (UINT32)PANO_MAX_PROCESS_STRINGS_LENGTH, &imageCut, &commandLineCut);
596 if (imageCut) {
598 }
599 if (commandLineCut) {
601 }
602
603 UINT32 payloadSize = (UINT32)FIELD_OFFSET(PANO_PROCESS_EVENT_DATA, Strings) +
604 (ImageNameLength + CommandLineLength) * (UINT32)sizeof(WCHAR);
605
606 void* dest;
607 PPANO_EVENT_NODE node = AllocEventNode(Type, payloadSize, &dest);
608 if (node == NULL) {
609 return STATUS_INSUFFICIENT_RESOURCES;
610 }
611
613 data->ProcessId = ProcessId;
614 data->ParentProcessId = ParentProcessId;
615 data->CreatingProcessId = CreatingProcessId;
616 data->CreatingThreadId = CreatingThreadId;
617 data->Flags = flags;
618 data->ImageNameLength = ImageNameLength;
619 data->CommandLineLength = CommandLineLength;
620 if (ImageNameLength != 0) {
621 RtlCopyMemory(data->Strings, ImageName, ImageNameLength * sizeof(WCHAR));
622 }
623 if (CommandLineLength != 0) {
624 RtlCopyMemory(data->Strings + ImageNameLength, CommandLine, CommandLineLength * sizeof(WCHAR));
625 }
626
627 SubmitEventNode(node);
628 return STATUS_SUCCESS;
629}
#define PANO_FLAG_COMMAND_LINE_TRUNCATED
PANO_EVENT_PROCESS_CREATED: the command line was truncated to fit the event.
struct _PANO_PROCESS_EVENT_DATA * PPANO_PROCESS_EVENT_DATA
struct _PANO_PROCESS_EVENT_DATA PANO_PROCESS_EVENT_DATA
The data for PANO_EVENT_PROCESS_CREATED and PANO_EVENT_PROCESS_TERMINATED.
#define PANO_MAX_PROCESS_STRINGS_LENGTH
The maximum combined number of WCHARs in the PANO_PROCESS_EVENT_DATA image name and command line so t...
UINT32 Flags
PANO_FLAG_* values. PANO_FLAG_NAME_TRUNCATED refers to the image name and PANO_FLAG_COMMAND_LINE_TRUN...
WCHAR Strings[1]
The image name immediately followed by the command line. Neither is null terminated.
UINT32 CommandLineLength
Length of the command line in WCHARs. PANO_EVENT_PROCESS_CREATED only.
UINT32 ImageNameLength
Length of the image name in WCHARs. PANO_EVENT_PROCESS_CREATED only.
UINT64 ParentProcessId
PANO_EVENT_PROCESS_CREATED only.
UINT64 CreatingProcessId
The process that created the new process, which can differ from the parent. PANO_EVENT_PROCESS_CREATE...
UINT64 CreatingThreadId
The thread that created the new process. PANO_EVENT_PROCESS_CREATED only.

References _PANO_PROCESS_EVENT_DATA::CommandLineLength, _PANO_PROCESS_EVENT_DATA::CreatingProcessId, _PANO_PROCESS_EVENT_DATA::CreatingThreadId, _PANO_PROCESS_EVENT_DATA::Flags, _PANO_PROCESS_EVENT_DATA::ImageNameLength, PANO_FLAG_COMMAND_LINE_TRUNCATED, PANO_FLAG_NAME_TRUNCATED, PANO_MAX_PROCESS_STRINGS_LENGTH, _PANO_PROCESS_EVENT_DATA::ParentProcessId, _PANO_PROCESS_EVENT_DATA::ProcessId, and _PANO_PROCESS_EVENT_DATA::Strings.

◆ PanoReportRegistryEvent()

NTSTATUS PanoReportRegistryEvent ( PANO_EVENT_TYPE Type,
UINT64 ProcessId,
UINT64 ThreadId,
UINT32 Flags,
UINT32 Detail,
UINT32 DataSize,
const WCHAR * KeyName,
UINT32 KeyNameLength,
const WCHAR * SecondName,
UINT32 SecondNameLength,
const void * Data,
UINT32 DataLength )

Definition at line 631 of file event_queue.cpp.

644{
645 if (KeyName == NULL) {
646 KeyNameLength = 0;
647 }
648 if (SecondName == NULL) {
649 SecondNameLength = 0;
650 }
651 if (Data == NULL) {
652 DataLength = 0;
653 }
654 if (DataLength > PANO_MAX_REGISTRY_DATA_SIZE) {
655 DataLength = PANO_MAX_REGISTRY_DATA_SIZE;
657 }
658
659 BOOLEAN keyCut, secondCut;
660 FitTwoStrings(&KeyNameLength, &SecondNameLength, (UINT32)PANO_MAX_REGISTRY_NAMES_LENGTH, &keyCut, &secondCut);
661 if (keyCut || secondCut) {
663 }
664
665 UINT32 payloadSize = (UINT32)FIELD_OFFSET(PANO_REGISTRY_EVENT_DATA, Strings) +
666 (KeyNameLength + SecondNameLength) * (UINT32)sizeof(WCHAR) + DataLength;
667
668 void* dest;
669 PPANO_EVENT_NODE node = AllocEventNode(Type, payloadSize, &dest);
670 if (node == NULL) {
671 return STATUS_INSUFFICIENT_RESOURCES;
672 }
673
675 data->ProcessId = ProcessId;
676 data->ThreadId = ThreadId;
677 data->Flags = Flags;
678 data->Detail = Detail;
679 data->DataSize = DataSize;
680 data->KeyNameLength = KeyNameLength;
681 data->SecondNameLength = SecondNameLength;
682 data->DataLength = DataLength;
683 if (KeyNameLength != 0) {
684 RtlCopyMemory(data->Strings, KeyName, KeyNameLength * sizeof(WCHAR));
685 }
686 if (SecondNameLength != 0) {
687 RtlCopyMemory(data->Strings + KeyNameLength, SecondName, SecondNameLength * sizeof(WCHAR));
688 }
689 if (DataLength != 0) {
690 RtlCopyMemory(data->Strings + KeyNameLength + SecondNameLength, Data, DataLength);
691 }
692
693 SubmitEventNode(node);
694 return STATUS_SUCCESS;
695}
struct _PANO_REGISTRY_EVENT_DATA PANO_REGISTRY_EVENT_DATA
The data for PANO_EVENT_REGISTRY_* events.
struct _PANO_REGISTRY_EVENT_DATA * PPANO_REGISTRY_EVENT_DATA
#define PANO_MAX_REGISTRY_DATA_SIZE
The most bytes of a value's data a PANO_EVENT_REGISTRY_SET_VALUE carries. Enough for the paths and co...
#define PANO_FLAG_DATA_TRUNCATED
PANO_EVENT_REGISTRY_SET_VALUE / _REPLACE_KEY: Data holds only the first PANO_MAX_REGISTRY_DATA_SIZE b...
#define PANO_MAX_REGISTRY_NAMES_LENGTH
The maximum combined number of WCHARs in both PANO_REGISTRY_EVENT_DATA names so that the whole respon...
WCHAR Strings[1]
The key name, then the second name (neither null terminated), then DataLength bytes of data....
UINT32 KeyNameLength
Length of the key's full name (\REGISTRY\MACHINE...) in WCHARs.
UINT32 Detail
Per event type: the REG_* value type (SET_VALUE), the REG_*_FORMAT (SAVE_KEY), the SECURITY_INFORMATI...
UINT32 DataSize
The full size of Data in bytes before it was cut to fit: the value's data (SET_VALUE) or the old hive...
UINT32 Flags
PANO_FLAG_* values.
UINT32 SecondNameLength
Length of the second name in WCHARs: the value name (SET_VALUE, QUERY_VALUE), the file (SAVE_KEY,...
UINT32 DataLength
Bytes in Data, at most PANO_MAX_REGISTRY_DATA_SIZE. SET_VALUE and REPLACE_KEY only.

References _PANO_REGISTRY_EVENT_DATA::DataLength, _PANO_REGISTRY_EVENT_DATA::DataSize, _PANO_REGISTRY_EVENT_DATA::Detail, _PANO_REGISTRY_EVENT_DATA::Flags, _PANO_REGISTRY_EVENT_DATA::KeyNameLength, PANO_FLAG_DATA_TRUNCATED, PANO_FLAG_NAME_TRUNCATED, PANO_MAX_REGISTRY_DATA_SIZE, PANO_MAX_REGISTRY_NAMES_LENGTH, _PANO_REGISTRY_EVENT_DATA::ProcessId, _PANO_REGISTRY_EVENT_DATA::SecondNameLength, _PANO_REGISTRY_EVENT_DATA::Strings, and _PANO_REGISTRY_EVENT_DATA::ThreadId.

◆ PanoReportRenameEvent()

NTSTATUS PanoReportRenameEvent ( UINT64 ProcessId,
UINT64 ThreadId,
UINT32 Flags,
const WCHAR * SourceName,
UINT32 SourceNameLength,
const WCHAR * DestinationName,
UINT32 DestinationNameLength )

Definition at line 527 of file event_queue.cpp.

535{
536 if (SourceName == NULL) {
537 SourceNameLength = 0;
538 }
539 if (DestinationName == NULL) {
540 DestinationNameLength = 0;
541 }
542
543 BOOLEAN sourceCut, destinationCut;
544 FitTwoStrings(&SourceNameLength, &DestinationNameLength, (UINT32)PANO_MAX_RENAME_NAMES_LENGTH, &sourceCut, &destinationCut);
545 if (sourceCut || destinationCut) {
547 }
548
549 UINT32 payloadSize = (UINT32)FIELD_OFFSET(PANO_RENAME_EVENT_DATA, Names) +
550 (SourceNameLength + DestinationNameLength) * (UINT32)sizeof(WCHAR);
551
552 void* dest;
553 PPANO_EVENT_NODE node = AllocEventNode(PANO_EVENT_FILE_RENAME, payloadSize, &dest);
554 if (node == NULL) {
555 return STATUS_INSUFFICIENT_RESOURCES;
556 }
557
559 data->ProcessId = ProcessId;
560 data->ThreadId = ThreadId;
561 data->Flags = Flags;
562 data->SourceNameLength = SourceNameLength;
563 data->DestinationNameLength = DestinationNameLength;
564 if (SourceNameLength != 0) {
565 RtlCopyMemory(data->Names, SourceName, SourceNameLength * sizeof(WCHAR));
566 }
567 if (DestinationNameLength != 0) {
568 RtlCopyMemory(data->Names + SourceNameLength, DestinationName, DestinationNameLength * sizeof(WCHAR));
569 }
570
571 SubmitEventNode(node);
572 return STATUS_SUCCESS;
573}
struct _PANO_RENAME_EVENT_DATA * PPANO_RENAME_EVENT_DATA
struct _PANO_RENAME_EVENT_DATA PANO_RENAME_EVENT_DATA
The data for PANO_EVENT_FILE_RENAME.
@ PANO_EVENT_FILE_RENAME
A file was renamed or moved (a PANO_RENAME_EVENT_DATA).
Definition pano_events.h:85
#define PANO_MAX_RENAME_NAMES_LENGTH
The maximum combined number of WCHARs in both PANO_RENAME_EVENT_DATA names so that the whole response...
WCHAR Names[1]
The original name immediately followed by the new name. Neither is null terminated.
UINT32 Flags
PANO_FLAG_* values.
UINT32 SourceNameLength
Length of the original name in WCHARs.
UINT32 DestinationNameLength
Length of the new name in WCHARs.

References _PANO_RENAME_EVENT_DATA::DestinationNameLength, _PANO_RENAME_EVENT_DATA::Flags, _PANO_RENAME_EVENT_DATA::Names, PANO_EVENT_FILE_RENAME, PANO_FLAG_NAME_TRUNCATED, PANO_MAX_RENAME_NAMES_LENGTH, _PANO_RENAME_EVENT_DATA::ProcessId, _PANO_RENAME_EVENT_DATA::SourceNameLength, and _PANO_RENAME_EVENT_DATA::ThreadId.

Variable Documentation

◆ Irql

KIRQL Irql
Initial value:
{
UNREFERENCED_PARAMETER(Csq)

Definition at line 158 of file event_queue.cpp.

Referenced by _Releases_lock_().