ReactOS  0.4.15-dev-2528-g5506091
wmidrv.c File Reference
#include <ntoskrnl.h>
#include <wmistr.h>
#include <wmiioctl.h>
#include "wmip.h"
#include <debug.h>
Include dependency graph for wmidrv.c:

Go to the source code of this file.

Classes

struct  _WMIP_REGISTER_GUIDS
 
struct  _WMIP_RESULT
 
struct  _WMI_UNREGISTER_GUID
 
struct  _WMI_GUID_OBJECT_ENTRY
 
struct  _WMI_NOTIFICATION
 
struct  _WMI_SET_MARK
 
struct  _WMI_OPEN_GUID_FOR_EVENTS
 
struct  _WMIP_RESULT2
 

Macros

#define NDEBUG
 

Typedefs

typedef struct _WMIP_REGISTER_GUIDS WMIP_REGISTER_GUIDS
 
typedef struct _WMIP_REGISTER_GUIDSPWMIP_REGISTER_GUIDS
 
typedef struct _WMIP_RESULT WMIP_RESULT
 
typedef struct _WMIP_RESULTPWMIP_RESULT
 
typedef struct _WMI_UNREGISTER_GUID WMI_UNREGISTER_GUID
 
typedef struct _WMI_UNREGISTER_GUIDPWMI_UNREGISTER_GUID
 
typedef struct _WMI_GUID_OBJECT_ENTRY WMI_GUID_OBJECT_ENTRY
 
typedef struct _WMI_GUID_OBJECT_ENTRYPWMI_GUID_OBJECT_ENTRY
 
typedef struct _WMI_NOTIFICATION WMI_NOTIFICATION
 
typedef struct _WMI_NOTIFICATIONPWMI_NOTIFICATION
 
typedef struct _WMI_SET_MARK WMI_SET_MARK
 
typedef struct _WMI_SET_MARKPWMI_SET_MARK
 
typedef struct _WMI_OPEN_GUID_FOR_EVENTS WMI_OPEN_GUID_FOR_EVENTS
 
typedef struct _WMI_OPEN_GUID_FOR_EVENTSPWMI_OPEN_GUID_FOR_EVENTS
 
typedef struct _WMIP_RESULT2 WMIP_RESULT2
 
typedef struct _WMIP_RESULT2PWMIP_RESULT2
 

Functions

NTSTATUS NTAPI WmipOpenCloseCleanup (_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
 
static NTSTATUS WmiTraceEvent (PVOID InputBuffer, KPROCESSOR_MODE PreviousMode)
 
static NTSTATUS WmiTraceUserMessage (PVOID InputBuffer, ULONG InputBufferLength)
 
static NTSTATUS WmipCaptureGuidObjectAttributes (_In_ POBJECT_ATTRIBUTES GuidObjectAttributes, _Out_ POBJECT_ATTRIBUTES CapuredObjectAttributes, _Out_ PUNICODE_STRING CapturedObjectName, _Out_ PWSTR ObjectNameBuffer, _In_ KPROCESSOR_MODE AccessMode)
 
static NTSTATUS WmipRegisterGuids (_In_ PDEVICE_OBJECT DeviceObject, _In_ PVOID Buffer, _In_ ULONG InputLength, _Inout_ PULONG OutputLength)
 
static NTSTATUS WmipUnregisterGuids (_In_ PVOID Buffer, _In_ ULONG InputLength, _Inout_ PULONG OutputLength)
 
VOID NTAPI WmipClearIrpObjectList (_In_ PIRP Irp)
 
VOID NTAPI WmipNotificationIrpCancel (_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
 
static VOID WmipInitializeIrpContext (PWMIP_IRP_CONTEXT IrpContext)
 
static NTSTATUS WmipReceiveNotifications (_Inout_ PIRP Irp, _In_ PVOID Buffer, _In_ ULONG InputLength, _Inout_ PULONG OutputLength)
 
static NTSTATUS WmipOpenGuidForEvents (PVOID Buffer, ULONG InputLength, PULONG OutputLength)
 
static NTSTATUS WmiSetMark (PWMI_SET_MARK Buffer, ULONG Length)
 
NTSTATUS NTAPI WmipIoControl (_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
 
NTSTATUS NTAPI WmipSystemControl (_Inout_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
 
NTSTATUS NTAPI WmipShutdown (_Inout_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
 
 _Function_class_ (FAST_IO_DEVICE_CONTROL)
 
NTSTATUS NTAPI WmipDockUndockEventCallback (_In_ PVOID NotificationStructure, _Inout_opt_ PVOID Context)
 
 _Function_class_ (DRIVER_INITIALIZE)
 

Variables

PDEVICE_OBJECT WmipServiceDeviceObject
 
PDEVICE_OBJECT WmipAdminDeviceObject
 
FAST_IO_DISPATCH WmipFastIoDispatch
 
DRIVER_DISPATCH WmipOpenCloseCleanup
 
DRIVER_DISPATCH WmipIoControl
 
DRIVER_DISPATCH WmipSystemControl
 
DRIVER_DISPATCH WmipShutdown
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 16 of file wmidrv.c.

Typedef Documentation

◆ PWMI_GUID_OBJECT_ENTRY

◆ PWMI_NOTIFICATION

◆ PWMI_OPEN_GUID_FOR_EVENTS

◆ PWMI_SET_MARK

◆ PWMI_UNREGISTER_GUID

◆ PWMIP_REGISTER_GUIDS

◆ PWMIP_RESULT

◆ PWMIP_RESULT2

◆ WMI_GUID_OBJECT_ENTRY

◆ WMI_NOTIFICATION

◆ WMI_OPEN_GUID_FOR_EVENTS

◆ WMI_SET_MARK

◆ WMI_UNREGISTER_GUID

◆ WMIP_REGISTER_GUIDS

◆ WMIP_RESULT

◆ WMIP_RESULT2

Function Documentation

◆ _Function_class_() [1/2]

_Function_class_ ( FAST_IO_DEVICE_CONTROL  )

Definition at line 560 of file wmidrv.c.

574 {
575  PAGED_CODE();
576 
578  {
579  if (InputBufferLength < 0x30)
580  {
581  DPRINT1("Buffer too small\n");
582  return FALSE;
583  }
584 
586  return TRUE;
587  }
589  {
590  if (InputBufferLength < 0x30)
591  {
592  DPRINT1("Buffer too small\n");
593  return FALSE;
594  }
595 
597  return TRUE;
598  }
599 
600  DPRINT1("Invalid io control code for fast dispatch: 0x%lx\n", IoControlCode);
601  return FALSE;
602 }
#define TRUE
Definition: types.h:120
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3066
_In_ WDFREQUEST _In_ size_t _In_ size_t InputBufferLength
Definition: wdfio.h:318
#define IOCTL_WMI_TRACE_EVENT
Definition: wmiioctl.h:12
#define FALSE
Definition: types.h:117
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR InputBuffer
Definition: wdfiotarget.h:949
_In_ WDFREQUEST _In_ size_t _In_ size_t _In_ ULONG IoControlCode
Definition: wdfio.h:318
static NTSTATUS WmiTraceEvent(PVOID InputBuffer, KPROCESSOR_MODE PreviousMode)
Definition: wmidrv.c:101
#define DPRINT1
Definition: precomp.h:8
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:155
static NTSTATUS WmiTraceUserMessage(PVOID InputBuffer, ULONG InputBufferLength)
Definition: wmidrv.c:111
#define IOCTL_WMI_TRACE_USER_MESSAGE
Definition: wmiioctl.h:15
#define PAGED_CODE()

◆ _Function_class_() [2/2]

_Function_class_ ( DRIVER_INITIALIZE  )

Definition at line 614 of file wmidrv.c.

621 {
622  static UNICODE_STRING ServiceDeviceName = RTL_CONSTANT_STRING(L"\\Device\\WMIDataDevice");
623  static UNICODE_STRING ServiceDosDeviceName = RTL_CONSTANT_STRING(L"\\DosDevices\\WMIDataDevice");
624  static UNICODE_STRING AdminDeviceName = RTL_CONSTANT_STRING(L"\\Device\\WMIAdminDevice");
625  static UNICODE_STRING AdminDosDeviceName = RTL_CONSTANT_STRING(L"\\DosDevices\\WMIAdminDevice");
627  PAGED_CODE();
628 
629  /* Create the service device object */
631  0,
632  &ServiceDeviceName,
635  0,
637  if (!NT_SUCCESS(Status))
638  {
639  DPRINT1("Failed to create service device: 0x%lx\n", Status);
640  return Status;
641  }
642 
643  /* Create a symbolic link for the service device */
644  Status = IoCreateSymbolicLink(&ServiceDosDeviceName, &ServiceDeviceName);
645  if (!NT_SUCCESS(Status))
646  {
647  DPRINT1("IoCreateSymbolicLink() failed: 0x%lx\n", Status);
649  return Status;
650  }
651 
652  /* Create the admin device object */
654  0,
655  &AdminDeviceName,
658  0,
660  if (!NT_SUCCESS(Status))
661  {
662  DPRINT1("Failed to create admin device: 0x%lx\n", Status);
664  IoDeleteSymbolicLink(&ServiceDosDeviceName);
665  return Status;
666  }
667 
668  /* Create a symbolic link for the admin device */
669  Status = IoCreateSymbolicLink(&AdminDosDeviceName, &AdminDeviceName);
670  if (!NT_SUCCESS(Status))
671  {
672  DPRINT1("IoCreateSymbolicLink() failed: 0x%lx\n", Status);
673  IoDeleteSymbolicLink(&ServiceDosDeviceName);
676  return Status;
677  }
678 
679  /* Initialize dispatch routines */
685  DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = WmipShutdown;
686 
687  /* Initialize fast dispatch */
690  WmipFastIoDispatch.FastIoDeviceControl = WmipFastIoDeviceControl;
691  DriverObject->FastIoDispatch = &WmipFastIoDispatch;
692 
693  /* Register the WMI service device */
695 
696  /* Register a shutdown notification */
698 
699  /* Initialization is done */
702 
703  return STATUS_SUCCESS;
704 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define IRP_MJ_SHUTDOWN
LONG NTSTATUS
Definition: precomp.h:26
PDEVICE_OBJECT WmipServiceDeviceObject
Definition: wmidrv.c:72
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
NTSTATUS NTAPI IoWMIRegistrationControl(IN PDEVICE_OBJECT DeviceObject, IN ULONG Action)
Definition: wmi.c:68
Status
Definition: gdiplustypes.h:24
#define WMIREG_ACTION_REGISTER
PDEVICE_OBJECT WmipAdminDeviceObject
Definition: wmidrv.c:73
DRIVER_DISPATCH WmipIoControl
Definition: wmidrv.c:80
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
DRIVER_DISPATCH WmipOpenCloseCleanup
Definition: wmidrv.c:79
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
static const WCHAR L[]
Definition: oid.c:1250
PFAST_IO_DEVICE_CONTROL FastIoDeviceControl
Definition: iotypes.h:1743
#define IRP_MJ_SYSTEM_CONTROL
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
DRIVER_DISPATCH WmipSystemControl
Definition: wmidrv.c:81
FAST_IO_DISPATCH WmipFastIoDispatch
Definition: wmidrv.c:74
#define FILE_DEVICE_UNKNOWN
Definition: winioctl.h:140
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NTAPI IoRegisterShutdownNotification(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1694
DRIVER_DISPATCH WmipShutdown
Definition: wmidrv.c:82
#define IRP_MJ_CLEANUP
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
#define STATUS_SUCCESS
Definition: shellext.h:65
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
ULONG SizeOfFastIoDispatch
Definition: iotypes.h:1733
#define PAGED_CODE()
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

◆ WmipCaptureGuidObjectAttributes()

static NTSTATUS WmipCaptureGuidObjectAttributes ( _In_ POBJECT_ATTRIBUTES  GuidObjectAttributes,
_Out_ POBJECT_ATTRIBUTES  CapuredObjectAttributes,
_Out_ PUNICODE_STRING  CapturedObjectName,
_Out_ PWSTR  ObjectNameBuffer,
_In_ KPROCESSOR_MODE  AccessMode 
)
static

Definition at line 121 of file wmidrv.c.

127 {
129 
130  _SEH2_TRY
131  {
132  /* Probe and copy the object attributes structure */
133  ProbeForRead(GuidObjectAttributes,
134  sizeof(OBJECT_ATTRIBUTES),
135  sizeof(PVOID));
136  *CapuredObjectAttributes = *GuidObjectAttributes;
137 
138  /* Probe and copy the object name UNICODE_STRING */
139  ProbeForRead(CapuredObjectAttributes->ObjectName,
140  sizeof(UNICODE_STRING),
141  sizeof(PVOID));
142  *CapturedObjectName = *CapuredObjectAttributes->ObjectName;
143 
144  /* Check if the object name has the expected length */
145  if (CapturedObjectName->Length != 45 * sizeof(WCHAR))
146  {
148  }
149 
150  /* Probe and copy the object name buffer */
151  ProbeForRead(CapturedObjectName->Buffer,
152  CapturedObjectName->Length,
153  sizeof(WCHAR));
155  CapturedObjectName->Buffer,
156  CapturedObjectName->Length);
157 
158  /* Fix pointers */
159  CapturedObjectName->Buffer = ObjectNameBuffer;
160  GuidObjectAttributes->ObjectName = CapturedObjectName;
161  }
163  {
164  DPRINT1("Got exception!\n");
166  }
167  _SEH2_END;
168 
169  return STATUS_SUCCESS;
170 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_SEH2_TRY
Definition: create.c:4226
_In_ PEPROCESS _In_ KPROCESSOR_MODE AccessMode
Definition: mmfuncs.h:395
_In_z_ PCCHAR ObjectNameBuffer
Definition: classpnp.h:982
#define ASSERT(a)
Definition: mode.c:45
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
_SEH2_END
Definition: create.c:4400
#define DPRINT1
Definition: precomp.h:8
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168

Referenced by WmipOpenGuidForEvents(), and WmipRegisterGuids().

◆ WmipClearIrpObjectList()

VOID NTAPI WmipClearIrpObjectList ( _In_ PIRP  Irp)

Definition at line 255 of file wmidrv.c.

257 {
258  PWMIP_IRP_CONTEXT IrpContext;
259  PLIST_ENTRY ListEntry;
260  PWMIP_GUID_OBJECT GuidObject;
261 
262  /* Get the IRP context */
263  IrpContext = (PWMIP_IRP_CONTEXT)Irp->Tail.Overlay.DriverContext;
264 
265  /* Loop all GUID objects attached to this IRP */
266  for (ListEntry = IrpContext->GuidObjectListHead.Flink;
267  ListEntry != &IrpContext->GuidObjectListHead;
268  ListEntry = ListEntry->Flink)
269  {
270  /* Get the GUID object */
271  GuidObject = CONTAINING_RECORD(ListEntry, WMIP_GUID_OBJECT, IrpLink);
272 
273  /* Make sure the IRP matches and clear it */
274  ASSERT(GuidObject->Irp == Irp);
275  GuidObject->Irp = NULL;
276 
277  /* Remove the entry */
278  RemoveEntryList(ListEntry);
279  }
280 }
LIST_ENTRY GuidObjectListHead
Definition: wmip.h:10
struct _WMIP_IRP_CONTEXT * PWMIP_IRP_CONTEXT
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
_In_ PIRP Irp
Definition: csq.h:116
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define ASSERT(a)
Definition: mode.c:45
#define for
Definition: utility.h:88
Definition: typedefs.h:119
#define NULL
Definition: types.h:112

Referenced by WmipNotificationIrpCancel().

◆ WmipDockUndockEventCallback()

NTSTATUS NTAPI WmipDockUndockEventCallback ( _In_ PVOID  NotificationStructure,
_Inout_opt_ PVOID  Context 
)

Definition at line 606 of file wmidrv.c.

609 {
611  return STATUS_NOT_IMPLEMENTED;
612 }
return STATUS_NOT_IMPLEMENTED
#define UNIMPLEMENTED_DBGBREAK(...)
Definition: debug.h:57

◆ WmipInitializeIrpContext()

static VOID WmipInitializeIrpContext ( PWMIP_IRP_CONTEXT  IrpContext)
static

Definition at line 302 of file wmidrv.c.

304 {
305  /* Initialize the list head for GUID objects */
307 }
LIST_ENTRY GuidObjectListHead
Definition: wmip.h:10
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944

Referenced by WmipReceiveNotifications().

◆ WmipIoControl()

NTSTATUS NTAPI WmipIoControl ( _In_ PDEVICE_OBJECT  DeviceObject,
_Inout_ PIRP  Irp 
)

Definition at line 448 of file wmidrv.c.

451 {
452  PIO_STACK_LOCATION IoStackLocation;
454  PVOID Buffer;
455  ULONG InputLength, OutputLength;
457  PAGED_CODE();
458 
459  /* Get the current stack location */
460  IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
461 
462  /* Get the io control parameters */
463  IoControlCode = IoStackLocation->Parameters.DeviceIoControl.IoControlCode;
464  Buffer = Irp->AssociatedIrp.SystemBuffer;
465  InputLength = IoStackLocation->Parameters.DeviceIoControl.InputBufferLength;
466  OutputLength = IoStackLocation->Parameters.DeviceIoControl.OutputBufferLength;
467 
468  switch (IoControlCode)
469  {
470 
472  {
474  Buffer,
475  InputLength,
476  &OutputLength);
477  break;
478  }
479 
481  {
483  InputLength,
484  &OutputLength);
485  break;
486  }
487 
489  {
491  Buffer,
492  InputLength,
493  &OutputLength);
494  break;
495  }
496 
497  case 0x228168:
498  {
499  DPRINT1("IOCTL 0x228168 is unimplemented, ignoring\n");
501  break;
502  }
503 
505  {
506  Status = WmipOpenGuidForEvents(Buffer, InputLength, &OutputLength);
507  break;
508  }
509 
510  case IOCTL_WMI_SET_MARK:
511  {
512  if (InputLength < FIELD_OFFSET(WMI_SET_MARK, Mark))
513  {
515  break;
516  }
517 
518  Status = WmiSetMark(Buffer, InputLength);
519  break;
520  }
521 
522  default:
523  DPRINT1("Unsupported yet IOCTL: 0x%lx\n", IoControlCode);
525  __debugbreak();
526  break;
527  }
528 
529  if (Status == STATUS_PENDING)
530  return Status;
531 
532  Irp->IoStatus.Status = Status;
533  Irp->IoStatus.Information = NT_SUCCESS(Status) ? OutputLength : 0;
534 
536  return Status;
537 }
static NTSTATUS WmipReceiveNotifications(_Inout_ PIRP Irp, _In_ PVOID Buffer, _In_ ULONG InputLength, _Inout_ PULONG OutputLength)
Definition: wmidrv.c:311
#define IOCTL_WMI_RECEIVE_NOTIFICATIONS
Definition: wmiioctl.h:28
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
void __cdecl __debugbreak(void)
Definition: intrin_ppc.h:698
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define IOCTL_WMI_UNREGISTER_GUIDS
Definition: wmiioctl.h:34
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
static NTSTATUS WmipOpenGuidForEvents(PVOID Buffer, ULONG InputLength, PULONG OutputLength)
Definition: wmidrv.c:383
Definition: bufpool.h:45
Status
Definition: gdiplustypes.h:24
static VOID Mark(PGUI_CONSOLE_DATA GuiData)
Definition: conwnd.c:300
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IOCTL_WMI_OPEN_GUID_FOR_EVENTS
Definition: wmiioctl.h:27
#define IOCTL_WMI_REGISTER_GUIDS
Definition: wmiioctl.h:30
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_In_ WDFREQUEST _In_ size_t _In_ size_t _In_ ULONG IoControlCode
Definition: wdfio.h:318
static NTSTATUS WmiSetMark(PWMI_SET_MARK Buffer, ULONG Length)
Definition: wmidrv.c:438
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:598
static NTSTATUS WmipRegisterGuids(_In_ PDEVICE_OBJECT DeviceObject, _In_ PVOID Buffer, _In_ ULONG InputLength, _Inout_ PULONG OutputLength)
Definition: wmidrv.c:174
#define STATUS_SUCCESS
Definition: shellext.h:65
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3127
#define IOCTL_WMI_SET_MARK
Definition: wmiioctl.h:16
static NTSTATUS WmipUnregisterGuids(_In_ PVOID Buffer, _In_ ULONG InputLength, _Inout_ PULONG OutputLength)
Definition: wmidrv.c:244
#define PAGED_CODE()

◆ WmipNotificationIrpCancel()

VOID NTAPI WmipNotificationIrpCancel ( _In_ PDEVICE_OBJECT  DeviceObject,
_Inout_ PIRP  Irp 
)

Definition at line 284 of file wmidrv.c.

287 {
288  /* Clear the list */
290 
291  /* Release the cancel spin lock */
292  IoReleaseCancelSpinLock(Irp->CancelIrql);
293 
294  /* Set the status to cancelled and complete the IRP */
295  Irp->IoStatus.Status = STATUS_CANCELLED;
296  Irp->IoStatus.Information = 0;
298 }
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
#define IO_NO_INCREMENT
Definition: iotypes.h:598
VOID NTAPI WmipClearIrpObjectList(_In_ PIRP Irp)
Definition: wmidrv.c:255

Referenced by WmipReceiveNotifications().

◆ WmipOpenCloseCleanup()

NTSTATUS NTAPI WmipOpenCloseCleanup ( _In_ PDEVICE_OBJECT  DeviceObject,
_Inout_ PIRP  Irp 
)

Definition at line 86 of file wmidrv.c.

89 {
90  PAGED_CODE();
91 
92  /* No work to do, just return success */
93  Irp->IoStatus.Status = STATUS_SUCCESS;
94  Irp->IoStatus.Information = 0;
96  return STATUS_SUCCESS;
97 }
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define STATUS_SUCCESS
Definition: shellext.h:65
#define PAGED_CODE()

◆ WmipOpenGuidForEvents()

static NTSTATUS WmipOpenGuidForEvents ( PVOID  Buffer,
ULONG  InputLength,
PULONG  OutputLength 
)
static

Definition at line 383 of file wmidrv.c.

387 {
388  PWMI_OPEN_GUID_FOR_EVENTS OpenGuidForEvents = Buffer;
390  OBJECT_ATTRIBUTES LocalObjectAttributes;
391  UNICODE_STRING LocalObjectName;
392  WCHAR LocalObjectNameBuffer[45 + 1];
394  HANDLE GuidObjectHandle;
395  PVOID GuidObject;
397 
398  if ((InputLength != sizeof(WMI_OPEN_GUID_FOR_EVENTS)) ||
399  (*OutputLength != sizeof(WMIP_RESULT2)))
400  {
401  return STATUS_UNSUCCESSFUL;
402  }
403 
404  /* Capture object attributes */
407  &LocalObjectAttributes,
408  &LocalObjectName,
409  LocalObjectNameBuffer,
410  PreviousMode);
411  if (!NT_SUCCESS(Status))
412  {
413  DPRINT1("ProbeAndCaptureGuidObjectAttributes failed: 0x%lx\n", Status);
414  return Status;
415  }
416 
417  /* Open a new GUID object */
418  Status = WmipOpenGuidObjectByName(&LocalObjectAttributes,
419  OpenGuidForEvents->DesiredAccess,
420  PreviousMode,
421  &GuidObjectHandle,
422  &GuidObject);
423  if (!NT_SUCCESS(Status))
424  {
425  DPRINT1("WmipOpenGuidObjectByName failed: 0x%lx\n", Status);
426  return Status;
427  }
428 
429  Result->Handle = GuidObjectHandle;
430 
431  ObDereferenceObject(GuidObject);
432 
433  return STATUS_SUCCESS;
434 }
struct _WMIP_RESULT2 WMIP_RESULT2
static NTSTATUS WmipCaptureGuidObjectAttributes(_In_ POBJECT_ATTRIBUTES GuidObjectAttributes, _Out_ POBJECT_ATTRIBUTES CapuredObjectAttributes, _Out_ PUNICODE_STRING CapturedObjectName, _Out_ PWSTR ObjectNameBuffer, _In_ KPROCESSOR_MODE AccessMode)
Definition: wmidrv.c:121
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
LONG NTSTATUS
Definition: precomp.h:26
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3066
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
Definition: bufpool.h:45
Status
Definition: gdiplustypes.h:24
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
NTSTATUS NTAPI WmipOpenGuidObjectByName(_In_ POBJECT_ATTRIBUTES ObjectAttributes, _In_ ACCESS_MASK DesiredAccess, _In_ KPROCESSOR_MODE AccessMode, _Out_ PHANDLE OutGuidObjectHandle, _Outptr_ PVOID *OutGuidObject)
Definition: guidobj.c:262
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ObDereferenceObject
Definition: obfuncs.h:203
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
ACCESS_MASK DesiredAccess
Definition: wmidrv.c:368
POBJECT_ATTRIBUTES ObjectAttributes
Definition: wmidrv.c:367
#define DPRINT1
Definition: precomp.h:8
#define STATUS_SUCCESS
Definition: shellext.h:65
struct _WMIP_RESULT2 * PWMIP_RESULT2

Referenced by WmipIoControl().

◆ WmipReceiveNotifications()

static NTSTATUS WmipReceiveNotifications ( _Inout_ PIRP  Irp,
_In_ PVOID  Buffer,
_In_ ULONG  InputLength,
_Inout_ PULONG  OutputLength 
)
static

FIXME: For now we don't do any actual work, but simply pretend we are waiting for notifications. We won't ever deliver any though.

Definition at line 311 of file wmidrv.c.

316 {
318  PWMIP_IRP_CONTEXT IrpContext;
320 
321  //__debugbreak();
322  if ((InputLength < sizeof(WMI_NOTIFICATION)) || (*OutputLength < 0x38))
323  {
325  }
326 
331 
332  // loop all objects
333  // reference the object
334  // on failure, fail the whole request
335 
336  // loop all objects
337  // update the irp (synchronization!)
338  // if we had one before complete the old irp with an error
339 
340  /* Get the IRP context and initialize it */
341  IrpContext = (PWMIP_IRP_CONTEXT)Irp->Tail.Overlay.DriverContext;
342  WmipInitializeIrpContext(IrpContext);
343 
344  // loop all objects
345  // insert the objects into the IRP list
346 
347  /* Set our cancel routine for cleanup */
349 
350  /* Check if the IRP is already being cancelled */
351  if (Irp->Cancel && IoSetCancelRoutine(Irp, NULL))
352  {
354  }
355  else
356  {
357  /* Mark the IRP as pending */
360  }
361 
362  return Status;
363 }
struct _WMI_NOTIFICATION * PWMI_NOTIFICATION
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
IoSetCancelRoutine(Irp, CancelRoutine)
struct _WMIP_IRP_CONTEXT * PWMIP_IRP_CONTEXT
_In_ PIRP Irp
Definition: csq.h:116
Definition: bufpool.h:45
Status
Definition: gdiplustypes.h:24
#define DBG_UNREFERENCED_LOCAL_VARIABLE(L)
Definition: ntbasedef.h:319
#define STATUS_PENDING
Definition: ntstatus.h:82
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
_In_ PWDFDEVICE_INIT _In_ PFN_WDF_DEVICE_SHUTDOWN_NOTIFICATION Notification
Definition: wdfcontrol.h:113
#define NULL
Definition: types.h:112
static VOID WmipInitializeIrpContext(PWMIP_IRP_CONTEXT IrpContext)
Definition: wmidrv.c:302
IoMarkIrpPending(Irp)
VOID NTAPI WmipNotificationIrpCancel(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: wmidrv.c:284

Referenced by WmipIoControl().

◆ WmipRegisterGuids()

static NTSTATUS WmipRegisterGuids ( _In_ PDEVICE_OBJECT  DeviceObject,
_In_ PVOID  Buffer,
_In_ ULONG  InputLength,
_Inout_ PULONG  OutputLength 
)
static

Definition at line 174 of file wmidrv.c.

179 {
182  OBJECT_ATTRIBUTES LocalObjectAttributes;
183  UNICODE_STRING LocalObjectName;
184  WCHAR LocalObjectNameBuffer[45 + 1];
186  HANDLE GuidObjectHandle;
187  PVOID GuidObject;
189 
190  /* Make sure the input buffer is large enough */
191  if ((InputLength < sizeof(WMIP_REGISTER_GUIDS)) ||
192  (RegisterGuids->RegInfo.BufferSize >
193  (InputLength - FIELD_OFFSET(WMIP_REGISTER_GUIDS, RegInfo))))
194  {
195  return STATUS_UNSUCCESSFUL;
196  }
197 
198  /* Make sure we have a resonable GUID count */
199  if ((RegisterGuids->RegInfo.GuidCount == 0) ||
200  (RegisterGuids->RegInfo.GuidCount > 0x10000))
201  {
202  return STATUS_UNSUCCESSFUL;
203  }
204 
205  /* Capture object attributes */
208  &LocalObjectAttributes,
209  &LocalObjectName,
210  LocalObjectNameBuffer,
211  PreviousMode);
212  if (!NT_SUCCESS(Status))
213  {
214  DPRINT1("WmipCaptureGuidObjectAttributes failed: 0x%lx\n", Status);
215  return Status;
216  }
217 
218  /* Open a new GUID object */
219  Status = WmipOpenGuidObjectByName(&LocalObjectAttributes,
221  PreviousMode,
222  &GuidObjectHandle,
223  &GuidObject);
224  if (!NT_SUCCESS(Status))
225  {
226  DPRINT1("WmipOpenGuidObjectByName failed: 0x%lx\n", Status);
227  return Status;
228  }
229 
230  /* Dereference the GUID object */
231  ObDereferenceObject(GuidObject);
232 
233  /* Return the handle (user mode will close it) */
234  Result->Handle = GuidObjectHandle;
235  Result->TraceHandle = 0;
236  *OutputLength = 24;
237 
238  return STATUS_SUCCESS;
239 }
static NTSTATUS WmipCaptureGuidObjectAttributes(_In_ POBJECT_ATTRIBUTES GuidObjectAttributes, _Out_ POBJECT_ATTRIBUTES CapuredObjectAttributes, _Out_ PUNICODE_STRING CapturedObjectName, _Out_ PWSTR ObjectNameBuffer, _In_ KPROCESSOR_MODE AccessMode)
Definition: wmidrv.c:121
LONG NTSTATUS
Definition: precomp.h:26
POBJECT_ATTRIBUTES ObjectAttributes
Definition: wmidrv.c:22
WMIREGINFOW RegInfo
Definition: wmidrv.c:29
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3066
struct _WMIP_RESULT * PWMIP_RESULT
ULONG GuidCount
Definition: wmistr.h:97
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
Definition: bufpool.h:45
Status
Definition: gdiplustypes.h:24
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
NTSTATUS NTAPI WmipOpenGuidObjectByName(_In_ POBJECT_ATTRIBUTES ObjectAttributes, _In_ ACCESS_MASK DesiredAccess, _In_ KPROCESSOR_MODE AccessMode, _Out_ PHANDLE OutGuidObjectHandle, _Outptr_ PVOID *OutGuidObject)
Definition: guidobj.c:262
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct _WMIP_REGISTER_GUIDS * PWMIP_REGISTER_GUIDS
#define ObDereferenceObject
Definition: obfuncs.h:203
#define SPECIFIC_RIGHTS_ALL
Definition: nt_native.h:71
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
ULONG BufferSize
Definition: wmistr.h:93
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define DPRINT1
Definition: precomp.h:8
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by WmipIoControl().

◆ WmipShutdown()

NTSTATUS NTAPI WmipShutdown ( _Inout_ PDEVICE_OBJECT  DeviceObject,
_Inout_ PIRP  Irp 
)

Definition at line 551 of file wmidrv.c.

554 {
555  Irp->IoStatus.Status = STATUS_SUCCESS;
557  return STATUS_SUCCESS;
558 }
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define STATUS_SUCCESS
Definition: shellext.h:65

◆ WmipSystemControl()

NTSTATUS NTAPI WmipSystemControl ( _Inout_ PDEVICE_OBJECT  DeviceObject,
_Inout_ PIRP  Irp 
)

Definition at line 541 of file wmidrv.c.

544 {
546  return STATUS_NOT_IMPLEMENTED;
547 }
return STATUS_NOT_IMPLEMENTED
#define UNIMPLEMENTED_DBGBREAK(...)
Definition: debug.h:57

◆ WmipUnregisterGuids()

static NTSTATUS WmipUnregisterGuids ( _In_ PVOID  Buffer,
_In_ ULONG  InputLength,
_Inout_ PULONG  OutputLength 
)
static

Definition at line 244 of file wmidrv.c.

248 {
249  /* For now we have nothing to do */
250  return STATUS_SUCCESS;
251 }
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by WmipIoControl().

◆ WmiSetMark()

static NTSTATUS WmiSetMark ( PWMI_SET_MARK  Buffer,
ULONG  Length 
)
static

Definition at line 438 of file wmidrv.c.

441 {
443  return STATUS_SUCCESS;
444 }
#define UNIMPLEMENTED
Definition: debug.h:115
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by WmipIoControl().

◆ WmiTraceEvent()

static NTSTATUS WmiTraceEvent ( PVOID  InputBuffer,
KPROCESSOR_MODE  PreviousMode 
)
static

Definition at line 101 of file wmidrv.c.

104 {
106  return STATUS_SUCCESS;
107 }
#define UNIMPLEMENTED_DBGBREAK(...)
Definition: debug.h:57
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by _Function_class_().

◆ WmiTraceUserMessage()

static NTSTATUS WmiTraceUserMessage ( PVOID  InputBuffer,
ULONG  InputBufferLength 
)
static

Definition at line 111 of file wmidrv.c.

114 {
116  return STATUS_SUCCESS;
117 }
#define UNIMPLEMENTED_DBGBREAK(...)
Definition: debug.h:57
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by _Function_class_().

Variable Documentation

◆ WmipAdminDeviceObject

PDEVICE_OBJECT WmipAdminDeviceObject

Definition at line 73 of file wmidrv.c.

Referenced by _Function_class_().

◆ WmipFastIoDispatch

FAST_IO_DISPATCH WmipFastIoDispatch

Definition at line 74 of file wmidrv.c.

Referenced by _Function_class_().

◆ WmipIoControl

DRIVER_DISPATCH WmipIoControl

Definition at line 80 of file wmidrv.c.

Referenced by _Function_class_().

◆ WmipOpenCloseCleanup

DRIVER_DISPATCH WmipOpenCloseCleanup

Definition at line 79 of file wmidrv.c.

Referenced by _Function_class_().

◆ WmipServiceDeviceObject

PDEVICE_OBJECT WmipServiceDeviceObject

Definition at line 72 of file wmidrv.c.

Referenced by _Function_class_().

◆ WmipShutdown

DRIVER_DISPATCH WmipShutdown

Definition at line 82 of file wmidrv.c.

Referenced by _Function_class_().

◆ WmipSystemControl

DRIVER_DISPATCH WmipSystemControl

Definition at line 81 of file wmidrv.c.

Referenced by _Function_class_().