-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload.c
More file actions
executable file
·258 lines (233 loc) · 8.42 KB
/
Copy pathload.c
File metadata and controls
executable file
·258 lines (233 loc) · 8.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/* loader.c */
//
// Notes:
// Define WIN95 to get Windows95 code otherwise NT code is produced.
// Under NT the Driver is loaded or unloaded, affecting all devices.
// Under Windows95 the individual device is loaded or unloaded. use the
// LoadDriver/UnLoadDriver functions in a loop to start or stop
// all Windows95 WinRT devices.
// Windows95 loads are cumulative, i.e. load it twice,
// you need to unload it twice.
//
//
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <WinRTctl.h>
#define WIN95
#if defined(WIN95)
// defines extracted for VXDLDR.H (subject to change)
struct _W32IoctlPkt {
USHORT W32IO_ErrorCode ;
USHORT W32IO_DeviceID ;
UCHAR W32IO_ModuleName[1] ;
} ;
// VxDLoader Function Requests
#define VXDLDR_APIFUNC_LOADDEVICE 1
#define VXDLDR_APIFUNC_UNLOADDEVICE 2
// VxDLoader Error codes
#define VXDLDR_ERR_OUT_OF_MEMORY 1
#define VXDLDR_ERR_IN_DOS 2
#define VXDLDR_ERR_FILE_OPEN_ERROR 3
#define VXDLDR_ERR_FILE_READ 4
#define VXDLDR_ERR_DUPLICATE_DEVICE 5
#define VXDLDR_ERR_BAD_DEVICE_FILE 6
#define VXDLDR_ERR_DEVICE_REFUSED 7
#define VXDLDR_ERR_NO_SUCH_DEVICE 8
#define VXDLDR_ERR_DEVICE_UNLOADABLE 9
#define VXDLDR_ERR_ALLOC_V86_AREA 10
#define VXDLDR_ERR_BAD_API_FUNCTION 11
#endif // WIN95
#if defined(WIN95)
// define this structure to reserve space at the end of _W32IoctlPkt struc
// for 31 more characters
typedef struct {
struct _W32IoctlPkt Res_DL_Pkt;
UCHAR Res_ModName[31];
} IOCTL_PKT;
#endif // WIN95
// prototypes
LONG LoadDriver(LONG);
//////////////////////////////////////////////////////////////////////////////
// LoadDriver() - load driver
// Inputs: deviceNumber - device number to load (Windows95 only)
// Outputs: return() - 0 OK, otherwise exit code
// Notes: Define WIN95 for Windows95 version
//////////////////////////////////////////////////////////////////////////////
LONG LoadDriver(LONG deviceNumber)
{
#if defined(WIN95)
// Windows95 Dynanmic VxD Load
HANDLE hVxDLdr; // Handle to VxD Loader
CHAR szCVxDName[MAX_PATH];
CHAR szTemp[MAX_PATH];
USHORT usErrorCode;
IOCTL_PKT DL_IOCTL_Pkt;
DWORD cbBytesReturned;
// Get file handle to VXDLDR VxD
hVxDLdr = CreateFile("\\\\.\\VXDLDR", 0,0,0,0,0,0);
if ( hVxDLdr == INVALID_HANDLE_VALUE )
{
printf("Unable to open VXDLDR\n");
return(-1);
}
// Build path & name of VxD. Assumes that VxD is in
// the system directory VMM32 (e.g. c:\WINDOWS\SYSTEM\VMM32)
GetSystemDirectory(szCVxDName, MAX_PATH);
sprintf(szTemp, "\\VMM32\\WRTDEV%d.VXD", deviceNumber);
lstrcat(szCVxDName, szTemp);
printf("Dynamically loading %s\n", szCVxDName);
// call the Vxd Loader to load our Vxd
DeviceIoControl(hVxDLdr, VXDLDR_APIFUNC_LOADDEVICE,
(LPVOID)szCVxDName, lstrlen(szCVxDName)+1,
(LPVOID)&DL_IOCTL_Pkt, sizeof(IOCTL_PKT),
&cbBytesReturned, NULL);
usErrorCode = DL_IOCTL_Pkt.Res_DL_Pkt.W32IO_ErrorCode;
// Done with the Loader
CloseHandle(hVxDLdr);
// Check for Errors
if (usErrorCode != 0)
{
printf("Error while dynamically loading %s,\n", szCVxDName);
switch( usErrorCode )
{
case VXDLDR_ERR_OUT_OF_MEMORY:
printf( "Not enough memory\n" );
break;
case VXDLDR_ERR_IN_DOS:
printf( "Loader could not reenter DOS\n" );
break;
case VXDLDR_ERR_FILE_OPEN_ERROR:
printf( "Could not find device\n" );
break;
case VXDLDR_ERR_FILE_READ:
printf( "Error reading device\n" );
break;
case VXDLDR_ERR_DUPLICATE_DEVICE:
printf( "Device already loaded\n" );
break;
case VXDLDR_ERR_BAD_DEVICE_FILE:
printf( "Not a valid device\n" );
break;
case VXDLDR_ERR_DEVICE_REFUSED:
printf( "Device refuses to load\n" );
break;
case VXDLDR_ERR_NO_SUCH_DEVICE:
printf( "Device not found\n" );
break;
default:
printf( "Error code %d\n", usErrorCode);
}
return(-1);
}
// Print the VxD's Module Name, which may be different than the filename.
// (If the module name is NULL, the device was probably loaded at
// boot time and is not dynamically load or unloadable.)
printf("%s Module Name is %s\n\n", szCVxDName,
DL_IOCTL_Pkt.Res_DL_Pkt.W32IO_ModuleName);
return(0);
#else // WIN95
// NT Service Manager Driver Load
SC_HANDLE hManager, hService; // For Service handles
DWORD error; // For error code
// Open the System Service Manager
if ( (hManager = OpenSCManager(NULL, NULL,
GENERIC_READ|GENERIC_WRITE|GENERIC_EXECUTE)) == NULL )
{ // failed getting to Service Manager
switch ((error = GetLastError()))
{
case ERROR_ACCESS_DENIED:
printf("ERROR_ACCESS_DENIED (OM).\n");
break;
case ERROR_DATABASE_DOES_NOT_EXIST:
printf("ERROR_DATABASE_DOES_NOT_EXIST (OM).\n");
break;
case ERROR_INVALID_PARAMETER:
printf("ERROR_INVALID_PARAMETER (OM).\n)");
break;
default:
printf("Open Service Manager error: %d (OM)\n", error);
break;
}
return(-1);
}
// Get a handle to the WinRT Driver service
if ( (hService = OpenService(hManager, "WinRT",
GENERIC_READ|GENERIC_WRITE|GENERIC_EXECUTE)) == NULL )
{ // failed getting to WinRT service
switch ( (error = GetLastError()) ) // - error
{
case ERROR_ACCESS_DENIED:
printf("ERROR_ACCESS_DENIED (OS)\n");
break;
case ERROR_INVALID_HANDLE:
printf("ERROR_INVALID_HANDLE (OS)\n");
break;
case ERROR_INVALID_NAME:
printf("ERROR_INVALID_NAME (OS)\n");
break;
case ERROR_SERVICE_DOES_NOT_EXIST:
printf("ERROR_SERVICE_DOES_NOT_EXIST (OS)\n");
break;
default:
printf("Service Manager Open error: %d (OS)", error);
break;
}
CloseServiceHandle(hManager);
return(-1);
}
// Start the WinRT driver
if ( !StartService(hService, 0, NULL) ) // Start the service
{ // WinRT failed to start
switch ( (error = GetLastError()) ) // - error
{
case ERROR_ACCESS_DENIED:
printf("ERROR_ACCESS_DENIED (SS)\n");
break;
case ERROR_INVALID_HANDLE:
printf("ERROR_INVALID_HANDLE (SS)\n");
break;
case ERROR_PATH_NOT_FOUND:
printf("ERROR_PATH_NOT_FOUND (SS)\n");
break;
case ERROR_SERVICE_ALREADY_RUNNING:
printf("The WinRT driver is already running.\n");
break;
case ERROR_SERVICE_DATABASE_LOCKED:
printf("ERROR_SERVICE_DATABASE_LOCKED (SS)\n");
break;
case ERROR_SERVICE_DEPENDENCY_DELETED:
printf("ERROR_SERVICE_DEPENDENCY_DELETED (SS)\n");
break;
case ERROR_SERVICE_DEPENDENCY_FAIL:
printf("ERROR_SERVICE_DEPENDENCY_FAIL (SS)\n");
break;
case ERROR_SERVICE_DISABLED:
printf("ERROR_SERVICE_DISABLED (SS)\n");
break;
case ERROR_SERVICE_LOGON_FAILED:
printf("ERROR_SERVICE_LOGON_FAILED (SS)\n");
break;
case ERROR_SERVICE_MARKED_FOR_DELETE:
printf("ERROR_SERVICE_MARKED_FOR_DELETE (SS)\n");
break;
case ERROR_SERVICE_NO_THREAD:
printf("ERROR_SERVICE_NO_THREAD (SS)\n");
break;
case ERROR_SERVICE_REQUEST_TIMEOUT:
printf("ERROR_SERVICE_REQUEST_TIMEOUT (SS)\n");
break;
default:
printf("Error startin WinRT: %d (SS)\n", error);
break;
}
CloseServiceHandle(hManager); // Close out handles
CloseServiceHandle(hService);
return(-1);
}
printf("WinRT Driver has been started.\n");
CloseServiceHandle(hManager); // Close out handles
CloseServiceHandle(hService);
return(0);
#endif // WIN95
}