ReactOS  0.4.14-dev-342-gdc047f9
main.c
Go to the documentation of this file.
1 #include "DriverTester.h"
2 
3 static BOOL
4 Initialize(LPCWSTR lpDriverPath)
5 {
6  if (!RegisterDriver(DRIVER_NAME, lpDriverPath))
7  {
8  wprintf(L"[%lu] Failed to install %s\n", GetLastError(), DRIVER_NAME);
9  return FALSE;
10  }
11 
12  return TRUE;
13 }
14 
15 static BOOL
16 Uninitialize(LPCWSTR lpDriverPath)
17 {
19  {
20  wprintf(L"[%lu] Failed to unregister %s\n", GetLastError(), DRIVER_NAME);
21  return FALSE;
22  }
23 
24  return TRUE;
25 }
26 
27 static BOOL
28 UsermodeMethod(LPCWSTR lpDriverPath)
29 {
30  wprintf(L"\nStarting %s.sys via the SCM\n", DRIVER_NAME);
31 
33  {
34  wprintf(L"[%lu] Failed to start %s\n", GetLastError(), DRIVER_NAME);
36  return FALSE;
37  }
38 
39  wprintf(L"\tStarted\n");
40 
41  wprintf(L"Stopping %s.sys via the SCM\n", DRIVER_NAME);
42 
43  if (!StopDriver(DRIVER_NAME))
44  {
45  wprintf(L"[%lu] Failed to stop %s\n", GetLastError(), DRIVER_NAME);
47  return FALSE;
48  }
49 
50  wprintf(L"\tStopped\n");
51 
52  return TRUE;
53 }
54 
55 static BOOL
57 {
58  wprintf(L"\nStarting %s.sys via native API\n", DRIVER_NAME);
59 
61  {
62  wprintf(L"[%lu] Failed to start %s\n", GetLastError(), DRIVER_NAME);
64  return FALSE;
65  }
66 
67  wprintf(L"\tStarted\n");
68 
69  wprintf(L"Stopping %s.sys via native API\n", DRIVER_NAME);
70 
72  {
73  wprintf(L"[%lu] Failed to stop %s\n", GetLastError(), DRIVER_NAME);
75  return FALSE;
76  }
77 
78  wprintf(L"\tStopped\n");
79 
80  return TRUE;
81 }
82 
83 
84 static BOOL
86 {
87  WCHAR szDevice[MAX_PATH];
88 
89  if (ConvertPath(lpDriverPath, szDevice))
90  {
91  wprintf(L"\nStarting %s.sys via NtSetSystemInformation with SystemLoadGdiDriverInformation\n", DRIVER_NAME);
93  {
94  wprintf(L"\tStarted\n");
95 
97  }
98 
99  wprintf(L"\nStarting %s.sys via NtSetSystemInformation with SystemExtendServiceTableInformation\n", DRIVER_NAME);
101  {
102  wprintf(L"\tStarted\n");
103 
105  }
106 
107  return TRUE;
108  }
109 
110  return FALSE;
111 }
112 
113 
114 int __cdecl wmain(int argc, wchar_t *argv[])
115 {
116  WCHAR buf[MAX_PATH];
117 
118  if (argc != 2)
119  {
120  wprintf(L"Usage: DriverTester.exe <path>");
121  return -1;
122  }
123 
124  if (!SearchPathW(NULL,
125  argv[1],
126  L".sys",
127  MAX_PATH,
128  buf,
129  NULL))
130  {
131  wprintf(L"%s does not exist", argv[1]);
132  return -1;
133  }
134 
135  if (Initialize(argv[1]))
136  {
137  //
138  // Load using conventional SCM methods
139  //
140  UsermodeMethod(argv[1]);
141 
142  //
143  // Load using undocumented NtLoad/UnloadDriver
144  //
146 
147  //
148  // Load using hidden unknown methods
149  //
151 
152  Uninitialize(argv[1]);
153  }
154 
155  return 0;
156 }
157 
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
#define __cdecl
Definition: accygwin.h:79
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
static VOID StopDriver(VOID)
#define wprintf(...)
Definition: whoami.c:18
#define argv
Definition: mplay32.c:18
int wmain(int argc, WCHAR *argv[])
Definition: main.c:269
BOOL NtStartDriver(LPCWSTR lpService)
Definition: undoc.c:133
BOOL NtStopDriver(LPCWSTR lpService)
Definition: undoc.c:164
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
static BOOL Uninitialize(LPCWSTR lpDriverPath)
Definition: main.c:16
static const WCHAR L[]
Definition: oid.c:1250
#define DRIVER_NAME
Definition: ext2fs.h:136
static BOOL Initialize(LPCWSTR lpDriverPath)
Definition: main.c:4
DWORD WINAPI SearchPathW(IN LPCWSTR lpPath OPTIONAL, IN LPCWSTR lpFileName, IN LPCWSTR lpExtension OPTIONAL, IN DWORD nBufferLength, OUT LPWSTR lpBuffer, OUT LPWSTR *lpFilePart OPTIONAL)
Definition: path.c:1297
BOOL LoadVia_SystemLoadGdiDriverInformation(LPWSTR lpDriverPath)
Definition: undoc.c:199
BOOLEAN StartDriver(VOID)
Definition: vcdcli.c:85
BOOL UnregisterDriver(LPCWSTR lpDriverName)
Definition: umode.c:135
static BOOL SneakyUndocumentedMethods(LPCWSTR lpDriverPath)
Definition: main.c:85
BOOL LoadVia_SystemExtendServiceTableInformation(LPWSTR lpDriverPath)
Definition: undoc.c:240
BOOL ConvertPath(LPCWSTR lpPath, LPWSTR lpDevice)
Definition: undoc.c:56
static BOOL UsermodeMethod(LPCWSTR lpDriverPath)
Definition: main.c:28
BOOL RegisterDriver(LPCWSTR lpDriverName, LPCWSTR lpPathName)
Definition: umode.c:5
static BOOL UndocumentedMethod(LPCWSTR lpDriverPath)
Definition: main.c:56