ReactOS  0.4.14-dev-98-gb0d4763
fltsupport.c File Reference
#include <kmt_test.h>
#include "kmtest.h"
#include <kmt_public.h>
#include <assert.h>
#include <debug.h>
Include dependency graph for fltsupport.c:

Go to the source code of this file.

Classes

struct  _KMTFLT_MESSAGE_HEADER
 

Macros

#define KMT_FLT_USER_MODE
 

Typedefs

typedef struct _KMTFLT_MESSAGE_HEADER KMTFLT_MESSAGE_HEADER
 
typedef struct _KMTFLT_MESSAGE_HEADERPKMTFLT_MESSAGE_HEADER
 

Functions

KmtCloseService

Close the specified driver service handle

Parameters
ServiceHandlePointer to a variable containing the service handle. Will be set to NULL on success
Returns
Win32 error code
DWORD KmtpCreateService (IN PCWSTR ServiceName, IN PCWSTR ServicePath, IN PCWSTR DisplayName OPTIONAL, IN DWORD ServiceType, OUT SC_HANDLE *ServiceHandle)
 
KmtFltAddAltitude

Sets up the mini-filter altitude data in the registry

Parameters
hPortThe altitude string to set
Returns
Win32 error code
DWORD EnablePrivilegeInCurrentProcess (_In_z_ LPWSTR lpPrivName, _In_ BOOL bEnable)
 
DWORD KmtFltAddAltitude (_In_z_ LPWSTR Altitude)
 
DWORD EnablePrivilege (_In_ HANDLE hToken, _In_z_ LPWSTR lpPrivName, _In_ BOOL bEnable)
 
KmtFltCreateService

Create the specified driver service and return a handle to it

Parameters
ServiceNameName of the service to create
ServicePathFile name of the driver, relative to the current directory
DisplayNameService display name
ServiceHandlePointer to a variable to receive the handle to the service
Returns
Win32 error code
DWORD KmtFltCreateService (_In_z_ PCWSTR ServiceName, _In_z_ PCWSTR DisplayName, _Out_ SC_HANDLE *ServiceHandle)
 
KmtFltDeleteService

Delete the specified filter driver

Parameters
ServiceNameIf *ServiceHandle is NULL, name of the service to delete
ServiceHandlePointer to a variable containing the service handle. Will be set to NULL on success
Returns
Win32 error code
DWORD KmtFltDeleteService (_In_opt_z_ PCWSTR ServiceName, _Inout_ SC_HANDLE *ServiceHandle)
 
KmtFltLoadDriver

Delete the specified filter driver

Returns
Win32 error code
DWORD KmtFltLoadDriver (_In_ BOOLEAN EnableDriverLoadPrivlege, _In_ BOOLEAN RestartIfRunning, _In_ BOOLEAN ConnectComms, _Out_ HANDLE *hPort)
 
KmtFltUnloadDriver

Unload the specified filter driver

Parameters
hPortHandle to the filter's comms port
DisonnectCommsTRUE to disconnect the comms connection before unloading
Returns
Win32 error code
DWORD KmtFltUnloadDriver (_In_ HANDLE *hPort, _In_ BOOLEAN DisonnectComms)
 
KmtFltConnectComms

Create a comms connection to the specified filter

Parameters
hPortHandle to the filter's comms port
Returns
Win32 error code
DWORD KmtFltConnectComms (_Out_ HANDLE *hPort)
 
KmtFltDisconnectComms

Disconenct from the comms port

Parameters
hPortHandle to the filter's comms port
Returns
Win32 error code
DWORD KmtFltDisconnectComms (_In_ HANDLE hPort)
 
KmtFltCloseService

Close the specified driver service handle

Parameters
ServiceHandlePointer to a variable containing the service handle. Will be set to NULL on success
Returns
Win32 error code
DWORD KmtFltCloseService (_Inout_ SC_HANDLE *ServiceHandle)
 
KmtFltRunKernelTest

Run the specified filter test part

Parameters
hPortHandle to the filter's comms port
TestNameName of the test to run
Returns
Win32 error code
DWORD KmtFltRunKernelTest (_In_ HANDLE hPort, _In_z_ PCSTR TestName)
 
KmtFltSendToDriver

Send an I/O control message with no arguments to the driver opened with KmtOpenDriver

Parameters
hPortHandle to the filter's comms port
MessageThe message to send to the filter
Returns
Win32 error code
DWORD KmtFltSendToDriver (_In_ HANDLE hPort, _In_ DWORD Message)
 
KmtFltSendStringToDriver

Send an I/O control message with a string argument to the driver opened with KmtOpenDriver

Parameters
hPortHandle to the filter's comms port
MessageThe message associated with the string
StringAn ANSI string to send to the filter
Returns
Win32 error code
DWORD KmtFltSendStringToDriver (_In_ HANDLE hPort, _In_ DWORD Message, _In_ PCSTR String)
 
KmtFltSendWStringToDriver

Send an I/O control message with a wide string argument to the driver opened with KmtOpenDriver

Parameters
hPortHandle to the filter's comms port
MessageThe message associated with the string
StringAn wide string to send to the filter
Returns
Win32 error code
DWORD KmtFltSendWStringToDriver (_In_ HANDLE hPort, _In_ DWORD Message, _In_ PCWSTR String)
 
KmtFltSendUlongToDriver

Send an I/O control message with an integer argument to the driver opened with KmtOpenDriver

Parameters
hPortHandle to the filter's comms port
MessageThe message associated with the value
ValueAn 32bit valueng to send to the filter
Returns
Win32 error code
DWORD KmtFltSendUlongToDriver (_In_ HANDLE hPort, _In_ DWORD Message, _In_ DWORD Value)
 
KmtSendBufferToDriver

Send an I/O control message with the specified arguments to the driver opened with KmtOpenDriver

Parameters
hPortHandle to the filter's comms port
MessageThe message associated with the value
InBufferPointer to a buffer to send to the filter
BufferSizeSize of the buffer pointed to by InBuffer
OutBufferPointer to a buffer to receive a response from the filter
OutBufferSizeSize of the buffer pointed to by OutBuffer
BytesReturnedNumber of bytes written in the reply buffer
Returns
Win32 error code
DWORD KmtFltSendBufferToDriver (_In_ HANDLE hPort, _In_ DWORD Message, _In_reads_bytes_(BufferSize) LPVOID InBuffer, _In_ DWORD BufferSize, _Out_writes_bytes_to_opt_(OutBufferSize, *BytesReturned) LPVOID OutBuffer, _In_ DWORD OutBufferSize, _Out_opt_ LPDWORD BytesReturned)
 

Variables

HANDLE KmtestHandle
 
static WCHAR TestServiceName [MAX_PATH]
 

Macro Definition Documentation

◆ KMT_FLT_USER_MODE

#define KMT_FLT_USER_MODE

Definition at line 10 of file fltsupport.c.

Typedef Documentation

◆ KMTFLT_MESSAGE_HEADER

◆ PKMTFLT_MESSAGE_HEADER

Function Documentation

◆ EnablePrivilege()

DWORD EnablePrivilege ( _In_ HANDLE  hToken,
_In_z_ LPWSTR  lpPrivName,
_In_ BOOL  bEnable 
)

Definition at line 532 of file fltsupport.c.

536 {
538  LUID luid;
539  BOOL bSuccess;
540  DWORD dwError = ERROR_SUCCESS;
541 
542  /* Get the luid for this privilege */
543  if (!LookupPrivilegeValueW(NULL, lpPrivName, &luid))
544  return GetLastError();
545 
546  /* Setup the struct with the priv info */
547  TokenPrivileges.PrivilegeCount = 1;
548  TokenPrivileges.Privileges[0].Luid = luid;
549  TokenPrivileges.Privileges[0].Attributes = bEnable ? SE_PRIVILEGE_ENABLED : 0;
550 
551  /* Enable the privilege info in the token */
553  FALSE,
555  sizeof(TOKEN_PRIVILEGES),
556  NULL,
557  NULL);
558  if (bSuccess == FALSE) dwError = GetLastError();
559 
560  /* return status */
561  return dwError;
562 }
BOOL WINAPI LookupPrivilegeValueW(LPCWSTR lpSystemName, LPCWSTR lpPrivilegeName, PLUID lpLuid)
Definition: misc.c:782
#define ERROR_SUCCESS
Definition: deptool.c:10
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
static BOOLEAN bSuccess
Definition: drive.cpp:417
#define SE_PRIVILEGE_ENABLED
Definition: setypes.h:63
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL WINAPI AdjustTokenPrivileges(HANDLE TokenHandle, BOOL DisableAllPrivileges, PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength)
Definition: security.c:376
_In_ BOOL bEnable
Definition: winddi.h:3426

Referenced by EnablePrivilegeInCurrentProcess().

◆ EnablePrivilegeInCurrentProcess()

DWORD EnablePrivilegeInCurrentProcess ( _In_z_ LPWSTR  lpPrivName,
_In_ BOOL  bEnable 
)

Definition at line 564 of file fltsupport.c.

567 {
568  HANDLE hToken;
569  BOOL bSuccess;
570  DWORD dwError = ERROR_SUCCESS;
571 
572  /* Get a handle to our token */
575  &hToken);
576  if (bSuccess == FALSE) return GetLastError();
577 
578  /* Enable the privilege in the agent token */
579  dwError = EnablePrivilege(hToken, lpPrivName, bEnable);
580 
581  /* We're done with this now */
582  CloseHandle(hToken);
583 
584  /* return status */
585  return dwError;
586 }
#define CloseHandle
Definition: compat.h:398
#define ERROR_SUCCESS
Definition: deptool.c:10
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
static BOOLEAN bSuccess
Definition: drive.cpp:417
unsigned int BOOL
Definition: ntddk_ex.h:94
DWORD EnablePrivilege(_In_ HANDLE hToken, _In_z_ LPWSTR lpPrivName, _In_ BOOL bEnable)
Definition: fltsupport.c:532
#define TOKEN_QUERY
Definition: setypes.h:874
HANDLE WINAPI GetCurrentProcess(VOID)
Definition: proc.c:1138
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ BOOL bEnable
Definition: winddi.h:3426
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:296
#define TOKEN_ADJUST_PRIVILEGES
Definition: setypes.h:876

Referenced by KmtFltLoadDriver().

◆ KmtFltAddAltitude()

DWORD KmtFltAddAltitude ( _In_z_ LPWSTR  Altitude)

Definition at line 448 of file fltsupport.c.

450 {
451  WCHAR DefaultInstance[128];
452  WCHAR KeyPath[256];
453  HKEY hKey = NULL;
454  HKEY hSubKey = NULL;
455  DWORD Zero = 0;
456  LONG Error;
457 
458  StringCbCopy(KeyPath, sizeof KeyPath, L"SYSTEM\\CurrentControlSet\\Services\\");
459  StringCbCat(KeyPath, sizeof KeyPath, TestServiceName);
460  StringCbCat(KeyPath, sizeof KeyPath, L"\\Instances\\");
461 
463  KeyPath,
464  0,
465  NULL,
468  NULL,
469  &hKey,
470  NULL);
471  if (Error != ERROR_SUCCESS)
472  {
473  return Error;
474  }
475 
476  StringCbCopy(DefaultInstance, sizeof DefaultInstance, TestServiceName);
477  StringCbCat(DefaultInstance, sizeof DefaultInstance, L" Instance");
478 
479  Error = RegSetValueExW(hKey,
480  L"DefaultInstance",
481  0,
482  REG_SZ,
483  (LPBYTE)DefaultInstance,
484  (wcslen(DefaultInstance) + 1) * sizeof(WCHAR));
485  if (Error != ERROR_SUCCESS)
486  {
487  goto Quit;
488  }
489 
490  Error = RegCreateKeyW(hKey, DefaultInstance, &hSubKey);
491  if (Error != ERROR_SUCCESS)
492  {
493  goto Quit;
494  }
495 
496  Error = RegSetValueExW(hSubKey,
497  L"Altitude",
498  0,
499  REG_SZ,
500  (LPBYTE)Altitude,
501  (wcslen(Altitude) + 1) * sizeof(WCHAR));
502  if (Error != ERROR_SUCCESS)
503  {
504  goto Quit;
505  }
506 
507  Error = RegSetValueExW(hSubKey,
508  L"Flags",
509  0,
510  REG_DWORD,
511  (LPBYTE)&Zero,
512  sizeof(DWORD));
513 
514 Quit:
515  if (hSubKey)
516  {
517  RegCloseKey(hSubKey);
518  }
519  if (hKey)
520  {
521  RegCloseKey(hKey);
522  }
523 
524  return Error;
525 
526 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_SET_VALUE
Definition: nt_native.h:1017
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
_Must_inspect_result_ _Inout_ PFLT_VOLUME _In_ PCUNICODE_STRING Altitude
Definition: fltkernel.h:1172
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4895
#define StringCbCat
Definition: strsafe.h:334
static WCHAR TestServiceName[MAX_PATH]
Definition: fltsupport.c:42
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL Error
Definition: chkdsk.c:66
#define StringCbCopy
Definition: strsafe.h:155
static const WCHAR L[]
Definition: oid.c:1250
LONG WINAPI RegCreateKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:1199
IN PVCB IN VBO IN ULONG OUT PBCB OUT PVOID IN BOOLEAN IN BOOLEAN Zero
Definition: fatprocs.h:402
#define REG_DWORD
Definition: sdbapi.c:596
#define KEY_CREATE_SUB_KEY
Definition: nt_native.h:1018
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define RegCreateKeyEx
Definition: winreg.h:501
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define REG_SZ
Definition: layer.c:22

Referenced by START_TEST().

◆ KmtFltCloseService()

DWORD KmtFltCloseService ( _Inout_ SC_HANDLE *  ServiceHandle)

Definition at line 242 of file fltsupport.c.

244 {
245  return KmtCloseService(ServiceHandle);
246 }
DWORD KmtCloseService(IN OUT SC_HANDLE *ServiceHandle)
Definition: service.c:392

◆ KmtFltConnectComms()

DWORD KmtFltConnectComms ( _Out_ HANDLE hPort)

Definition at line 207 of file fltsupport.c.

209 {
210  return KmtFltConnect(TestServiceName, hPort);
211 }
static WCHAR TestServiceName[MAX_PATH]
Definition: fltsupport.c:42
DWORD KmtFltConnect(_In_z_ PCWSTR ServiceName, _Out_ HANDLE *hPort)
Definition: filter.c:119

Referenced by KmtFltLoadDriver(), and START_TEST().

◆ KmtFltCreateService()

DWORD KmtFltCreateService ( _In_z_ PCWSTR  ServiceName,
_In_z_ PCWSTR  DisplayName,
_Out_ SC_HANDLE *  ServiceHandle 
)

Definition at line 63 of file fltsupport.c.

67 {
68  WCHAR ServicePath[MAX_PATH];
69 
70  StringCbCopy(ServicePath, sizeof ServicePath, ServiceName);
71  StringCbCat(ServicePath, sizeof ServicePath, L"_drv.sys");
72 
73  StringCbCopy(TestServiceName, sizeof TestServiceName, L"Kmtest-");
75 
77  ServicePath,
78  DisplayName,
80  ServiceHandle);
81 }
DWORD KmtpCreateService(IN PCWSTR ServiceName, IN PCWSTR ServicePath, IN PCWSTR DisplayName OPTIONAL, IN DWORD ServiceType, OUT SC_HANDLE *ServiceHandle)
Definition: service.c:414
#define SERVICE_FILE_SYSTEM_DRIVER
Definition: cmtypes.h:952
#define StringCbCat
Definition: strsafe.h:334
LPTSTR ServiceName
Definition: ServiceMain.c:15
static WCHAR TestServiceName[MAX_PATH]
Definition: fltsupport.c:42
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
#define StringCbCopy
Definition: strsafe.h:155
static const WCHAR L[]
Definition: oid.c:1250

Referenced by START_TEST().

◆ KmtFltDeleteService()

DWORD KmtFltDeleteService ( _In_opt_z_ PCWSTR  ServiceName,
_Inout_ SC_HANDLE *  ServiceHandle 
)

Definition at line 97 of file fltsupport.c.

100 {
101  return KmtDeleteService(ServiceName, ServiceHandle);
102 }
LPTSTR ServiceName
Definition: ServiceMain.c:15
DWORD KmtDeleteService(IN PCWSTR ServiceName OPTIONAL, IN OUT SC_HANDLE *ServiceHandle)
Definition: service.c:356

Referenced by START_TEST().

◆ KmtFltDisconnectComms()

DWORD KmtFltDisconnectComms ( _In_ HANDLE  hPort)

Definition at line 224 of file fltsupport.c.

226 {
227  return KmtFltDisconnect(hPort);
228 }
DWORD KmtFltDisconnect(_In_ HANDLE hPort)
Definition: filter.c:151

Referenced by START_TEST().

◆ KmtFltLoadDriver()

DWORD KmtFltLoadDriver ( _In_ BOOLEAN  EnableDriverLoadPrivlege,
_In_ BOOLEAN  RestartIfRunning,
_In_ BOOLEAN  ConnectComms,
_Out_ HANDLE hPort 
)

Definition at line 112 of file fltsupport.c.

118 {
119  DWORD Error;
120 
121  if (EnableDriverLoadPrivlege)
122  {
124  if (Error)
125  {
126  return Error;
127  }
128  }
129 
131  if ((Error == ERROR_SERVICE_ALREADY_RUNNING) && RestartIfRunning)
132  {
134  if (Error)
135  {
136  // TODO
137  __debugbreak();
138  }
139 
141  }
142 
143  if (Error)
144  {
145  return Error;
146  }
147 
148  if (ConnectComms)
149  {
150  Error = KmtFltConnectComms(hPort);
151  }
152 
153  return Error;
154 }
#define TRUE
Definition: types.h:120
void __cdecl __debugbreak(void)
Definition: intrin_ppc.h:698
DWORD EnablePrivilegeInCurrentProcess(_In_z_ LPWSTR lpPrivName, _In_ BOOL bEnable)
Definition: fltsupport.c:564
static WCHAR TestServiceName[MAX_PATH]
Definition: fltsupport.c:42
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL Error
Definition: chkdsk.c:66
DWORD KmtFltLoad(_In_z_ PCWSTR ServiceName)
Definition: filter.c:30
DWORD KmtFltConnectComms(_Out_ HANDLE *hPort)
Definition: fltsupport.c:207
DWORD KmtFltUnload(_In_z_ PCWSTR ServiceName)
Definition: filter.c:336
#define ERROR_SERVICE_ALREADY_RUNNING
Definition: winerror.h:607
#define SE_LOAD_DRIVER_NAME
Definition: winnt_old.h:374

Referenced by START_TEST().

◆ KmtFltRunKernelTest()

DWORD KmtFltRunKernelTest ( _In_ HANDLE  hPort,
_In_z_ PCSTR  TestName 
)

Definition at line 261 of file fltsupport.c.

264 {
265  return KmtFltSendStringToDriver(hPort, KMTFLT_RUN_TEST, TestName);
266 }
#define KMTFLT_RUN_TEST
Definition: kmt_public.h:30
DWORD KmtFltSendStringToDriver(_In_ HANDLE hPort, _In_ DWORD Message, _In_ PCSTR String)
Definition: fltsupport.c:305

◆ KmtFltSendBufferToDriver()

DWORD KmtFltSendBufferToDriver ( _In_ HANDLE  hPort,
_In_ DWORD  Message,
_In_reads_bytes_(BufferSize) LPVOID  InBuffer,
_In_ DWORD  BufferSize,
_Out_writes_bytes_to_opt_(OutBufferSize, *BytesReturned) LPVOID  OutBuffer,
_In_ DWORD  OutBufferSize,
_Out_opt_ LPDWORD  BytesReturned 
)

Definition at line 384 of file fltsupport.c.

392 {
397  DWORD Error;
398 
399  assert(hPort);
400 
401  if (BufferSize)
402  {
403  assert(InBuffer);
404 
407  if (!Ptr)
408  {
410  }
411  FreeMemory = TRUE;
412  }
413  else
414  {
416  Ptr = &Header;
417  }
418 
419  Ptr->Message = Message;
420  if (BufferSize)
421  {
422  Ptr->Buffer = (Ptr + 1);
423  StringCbCopy(Ptr->Buffer, BufferSize, InBuffer);
424  Ptr->BufferSize = BufferSize;
425  }
426 
428 
429  if (FreeMemory)
430  {
431  HeapFree(GetProcessHeap(), 0, Ptr);
432  }
433 
434  return Error;
435 }
static VOID FreeMemory(PCREATE_DATA Data)
Definition: create.c:134
#define TRUE
Definition: types.h:120
DWORD KmtFltSendMessage(_In_ HANDLE hPort, _In_reads_bytes_(dwInBufferSize) LPVOID InBuffer, _In_ DWORD InBufferSize, _Out_writes_bytes_to_opt_(dutBufferSize, *BytesReturned) LPVOID OutBuffer, _In_ DWORD OutBufferSize, _Out_opt_ LPDWORD BytesReturned)
Definition: filter.c:187
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
_In_ PIRP _In_ ULONG _In_ ULONG _In_ ULONG _In_ ULONG OutBufferSize
Definition: classpnp.h:429
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define assert(x)
Definition: debug.h:53
struct _KMTFLT_MESSAGE_HEADER KMTFLT_MESSAGE_HEADER
Definition: Header.h:8
unsigned char BOOLEAN
_In_ PIRP _In_ ULONG _In_ ULONG _In_ ULONG InBufferSize
Definition: classpnp.h:429
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define BufferSize
Definition: classpnp.h:419
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL Error
Definition: chkdsk.c:66
CHAR Message[80]
Definition: alive.c:5
#define StringCbCopy
Definition: strsafe.h:155
_In_ FILTER_INFORMATION_CLASS _In_ ULONG _Out_ PULONG BytesReturned
Definition: fltkernel.h:1716
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define HeapFree(x, y, z)
Definition: compat.h:394

Referenced by KmtFltSendStringToDriver(), KmtFltSendToDriver(), KmtFltSendUlongToDriver(), and KmtFltSendWStringToDriver().

◆ KmtFltSendStringToDriver()

DWORD KmtFltSendStringToDriver ( _In_ HANDLE  hPort,
_In_ DWORD  Message,
_In_ PCSTR  String 
)

Definition at line 305 of file fltsupport.c.

309 {
310  assert(hPort);
311  assert(String);
313 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define assert(x)
Definition: debug.h:53
static WCHAR String[]
Definition: stringtable.c:55
smooth NULL
Definition: ftsmooth.c:416
DWORD KmtFltSendBufferToDriver(_In_ HANDLE hPort, _In_ DWORD Message, _In_reads_bytes_(BufferSize) LPVOID InBuffer, _In_ DWORD BufferSize, _Out_writes_bytes_to_opt_(OutBufferSize, *BytesReturned) LPVOID OutBuffer, _In_ DWORD OutBufferSize, _Out_opt_ LPDWORD BytesReturned)
Definition: fltsupport.c:384
unsigned long DWORD
Definition: ntddk_ex.h:95
CHAR Message[80]
Definition: alive.c:5

Referenced by KmtFltRunKernelTest().

◆ KmtFltSendToDriver()

DWORD KmtFltSendToDriver ( _In_ HANDLE  hPort,
_In_ DWORD  Message 
)

Definition at line 281 of file fltsupport.c.

284 {
285  assert(hPort);
286  return KmtFltSendBufferToDriver(hPort, Message, NULL, 0, NULL, 0, NULL);
287 }
#define assert(x)
Definition: debug.h:53
smooth NULL
Definition: ftsmooth.c:416
DWORD KmtFltSendBufferToDriver(_In_ HANDLE hPort, _In_ DWORD Message, _In_reads_bytes_(BufferSize) LPVOID InBuffer, _In_ DWORD BufferSize, _Out_writes_bytes_to_opt_(OutBufferSize, *BytesReturned) LPVOID OutBuffer, _In_ DWORD OutBufferSize, _Out_opt_ LPDWORD BytesReturned)
Definition: fltsupport.c:384
CHAR Message[80]
Definition: alive.c:5

◆ KmtFltSendUlongToDriver()

DWORD KmtFltSendUlongToDriver ( _In_ HANDLE  hPort,
_In_ DWORD  Message,
_In_ DWORD  Value 
)

Definition at line 353 of file fltsupport.c.

357 {
358  return KmtFltSendBufferToDriver(hPort, Message, &Value, sizeof(Value), NULL, 0, NULL);
359 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2343
smooth NULL
Definition: ftsmooth.c:416
DWORD KmtFltSendBufferToDriver(_In_ HANDLE hPort, _In_ DWORD Message, _In_reads_bytes_(BufferSize) LPVOID InBuffer, _In_ DWORD BufferSize, _Out_writes_bytes_to_opt_(OutBufferSize, *BytesReturned) LPVOID OutBuffer, _In_ DWORD OutBufferSize, _Out_opt_ LPDWORD BytesReturned)
Definition: fltsupport.c:384
CHAR Message[80]
Definition: alive.c:5

◆ KmtFltSendWStringToDriver()

DWORD KmtFltSendWStringToDriver ( _In_ HANDLE  hPort,
_In_ DWORD  Message,
_In_ PCWSTR  String 
)

Definition at line 330 of file fltsupport.c.

334 {
335  return KmtFltSendBufferToDriver(hPort, Message, (PVOID)String, (DWORD)wcslen(String) * sizeof(WCHAR), NULL, 0, NULL);
336 }
static WCHAR String[]
Definition: stringtable.c:55
smooth NULL
Definition: ftsmooth.c:416
DWORD KmtFltSendBufferToDriver(_In_ HANDLE hPort, _In_ DWORD Message, _In_reads_bytes_(BufferSize) LPVOID InBuffer, _In_ DWORD BufferSize, _Out_writes_bytes_to_opt_(OutBufferSize, *BytesReturned) LPVOID OutBuffer, _In_ DWORD OutBufferSize, _Out_opt_ LPDWORD BytesReturned)
Definition: fltsupport.c:384
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
CHAR Message[80]
Definition: alive.c:5
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

◆ KmtFltUnloadDriver()

DWORD KmtFltUnloadDriver ( _In_ HANDLE hPort,
_In_ BOOLEAN  DisonnectComms 
)

Definition at line 169 of file fltsupport.c.

172 {
174 
175  if (DisonnectComms)
176  {
177  Error = KmtFltDisconnect(hPort);
178 
179  if (Error)
180  {
181  return Error;
182  }
183  }
184 
186 
187  if (Error)
188  {
189  // TODO
190  __debugbreak();
191  }
192 
193  return Error;
194 }
#define ERROR_SUCCESS
Definition: deptool.c:10
void __cdecl __debugbreak(void)
Definition: intrin_ppc.h:698
static WCHAR TestServiceName[MAX_PATH]
Definition: fltsupport.c:42
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL Error
Definition: chkdsk.c:66
DWORD KmtFltUnload(_In_z_ PCWSTR ServiceName)
Definition: filter.c:336
DWORD KmtFltDisconnect(_In_ HANDLE hPort)
Definition: filter.c:151

Referenced by START_TEST().

◆ KmtpCreateService()

DWORD KmtpCreateService ( IN PCWSTR  ServiceName,
IN PCWSTR  ServicePath,
IN PCWSTR DisplayName  OPTIONAL,
IN DWORD  ServiceType,
OUT SC_HANDLE *  ServiceHandle 
)

Definition at line 414 of file service.c.

420 {
422  WCHAR DriverPath[MAX_PATH];
423  HRESULT result = S_OK;
424 
425  assert(ServiceHandle);
426  assert(ServiceName && ServicePath);
427 
428  if (!GetModuleFileName(NULL, DriverPath, sizeof DriverPath / sizeof DriverPath[0]))
430 
431  assert(wcsrchr(DriverPath, L'\\') != NULL);
432  wcsrchr(DriverPath, L'\\')[1] = L'\0';
433 
434  result = StringCbCat(DriverPath, sizeof DriverPath, ServicePath);
435  if (FAILED(result))
437 
438  if (GetFileAttributes(DriverPath) == INVALID_FILE_ATTRIBUTES)
440 
441  *ServiceHandle = CreateService(ScmHandle, ServiceName, DisplayName,
442  SERVICE_ACCESS, ServiceType, SERVICE_DEMAND_START,
443  SERVICE_ERROR_NORMAL, DriverPath, NULL, NULL, NULL, NULL, NULL);
444 
445  if (!*ServiceHandle)
447 
448 cleanup:
449  return Error;
450 }
#define SERVICE_ACCESS
Definition: service.c:15
#define SERVICE_ERROR_NORMAL
Definition: cmtypes.h:980
#define ERROR_SUCCESS
Definition: deptool.c:10
#define error_goto(Error, label)
Definition: kmtest.h:21
#define assert(x)
Definition: debug.h:53
#define CreateService
Definition: winsvc.h:569
smooth NULL
Definition: ftsmooth.c:416
_Check_return_ _CRTIMP _CONST_RETURN wchar_t *__cdecl wcsrchr(_In_z_ const wchar_t *_Str, _In_ wchar_t _Ch)
#define StringCbCat
Definition: strsafe.h:334
LPTSTR ServiceName
Definition: ServiceMain.c:15
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL Error
Definition: chkdsk.c:66
#define GetModuleFileName
Definition: winbase.h:3655
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
static const WCHAR L[]
Definition: oid.c:1250
#define GetFileAttributes
Definition: winbase.h:3639
#define S_OK
Definition: intsafe.h:59
#define error_value_goto(Error, value, label)
Definition: kmtest.h:22
char * cleanup(char *str)
Definition: wpickclick.c:99
#define SERVICE_DEMAND_START
Definition: cmtypes.h:976
GLuint64EXT * result
Definition: glext.h:11304
static SC_HANDLE ScmHandle
Definition: service.c:30

Referenced by KmtCreateService(), and KmtFltCreateService().

Variable Documentation

◆ KmtestHandle

HANDLE KmtestHandle

Definition at line 32 of file kmtest.c.

◆ TestServiceName

WCHAR TestServiceName[MAX_PATH]
static