ReactOS  r75919
DriverTester.h File Reference
#include <windows.h>
#include <stdio.h>
#include <winternl.h>
Include dependency graph for DriverTester.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _SYSTEM_GDI_DRIVER_INFORMATION
 
struct  _OBJECT_NAME_INFORMATION
 

Macros

#define _WIN32_WINNT   0x0500
 
#define DRIVER_NAME   L"TestDriver"
 
#define STATUS_SUCCESS   ((NTSTATUS)0x00000000L)
 
#define STATUS_PRIVILEGE_NOT_HELD   ((NTSTATUS)0xC0000061L)
 
#define SystemLoadGdiDriverInformation   26
 
#define SystemExtendServiceTableInformation   38
 

Typedefs

typedef LONG NTSTATUS
 
typedef struct
_SYSTEM_GDI_DRIVER_INFORMATION 
SYSTEM_GDI_DRIVER_INFORMATION
 
typedef struct
_SYSTEM_GDI_DRIVER_INFORMATION
PSYSTEM_GDI_DRIVER_INFORMATION
 
typedef enum
_OBJECT_INFORMATION_CLASS 
OBJECT_INFO_CLASS
 
typedef struct
_OBJECT_NAME_INFORMATION 
OBJECT_NAME_INFORMATION
 
typedef struct
_OBJECT_NAME_INFORMATION
POBJECT_NAME_INFORMATION
 

Enumerations

enum  _OBJECT_INFORMATION_CLASS {
  ObjectBasicInformation, ObjectNameInformation, ObjectTypeInformation, ObjectAllTypesInformation,
  ObjectHandleInformation, ObjectBasicInformation = 0, ObjectTypeInformation = 2, ObjectBasicInformation,
  ObjectNameInformation, ObjectTypeInformation, ObjectTypesInformation, ObjectDataInformation
}
 

Functions

BOOL RegisterDriver (LPCWSTR lpDriverName, LPCWSTR lpPathName)
 
BOOL StartDriver (LPCWSTR lpDriverName)
 
BOOL StopDriver (LPCWSTR lpDriverName)
 
BOOL UnregisterDriver (LPCWSTR lpDriverName)
 
BOOL ConvertPath (LPCWSTR lpPath, LPWSTR lpDevice)
 
BOOL LoadVia_SystemLoadGdiDriverInformation (LPWSTR lpDriverPath)
 
BOOL LoadVia_SystemExtendServiceTableInformation (LPWSTR lpDriverPath)
 
BOOL NtStartDriver (LPCWSTR lpService)
 
BOOL NtStopDriver (LPCWSTR lpService)
 
NTSYSAPI NTSTATUS NTAPI NtSetSystemInformation (IN INT SystemInformationClass, IN PVOID SystemInformation, IN ULONG SystemInformationLength)
 
NTSTATUS NtUnloadDriver (IN PUNICODE_STRING DriverServiceName)
 
NTSTATUS NtQueryObject (IN HANDLE Handle, IN OBJECT_INFO_CLASS ObjectInformationClass, OUT PVOID ObjectInformation, IN ULONG ObjectInformationLength, OUT PULONG ReturnLength)
 

Macro Definition Documentation

#define _WIN32_WINNT   0x0500

Definition at line 1 of file DriverTester.h.

#define DRIVER_NAME   L"TestDriver"

Definition at line 6 of file DriverTester.h.

#define STATUS_PRIVILEGE_NOT_HELD   ((NTSTATUS)0xC0000061L)

Definition at line 9 of file DriverTester.h.

Referenced by add_device(), CdInvalidateVolumes(), EmptyWorkingSet(), ExpRaiseHardError(), Ext2InvalidateVolumes(), FFSInvalidateVolumes(), find_subvol(), FormatEx2(), fsctl_set_xattr(), invalidate_volumes(), KbdHid_ReadCompletion(), KsRemoveBusEnumInterface(), LoadVia_SystemExtendServiceTableInformation(), LoadVia_SystemLoadGdiDriverInformation(), mknod(), MmAdjustWorkingSetSize(), MouHid_ReadCompletion(), NtAllocateVirtualMemory(), NtCloseObjectAuditAlarm(), NtCreateProfile(), NtGetPlugPlayEvent(), NtLoadDriver(), NtLoadKeyEx(), NtLockVirtualMemory(), NtMakePermanentObject(), NtOpenObjectAuditAlarm(), NtPlugPlayControl(), NtPrivilegedServiceAuditAlarm(), NtQuerySystemEnvironmentValue(), NtSaveKeyEx(), NtSaveMergedKeys(), NtSetDefaultHardErrorPort(), NtSetInformationObject(), NtSetInformationProcess(), NtSetInformationThread(), NtSetInformationToken(), NtSetSystemEnvironmentValue(), NtSetSystemPowerState(), NtSetSystemTime(), NtUnloadKey2(), NtUnlockVirtualMemory(), ObCreateObject(), pause_balance(), pause_scrub(), probe_volume(), PspSetPrimaryToken(), PspSetQuotaLimits(), query_scrub(), read_send_buffer(), recvd_subvol(), remove_device(), reserve_subvol(), reset_stats(), resize_device(), resume_balance(), resume_scrub(), RfsdInvalidateVolumes(), RtlAcquirePrivilege(), RtlAdjustPrivilege(), run_error_tests(), send_subvol(), SepAccessCheckAndAuditAlarm(), SePrivilegePolicyCheck(), SmpAcquirePrivilege(), SSI_DEF(), start_balance(), start_scrub(), START_TEST(), stop_balance(), stop_scrub(), test_CallNtPowerInformation(), Test_TimeAdjustment(), TestHardError(), UDFInvalidateVolumes(), and UserInitiateShutdown().

#define STATUS_SUCCESS   ((NTSTATUS)0x00000000L)

Definition at line 8 of file DriverTester.h.

#define SystemExtendServiceTableInformation   38
#define SystemLoadGdiDriverInformation   26

Definition at line 34 of file DriverTester.h.

Referenced by LDEVOBJ_bLoadImage(), and LoadVia_SystemLoadGdiDriverInformation().

Typedef Documentation

typedef NTSTATUS

Definition at line 11 of file DriverTester.h.

Enumeration Type Documentation

Enumerator
ObjectBasicInformation 
ObjectNameInformation 
ObjectTypeInformation 
ObjectAllTypesInformation 
ObjectHandleInformation 
ObjectBasicInformation 
ObjectTypeInformation 
ObjectBasicInformation 
ObjectNameInformation 
ObjectTypeInformation 
ObjectTypesInformation 
ObjectDataInformation 

Definition at line 53 of file DriverTester.h.

Function Documentation

BOOL ConvertPath ( LPCWSTR  lpPath,
LPWSTR  lpDevice 
)

Definition at line 56 of file undoc.c.

Referenced by SneakyUndocumentedMethods().

58 {
59  LPWSTR lpFullPath = NULL;
60  DWORD size;
61 
62  if (lpPath)
63  {
64  size = GetLongPathNameW(lpPath,
65  0,
66  0);
67  if (!size)
68  return FALSE;
69 
70  size = (size + 1) * sizeof(WCHAR);
71 
72  lpFullPath = HeapAlloc(GetProcessHeap(),
73  0,
74  size);
75  if (!lpFullPath)
76  return FALSE;
77 
78  if (GetLongPathNameW(lpPath,
79  lpFullPath,
80  size))
81  {
85  DWORD len;
86 
87  hDevice = CreateFileW(lpFullPath,
89  0,
90  NULL,
93  NULL);
94 
95  HeapFree(GetProcessHeap(), 0, lpFullPath);
96 
97  if(hDevice == INVALID_HANDLE_VALUE)
98  {
99  wprintf(L"[%x] Failed to open %s\n", GetLastError(), DRIVER_NAME);
100  return FALSE;
101  }
102 
103  size = MAX_PATH * sizeof(WCHAR);
104  pObjName = HeapAlloc(GetProcessHeap(), 0, size);
105  if (!pObjName)
106  return FALSE;
107 
108  Status = NtQueryObject(hDevice,
110  pObjName,
111  size,
112  &size);
113  if (Status == STATUS_SUCCESS)
114  {
115  len = pObjName->Name.Length / sizeof(WCHAR);
116  wcsncpy(lpDevice, pObjName->Name.Buffer, len);
117  lpDevice[len] = UNICODE_NULL;
118 
119  HeapFree(GetProcessHeap(), 0, pObjName);
120 
121  return TRUE;
122  }
123 
124  HeapFree(GetProcessHeap(), 0, pObjName);
125  }
126  }
127 
128  return FALSE;
129 }
#define TRUE
Definition: types.h:120
Definition: bidi.c:75
__wchar_t WCHAR
Definition: xmlstorage.h:180
return STATUS_SUCCESS
Definition: btrfs.c:2664
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
#define wprintf(...)
Definition: whoami.c:18
#define WCHAR
Definition: msvc.h:43
DWORD DWORD
Definition: winlogon.h:75
#define FALSE
Definition: types.h:117
#define UNICODE_NULL
#define GENERIC_WRITE
Definition: nt_native.h:90
smooth NULL
Definition: ftsmooth.c:513
static POBJECTS_AND_NAME_A pObjName
Definition: security.c:80
#define OPEN_EXISTING
Definition: compat.h:426
DWORD WINAPI GetLongPathNameW(IN LPCWSTR lpszShortPath, OUT LPWSTR lpszLongPath, IN DWORD cchBuffer)
Definition: path.c:1454
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
NTSTATUS NtQueryObject(IN HANDLE Handle, IN OBJECT_INFO_CLASS ObjectInformationClass, OUT PVOID ObjectInformation, IN ULONG ObjectInformationLength, OUT PULONG ReturnLength)
#define MAX_PATH
Definition: compat.h:26
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define DRIVER_NAME
Definition: ext2fs.h:135
GLenum GLsizei len
Definition: glext.h:6722
#define GENERIC_READ
Definition: compat.h:124
HVIDEOINPUTDEVICENV hDevice
Definition: wglext.h:889
Status
Definition: gdiplustypes.h:24
DWORD *typedef HANDLE
Definition: winlogon.h:52
LONG NTSTATUS
Definition: DriverTester.h:11
_CRTIMP wchar_t *__cdecl wcsncpy(wchar_t *_Dest, const wchar_t *_Source, size_t _Count)
GLsizeiptr size
Definition: glext.h:5919
#define CreateFileW
Definition: compat.h:400
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define HeapFree(x, y, z)
Definition: compat.h:394
BOOL LoadVia_SystemExtendServiceTableInformation ( LPWSTR  lpDriverPath)

Definition at line 240 of file undoc.c.

Referenced by SneakyUndocumentedMethods().

241 {
244  DWORD bufSize;
245 
246  RtlInitUnicodeString(&Buffer, lpDriverPath);
247  bufSize = sizeof(UNICODE_STRING);
248 
249  if (SetPrivilege(TRUE))
250  {
252  &Buffer,
253  bufSize);
254  if (Status == STATUS_PRIVILEGE_NOT_HELD)
255  {
256  wprintf(L"SystemExtendServiceTableInformation can only be used in kmode.\n");
257  }
258  else if (Status == STATUS_SUCCESS)
259  {
260  wprintf(L"SystemExtendServiceTableInformation incorrectly loaded the driver\n");
261  NtUnloadDriver(&Buffer);
262 
263  return TRUE;
264  }
265  else
266  {
267  DWORD err = RtlNtStatusToDosError(Status);
268  wprintf(L"LoadVia_SystemExtendServiceTableInformation failed [%lu] - 0x%x\n", err, Status);
269  }
270 
272  }
273 
274  return FALSE;
275 }
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
#define TRUE
Definition: types.h:120
Definition: bidi.c:75
return STATUS_SUCCESS
Definition: btrfs.c:2664
ULONG NTAPI RtlNtStatusToDosError(IN NTSTATUS Status)
Definition: error.c:96
#define wprintf(...)
Definition: whoami.c:18
DWORD DWORD
Definition: winlogon.h:75
GLuint GLsizei bufSize
Definition: glext.h:6040
#define FALSE
Definition: types.h:117
int int int * err
Definition: fci.h:172
NTSYSAPI NTSTATUS NTAPI NtSetSystemInformation(IN INT SystemInformationClass, IN PVOID SystemInformation, IN ULONG SystemInformationLength)
UINTN VOID * Buffer
Definition: acefiex.h:370
#define SystemExtendServiceTableInformation
Definition: DriverTester.h:35
static BOOL SetPrivilege(BOOL bSet)
Definition: undoc.c:4
Status
Definition: gdiplustypes.h:24
LONG NTSTATUS
Definition: DriverTester.h:11
NTSTATUS NtUnloadDriver(IN PUNICODE_STRING DriverServiceName)
Definition: driver.c:2092
struct _UNICODE_STRING UNICODE_STRING
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
BOOL LoadVia_SystemLoadGdiDriverInformation ( LPWSTR  lpDriverPath)

Definition at line 199 of file undoc.c.

Referenced by SneakyUndocumentedMethods().

200 {
203  DWORD bufSize;
204 
205  bufSize = sizeof(SYSTEM_GDI_DRIVER_INFORMATION);
206 
207  ZeroMemory(&Buffer, bufSize);
208  RtlInitUnicodeString(&Buffer.DriverName, lpDriverPath);
209 
210  if (SetPrivilege(TRUE))
211  {
213  &Buffer,
214  bufSize);
215  if (Status == STATUS_PRIVILEGE_NOT_HELD)
216  {
217  wprintf(L"SystemLoadGdiDriverInformation can only be used in kmode.\n");
218  }
219  else if (Status == STATUS_SUCCESS)
220  {
221  wprintf(L"SystemLoadGdiDriverInformation incorrectly loaded the driver\n");
222  NtUnloadDriver(&Buffer.DriverName);
223 
224  return TRUE;
225  }
226  else
227  {
228  DWORD err = RtlNtStatusToDosError(Status);
229  wprintf(L"LoadVia_SystemLoadGdiDriverInformation failed [%lu]\n", err);
230  }
231 
233  }
234 
235  return FALSE;
236 }
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
#define TRUE
Definition: types.h:120
Definition: bidi.c:75
return STATUS_SUCCESS
Definition: btrfs.c:2664
ULONG NTAPI RtlNtStatusToDosError(IN NTSTATUS Status)
Definition: error.c:96
#define ZeroMemory
Definition: winbase.h:1621
#define wprintf(...)
Definition: whoami.c:18
DWORD DWORD
Definition: winlogon.h:75
GLuint GLsizei bufSize
Definition: glext.h:6040
#define FALSE
Definition: types.h:117
int int int * err
Definition: fci.h:172
NTSYSAPI NTSTATUS NTAPI NtSetSystemInformation(IN INT SystemInformationClass, IN PVOID SystemInformation, IN ULONG SystemInformationLength)
UINTN VOID * Buffer
Definition: acefiex.h:370
static BOOL SetPrivilege(BOOL bSet)
Definition: undoc.c:4
Status
Definition: gdiplustypes.h:24
#define SystemLoadGdiDriverInformation
Definition: DriverTester.h:34
LONG NTSTATUS
Definition: DriverTester.h:11
NTSTATUS NtUnloadDriver(IN PUNICODE_STRING DriverServiceName)
Definition: driver.c:2092
struct _SYSTEM_GDI_DRIVER_INFORMATION SYSTEM_GDI_DRIVER_INFORMATION
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSTATUS NtQueryObject ( IN HANDLE  Handle,
IN OBJECT_INFO_CLASS  ObjectInformationClass,
OUT PVOID  ObjectInformation,
IN ULONG  ObjectInformationLength,
OUT PULONG  ReturnLength 
)
BOOL NtStartDriver ( LPCWSTR  lpService)

Definition at line 133 of file undoc.c.

Referenced by UndocumentedMethod().

134 {
135  WCHAR szDriverPath[MAX_PATH];
136  UNICODE_STRING DriverPath;
137  NTSTATUS Status = -1;
138 
139  wcscpy(szDriverPath,
140  L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\");
141  wcscat(szDriverPath,
142  lpService);
143 
144  RtlInitUnicodeString(&DriverPath,
145  szDriverPath);
146 
147  if (SetPrivilege(TRUE))
148  {
149  Status = NtLoadDriver(&DriverPath);
150  if (Status != STATUS_SUCCESS)
151  {
152  DWORD err = RtlNtStatusToDosError(Status);
153  wprintf(L"NtUnloadDriver failed [%lu]\n", err);
154  }
155 
157  }
158 
159  return (Status == STATUS_SUCCESS);
160 }
#define TRUE
Definition: types.h:120
Definition: bidi.c:75
__wchar_t WCHAR
Definition: xmlstorage.h:180
return STATUS_SUCCESS
Definition: btrfs.c:2664
ULONG NTAPI RtlNtStatusToDosError(IN NTSTATUS Status)
Definition: error.c:96
#define wprintf(...)
Definition: whoami.c:18
DWORD DWORD
Definition: winlogon.h:75
#define FALSE
Definition: types.h:117
int int int * err
Definition: fci.h:172
#define MAX_PATH
Definition: compat.h:26
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static BOOL SetPrivilege(BOOL bSet)
Definition: undoc.c:4
Status
Definition: gdiplustypes.h:24
LONG NTSTATUS
Definition: DriverTester.h:11
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSTATUS NTAPI NtLoadDriver(IN PUNICODE_STRING DriverServiceName)
Definition: driver.c:2031
BOOL NtStopDriver ( LPCWSTR  lpService)

Definition at line 164 of file undoc.c.

Referenced by SneakyUndocumentedMethods(), and UndocumentedMethod().

165 {
166  WCHAR szDriverPath[MAX_PATH];
167  UNICODE_STRING DriverPath;
168  NTSTATUS Status = -1;
169 
170  wcscpy(szDriverPath,
171  L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\");
172  wcscat(szDriverPath,
173  lpService);
174 
175  RtlInitUnicodeString(&DriverPath,
176  szDriverPath);
177 
178  if (SetPrivilege(TRUE))
179  {
180  Status = NtUnloadDriver(&DriverPath);
181  if (Status != STATUS_SUCCESS)
182  {
183  DWORD err = RtlNtStatusToDosError(Status);
184  wprintf(L"NtUnloadDriver failed [%lu]\n", err);
185  }
186 
188  }
189 
190  return (Status == STATUS_SUCCESS);
191 }
#define TRUE
Definition: types.h:120
Definition: bidi.c:75
__wchar_t WCHAR
Definition: xmlstorage.h:180
return STATUS_SUCCESS
Definition: btrfs.c:2664
ULONG NTAPI RtlNtStatusToDosError(IN NTSTATUS Status)
Definition: error.c:96
#define wprintf(...)
Definition: whoami.c:18
DWORD DWORD
Definition: winlogon.h:75
#define FALSE
Definition: types.h:117
int int int * err
Definition: fci.h:172
#define MAX_PATH
Definition: compat.h:26
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static BOOL SetPrivilege(BOOL bSet)
Definition: undoc.c:4
Status
Definition: gdiplustypes.h:24
LONG NTSTATUS
Definition: DriverTester.h:11
NTSTATUS NtUnloadDriver(IN PUNICODE_STRING DriverServiceName)
Definition: driver.c:2092
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSTATUS NtUnloadDriver ( IN PUNICODE_STRING  DriverServiceName)

Definition at line 2092 of file driver.c.

Referenced by LoadVia_SystemExtendServiceTableInformation(), LoadVia_SystemLoadGdiDriverInformation(), NtStopDriver(), ScmUnloadDriver(), and wmain().

2093 {
2094  return IopUnloadDriver(DriverServiceName, FALSE);
2095 }
#define FALSE
Definition: types.h:117
NTSTATUS NTAPI IopUnloadDriver(PUNICODE_STRING DriverServiceName, BOOLEAN UnloadPnpDrivers)
Definition: driver.c:1172
BOOL RegisterDriver ( LPCWSTR  lpDriverName,
LPCWSTR  lpPathName 
)

Definition at line 5 of file umode.c.

Referenced by Initialize().

7 {
8  SC_HANDLE hSCManager;
9  SC_HANDLE hService;
10 
11  hSCManager = OpenSCManagerW(NULL,
12  NULL,
14  if (!hSCManager)
15  return FALSE;
16 
17 retry:
18  hService = CreateServiceW(hSCManager,
19  lpDriverName,
20  lpDriverName,
25  lpPathName,
26  NULL,
27  NULL,
28  NULL,
29  NULL,
30  NULL);
31 
32  if (hService)
33  {
34  CloseServiceHandle(hService);
35  CloseServiceHandle(hSCManager);
36  return TRUE;
37  }
38  else
39  {
41 
43  {
45  goto retry;
46  }
47 
48  CloseServiceHandle(hSCManager);
49 
50  // return TRUE if the driver is already registered
51  return (err == ERROR_SERVICE_EXISTS);
52  }
53 }
BOOL StopDriver(LPCWSTR lpDriverName)
Definition: umode.c:94
#define SERVICE_ERROR_NORMAL
Definition: cmtypes.h:980
#define TRUE
Definition: types.h:120
SC_HANDLE WINAPI CreateServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, LPCWSTR lpDisplayName, DWORD dwDesiredAccess, DWORD dwServiceType, DWORD dwStartType, DWORD dwErrorControl, LPCWSTR lpBinaryPathName, LPCWSTR lpLoadOrderGroup, LPDWORD lpdwTagId, LPCWSTR lpDependencies, LPCWSTR lpServiceStartName, LPCWSTR lpPassword)
Definition: scm.c:675
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
#define SERVICE_ALL_ACCESS
Definition: winsvc.h:62
DWORD DWORD
Definition: winlogon.h:75
#define FALSE
Definition: types.h:117
int int int * err
Definition: fci.h:172
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:458
smooth NULL
Definition: ftsmooth.c:513
#define ERROR_SERVICE_MARKED_FOR_DELETE
Definition: winerror.h:623
#define ERROR_SERVICE_EXISTS
Definition: winerror.h:624
SC_HANDLE WINAPI OpenSCManagerW(LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:1835
#define DRIVER_NAME
Definition: ext2fs.h:135
SC_HANDLE hSCManager
Definition: sc.c:12
#define SC_MANAGER_ALL_ACCESS
Definition: winsvc.h:13
#define SERVICE_DEMAND_START
Definition: cmtypes.h:976
#define SERVICE_KERNEL_DRIVER
Definition: cmtypes.h:951
BOOL StartDriver ( LPCWSTR  lpDriverName)

Definition at line 56 of file umode.c.

Referenced by UsermodeMethod().

57 {
58  SC_HANDLE hSCManager;
59  SC_HANDLE hService;
60  BOOL bRet;
61 
62  hSCManager = OpenSCManagerW(NULL,
63  NULL,
65  if (!hSCManager)
66  return FALSE;
67 
68  hService = OpenServiceW(hSCManager,
69  lpDriverName,
71  if (!hService)
72  {
73  CloseServiceHandle(hSCManager);
74  return FALSE;
75  }
76 
77  bRet = StartServiceW(hService, 0, NULL);
78  if (!bRet)
79  {
81  {
82  wprintf(L"%s.sys already running\n", DRIVER_NAME);
83  bRet = TRUE;
84  }
85  }
86 
87  CloseServiceHandle(hService);
88  CloseServiceHandle(hSCManager);
89 
90  return bRet;
91 }
#define TRUE
Definition: types.h:120
Definition: bidi.c:75
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
#define SERVICE_ALL_ACCESS
Definition: winsvc.h:62
#define wprintf(...)
Definition: whoami.c:18
#define FALSE
Definition: types.h:117
SC_HANDLE WINAPI OpenServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, DWORD dwDesiredAccess)
Definition: scm.c:1929
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:458
smooth NULL
Definition: ftsmooth.c:513
BOOL WINAPI StartServiceW(SC_HANDLE hService, DWORD dwNumServiceArgs, LPCWSTR *lpServiceArgVectors)
Definition: scm.c:2750
unsigned int BOOL
Definition: ntddk_ex.h:94
SC_HANDLE WINAPI OpenSCManagerW(LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:1835
#define DRIVER_NAME
Definition: ext2fs.h:135
SC_HANDLE hSCManager
Definition: sc.c:12
#define SC_MANAGER_ALL_ACCESS
Definition: winsvc.h:13
#define ERROR_SERVICE_ALREADY_RUNNING
Definition: winerror.h:607
BOOL StopDriver ( LPCWSTR  lpDriverName)

Definition at line 94 of file umode.c.

Referenced by RegisterDriver(), and UsermodeMethod().

95 {
96  SC_HANDLE hSCManager;
97  SC_HANDLE hService;
99  BOOL bRet;
100 
101  hSCManager = OpenSCManagerW(NULL,
102  NULL,
104  if (!hSCManager)
105  return FALSE;
106 
107  hService = OpenServiceW(hSCManager,
108  lpDriverName,
110  if (!hService)
111  {
112  CloseServiceHandle(hSCManager);
113  return FALSE;
114  }
115 
116  bRet = ControlService(hService,
118  &serviceStatus);
119  if (!bRet)
120  {
122  {
123  wprintf(L"%s.sys wasn't running\n", DRIVER_NAME);
124  bRet = TRUE;
125  }
126  }
127 
128  CloseServiceHandle(hService);
129  CloseServiceHandle(hSCManager);
130 
131  return bRet;
132 }
#define TRUE
Definition: types.h:120
Definition: bidi.c:75
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
#define SERVICE_ALL_ACCESS
Definition: winsvc.h:62
#define wprintf(...)
Definition: whoami.c:18
#define ERROR_SERVICE_NOT_ACTIVE
Definition: winerror.h:613
#define FALSE
Definition: types.h:117
SC_HANDLE WINAPI OpenServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, DWORD dwDesiredAccess)
Definition: scm.c:1929
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:458
smooth NULL
Definition: ftsmooth.c:513
unsigned int BOOL
Definition: ntddk_ex.h:94
SERVICE_STATUS serviceStatus
Definition: tftpd.cpp:63
SC_HANDLE WINAPI OpenSCManagerW(LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:1835
#define DRIVER_NAME
Definition: ext2fs.h:135
SC_HANDLE hSCManager
Definition: sc.c:12
BOOL WINAPI ControlService(SC_HANDLE hService, DWORD dwControl, LPSERVICE_STATUS lpServiceStatus)
Definition: scm.c:500
#define SC_MANAGER_ALL_ACCESS
Definition: winsvc.h:13
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36
BOOL UnregisterDriver ( LPCWSTR  lpDriverName)

Definition at line 135 of file umode.c.

Referenced by UndocumentedMethod(), Uninitialize(), and UsermodeMethod().

136 {
137  SC_HANDLE hService;
138  SC_HANDLE hSCManager;
139  BOOL bRet;
140 
141  hSCManager = OpenSCManagerW(NULL,
142  NULL,
144  if (!hSCManager)
145  return FALSE;
146 
147  hService = OpenServiceW(hSCManager,
148  lpDriverName,
150  if (!hService)
151  {
152  CloseServiceHandle(hSCManager);
153  return FALSE;
154  }
155 
156  bRet = DeleteService(hService);
157 
158  CloseServiceHandle(hService);
159  CloseServiceHandle(hSCManager);
160 
161  return bRet;
162 }
#define SERVICE_ALL_ACCESS
Definition: winsvc.h:62
BOOL WINAPI DeleteService(SC_HANDLE hService)
Definition: scm.c:771
#define FALSE
Definition: types.h:117
SC_HANDLE WINAPI OpenServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, DWORD dwDesiredAccess)
Definition: scm.c:1929
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:458
smooth NULL
Definition: ftsmooth.c:513
unsigned int BOOL
Definition: ntddk_ex.h:94
SC_HANDLE WINAPI OpenSCManagerW(LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:1835
SC_HANDLE hSCManager
Definition: sc.c:12
#define SC_MANAGER_ALL_ACCESS
Definition: winsvc.h:13