source: trunk/src/win32k/test/fakea.asm@ 4384

Last change on this file since 4384 was 4347, checked in by bird, 25 years ago

Implemented tool for generating calltab for kernel imports. (mkcalltab)
Implemented API for accessing memory in another process. (*ProcessReadWrite)
Added kernel imports needed to implemented ProcessReadWrite.
Removed unused kernel imports.

File size: 14.0 KB
Line 
1; $Id: fakea.asm,v 1.3 2000-10-01 02:58:21 bird Exp $
2;
3; Fake assembly imports.
4;
5; Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
6;
7; Project Odin Software License can be found in LICENSE.TXT
8;
9
10 .386
11
12;
13; Defined Constants And Macros
14;
15 INCL_BASE EQU 1
16
17;
18; Include files
19;
20 include devsegdf.inc
21 include devhlp.inc
22 include os2.inc
23 include options.inc
24
25
26;
27; Exported symbols
28;
29 public fakepTCBCur
30 public fakepPTDACur
31 public fakeptda_start
32 public fakeptda_environ
33 public fakeptda_handle
34 public fakeptda_module
35 public fakeptda_ptdasem
36 public fakeptda_pBeginLIBPATH
37 public fakef_FuStrLenZ
38 public fakef_FuStrLen
39 public fakef_FuBuff
40 public fakeg_tkExecPgm
41 public faketkStartProcess
42 public CalltkExecPgm
43 public _fakeldrOpenPath@20
44
45
46;
47; Imported Functions and Variables.
48;
49 extrn tkExecPgmWorker:PROC ; fake.c
50 extrn _fakeLDRClearSem@0:PROC ; fake.c
51 extrn _fakeKSEMRequestMutex@8:PROC ; fake.c
52 extrn _fakeldrOpenPath_old@16:PROC ; fake.c
53 extrn _fakeldrOpenPath_new@20:PROC ; fake.c
54 extrn _options:options ; d16globl.c
55
56
57DATA16 SEGMENT
58; Fake data in 16-bit segment.
59fakepTCBCur dd offset FLAT:fakeTCB
60fakepPTDACur dd offset FLAT:fakeptda_start
61
62; PTDA - Only use environ and ExecChild.
63fakeptda_start LABEL DWORD
64fakeptda_pPTDAParent dd 0
65fakeptda_pPTDASelf dd offset FLAT:fakeptda_start
66fakeptda_pPTDAFirstChild dd 0
67fakeptda_pPTDAExecChild dd offset FLAT:fakeptda_start
68fakeptda_dummy db 123 dup (0)
69fakeptda_environ dw 1 ; 1 is the hardcoded HOB of the win32ktst.exe's environment.
70fakeptda_ptdasem db 20 dup (0) ; PTDA semaphore - Intra-Process serialisation mutex KSEM (sg244640).
71fakeptda_handle dw 2 ; 2 is the hardcoded HPTDA of the current process.
72fakeptda_module dw 1 ; 1 is the hardcoded HMTE of the current executable module.
73fakeptda_pBeginLIBPATH dd 0 ; BEGINLIBPATH not implemented.
74 dd 0 ; ENDLIBPATH not implemented.
75
76
77; TCB - just needs some dummy data for reading and writing to the TCBFailErr.
78fakeTCB db 220h dup (0CCh)
79
80DATA16 ENDS
81
82
83CODE16 SEGMENT
84
85
86; Scans strings until empy-string is reached.
87; input: bx:di
88; uses: nearly all (save bp)
89; return: cx size - CF clear
90; ax error- CF set
91fakef_FuStrLenZ PROC FAR
92 push 2 ; required by all 16-bit far procedures.
93 push 2 ; dummy code.
94 push 2 ; dummy code.
95 push 2 ; dummy code.
96 push es
97
98 mov dx, di ; save di pointer.
99 cmp bx, 7 ; check if NULL ptr.
100 jle ffslz_badselector
101
102 mov es, bx ; es:di -> string
103 mov cx, di
104 not cx ; maximum length is to segment end.
105 xor ax, ax ; test against zero (scasb uses al to cmp with).
106
107ffslz_loop:
108 repnz scasb
109 jnz ffslz_no_term ; jump if cx = 0
110 dec cx ; check if next is NULL too
111 scasb
112 jnz ffslz_loop
113
114ffslz_retok:
115 mov cx, di
116 sub cx, dx ; cx <- size (end ptr - start ptr)
117 pop es
118 add sp, 8
119 clc
120 db 66h
121 retf
122
123ffslz_badselector:
124 mov ax, ERROR_INVALID_SELECTOR
125 jmp ffslz_reterr
126
127;ffslz_invalidptr:
128; mov ax, ERROR_INVALID_ACCESS
129; jmp ffslz_reterr
130
131ffslz_no_term:
132 mov ax, ERROR_TERMINATOR_NOT_FOUND
133ffslz_reterr:
134 pop es
135 add sp, 8
136 stc
137 db 66h
138 retf
139fakef_FuStrLenZ ENDP
140
141
142;
143; Stringlength - Fake
144; input: bx:di
145; uses: nearly all (save bp)
146; return: cx size - CF clear
147; ax error- CF set
148fakef_FuStrLen PROC FAR
149 push 2 ; required by all 16-bit far procedures.
150 push 2 ; dummy code.
151 push 2 ; dummy code.
152 push 2 ; dummy code.
153 push es
154
155 mov dx, di ; save di pointer.
156 cmp bx, 7 ; check if NULL ptr.
157 jle ffslz_badselector
158
159 mov es, bx ; es:di -> string
160 mov cx, di
161 not cx ; maximum length is to segment end.
162 xor ax, ax ; test against zero (scasb uses al to cmp with).
163
164 repnz scasb
165 jnz ffslz_no_term ; jump if cx = 0
166
167ffslz_retok:
168 mov cx, di
169 sub cx, dx ; cx <- size (end ptr - start ptr)
170 pop es
171 add sp, 8
172 clc
173 db 66h
174 retf
175
176ffslz_badselector:
177 mov ax, ERROR_INVALID_SELECTOR
178 jmp ffslz_reterr
179
180;ffslz_invalidptr:
181; mov ax, ERROR_INVALID_ACCESS
182; jmp ffslz_reterr
183
184ffslz_no_term:
185 mov ax, ERROR_TERMINATOR_NOT_FOUND
186ffslz_reterr:
187 pop es
188 add sp, 8
189 stc
190 db 66h
191 retf
192fakef_FuStrLen ENDP
193
194
195;memcpy
196;input: bx:si pointer to source
197; es:di pointer to target
198; cx count of bytes to copy
199;uses: nearly all (save bp), es, ds
200;return: success CF clear
201; failure CF set
202fakef_FuBuff PROC FAR
203 push 2 ; required by all 16-bit far procedures.
204 push 2 ; dummy code.
205 push 2 ; dummy code.
206 push 2 ; dummy code.
207 push es
208
209 cmp bx, 7 ; check if NULL ptr.
210 jle ffslz_badselector
211 mov ax, es
212 cmp bx, 7 ; check if NULL ptr.
213 jle ffslz_badselector
214
215 mov ds, bx ; ds:si -> string
216 mov ax, di
217 not ax
218 cmp ax, cx ; crosses segment boundrary...
219 jb ffslz_invalidptr
220 mov ax, si
221 not ax
222 cmp ax, cx ; crosses segment boundrary...
223 jb ffslz_invalidptr
224
225; movzx esi, si
226; movzx edi, di
227; movzx ecx, cx
228; db 66h ; force it use extended registers.
229 rep movsb
230
231ffslz_retok:
232 xor ax, ax
233 mov cx, di
234 sub cx, dx ; cx <- size (end ptr - start ptr)
235 pop es
236 add sp, 8
237 clc
238 db 66h
239 retf
240
241ffslz_badselector:
242 mov ax, ERROR_INVALID_SELECTOR
243 jmp ffslz_reterr
244
245ffslz_invalidptr:
246 int 3
247 mov ax, ERROR_INVALID_ACCESS
248 jmp ffslz_reterr
249
250ffslz_no_term:
251 mov ax, ERROR_TERMINATOR_NOT_FOUND
252ffslz_reterr:
253 pop es
254 add sp, 8
255 stc
256 db 66h
257 retf
258fakef_FuBuff ENDP
259
260
261
262
263CODE16 ENDS
264
265
266
267CODE32 SEGMENT
268;;
269; Faker of which simply clears the loader semaphore.
270; @cproto none! (void _Optlink faketkStartProcess(void))
271; @returns
272; @param
273; @uses
274; @equiv
275; @time
276; @sketch
277; @status
278; @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
279; @remark
280faketkStartProcess PROC NEAR
281 push ebp
282 mov ebp, esp
283
284 push ebx
285 push ecx
286
287 call _fakeLDRClearSem@0
288
289 pop ecx
290 pop ebx
291
292 xor eax, eax
293 leave
294 ret
295faketkStartProcess ENDP
296
297
298;;
299; Fake g_tkExecPgm implementation.
300; @proto none. (void _Optlink fakeg_tkExecPgm(void);)
301; @returns same as tkExecPgm: eax, edx and carry flag
302; @param ax Exec flag
303; ds:dx Filename address. (String)
304; es:bx Environment address. (String)
305; di:si Argument address. (String)
306; @uses all - bp
307; @sketch Copy the filename and arguments into a buffer we
308; may modify later if this is a UNIX shellscript or
309; a PE-file started by pe.exe.
310; @status completely implemented.
311; @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
312;
313;
314fakeg_tkExecPgm PROC NEAR
315 push ebp
316 mov ebp, esp
317
318 ;
319 ; Call C worker
320 ;
321 sub esp, 10h
322 movzx eax, ax
323 mov [esp + 00h], eax ; ExecFlag DWORD
324
325 mov ax, es
326 SelToFlat
327 mov [esp + 08h], eax ; Environment ptr.
328 mov ecx, eax
329
330 mov ax, ds
331 mov bx, dx
332 SelToFlat
333 mov [esp + 0ch], eax ; Filename ptr
334
335 mov ax, di
336 mov bx, si
337 SelToFlat
338 mov [esp + 04h], eax ; Argument ptr
339 mov edx, eax
340
341 mov eax, [esp + 00h] ; ExecFlag DWORD in eax
342
343 mov bx, seg FLAT:DATA32
344 mov ds, bx ; Make ds flat
345 mov es, bx ; Make es flat
346
347 call tkExecPgmWorker ;(ULONG flags, arg, env, prog)
348 add esp, 10 ; eax, edx, ecx,
349 ; ebp+8, ebp+c, ebp+10, ebp+14
350 ; esp+0, esp+4, esp+08, esp+0c
351 or eax, eax
352 jnz ftkep_ret
353 call faketkStartProcess ; If succesfully so far. call start process.
354 jmp ftkep_ret2 ; <Currently no parameters are implemented.>
355
356ftkep_ret:
357 push eax
358 call _fakeLDRClearSem@0 ; clear the semaphore.
359 pop eax
360
361ftkep_ret2:
362 leave
363 ret
364fakeg_tkExecPgm ENDP
365
366
367;;
368; Calls the fakeg_tkExecPgm procedure.
369; @cproto ULONG _Optlink CalltkExecPgm(
370; ULONG execFlags,
371; PCSZ pArg,
372; PCSZ pEnv,
373; PCSZ pExecName);
374; @returns
375; @param eax (ebp +08h) execFlags
376; @param edx (ebp +0ch) pArg
377; @param ecx (ebp +10h) pEnv
378; @param ebp + 14h pExecName
379; @uses eax, ecx, edx
380; @status completely implemented.
381; @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
382; @remark
383CalltkExecPgm PROC NEAR
384 push ebp
385 mov ebp, esp
386 push ebx
387 push edi
388 push esi
389 push es
390 push ds
391
392 ; Save parameters
393 mov [ebp+08h], eax
394
395 ;
396 ; create input for fakeg_tkExecPgm
397 ;
398 mov eax, edx
399 xor edi, edi
400 xor esi, esi
401 or eax, eax
402 jz ctkep1
403 FlatToSel
404 mov di, ax
405 mov esi, ebx ; di:si -> arguments
406ctkep1:
407
408 mov eax, [ebp + 14h]
409 xor edx, edx
410 mov ds, dx
411 or eax, eax
412 jz ctkep2
413 FlatToSel
414 mov ds, ax
415 mov edx, ebx ; ds:dx -> executable filename
416ctkep2:
417
418 mov eax, ecx
419 xor ebx, ebx
420 mov es, bx
421 or eax, eax
422 jz ctkep3
423 FlatToSel
424 mov es, ax
425 mov eax, ebx ; es:bx -> environment.
426ctkep3:
427
428 mov eax, [ebp+08h] ; ax = exec flags.
429
430 call far ptr FLAT:fakeg_tkExecPgm
431
432 ;
433 ; Restore and return.
434 ;
435 pop ds
436 pop es
437 pop esi
438 pop edi
439 pop ebx
440 leave
441 ret
442CalltkExecPgm ENDP
443
444
445;;
446; Gets the selector for the CODE16 segment.
447; @cproto USHORT _Optlink GetSelectorCODE16(void)
448; @returns Selector for the CODE16 segment.
449; @uses eax
450; @status completely implemented.
451; @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
452GetSelectorCODE16 PROC NEAR
453 xor eax, eax
454 mov ax, seg CODE16
455 ret
456GetSelectorCODE16 ENDP
457
458
459;;
460; Gets the selector for the DATA16 segment.
461; @cproto USHORT _Optlink GetSelectorDATA16(void)
462; @returns Selector for the DATA16 segment.
463; @uses eax
464; @status completely implemented.
465; @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
466GetSelectorDATA16 PROC NEAR
467 xor eax, eax
468 mov ax, seg DATA16
469 ret
470GetSelectorDATA16 ENDP
471
472
473;;
474; Gets the selector for the CODE32 segment.
475; @cproto USHORT _Optlink GetSelectorCODE32(void)
476; @returns Selector for the CODE32 segment.
477; @uses eax
478; @status completely implemented.
479; @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
480GetSelectorCODE32 PROC NEAR
481 xor eax, eax
482 mov ax, seg FLAT:CODE32
483 ret
484GetSelectorCODE32 ENDP
485
486;;
487; Gets the selector for the DATA32 segment.
488; @cproto USHORT _Optlink GetSelectorDATA32(void)
489; @returns Selector for the DATA32 segment.
490; @uses eax
491; @status completely implemented.
492; @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
493GetSelectorDATA32 PROC NEAR
494 xor eax, eax
495 mov ax, seg FLAT:DATA32
496 ret
497GetSelectorDATA32 ENDP
498
499
500;;
501; Wrapper for fakeldrOpenPath.
502; @cproto ULONG LDRCALL fakeldrOpenPath(PCHAR pachFilename, USHORT cchFilename, ldrlv_t *plv, PULONG pful, ULONG lLibPath);
503; @returns Return of the current fakeldrOpenPath
504; @param pachFilename Pointer to modulename. Not zero terminated!
505; @param cchFilename Modulename length.
506; @param plv Loader local variables? (Struct from KERNEL.SDF)
507; @param pful Pointer to flags which are passed on to ldrOpen.
508; @param lLibPath New parameter in build 14053.
509; ldrGetMte calls with 1
510; ldrOpenNewExe calls with 3
511; This is compared to the initial libpath index.
512; The libpath index is:
513; BEGINLIBPATH 1
514; LIBPATH 2
515; ENDLIBPATH 3
516; The initial libpath index is either 1 or 2.
517; - ignored -
518; @uses ecx, eax, edx
519; @sketch
520; @status
521; @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
522; @remark
523_fakeldrOpenPath@20 PROC NEAR
524 ASSUME ds:FLAT
525 ; dummy prolog.
526 push ebp
527 mov ebp, esp
528 sub esp, 10h
529 add esp, 10h
530 pop ebp
531 ; real code
532 cmp FLAT:DATA16:_options.ulBuild, 14053
533 jge new
534 jmp near ptr FLAT:CODE32:_fakeldrOpenPath_old@16
535new:
536 jmp near ptr FLAT:CODE32:_fakeldrOpenPath_new@20
537_fakeldrOpenPath@20 ENDP
538
539
540CODE32 ENDS
541
542END
Note: See TracBrowser for help on using the repository browser.