Rev 9715 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 9715 | Rev 9977 | ||
---|---|---|---|
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2022. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2022. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
5 | ;; ;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
7 | 7 | ||
8 | ; External kernel dependencies (libraries) loading. |
8 | ; External kernel dependencies (libraries) loading. |
9 | ; The code currently does not work, requires correcting dll.inc. |
9 | ; The code currently does not work, requires correcting dll.inc. |
10 | 10 | ||
11 | $Revision: 9715 $ |
11 | $Revision: 9977 $ |
12 | 12 | ||
13 | if 0 |
13 | if 0 |
14 | iglobal |
14 | iglobal |
15 | tmp_file_name_size dd 1 |
15 | tmp_file_name_size dd 1 |
16 | endg |
16 | endg |
17 | 17 | ||
18 | uglobal |
18 | uglobal |
19 | tmp_file_name_table dd ? |
19 | tmp_file_name_table dd ? |
20 | s_libname rb 64 |
20 | s_libname rb 64 |
21 | def_val_1 db ? |
21 | def_val_1 db ? |
22 | endg |
22 | endg |
23 | 23 | ||
24 | macro library [name,fname] |
24 | macro library [name,fname] |
25 | { |
25 | { |
26 | forward |
26 | forward |
27 | dd __#name#_library_table__,__#name#_library_name__ |
27 | dd __#name#_library_table__,__#name#_library_name__ |
28 | common |
28 | common |
29 | dd 0 |
29 | dd 0 |
30 | forward |
30 | forward |
31 | __#name#_library_name__ db fname,0 |
31 | __#name#_library_name__ db fname,0 |
32 | } |
32 | } |
33 | 33 | ||
34 | macro import lname,[name,sname] |
34 | macro import lname,[name,sname] |
35 | { |
35 | { |
36 | common |
36 | common |
37 | align 4 |
37 | align 4 |
38 | __#lname#_library_table__: |
38 | __#lname#_library_table__: |
39 | forward |
39 | forward |
40 | name dd __#name#_import_name__ |
40 | name dd __#name#_import_name__ |
41 | common |
41 | common |
42 | dd 0 |
42 | dd 0 |
43 | forward |
43 | forward |
44 | __#name#_import_name__ db sname,0 |
44 | __#name#_import_name__ db sname,0 |
45 | } |
45 | } |
46 | 46 | ||
47 | macro export [name,sname] |
47 | macro export [name,sname] |
48 | { |
48 | { |
49 | align 4 |
49 | align 4 |
50 | forward |
50 | forward |
51 | dd __#name#_export_name__,name |
51 | dd __#name#_export_name__,name |
52 | common |
52 | common |
53 | dd 0 |
53 | dd 0 |
54 | forward |
54 | forward |
55 | __#name#_export_name__ db sname,0 |
55 | __#name#_export_name__ db sname,0 |
56 | } |
56 | } |
57 | 57 | ||
58 | 58 | ||
59 | 59 | ||
60 | align 4 ; loading library (use kernel functions) |
60 | align 4 ; loading library (use kernel functions) |
61 | proc load_k_library stdcall, file_name:dword |
61 | proc load_k_library stdcall, file_name:dword |
62 | locals |
62 | locals |
63 | coff dd ? |
63 | coff dd ? |
64 | sym dd ? |
64 | sym dd ? |
65 | strings dd ? |
65 | strings dd ? |
66 | img_size dd ? |
66 | img_size dd ? |
67 | img_base dd ? |
67 | img_base dd ? |
68 | exports dd ? |
68 | exports dd ? |
69 | endl |
69 | endl |
70 | 70 | ||
71 | cli |
71 | cli |
72 | 72 | ||
73 | stdcall load_file, [file_name] |
73 | stdcall load_file, [file_name] |
74 | test eax, eax |
74 | test eax, eax |
75 | jz .fail |
75 | jz .fail |
76 | 76 | ||
77 | mov [coff], eax |
77 | mov [coff], eax |
78 | movzx ecx, [eax + CFH.nSections] |
78 | movzx ecx, [eax + CFH.nSections] |
79 | xor ebx, ebx |
79 | xor ebx, ebx |
80 | 80 | ||
81 | lea edx, [eax+20] |
81 | lea edx, [eax+20] |
82 | @@: |
82 | @@: |
83 | add ebx, [edx + CFS.SizeOfRawData] |
83 | add ebx, [edx + CFS.SizeOfRawData] |
84 | add ebx, 15 |
84 | add ebx, 15 |
85 | and ebx, not 15 |
85 | and ebx, not 15 |
86 | add edx, COFF_SECTION_SIZE |
86 | add edx, COFF_SECTION_SIZE |
87 | dec ecx |
87 | dec ecx |
88 | jnz @B |
88 | jnz @B |
89 | mov [img_size], ebx |
89 | mov [img_size], ebx |
90 | 90 | ||
91 | stdcall kernel_alloc, [img_size] |
91 | stdcall kernel_alloc, [img_size] |
92 | 92 | ||
93 | test eax, eax |
93 | test eax, eax |
94 | jz .fail |
94 | jz .fail |
95 | mov [img_base], eax |
95 | mov [img_base], eax |
96 | 96 | ||
97 | mov edx, [coff] |
97 | mov edx, [coff] |
98 | movzx ebx, [edx + CFH.nSections] |
98 | movzx ebx, [edx + CFH.nSections] |
99 | mov edi, [img_base] |
99 | mov edi, [img_base] |
100 | lea eax, [edx+20] |
100 | lea eax, [edx+20] |
101 | @@: |
101 | @@: |
102 | mov [eax + CFS.VirtualAddress], edi |
102 | mov [eax + CFS.VirtualAddress], edi |
103 | mov esi, [eax + CFS.PtrRawData] |
103 | mov esi, [eax + CFS.PtrRawData] |
104 | test esi, esi |
104 | test esi, esi |
105 | jnz .copy |
105 | jnz .copy |
106 | add edi, [eax + CFS.SizeOfRawData] |
106 | add edi, [eax + CFS.SizeOfRawData] |
107 | jmp .next |
107 | jmp .next |
108 | .copy: |
108 | .copy: |
109 | add esi, edx |
109 | add esi, edx |
110 | mov ecx, [eax + CFS.SizeOfRawData] |
110 | mov ecx, [eax + CFS.SizeOfRawData] |
111 | cld |
111 | cld |
112 | rep movsb |
112 | rep movsb |
113 | .next: |
113 | .next: |
114 | add edi, 15 |
114 | add edi, 15 |
115 | and edi, not 15 |
115 | and edi, not 15 |
116 | add eax, COFF_SECTION_SIZE |
116 | add eax, COFF_SECTION_SIZE |
117 | dec ebx |
117 | dec ebx |
118 | jnz @B |
118 | jnz @B |
119 | 119 | ||
120 | mov ebx, [edx + CFH.pSymTable] |
120 | mov ebx, [edx + CFH.pSymTable] |
121 | add ebx, edx |
121 | add ebx, edx |
122 | mov [sym], ebx |
122 | mov [sym], ebx |
123 | mov ecx, [edx + CFH.nSymbols] |
123 | mov ecx, [edx + CFH.nSymbols] |
124 | add ecx, ecx |
124 | add ecx, ecx |
125 | lea ecx, [ecx + ecx*8];ecx*=18 = nSymbols*CSYM_SIZE |
125 | lea ecx, [ecx + ecx*8];ecx*=18 = nSymbols*CSYM_SIZE |
126 | add ecx, [sym] |
126 | add ecx, [sym] |
127 | mov [strings], ecx |
127 | mov [strings], ecx |
128 | 128 | ||
129 | lea eax, [edx+20] |
129 | lea eax, [edx+20] |
130 | 130 | ||
131 | stdcall fix_coff_symbols, eax, [sym], [edx + CFH.nSymbols], \ |
131 | stdcall fix_coff_symbols, eax, [sym], [edx + CFH.nSymbols], \ |
132 | [strings], dword 0 |
132 | [strings], dword 0 |
133 | test eax, eax |
133 | test eax, eax |
134 | jnz @F |
134 | jnz @F |
135 | 135 | ||
136 | @@: |
136 | @@: |
137 | mov edx, [coff] |
137 | mov edx, [coff] |
138 | movzx ebx, [edx + CFH.nSections] |
138 | movzx ebx, [edx + CFH.nSections] |
139 | mov edi, 0 |
139 | xor edi, edi |
140 | lea eax, [edx+20] |
140 | lea eax, [edx+20] |
141 | @@: |
141 | @@: |
142 | add [eax + CFS.VirtualAddress], edi ;patch user space offset |
142 | add [eax + CFS.VirtualAddress], edi ;patch user space offset |
143 | add eax, COFF_SECTION_SIZE |
143 | add eax, COFF_SECTION_SIZE |
144 | dec ebx |
144 | dec ebx |
145 | jnz @B |
145 | jnz @B |
146 | 146 | ||
147 | add edx, 20 |
147 | add edx, 20 |
148 | stdcall fix_coff_relocs, [coff], edx, [sym] |
148 | stdcall fix_coff_relocs, [coff], edx, [sym] |
149 | 149 | ||
150 | mov ebx, [coff] |
150 | mov ebx, [coff] |
151 | stdcall get_coff_sym, [sym], [ebx+CFH.nSymbols], szEXPORTS |
151 | stdcall get_coff_sym, [sym], [ebx+CFH.nSymbols], szEXPORTS |
152 | mov [exports], eax |
152 | mov [exports], eax |
153 | 153 | ||
154 | stdcall kernel_free, [coff] |
154 | stdcall kernel_free, [coff] |
155 | 155 | ||
156 | mov eax, [exports] |
156 | mov eax, [exports] |
157 | ret |
157 | ret |
158 | .fail: |
158 | .fail: |
159 | xor eax, eax |
159 | xor eax, eax |
160 | ret |
160 | ret |
161 | endp |
161 | endp |
162 | 162 | ||
163 | 163 | ||
164 | proc dll.Load, import_table:dword |
164 | proc dll.Load, import_table:dword |
165 | mov esi, [import_table] |
165 | mov esi, [import_table] |
166 | .next_lib: |
166 | .next_lib: |
167 | mov edx, [esi] |
167 | mov edx, [esi] |
168 | or edx, edx |
168 | or edx, edx |
169 | jz .exit |
169 | jz .exit |
170 | push esi |
170 | push esi |
171 | 171 | ||
172 | mov edi, s_libname |
172 | mov edi, s_libname |
173 | 173 | ||
174 | mov al, '/' |
174 | mov al, '/' |
175 | stosb |
175 | stosb |
176 | mov esi, sysdir_path |
176 | mov esi, sysdir_path |
177 | @@: |
177 | @@: |
178 | lodsb |
178 | lodsb |
179 | stosb |
179 | stosb |
180 | or al, al |
180 | or al, al |
181 | jnz @b |
181 | jnz @b |
182 | dec edi |
182 | dec edi |
183 | mov [edi], dword '/lib' |
183 | mov [edi], dword '/lib' |
184 | mov [edi+4], byte '/' |
184 | mov [edi+4], byte '/' |
185 | add edi, 5 |
185 | add edi, 5 |
186 | pop esi |
186 | pop esi |
187 | push esi |
187 | push esi |
188 | mov esi, [esi+4] |
188 | mov esi, [esi+4] |
189 | @@: |
189 | @@: |
190 | lodsb |
190 | lodsb |
191 | stosb |
191 | stosb |
192 | or al, al |
192 | or al, al |
193 | jnz @b |
193 | jnz @b |
194 | 194 | ||
195 | pushad |
195 | pushad |
196 | stdcall load_k_library, s_libname |
196 | stdcall load_k_library, s_libname |
197 | mov [esp+28], eax |
197 | mov [esp+28], eax |
198 | popad |
198 | popad |
199 | or eax, eax |
199 | or eax, eax |
200 | jz .fail |
200 | jz .fail |
201 | stdcall dll.Link, eax, edx |
201 | stdcall dll.Link, eax, edx |
202 | stdcall dll.Init, [eax+4] |
202 | stdcall dll.Init, [eax+4] |
203 | pop esi |
203 | pop esi |
204 | add esi, 8 |
204 | add esi, 8 |
205 | jmp .next_lib |
205 | jmp .next_lib |
206 | .exit: |
206 | .exit: |
207 | xor eax, eax |
207 | xor eax, eax |
208 | ret |
208 | ret |
209 | .fail: |
209 | .fail: |
210 | add esp, 4 |
210 | add esp, 4 |
211 | xor eax, eax |
211 | xor eax, eax |
212 | inc eax |
212 | inc eax |
213 | ret |
213 | ret |
214 | endp |
214 | endp |
215 | 215 | ||
216 | proc dll.Link, exp:dword,imp:dword |
216 | proc dll.Link, exp:dword,imp:dword |
217 | push eax |
217 | push eax |
218 | mov esi, [imp] |
218 | mov esi, [imp] |
219 | test esi, esi |
219 | test esi, esi |
220 | jz .done |
220 | jz .done |
221 | .next: |
221 | .next: |
222 | lodsd |
222 | lodsd |
223 | test eax, eax |
223 | test eax, eax |
224 | jz .done |
224 | jz .done |
225 | stdcall dll.GetProcAddress, [exp], eax |
225 | stdcall dll.GetProcAddress, [exp], eax |
226 | or eax, eax |
226 | or eax, eax |
227 | jz @f |
227 | jz @f |
228 | mov [esi-4], eax |
228 | mov [esi-4], eax |
229 | jmp .next |
229 | jmp .next |
230 | @@: |
230 | @@: |
231 | mov dword[esp], 0 |
231 | mov dword[esp], 0 |
232 | .done: |
232 | .done: |
233 | pop eax |
233 | pop eax |
234 | ret |
234 | ret |
235 | endp |
235 | endp |
236 | 236 | ||
237 | proc dll.Init, dllentry:dword |
237 | proc dll.Init, dllentry:dword |
238 | pushad |
238 | pushad |
239 | mov eax, mem.Alloc |
239 | mov eax, mem.Alloc |
240 | mov ebx, mem.Free |
240 | mov ebx, mem.Free |
241 | mov ecx, mem.ReAlloc |
241 | mov ecx, mem.ReAlloc |
242 | mov edx, dll.Load |
242 | mov edx, dll.Load |
243 | stdcall [dllentry] |
243 | stdcall [dllentry] |
244 | popad |
244 | popad |
245 | ret |
245 | ret |
246 | endp |
246 | endp |
247 | 247 | ||
248 | proc dll.GetProcAddress, exp:dword,sz_name:dword |
248 | proc dll.GetProcAddress, exp:dword,sz_name:dword |
249 | mov edx, [exp] |
249 | mov edx, [exp] |
250 | .next: |
250 | .next: |
251 | test edx, edx |
251 | test edx, edx |
252 | jz .end |
252 | jz .end |
253 | stdcall strncmp, [edx], [sz_name], dword -1 |
253 | stdcall strncmp, [edx], [sz_name], dword -1 |
254 | test eax, eax |
254 | test eax, eax |
255 | jz .ok |
255 | jz .ok |
256 | add edx, 8 |
256 | add edx, 8 |
257 | jmp .next |
257 | jmp .next |
258 | .ok: |
258 | .ok: |
259 | mov eax, [edx+4] |
259 | mov eax, [edx+4] |
260 | .end: |
260 | .end: |
261 | ret |
261 | ret |
262 | endp |
262 | endp |
263 | 263 | ||
264 | ;----------------------------------------------------------------------------- |
264 | ;----------------------------------------------------------------------------- |
265 | proc mem.Alloc size ;///////////////////////////////////////////////////////// |
265 | proc mem.Alloc size ;///////////////////////////////////////////////////////// |
266 | ;----------------------------------------------------------------------------- |
266 | ;----------------------------------------------------------------------------- |
267 | push ebx ecx |
267 | push ebx ecx |
268 | ; mov eax,[size] |
268 | ; mov eax,[size] |
269 | ; lea ecx,[eax+4+4095] |
269 | ; lea ecx,[eax+4+4095] |
270 | ; and ecx,not 4095 |
270 | ; and ecx,not 4095 |
271 | ; stdcall kernel_alloc, ecx |
271 | ; stdcall kernel_alloc, ecx |
272 | ; add ecx,-4 |
272 | ; add ecx,-4 |
273 | ; mov [eax],ecx |
273 | ; mov [eax],ecx |
274 | ; add eax,4 |
274 | ; add eax,4 |
275 | 275 | ||
276 | stdcall kernel_alloc, [size] |
276 | stdcall kernel_alloc, [size] |
277 | 277 | ||
278 | pop ecx ebx |
278 | pop ecx ebx |
279 | ret |
279 | ret |
280 | endp |
280 | endp |
281 | 281 | ||
282 | ;----------------------------------------------------------------------------- |
282 | ;----------------------------------------------------------------------------- |
283 | proc mem.ReAlloc mptr,size;/////////////////////////////////////////////////// |
283 | proc mem.ReAlloc mptr,size;/////////////////////////////////////////////////// |
284 | ;----------------------------------------------------------------------------- |
284 | ;----------------------------------------------------------------------------- |
285 | push ebx ecx esi edi eax |
285 | push ebx ecx esi edi eax |
286 | mov eax, [mptr] |
286 | mov eax, [mptr] |
287 | mov ebx, [size] |
287 | mov ebx, [size] |
288 | or eax, eax |
288 | or eax, eax |
289 | jz @f |
289 | jz @f |
290 | lea ecx, [ebx+4+4095] |
290 | lea ecx, [ebx+4+4095] |
291 | and ecx, not 4095 |
291 | and ecx, not 4095 |
292 | add ecx, -4 |
292 | add ecx, -4 |
293 | cmp ecx, [eax-4] |
293 | cmp ecx, [eax-4] |
294 | je .exit |
294 | je .exit |
295 | @@: |
295 | @@: |
296 | mov eax, ebx |
296 | mov eax, ebx |
297 | call mem.Alloc |
297 | call mem.Alloc |
298 | xchg eax, [esp] |
298 | xchg eax, [esp] |
299 | or eax, eax |
299 | or eax, eax |
300 | jz .exit |
300 | jz .exit |
301 | mov esi, eax |
301 | mov esi, eax |
302 | xchg eax, [esp] |
302 | xchg eax, [esp] |
303 | mov edi, eax |
303 | mov edi, eax |
304 | mov ecx, [esi-4] |
304 | mov ecx, [esi-4] |
305 | cmp ecx, [edi-4] |
305 | cmp ecx, [edi-4] |
306 | jbe @f |
306 | jbe @f |
307 | mov ecx, [edi-4] |
307 | mov ecx, [edi-4] |
308 | @@: |
308 | @@: |
309 | add ecx, 3 |
309 | add ecx, 3 |
310 | shr ecx, 2 |
310 | shr ecx, 2 |
311 | cld |
311 | cld |
312 | rep movsd |
312 | rep movsd |
313 | xchg eax, [esp] |
313 | xchg eax, [esp] |
314 | call mem.Free |
314 | call mem.Free |
315 | .exit: |
315 | .exit: |
316 | pop eax edi esi ecx ebx |
316 | pop eax edi esi ecx ebx |
317 | ret |
317 | ret |
318 | endp |
318 | endp |
319 | 319 | ||
320 | ;----------------------------------------------------------------------------- |
320 | ;----------------------------------------------------------------------------- |
321 | proc mem.Free mptr ;////////////////////////////////////////////////////////// |
321 | proc mem.Free mptr ;////////////////////////////////////////////////////////// |
322 | ;----------------------------------------------------------------------------- |
322 | ;----------------------------------------------------------------------------- |
323 | ; mov eax,[mptr] |
323 | ; mov eax,[mptr] |
324 | ; or eax,eax |
324 | ; or eax,eax |
325 | ; jz @f |
325 | ; jz @f |
326 | ; push ebx ecx |
326 | ; push ebx ecx |
327 | ; lea ecx,[eax-4] |
327 | ; lea ecx,[eax-4] |
328 | ; stdcall kernel_free, ecx |
328 | ; stdcall kernel_free, ecx |
329 | ; pop ecx ebx |
329 | ; pop ecx ebx |
330 | ; @@: ret |
330 | ; @@: ret |
331 | stdcall kernel_free, [mptr] |
331 | stdcall kernel_free, [mptr] |
332 | ret |
332 | ret |
333 | endp |
333 | endp |
334 | 334 | ||
335 | proc load_file_parse_table |
335 | proc load_file_parse_table |
336 | stdcall kernel_alloc, 0x1000 |
336 | stdcall kernel_alloc, 0x1000 |
337 | mov [tmp_file_name_table], eax |
337 | mov [tmp_file_name_table], eax |
338 | mov edi, eax |
338 | mov edi, eax |
339 | mov esi, sysdir_name |
339 | mov esi, sysdir_name |
340 | mov ecx, 128/4 |
340 | mov ecx, 128/4 |
341 | rep movsd |
341 | rep movsd |
342 | invoke ini.enum_keys, conf_fname, conf_path_sect, get_every_key |
342 | invoke ini.enum_keys, conf_fname, conf_path_sect, get_every_key |
343 | mov eax, [tmp_file_name_table] |
343 | mov eax, [tmp_file_name_table] |
344 | mov [full_file_name_table], eax |
344 | mov [full_file_name_table], eax |
345 | mov eax, [tmp_file_name_size] |
345 | mov eax, [tmp_file_name_size] |
346 | mov [full_file_name_table.size], eax |
346 | mov [full_file_name_table.size], eax |
347 | ret |
347 | ret |
348 | endp |
348 | endp |
349 | 349 | ||
350 | proc get_every_key stdcall, f_name, sec_name, key_name |
350 | proc get_every_key stdcall, f_name, sec_name, key_name |
351 | mov esi, [key_name] |
351 | mov esi, [key_name] |
352 | mov ecx, esi |
352 | mov ecx, esi |
353 | cmp byte [esi], '/' |
353 | cmp byte [esi], '/' |
354 | jnz @f |
354 | jnz @f |
355 | inc esi |
355 | inc esi |
356 | @@: |
356 | @@: |
357 | mov edi, [tmp_file_name_size] |
357 | mov edi, [tmp_file_name_size] |
358 | shl edi, 7 |
358 | shl edi, 7 |
359 | cmp edi, 0x1000 |
359 | cmp edi, 0x1000 |
360 | jae .stop_parse |
360 | jae .stop_parse |
361 | add edi, [tmp_file_name_table] |
361 | add edi, [tmp_file_name_table] |
362 | lea ebx, [edi+64] |
362 | lea ebx, [edi+64] |
363 | @@: |
363 | @@: |
364 | cmp edi, ebx |
364 | cmp edi, ebx |
365 | jae .skip_this_key |
365 | jae .skip_this_key |
366 | lodsb |
366 | lodsb |
367 | test al, al |
367 | test al, al |
368 | jz @f |
368 | jz @f |
369 | or al, 20h |
369 | or al, 20h |
370 | stosb |
370 | stosb |
371 | jmp @b |
371 | jmp @b |
372 | 372 | ||
373 | .stop_parse: |
373 | .stop_parse: |
374 | xor eax, eax |
374 | xor eax, eax |
375 | ret |
375 | ret |
376 | 376 | ||
377 | @@: |
377 | @@: |
378 | stosb |
378 | stosb |
379 | invoke ini.get_str, [f_name], [sec_name], ecx, ebx, 64, def_val_1 |
379 | invoke ini.get_str, [f_name], [sec_name], ecx, ebx, 64, def_val_1 |
380 | cmp byte [ebx], '/' |
380 | cmp byte [ebx], '/' |
381 | jnz @f |
381 | jnz @f |
382 | lea esi, [ebx+1] |
382 | lea esi, [ebx+1] |
383 | mov edi, ebx |
383 | mov edi, ebx |
384 | mov ecx, 63 |
384 | mov ecx, 63 |
385 | rep movsb |
385 | rep movsb |
386 | @@: |
386 | @@: |
387 | push ebp |
387 | push ebp |
388 | mov ebp, [tmp_file_name_table] |
388 | mov ebp, [tmp_file_name_table] |
389 | mov ecx, [tmp_file_name_size] |
389 | mov ecx, [tmp_file_name_size] |
390 | jecxz .noreplace |
390 | jecxz .noreplace |
391 | mov eax, ecx |
391 | mov eax, ecx |
392 | dec eax |
392 | dec eax |
393 | shl eax, 7 |
393 | shl eax, 7 |
394 | add ebp, eax |
394 | add ebp, eax |
395 | .replace_loop: |
395 | .replace_loop: |
396 | mov edi, ebx |
396 | mov edi, ebx |
397 | mov esi, ebp |
397 | mov esi, ebp |
398 | @@: |
398 | @@: |
399 | lodsb |
399 | lodsb |
400 | test al, al |
400 | test al, al |
401 | jz .doreplace |
401 | jz .doreplace |
402 | mov dl, [edi] |
402 | mov dl, [edi] |
403 | inc edi |
403 | inc edi |
404 | test dl, dl |
404 | test dl, dl |
405 | jz .replace_loop_cont |
405 | jz .replace_loop_cont |
406 | or dl, 20h |
406 | or dl, 20h |
407 | cmp al, dl |
407 | cmp al, dl |
408 | jz @b |
408 | jz @b |
409 | jmp .replace_loop_cont |
409 | jmp .replace_loop_cont |
410 | 410 | ||
411 | .doreplace: |
411 | .doreplace: |
412 | cmp byte [edi], 0 |
412 | cmp byte [edi], 0 |
413 | jz @f |
413 | jz @f |
414 | cmp byte [edi], '/' |
414 | cmp byte [edi], '/' |
415 | jnz .replace_loop_cont |
415 | jnz .replace_loop_cont |
416 | @@: |
416 | @@: |
417 | lea esi, [ebp+64] |
417 | lea esi, [ebp+64] |
418 | call .replace |
418 | call .replace |
419 | jc .skip_this_key2 |
419 | jc .skip_this_key2 |
420 | .replace_loop_cont: |
420 | .replace_loop_cont: |
421 | sub ebp, 128 |
421 | sub ebp, 128 |
422 | loop .replace_loop |
422 | loop .replace_loop |
423 | .noreplace: |
423 | .noreplace: |
424 | pop ebp |
424 | pop ebp |
425 | inc [tmp_file_name_size] |
425 | inc [tmp_file_name_size] |
426 | .skip_this_key: |
426 | .skip_this_key: |
427 | xor eax, eax |
427 | xor eax, eax |
428 | inc eax |
428 | inc eax |
429 | ret |
429 | ret |
430 | 430 | ||
431 | .skip_this_key2: |
431 | .skip_this_key2: |
432 | pop ebp |
432 | pop ebp |
433 | jmp .skip_this_key |
433 | jmp .skip_this_key |
434 | endp |
434 | endp |
435 | 435 | ||
436 | proc get_every_key.replace |
436 | proc get_every_key.replace |
437 | ; in: ebx->destination, esi->first part of name, edi->second part of name |
437 | ; in: ebx->destination, esi->first part of name, edi->second part of name |
438 | ; maximum length is 64 bytes |
438 | ; maximum length is 64 bytes |
439 | ; out: CF=1 <=> overflow |
439 | ; out: CF=1 <=> overflow |
440 | sub esp, 64 ; allocate temporary buffer in stack |
440 | sub esp, 64 ; allocate temporary buffer in stack |
441 | push esi |
441 | push esi |
442 | lea esi, [esp+4] ; esi->tmp buffer |
442 | lea esi, [esp+4] ; esi->tmp buffer |
443 | xchg esi, edi ; edi->tmp buffer, esi->source |
443 | xchg esi, edi ; edi->tmp buffer, esi->source |
444 | @@: ; save second part of name to temporary buffer |
444 | @@: ; save second part of name to temporary buffer |
445 | lodsb |
445 | lodsb |
446 | stosb |
446 | stosb |
447 | test al, al |
447 | test al, al |
448 | jnz @b |
448 | jnz @b |
449 | pop esi |
449 | pop esi |
450 | mov edi, ebx |
450 | mov edi, ebx |
451 | @@: ; copy first part of name to destination |
451 | @@: ; copy first part of name to destination |
452 | lodsb |
452 | lodsb |
453 | test al, al |
453 | test al, al |
454 | jz @f |
454 | jz @f |
455 | stosb |
455 | stosb |
456 | jmp @b |
456 | jmp @b |
457 | 457 | ||
458 | @@: ; restore second part of name from temporary buffer to destination |
458 | @@: ; restore second part of name from temporary buffer to destination |
459 | lea edx, [ebx+64] ; limit of destination |
459 | lea edx, [ebx+64] ; limit of destination |
460 | mov esi, esp |
460 | mov esi, esp |
461 | @@: |
461 | @@: |
462 | cmp edi, edx |
462 | cmp edi, edx |
463 | jae .overflow |
463 | jae .overflow |
464 | lodsb |
464 | lodsb |
465 | stosb |
465 | stosb |
466 | test al, al |
466 | test al, al |
467 | jnz @b |
467 | jnz @b |
468 | add esp, 64 ; CF is cleared |
468 | add esp, 64 ; CF is cleared |
469 | ret |
469 | ret |
470 | 470 | ||
471 | .overflow: ; name is too long |
471 | .overflow: ; name is too long |
472 | add esp, 64 |
472 | add esp, 64 |
473 | stc |
473 | stc |
474 | ret |
474 | ret |
475 | endp |
475 | endp |
476 | end if=> |
476 | end if=> |