| 291 | |
| 292 | |
| 293 | NTSTATUS DriverMonGenericDispatch(PDEVICE_OBJECT DeviceObject, PIRP Irp) { |
| 294 | auto driver = DeviceObject->DriverObject; |
| 295 | auto stack = IoGetCurrentIrpStackLocation(Irp); |
| 296 | |
| 297 | IrpArrivedInfo* info = nullptr; |
| 298 | |
| 299 | for (int i = 0; i < MaxMonitoredDrivers; i++) { |
| 300 | if (globals.Drivers[i].DriverObject != driver) |
| 301 | continue; |
| 302 | |
| 303 | if (globals.IsMonitoring && globals.NotifyEvent) { |
| 304 | NT_ASSERT(driver == DeviceObject->DriverObject); |
| 305 | |
| 306 | KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_TRACE_LEVEL, "Driver 0x%p intercepted!\n", driver)); |
| 307 | |
| 308 | info = static_cast<IrpArrivedInfo*>(ExAllocatePool(NonPagedPool, MaxDataSize + sizeof(IrpArrivedInfo))); |
| 309 | if (info) { |
| 310 | info->Type = DataItemType::IrpArrived; |
| 311 | KeQuerySystemTime((PLARGE_INTEGER)&info->Time); |
| 312 | info->Size = sizeof(IrpArrivedInfo); |
| 313 | info->DeviceObject = DeviceObject; |
| 314 | info->Irp = Irp; |
| 315 | info->DriverObject = driver; |
| 316 | info->MajorFunction = static_cast<IrpMajorCode>(stack->MajorFunction); |
| 317 | info->MinorFunction = static_cast<IrpMinorCode>(stack->MinorFunction); |
| 318 | info->ProcessId = HandleToUlong(PsGetCurrentProcessId()); |
| 319 | info->ThreadId = HandleToUlong(PsGetCurrentThreadId()); |
| 320 | info->Irql = KeGetCurrentIrql(); |
| 321 | info->DataSize = 0; |
| 322 | |
| 323 | switch (info->MajorFunction) { |
| 324 | case IrpMajorCode::WRITE: |
| 325 | info->Write.Length = stack->Parameters.Write.Length; |
| 326 | info->Write.Offset = stack->Parameters.Write.ByteOffset.QuadPart; |
| 327 | if(info->Write.Length>0){ |
| 328 | auto dataSize = min(MaxDataSize, info->Write.Length); |
| 329 | if (NT_SUCCESS(GetDataFromIrp(DeviceObject, Irp, stack, info->MajorFunction, (PUCHAR)info + sizeof(IrpArrivedInfo), dataSize))) { |
| 330 | info->DataSize = dataSize; |
| 331 | info->Size += (USHORT)dataSize; |
| 332 | } |
| 333 | } |
| 334 | break; |
| 335 | |
| 336 | case IrpMajorCode::DEVICE_CONTROL: |
| 337 | case IrpMajorCode::INTERNAL_DEVICE_CONTROL: |
| 338 | info->DeviceIoControl.IoControlCode = stack->Parameters.DeviceIoControl.IoControlCode; |
| 339 | info->DeviceIoControl.InputBufferLength = stack->Parameters.DeviceIoControl.InputBufferLength; |
| 340 | info->DeviceIoControl.OutputBufferLength = stack->Parameters.DeviceIoControl.OutputBufferLength; |
| 341 | if (info->DeviceIoControl.InputBufferLength > 0) { |
| 342 | auto dataSize = min(MaxDataSize, info->DeviceIoControl.InputBufferLength); |
| 343 | if (NT_SUCCESS(GetDataFromIrp(DeviceObject, Irp, stack, info->MajorFunction, (PUCHAR)info + sizeof(IrpArrivedInfo), dataSize))) { |
| 344 | info->DataSize = dataSize; |
| 345 | info->Size += (USHORT)dataSize; |
| 346 | } |
| 347 | } |
| 348 | break; |
| 349 | } |
| 350 |
nothing calls this directly
no test coverage detected