1 | ; $Id: mytkExecPgm.asm,v 1.4 2000-02-21 05:00:53 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 | DATA32 SEGMENT
|
---|
20 | extrn g_tkExecPgm:PROC
|
---|
21 | DATA32 ENDS
|
---|
22 | extrn AcquireBuffer:PROC
|
---|
23 | extrn ReleaseBuffer:PROC
|
---|
24 | extrn QueryBufferSegmentOffset:PROC
|
---|
25 | extrn f_FuStrLenZ
|
---|
26 | extrn f_FuBuff
|
---|
27 |
|
---|
28 | ;
|
---|
29 | ; Exported symbols
|
---|
30 | ;
|
---|
31 | public mytkExecPgm
|
---|
32 | public pszFilename
|
---|
33 | public pszArguments
|
---|
34 |
|
---|
35 |
|
---|
36 | DATA32 SEGMENT
|
---|
37 | pszFilename dd 0 ; Pointer to the filename (in the buffer)
|
---|
38 | pszArguments dd 0 ; Pointer to the arguments (int the buffer)
|
---|
39 | DATA32 ENDS
|
---|
40 |
|
---|
41 |
|
---|
42 | CODE32 SEGMENT
|
---|
43 |
|
---|
44 | ;;
|
---|
45 | ;
|
---|
46 | ; @returns same as tkExecPgm: eax, edx and carry flag
|
---|
47 | ; @param ax Exec flag
|
---|
48 | ; ds:dx Filename address. (String)
|
---|
49 | ; es:bx Environment address. (String)
|
---|
50 | ; di:si Argument address. (String)
|
---|
51 | ; @uses all - bp
|
---|
52 | ; @status
|
---|
53 | ; @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
|
---|
54 | ; @remark Current implemententation assumes that there is one buffer,
|
---|
55 | ; this serializes the usage of the two pointers.
|
---|
56 | ;
|
---|
57 | ; The buffer we are using is a C struct as follows.
|
---|
58 | ; struct Buffer
|
---|
59 | ; {
|
---|
60 | ; char szFilename[261]; /* offset 0 */
|
---|
61 | ; char achArg[1536-261]; /* offset 261 */
|
---|
62 | ; };
|
---|
63 | ;
|
---|
64 | mytkExecPgm PROC FAR
|
---|
65 | pBuffer = dword ptr -04h
|
---|
66 | ;SegBuffer = word ptr (dword ptr -08h)
|
---|
67 | SegBuffer = -08h
|
---|
68 | ;OffBuffer = word ptr (dword ptr -0Ch)
|
---|
69 | OffBuffer = -0Ch
|
---|
70 | cchFilename = dword ptr -10h
|
---|
71 | cchArgs = dword ptr -14h
|
---|
72 | ASSUME CS:CODE32, DS:NOTHING, SS:NOTHING
|
---|
73 | push ebp
|
---|
74 | mov ebp, esp
|
---|
75 | lea esp, [ebp + cchArgs]
|
---|
76 |
|
---|
77 | push eax
|
---|
78 | push ecx
|
---|
79 | push ds
|
---|
80 | push es
|
---|
81 | push edi
|
---|
82 |
|
---|
83 | IF 0
|
---|
84 | ; ; Check if this overloading has anything too say, after all it is using some stack space!
|
---|
85 | ; jmp mytkExecPgm_CalltkExecPgm_X1
|
---|
86 | ENDIF
|
---|
87 |
|
---|
88 | ; parameter validations
|
---|
89 | mov ax, ds ; pointer to filename
|
---|
90 | cmp ax, 4
|
---|
91 | jb mytkExecPgm_CalltkExecPgm_X1
|
---|
92 |
|
---|
93 | ; This test is currently disabled. We'll pass on an empty string if the argument pointer is NULL.
|
---|
94 | ; Hopefully an empty string is treated equally to an NULL pointer.
|
---|
95 | ; cmp di, 4
|
---|
96 | ; jl mytkExecPgm_CalltkExecPgm_X1
|
---|
97 |
|
---|
98 | ; filename length
|
---|
99 | mov ax, ds
|
---|
100 | mov es, ax
|
---|
101 | xor eax, eax
|
---|
102 | movzx edi, dx ; es:di is now filename address (ds:dx).
|
---|
103 | mov ecx, 0ffffffffh
|
---|
104 | cld
|
---|
105 | repne scasb
|
---|
106 | not ecx
|
---|
107 |
|
---|
108 | ;
|
---|
109 | ; if filename length is more that CCHMAXPATH then we don't do anything!.
|
---|
110 | ;
|
---|
111 | cmp ecx, 260
|
---|
112 | jae mytkExecPgm_CalltkExecPgm_X1; length >= 260
|
---|
113 | mov [ebp+cchFilename], ecx
|
---|
114 |
|
---|
115 | ;
|
---|
116 | ; args length
|
---|
117 | ; Note: the arguments are a series of ASCIIZs ended by an empty string (ie. '\0').
|
---|
118 | ;
|
---|
119 | pop edi
|
---|
120 | push edi
|
---|
121 | xor ecx, ecx
|
---|
122 | cmp di, 4 ; The argument might me a invalid pointer...
|
---|
123 | jb mytkExecPgm_CalltkExecPgm_1
|
---|
124 | mov es, di
|
---|
125 | movzx edi, si ; es:edi is now args address (di:si), eax is still 0
|
---|
126 | dec ecx
|
---|
127 | cld
|
---|
128 | mytkExecPgm_CalltkExecPgm_loop: ; loop true all ASCIIZ strings
|
---|
129 | repne scasb ; scans forwards until '\0' is read. es:edi is pointing at the char after the '\0'.
|
---|
130 | cmp byte ptr es:[edi], 0 ; is this char '\0' ? stop looping : loop once more;
|
---|
131 | jnz mytkExecPgm_CalltkExecPgm_loop
|
---|
132 | dec ecx ; update count - count terminating zero too
|
---|
133 | not ecx
|
---|
134 |
|
---|
135 | mytkExecPgm_CalltkExecPgm_1:
|
---|
136 | mov [ebp+cchArgs], ecx
|
---|
137 | add ecx, [ebp+cchFilename] ; filename
|
---|
138 | add ecx, 3 + 260 ; 260 = new argument from a scrip file or something.
|
---|
139 | ; 3 = two '\0's and a space after added argument.
|
---|
140 | cmp ecx, 1536 ; 1536 = Buffersize. FIXME! Define this!!!
|
---|
141 | jae mytkExecPgm_CalltkExecPgm_X1; jmp if argument + file + new file > buffer size
|
---|
142 |
|
---|
143 | ;
|
---|
144 | ; Aquire a buffer
|
---|
145 | ;
|
---|
146 | call AcquireBuffer
|
---|
147 | or eax, eax
|
---|
148 | jz mytkExecPgm_CalltkExecPgm_X1; Failed to get buffer.
|
---|
149 | mov [ebp+pBuffer], eax
|
---|
150 |
|
---|
151 | ;
|
---|
152 | ; Get Segment and offset for the buffer
|
---|
153 | ;
|
---|
154 | call QueryBufferSegmentOffset
|
---|
155 | mov cx, es
|
---|
156 | mov [ebp+OffBuffer], ax
|
---|
157 | mov [ebp+SegBuffer], es
|
---|
158 | test eax, 000570000h
|
---|
159 | jnz mytkExecPgm_CalltkExecPgm_X2
|
---|
160 |
|
---|
161 | ;
|
---|
162 | ; Copy filename to pBuffer.
|
---|
163 | ;
|
---|
164 | push esi
|
---|
165 | mov edi, eax ; es:di pBuffer
|
---|
166 | movzx esi, dx ; ds:si Filename pointer (input ds:dx)
|
---|
167 | mov ecx, [ebp+cchFilename]
|
---|
168 | cld
|
---|
169 | rep movsb
|
---|
170 |
|
---|
171 | ;
|
---|
172 | ; Copy Args to pBuffer + 261
|
---|
173 | ;
|
---|
174 | ; stack: esi, edi, es, ds, ecx, eax
|
---|
175 | pop esi
|
---|
176 | pop edi
|
---|
177 | push edi
|
---|
178 | push esi
|
---|
179 | add eax, 261 ; we'll use eax in the branch
|
---|
180 | cmp di, 4
|
---|
181 | jb mytkExecPgm_CalltkExecPgm_2
|
---|
182 | and esi, 00000ffffh ; remove high part of the register
|
---|
183 | mov ds, di ; ds:si -> arguments
|
---|
184 | mov edi, eax ; es:di -> pBuffer + 261
|
---|
185 | mov ecx, [ebp+cchArgs]
|
---|
186 | cld
|
---|
187 | rep movsb
|
---|
188 | jmp mytkExecPgm_CalltkExecPgm_3
|
---|
189 |
|
---|
190 | mytkExecPgm_CalltkExecPgm_2:
|
---|
191 | mov byte ptr es:[eax], 0 ; Terminate the empty string!
|
---|
192 |
|
---|
193 | ;
|
---|
194 | ; Set Pointers, pszFilename and pszArguments
|
---|
195 | ;
|
---|
196 | mytkExecPgm_CalltkExecPgm_3:
|
---|
197 | mov ax, seg FLAT:DATA32
|
---|
198 | mov ds, ax
|
---|
199 | ASSUME ds:FLAT
|
---|
200 | mov eax, ss:[ebp+pBuffer]
|
---|
201 | mov pszFilename, eax
|
---|
202 | add eax, 261
|
---|
203 | mov pszArguments, eax
|
---|
204 |
|
---|
205 | ;
|
---|
206 | ; Restore variables pushed on the stack
|
---|
207 | ;
|
---|
208 | ; stack: esi, edi, es, ds, ecx, eax
|
---|
209 | pop esi
|
---|
210 | pop edi
|
---|
211 | pop es
|
---|
212 | pop ds
|
---|
213 | pop ecx
|
---|
214 | pop eax
|
---|
215 |
|
---|
216 | ;
|
---|
217 | ; Set new input parameters (call g_tkExecPgm)
|
---|
218 | ;
|
---|
219 | ; ds:dx is to become SegBuffer:OffBuffer
|
---|
220 | ; di:si is to become SegBuffer:OffBuffer+261
|
---|
221 | ;
|
---|
222 | ; The some of the old values are stored on the stack (for the time being)
|
---|
223 | push ds
|
---|
224 | push edi
|
---|
225 | push esi
|
---|
226 |
|
---|
227 | mov di, [ebp+SegBuffer]
|
---|
228 | mov ds, di
|
---|
229 | mov si, [ebp+OffBuffer]
|
---|
230 | mov dx, si ; ds:dx SegBuffer:OffBuffer
|
---|
231 | add si, 261 ; di:si SegBuffer:OffBuffer+261
|
---|
232 |
|
---|
233 | ;
|
---|
234 | ; Call g_tkExecPgm
|
---|
235 | ;
|
---|
236 | push cs
|
---|
237 | call near ptr FLAT:g_tkExecPgm
|
---|
238 | pushfd
|
---|
239 |
|
---|
240 | ;
|
---|
241 | ; Release buffer
|
---|
242 | ;
|
---|
243 | push eax
|
---|
244 | mov eax, [ebp + pBuffer]
|
---|
245 | call ReleaseBuffer
|
---|
246 | mov [ebp + pBuffer], 0
|
---|
247 | pop eax
|
---|
248 |
|
---|
249 | ;
|
---|
250 | ; Return
|
---|
251 | ;
|
---|
252 | popfd
|
---|
253 | pop esi
|
---|
254 | pop edi
|
---|
255 | pop ds
|
---|
256 | leave
|
---|
257 | retf
|
---|
258 |
|
---|
259 | mytkExecPgm_CalltkExecPgm_X2:
|
---|
260 | ;
|
---|
261 | ; Release buffer
|
---|
262 | ;
|
---|
263 | mov eax, [ebp + pBuffer]
|
---|
264 | call ReleaseBuffer
|
---|
265 | mov [ebp + pBuffer], 0
|
---|
266 |
|
---|
267 | mytkExecPgm_CalltkExecPgm_X1:
|
---|
268 | pop edi
|
---|
269 | pop es
|
---|
270 | pop ds
|
---|
271 | pop ecx
|
---|
272 | pop eax
|
---|
273 |
|
---|
274 | mytkExecPgm_CalltkExecPgm:
|
---|
275 | call far ptr FLAT:g_tkExecPgmStub
|
---|
276 | leave
|
---|
277 | retf
|
---|
278 | mytkExecPgm ENDP
|
---|
279 |
|
---|
280 |
|
---|
281 | ;;
|
---|
282 | ; Stub which jumps to g_tkExecPgmStub.
|
---|
283 | ; (This way I will hopefully get the right selector.)
|
---|
284 | g_tkExecPgmStub PROC FAR
|
---|
285 | jmp near ptr FLAT:g_tkExecPgm
|
---|
286 | g_tkExecPgmStub ENDP
|
---|
287 |
|
---|
288 |
|
---|
289 | CODE32 ENDS
|
---|
290 | END
|
---|
291 |
|
---|