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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
|
;/**********************************************************************/
;/** Microsoft Windows/NT **/
;/** Copyright(c) Microsoft Corp., 1993 **/
;/**********************************************************************/
;/*
; vxdFile.asm
;
; Contains simple VXD File I/O routines for lmhosts support
;
; FILE HISTORY:
; Johnl 06-Oct-1993 Created
;
;*/
.386p
include vmm.inc
include v86mmgr.inc
include dosmgr.inc
include opttest.inc
include netvxd.inc
include debug.inc
;
; Must match manifest in vxd\fileio.c
;
LMHOSTS_READ_BUFF_SIZE equ 256
EXTRN _pMappedFilePath:DWORD
EXTRN _pMappedFileBuff:DWORD
EXTRN _pFileBuff:DWORD
EXTRN _pFilePath:DWORD
EXTRN _fInInit:DWORD
EXTRN _GetInDosFlag:NEAR
;****************************************************************************
;** CheckInDos Macro
;
; Breaks if the Indos flag is set
;
; Uses EAX
;
CheckInDos MACRO
IFDEF DEBUG
push eax
cmp _fInInit, 0 ; Can't call while initializing
jnz @f
call _GetInDosFlag
cmp ax, 0
je @f
Debug_Out "In dos flag set and about to make dos call!"
@@:
pop eax
ENDIF
ENDM
;****************************************************************************
;** PushState Macro
;
; Saves the client state and begins nested exec block. ebx will contain
; the current VM's client handle
;
; Uses ECX!!
; EBX will be set to the client area
;
PushState MACRO
CheckInDos
push ebx
VMMcall Get_Cur_VM_Handle ; Puts current handle into EBX
mov ebx, [ebx.CB_Client_Pointer]
mov ecx, 0
VMMCall Begin_Critical_Section
Push_Client_State ; This pushes lots of crap
VMMcall Begin_Nest_V86_Exec
ENDM
;****************************************************************************
;** PopState Macro
;
; Restores client state and ends the nested exec block
;
;
PopState MACRO
VMMcall End_Nest_Exec
Pop_Client_State
VMMCall End_Critical_Section
pop ebx
ENDM
VxD_ICODE_SEG
;****************************************************************************
;** _VxdInitLmHostsSupport
;
; Allocates and maps memory for lmhosts support
;
; This is an Init time only routine
;
; Entry: [ESP+4] - Pointer to full path of file,
; [ESP+8] - strlen of path
;
; Exit: TRUE if successful, FALSE otherwise
;
BeginProc _VxdInitLmHostsSupport
push esi
push edi
mov ecx, [esp+16]
add ecx, LMHOSTS_READ_BUFF_SIZE
push ecx ; save ecx for the map call
VMMCall _Allocate_Global_V86_Data_Area, <ecx, GVDAZeroInit>
pop ecx
or eax,eax ; zero if error
jz ILMH_50
push eax
mov _pFileBuff, eax ; Save the linear address so we can access
add eax, LMHOSTS_READ_BUFF_SIZE ; from the vxd
mov _pFilePath, eax
pop eax
shl eax, 12 ; Convert linear to V86 address
shr ax, 12
mov _pMappedFileBuff, eax
add eax, LMHOSTS_READ_BUFF_SIZE
mov _pMappedFilePath, eax
jmp ILMH_70
ILMH_40:
; Free allocated V86 global memory (how?)
ILMH_50:
; error occurred, eax already contains zero
ILMH_70:
pop edi
pop esi
ret
EndProc _VxdInitLmHostsSupport
;****************************************************************************
;** _VxdWindowsPath
;
; Gets a pointer to (null-terminated) path to the windows directory
;
; This is an Init time only routine
;
; Entry: nothing
;
; Exit: pointer to path to windows directory
;
BeginProc _VxdWindowsPath
PushState ; Pushes lots of crap
VmmCall Get_Config_Directory
mov eax, edx ; path is returned in edx
PopState ; now pop all that crap
ret
EndProc _VxdWindowsPath
VxD_ICODE_ENDS
VxD_CODE_SEG
;****************************************************************************
;** _VxdFileOpen
;
; Opens a file
;
; Entry: [ESP+4] - Pointer to full path of file, path must be mapped
; to v86 memory before calling this
;
; Exit: EAX will contain a handle to the openned file
;
BeginProc _VxdFileOpen
push edi
push esi
mov dx, word ptr [esp+12] ; Just the offset
mov di, word ptr [esp+14] ; Just the segment
PushState ; This pushes lots of crap
mov [ebx.Client_ax], 3d00h ; Open file, read only, share
mov [ebx.Client_dx], dx
mov [ebx.Client_ds], di
mov eax, 21h
VmmCall Exec_Int
test [ebx.Client_Flags], CF_Mask ; Carry set if error
jz VFO_6 ; Carry set if error
mov eax, 0 ; Failed to open the file
jmp VFO_10
VFO_6:
movzx eax, [ebx.Client_ax] ; Handle of file
VFO_10:
PopState
pop esi
pop edi
ret
EndProc _VxdFileOpen
;****************************************************************************
;** _VxdFileRead
;
; Reads x bytes from a previously openned file
;
; Entry: [ESP+4] - Handle from _VxdFileOpen
; [ESP+8] - Count of bytes to read
; [ESP+12]- Mapped memory of destination buffer
;
; Exit: EAX will contain the number of bytes read, 0 if EOF or
; an error occurred.
;
BeginProc _VxdFileRead
push edi
push esi
mov ax, [esp+12] ; File Handle
mov si, [esp+16] ; Bytes to read
mov dx, [esp+20] ; Just the offset
mov di, [esp+22] ; Just the segment
PushState ; Pushes lots of crap (uses cx)
mov [ebx.Client_ax], 3f00h ; File Read
mov [ebx.Client_bx], ax ; File Handle
mov [ebx.Client_cx], si ; Bytes to read
mov [ebx.Client_dx], dx ; Mapped destination buffer
mov [ebx.Client_ds], di
mov eax, 21h
VmmCall Exec_Int
test [ebx.Client_Flags], CF_Mask ; Carry set if error
jz VFR_6 ; Carry set if error
mov eax, 0 ; Failed to open the file
jmp VFR_7
VFR_6:
movzx eax, [ebx.Client_ax] ; Bytes read
VFR_7:
VFR_10:
PopState
pop esi
pop edi
ret
EndProc _VxdFileRead
;****************************************************************************
;** _VxdFileClose
;
; Closes a file openned with VxdOpenFile
;
; Entry: [ESP+4] - Handle from _VxdFileOpen
;
BeginProc _VxdFileClose
mov ax, [esp+4] ; File Handle
PushState ; Pushes lots of crap
mov [ebx.Client_ax], 3e00h ; File Close
mov [ebx.Client_bx], ax ; File Handle
mov eax, 21h
VmmCall Exec_Int
test [ebx.Client_Flags], CF_Mask ; Carry set if error
jz VFCL_10 ; Carry set if error
Debug_Out "VxdFileClose - Close failed"
mov eax, 0 ; Failed to close the file
VFCL_10:
PopState
ret
EndProc _VxdFileClose
VxD_CODE_ENDS
END
|