source: trunk/src/win32k/ldr/mytkExecPgm.asm@ 2912

Last change on this file since 2912 was 2872, checked in by bird, 26 years ago

Oopps. Forgot an int 3.

File size: 12.6 KB
Line 
1; $Id: mytkExecPgm.asm,v 1.10 2000-02-23 16:53:04 bird Exp $
2;
3; mytkExecPgm - tkExecPgm overload
4;
5; Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
6;
7; Project Odin Software License can be found in LICENSE.TXT
8;
9 .386p
10
11;
12; Include files
13;
14 include devsegdf.inc
15
16;
17; Imported Functions
18;
19 extrn _g_tkExecPgm:PROC
20 extrn AcquireBuffer:PROC
21 extrn ReleaseBuffer:PROC
22 extrn QueryBufferSegmentOffset:PROC
23
24 ; Scans strings until empy-string is reached.
25 ; input: bx:di
26 ; uses: nearly all (save bp)
27 ; return: cx size - CF clear
28 ; ax error- CF set
29 extrn _f_FuStrLenZ:PROC
30
31 ; Stringlength
32 ; input: bx:di
33 ; uses: nearly all (save bp)
34 ; return: cx size - CF clear
35 ; ax error- CF set
36 extrn _f_FuStrLen:PROC
37
38 ;memcpy
39 ;input: bx:si pointer to source
40 ; es:di pointer to target
41 ; cx count of bytes to copy
42 ;uses: nearly all (save bp), es, ds
43 ;return: success CF clear
44 ; failure CF set
45 extrn _f_FuBuff:PROC
46
47;
48; Exported symbols
49;
50 public mytkExecPgm
51
52
53
54CODE32 SEGMENT
55
56;;
57;
58; @returns same as tkExecPgm: eax, edx and carry flag
59; @param ax Exec flag
60; ds:dx Filename address. (String)
61; es:bx Environment address. (String)
62; di:si Argument address. (String)
63; @uses all - bp
64; @sketch Copy the filename and arguments into a buffer we
65; may modify later if this is a UNIX shellscript or
66; a PE-file started by pe.exe.
67; @status
68; @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
69; @remark
70;
71; The buffer we are using is a C struct as follows.
72; struct Buffer
73; {
74; char szFilename[261]; /* offset 0 */
75; char achArg[1536-261]; /* offset 261 */
76; };
77;
78mytkExecPgm PROC FAR
79pBuffer = dword ptr -04h
80SegBuffer = -08h
81OffBuffer = -0Ch
82cchFilename = dword ptr -10h
83cchArgs = dword ptr -14h
84;usExecFlag = -18h
85;SegFilename = -1ch
86;OffFilename = -1eh
87;SegEnv = -20h
88;OffEnv = -22h
89;SegArg = -24h
90;OffArg = -26h
91
92 ASSUME CS:CODE32, DS:NOTHING, SS:NOTHING
93; int 3
94 push ebp
95 mov ebp, esp
96 lea esp, [ebp + cchArgs]
97
98 push eax
99 push ecx
100 push ds
101 push es
102 push edi
103
104 ; parameter validations
105 mov ax, ds ; pointer to filename
106 cmp ax, 4
107 jb mytkExecPgm_CalltkExecPgm_X1
108
109 ;
110 ; filename length
111 ;
112 mov ax, ds
113 mov es, ax
114 pushad
115 push es
116 push ds
117 mov bx, ds
118 mov di, dx ; es:di is now filename address (ds:dx).
119 push cs ; Problem calling far into the calltab segement.
120 call near ptr FLAT:_f_FuStrLen
121 movzx ecx, cx
122 mov [ebp+cchFilename], ecx
123 pop ds
124 pop es
125 popad
126 jc mytkExecPgm_CalltkExecPgm_X1; If the FuStrLen call failed we bail out!
127
128 ;
129 ; if filename length is more that CCHMAXPATH then we don't do anything!.
130 ;
131 cmp [ebp+cchFilename], 260
132 jae mytkExecPgm_CalltkExecPgm_X1; length >= 260
133
134 ;
135 ; args length
136 ; Note: the arguments are a series of ASCIIZs ended by an empty string (ie. '\0').
137 ;
138 pop edi
139 push edi
140 xor ecx, ecx
141 cmp di, 4 ; The argument might me a invalid pointer...
142 jb mytkExecPgm_CalltkExecPgm_1
143
144 pushad
145 push es
146 push ds
147 mov bx, di ;
148 mov di, si ; bx:di -> arguments
149 push cs ; Problem calling far into the calltab segement.
150 call near ptr FLAT:_f_FuStrLenZ
151 movzx ecx, cx
152 mov [ebp+cchArgs], ecx
153 pop ds
154 pop es
155 popad
156 jc mytkExecPgm_CalltkExecPgm_X1
157
158mytkExecPgm_CalltkExecPgm_1:
159 mov ecx, [ebp+cchArgs]
160 add ecx, [ebp+cchFilename] ; filename
161 add ecx, 3 + 260 ; 260 = new argument from a scrip file or something.
162 ; 3 = two '\0's and a space after added argument.
163 cmp ecx, 1536 ; 1536 = Buffersize. FIXME! Define this!!!
164 jae mytkExecPgm_CalltkExecPgm_X1; jmp if argument + file + new file > buffer size
165
166 ;
167 ; Aquire a buffer
168 ;
169 call AcquireBuffer
170 or eax, eax
171 jz mytkExecPgm_CalltkExecPgm_X1; Failed to get buffer.
172 mov [ebp+pBuffer], eax
173
174 ;
175 ; Get Segment and offset for the buffer
176 ;
177 call QueryBufferSegmentOffset
178 mov cx, es
179 mov [ebp+OffBuffer], ax
180 mov [ebp+SegBuffer], es
181 test eax, 000570000h
182 jnz mytkExecPgm_CalltkExecPgm_X2
183
184 ;
185 ; Copy filename to pBuffer.
186 ;
187 pushad
188 push es
189 push ds
190 mov di, ax ; es:di pBuffer
191 mov si, dx
192 mov bx, ds ; bx:si Filename pointer (input ds:dx)
193 mov ecx, [ebp+cchFilename]
194 push cs ; Problem calling far into the calltab segement.
195 call near ptr FLAT:_f_FuBuff
196 pop ds
197 pop es
198 popad
199 jc mytkExecPgm_CalltkExecPgm_X2
200
201 ;
202 ; Copy Args to pBuffer + 261
203 ;
204 ; stack: edi, es, ds, ecx, eax
205 pop edi
206 push edi
207 add eax, 261 ; we'll use eax in the branch
208 cmp di, 4
209 jb mytkExecPgm_CalltkExecPgm_2
210 pushad
211 push es
212 push ds
213 mov ecx, [ebp+cchArgs]
214 mov bx, di ; ds:si -> arguments
215 mov di, ax ; es:di -> buffer + 261
216 push cs ; Problem calling far into the calltab segement.
217 call near ptr FLAT:_f_FuBuff
218 pop ds
219 pop es
220 popad
221 jc mytkExecPgm_CalltkExecPgm_X2
222 jmp mytkExecPgm_CalltkExecPgm_3
223
224mytkExecPgm_CalltkExecPgm_2:
225 mov word ptr es:[eax], 0 ; Terminate the empty string!
226
227 ;
228 ; Restore variables pushed on the stack
229 ;
230 ; stack: edi, es, ds, ecx, eax
231mytkExecPgm_CalltkExecPgm_3:
232 pop edi
233 pop es
234 pop ds
235 pop ecx
236 pop eax
237
238 ;
239 ; Set new input parameters (call _g_tkExecPgm)
240 ;
241 ; ds:dx is to become SegBuffer:OffBuffer
242 ; di:si is to become SegBuffer:OffBuffer+261
243 ;
244 ; The some of the old values are stored on the stack (for the time being)
245 push ds
246 push edi
247 push esi
248
249 mov di, [ebp+SegBuffer]
250 mov ds, di
251 mov si, [ebp+OffBuffer]
252 mov dx, si ; ds:dx SegBuffer:OffBuffer
253 add si, 261 ; di:si SegBuffer:OffBuffer+261
254
255 ;
256 ; Call _g_tkExecPgm
257 ;
258 push cs ; Problem calling far into the calltab segement.
259 call near ptr FLAT:_g_tkExecPgm
260 pushfd
261
262 ;
263 ; Release buffer
264 ;
265 push eax
266 mov eax, [ebp + pBuffer]
267 call ReleaseBuffer
268 mov [ebp + pBuffer], 0
269 pop eax
270
271 ;
272 ; Return
273 ;
274 popfd
275 pop esi
276 pop edi
277 pop ds
278 leave
279 retf
280
281mytkExecPgm_CalltkExecPgm_X2:
282 ;
283 ; Release buffer
284 ;
285 mov eax, [ebp + pBuffer]
286 call ReleaseBuffer
287 mov [ebp + pBuffer], 0
288
289mytkExecPgm_CalltkExecPgm_X1:
290 pop edi
291 pop es
292 pop ds
293 pop ecx
294 pop eax
295
296mytkExecPgm_CalltkExecPgm:
297 push cs
298 call near ptr FLAT:_g_tkExecPgm
299 leave
300 retf
301mytkExecPgm ENDP
302
303
304
305CODE32 ENDS
306
307if 0 ; alternate implementation.
308mytkExecPgm PROC FAR
309pBuffer = dword ptr -04h
310SegBuffer = -08h
311OffBuffer = -0Ch
312cchFilename = -10h
313cchArgs = -14h
314usExecFlag = -18h
315SegFilename = -1ch
316OffFilename = -1eh
317SegEnv = -20h
318OffEnv = -22h
319SegArg = -24h
320OffArg = -26h
321
322 ASSUME CS:CODE32, DS:NOTHING, SS:NOTHING
323 push ebp
324 mov ebp, esp
325 lea esp, [ebp + OffArg]
326
327 ; save input parameters
328 mov [ebp + usExecFlag], ax
329 mov ax, es
330 mov [ebp + SegEnv], ax
331 mov [ebp + OffEnv], bx
332 mov [ebp + SegArg], di
333 mov [ebp + OffArg], si
334 mov ax, ds
335 mov [ebp + SegFilename], ax
336 mov [ebp + OffFilename], dx
337
338 ; parameter validations
339 cmp ax, 4 ; pointer to filename
340 jb mytkExecPgm_CalltkExecPgm_X1
341
342 ;
343 ; filename length
344 ;
345 mov bx, ax
346 mov di, dx ; bx:di is now filename address
347 push cs ; Problem calling far into the calltab segement.
348 call near ptr FLAT:_f_FuStrLen
349 jc mytkExecPgm_CalltkExecPgm_X1; If the FuStrLen call failed we bail out!
350
351 ;
352 ; if filename length is more that CCHMAXPATH then we don't do anything!.
353 ;
354 cmp cx, 260
355 jae mytkExecPgm_CalltkExecPgm_X1; length >= 260
356 mov [ebp+cchFilename], cx
357
358 ;
359 ; args length
360 ; Note: the arguments are a series of ASCIIZs ended by an empty string (ie. '\0').
361 ;
362 mov bx, [ebp+SegArg]
363 cmp bx, 4 ; The argument might me an NULL pointer
364 xor cx, cx
365 jb mytkExecPgm_CalltkExecPgm_1
366
367 mov di, [ebp+OffArg] ; bx:di -> arguments
368 push cs ; Problem calling far into the calltab segement.
369 call near ptr FLAT:_f_FuStrLenZ
370 mov [ebp+cchArgs], cx
371 jc mytkExecPgm_CalltkExecPgm_X1
372
373mytkExecPgm_CalltkExecPgm_1:
374 add cx, [ebp+cchFilename] ; filename length
375 add cx, 3 + 260 ; 260 = new argument from a scrip file or something.
376 ; 3 = two '\0's and a space after added argument.
377 cmp ecx, 1536 ; 1536 = Buffersize. FIXME! Define this!!!
378 jae mytkExecPgm_CalltkExecPgm_X1; jmp if argument + file + new file > buffer size
379
380 ;
381 ; Aquire a buffer
382 ;
383 call AcquireBuffer
384 mov [ebp+pBuffer], eax
385 or eax, eax
386 jz mytkExecPgm_CalltkExecPgm_X1; Failed to get buffer.
387
388 ;
389 ; Get Segment and offset for the buffer
390 ;
391 call QueryBufferSegmentOffset
392 mov cx, es
393 mov [ebp+OffBuffer], ax
394 mov [ebp+SegBuffer], es
395 test eax, 000570000h
396 jnz mytkExecPgm_CalltkExecPgm_X2
397
398 ;
399 ; Copy filename to pBuffer.
400 ;
401 mov di, ax ; es:di pBuffer
402 mov si, dx
403 mov bx, ds ; bx:si Filename pointer (input ds:dx)
404 mov cx, [ebp+cchFilename] ; cx = length of area to copy
405 push cs ; Problem calling far into the calltab segement.
406 call near ptr FLAT:_f_FuBuff
407 jc mytkExecPgm_CalltkExecPgm_X2
408
409 ;
410 ; Copy Args to pBuffer + 261
411 ;
412 mov si, [ebp+SegArg]
413 cmp si, 4
414 jb mytkExecPgm_CalltkExecPgm_2
415 mov ds, si
416 mov si, [ebp+OffArg] ; ds:si -> arguments
417 mov di, [ebp+SegBuffer]
418 mov es, di
419 mov di, [ebp+OffBuffer]
420 add di, 261 ; es:di -> buffer + 261
421 mov cx, [ebp+cchArgs] ; cx = length of area to copy
422 push cs ; Problem calling far into the calltab segement.
423 call near ptr FLAT:_f_FuBuff
424 jc mytkExecPgm_CalltkExecPgm_X2
425 jmp mytkExecPgm_CalltkExecPgm_3
426
427mytkExecPgm_CalltkExecPgm_2:
428 mov word ptr es:[eax], 0 ; Terminate the empty string!
429
430 ;
431 ; Set new input parameters (call _g_tkExecPgm)
432 ;
433 ; ds:dx is to become SegBuffer:OffBuffer
434 ; di:si is to become SegBuffer:OffBuffer+261
435 ;
436mytkExecPgm_CalltkExecPgm_3:
437 mov di, [ebp+SegBuffer]
438 mov ds, di
439 mov si, [ebp+OffBuffer]
440 mov dx, si ; ds:dx SegBuffer:OffBuffer
441 add si, 261 ; di:si SegBuffer:OffBuffer+261
442 mov bx, [ebp+SegEnv]
443 mov es, bx
444 mov bx, [ebp+SegEnv]
445
446 ;
447 ; Call _g_tkExecPgm
448 ;
449 push cs ; Problem calling far into the calltab segement.
450 call near ptr FLAT:_g_tkExecPgm
451 pushfd
452
453 ;
454 ; Release buffer
455 ;
456 push eax
457 mov eax, [ebp + pBuffer]
458 call ReleaseBuffer
459 mov [ebp + pBuffer], 0
460 pop eax
461
462 ;
463 ; Return
464 ;
465 push [ebp + SegFilename]
466 pop ds
467 push [ebp + SegEnv]
468 pop es
469 popfd
470 leave
471 retf
472
473mytkExecPgm_CalltkExecPgm_X2:
474 ;
475 ; Release buffer
476 ;
477 mov eax, [ebp + pBuffer]
478 call ReleaseBuffer
479 mov [ebp + pBuffer], 0
480
481mytkExecPgm_CalltkExecPgm_X1:
482 pop ds
483
484mytkExecPgm_CalltkExecPgm:
485 push cs
486 call near ptr FLAT:_g_tkExecPgm
487 leave
488 retf
489mytkExecPgm ENDP
490
491CODE32 ENDS
492endif
493
494
495END
496
Note: See TracBrowser for help on using the repository browser.