[THEMES]
[reactos.git] / rostests / win32 / DriverLoading / Application / main.c
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 {
18 if (!UnregisterDriver(DRIVER_NAME))
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
32 if (!StartDriver(DRIVER_NAME))
33 {
34 wprintf(L"[%lu] Failed to start %s\n", GetLastError(), DRIVER_NAME);
35 UnregisterDriver(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);
46 UnregisterDriver(DRIVER_NAME);
47 return FALSE;
48 }
49
50 wprintf(L"\tStopped\n");
51
52 return TRUE;
53 }
54
55 static BOOL
56 UndocumentedMethod(LPCWSTR lpDriverPath)
57 {
58 wprintf(L"\nStarting %s.sys via native API\n", DRIVER_NAME);
59
60 if (!NtStartDriver(DRIVER_NAME))
61 {
62 wprintf(L"[%lu] Failed to start %s\n", GetLastError(), DRIVER_NAME);
63 UnregisterDriver(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
71 if (!NtStopDriver(DRIVER_NAME))
72 {
73 wprintf(L"[%lu] Failed to stop %s\n", GetLastError(), DRIVER_NAME);
74 UnregisterDriver(DRIVER_NAME);
75 return FALSE;
76 }
77
78 wprintf(L"\tStopped\n");
79
80 return TRUE;
81 }
82
83
84 static BOOL
85 SneakyUndocumentedMethods(LPCWSTR lpDriverPath)
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);
92 if (LoadVia_SystemLoadGdiDriverInformation(szDevice))
93 {
94 wprintf(L"\tStarted\n");
95
96 NtStopDriver(DRIVER_NAME);
97 }
98
99 wprintf(L"\nStarting %s.sys via NtSetSystemInformation with SystemExtendServiceTableInformation\n", DRIVER_NAME);
100 if (LoadVia_SystemExtendServiceTableInformation(szDevice))
101 {
102 wprintf(L"\tStarted\n");
103
104 NtStopDriver(DRIVER_NAME);
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 //
145 UndocumentedMethod(argv[1]);
146
147 //
148 // Load using hidden unknown methods
149 //
150 SneakyUndocumentedMethods(argv[1]);
151
152 Uninitialize(argv[1]);
153 }
154
155 return 0;
156 }
157