Rev 8083 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3374 | IgorA | 1 | ;13.03.2013 - use @notify |
2 | ;08.06.2010 - new macros @use_library_mem |
||
3 | ;08.05.2009 - bugfix |
||
1108 | Lrz | 4 | ;14.04.2009 - a macros for code load library the box_lib.obj from '/sys/lib/' or current dirrectory. |
5 | ; The macros for load any library/libraries: |
||
6 | ; Copyright (c) 2009, |
||
7 | ; All rights reserved. |
||
8 | ; |
||
9 | ; Redistribution and use in source and binary forms, with or without |
||
10 | ; modification, are permitted provided that the following conditions are met: |
||
11 | ; * Redistributions of source code must retain the above copyright |
||
12 | ; notice, this list of conditions and the following disclaimer. |
||
13 | ; * Redistributions in binary form must reproduce the above copyright |
||
14 | ; notice, this list of conditions and the following disclaimer in the |
||
15 | ; documentation and/or other materials provided with the distribution. |
||
16 | ; * Neither the name of the |
||
17 | ; names of its contributors may be used to endorse or promote products |
||
18 | ; derived from this software without specific prior written permission. |
||
19 | ; |
||
20 | ; THIS SOFTWARE IS PROVIDED BY Alexey Teplov aka |
||
21 | ; EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
||
22 | ; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||
23 | ; DISCLAIMED. IN NO EVENT SHALL |
||
24 | ; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||
25 | ; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||
26 | ; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
||
27 | ; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
28 | ; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||
29 | ; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
30 | ;***************************************************************************** |
||
31 | ; This macros based on source code: |
||
3374 | IgorA | 32 | ; |
33 | ; Mario79, Mario - Marat Zakiyanov / Марат Закиянов |
||
34 | ; Diamondz - Evgeny Grechnikov / Евгений Гречников |
||
1108 | Lrz | 35 | ;------------------------ |
36 | ; DESCRIPTION |
||
37 | ; Macro load_library |
||
38 | ; Logick of work. |
||
39 | ; A first time we must to check system path, where I belive find a system library. System path is "/sys/lib/". |
||
40 | ; If I cannot found my library, i must to check second way. Second way is current dirrectory. |
||
41 | ; If we cannot load library, we must show the error message: |
||
42 | ; "I'm sorry,the programm cannot found system library box_lib.obj." |
||
43 | ; "The find was make on 2 ways: /sys/lib/ and current dirrectory." |
||
44 | ; |
||
45 | ; |
||
46 | ;--------------------------------------------------------------------- |
||
47 | ; Macro sys_load_library |
||
48 | ; A first time we must to check own path in current dirrectory the program, where I belive find a system library. |
||
49 | ; If I cannot found my library, i must to check second way. Second way is system path a "/sys/lib/". |
||
50 | ; If we cannot load library, we must show the error message: |
||
51 | ; "I'm sorry,the programm cannot found system library box_lib.obj." |
||
52 | ; "The find was make on 2 ways: /sys/lib/ and current dirrectory." |
||
53 | ; |
||
54 | ;--------------------------------------------------------------------- |
||
55 | ; How can I use it? |
||
56 | ;--------------------------------------------------------------------- |
||
57 | ;-Example using single load library |
||
58 | ;-universal load library/librarys |
||
1127 | Lrz | 59 | ;load_library library_name__, cur_dir_path__, library_path__, system_path__, \ |
60 | ;err_message_found_lib__, head_f_l__, myimport, err_message_import__, head_f_i__ |
||
1108 | Lrz | 61 | ;-if return code =-1 then exit, else normally work |
62 | ; cmp eax,-1 |
||
63 | ; jz exit |
||
64 | ;- Well, if you get |
||
65 | ; |
||
66 | ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
||
3374 | IgorA | 67 | ;DATA данные |
68 | ;Всегда соблюдать последовательность в имени. |
||
1127 | Lrz | 69 | ;system_path__ db '/sys/lib/' |
70 | ;library_name__ db 'box_lib.obj',0 |
||
3374 | IgorA | 71 | ; Если есть желание разъединить, то нужно использовать следующию конструкцию |
1127 | Lrz | 72 | ;system_path__ db '/sys/lib/box_lib.obj',0 |
3374 | IgorA | 73 | ;... любая последовательность других команд и определений. |
1127 | Lrz | 74 | ;library_name__ db 'box_lib.obj',0 |
1108 | Lrz | 75 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
76 | |||
1127 | Lrz | 77 | ;err_message_found_lib__ db 'Sorry I cannot found library box_lib.obj',0 |
78 | ;head_f_i__: |
||
79 | ;head_f_l__ db 'System error',0 |
||
80 | ;err_message_import__ db 'Error on load import library box_lib.obj',0 |
||
1108 | Lrz | 81 | |
82 | ;myimport: |
||
83 | ; |
||
8083 | IgorA | 84 | ;edit_box_draw dd aEdit_box_draw |
85 | ;edit_box_key dd aEdit_box_key |
||
86 | ;edit_box_mouse dd aEdit_box_mouse |
||
87 | ;version_ed dd aVersion_ed |
||
88 | ; dd 0,0 |
||
1108 | Lrz | 89 | ;aEdit_box_draw db 'edit_box',0 |
90 | ;aEdit_box_key db 'edit_box_key',0 |
||
91 | ;aEdit_box_mouse db 'edit_box_mouse',0 |
||
92 | ;aVersion_ed db 'version_ed',0 |
||
93 | |||
94 | |||
95 | |||
96 | macro @use_library |
||
97 | { |
||
1127 | Lrz | 98 | local lp1 |
4987 | IgorA | 99 | local lp2 |
100 | local lp3 |
||
101 | local lp4 |
||
6245 | IgorA | 102 | local lp5 |
103 | local lp6 |
||
3374 | IgorA | 104 | local file_name |
1488 | IgorA | 105 | |
3374 | IgorA | 106 | library_fun_memory_alloc equ 0 ;не использовать в макросах проверку на функции 'lib_init' |
1108 | Lrz | 107 | |
108 | align 4 |
||
3374 | IgorA | 109 | arrea_xx dd 0 |
8088 | dunkaist | 110 | file_name db '/sys/@notify',0 |
1127 | Lrz | 111 | |
112 | align 4 |
||
3374 | IgorA | 113 | run_notify_struct: |
114 | .Function dd 7 |
||
115 | .Position dd 0 |
||
116 | .Flags dd ? |
||
117 | .Count dd 0 |
||
118 | .Buffer dd 0 |
||
119 | db 0 |
||
120 | .FileName dd file_name |
||
1108 | Lrz | 121 | |
1204 | Lrz | 122 | @library_name equ dword [esp+16] |
123 | @cur_dir_path equ dword [esp+12] |
||
124 | @library_path equ dword [esp+8] |
||
125 | @point_dir_name equ dword [esp+4] |
||
126 | |||
8083 | IgorA | 127 | ;description: |
128 | ; готовим текст для показа через @notify: |
||
129 | ; 1) выделяем память в [arrea_xx] но не больше одного раза |
||
130 | ; 2) копируем заголовок (если есть имя функции то добавляем его к заголовку) и текст сообщения в [arrea_xx] |
||
131 | ;input: |
||
132 | ; ebp+8 - head message |
||
133 | ; ebp+12 - error message |
||
134 | ; ebp+16 - 0 или имя функции, которую не удалось экспортировать |
||
135 | ;output: |
||
136 | ; eax = -1 |
||
1108 | Lrz | 137 | align 4 |
8083 | IgorA | 138 | l_lib_init_error_window: |
139 | push ebp |
||
140 | mov ebp,esp |
||
141 | cmp dword[arrea_xx],0 |
||
142 | jne .no_msg ;если раньше было создано другое сообщение |
||
143 | pushad |
||
144 | |||
145 | mcall 68,11 |
||
146 | mcall 68,12,4096 |
||
147 | mov [arrea_xx],eax |
||
148 | |||
149 | mov edi,eax |
||
150 | mov esi,[ebp+8] |
||
151 | align 4 |
||
152 | @@: |
||
153 | movsb |
||
154 | cmp byte[esi],0 |
||
155 | jne @b |
||
156 | mov word[edi],0xa0d |
||
157 | add edi,2 |
||
158 | |||
159 | ;добавляем имя функции в заголовок |
||
160 | mov esi,[ebp+16] |
||
161 | or esi,esi |
||
162 | jz .lp1 |
||
163 | mov word[edi-2],0x2020 |
||
164 | @@: |
||
165 | movsb |
||
166 | cmp byte[esi],0 |
||
167 | jne @b |
||
168 | mov word[edi],0xa0d |
||
169 | add edi,2 |
||
170 | .lp1: |
||
171 | |||
172 | mov esi,[ebp+12] |
||
173 | align 4 |
||
174 | @@: |
||
175 | movsb |
||
176 | cmp byte[esi],0 |
||
177 | jne @b |
||
178 | mov byte[edi],0 |
||
179 | popad |
||
180 | .no_msg: |
||
181 | or eax,-1 |
||
182 | pop ebp |
||
183 | ret 12 |
||
184 | |||
185 | align 4 |
||
1108 | Lrz | 186 | @copy_path: |
5881 | IgorA | 187 | mov esi,@cur_dir_path |
188 | mov edi,@library_path |
||
189 | xor eax,eax |
||
190 | cld |
||
1204 | Lrz | 191 | align 4 |
1108 | Lrz | 192 | .lp1: |
5881 | IgorA | 193 | lodsb |
194 | stosb |
||
195 | test eax,eax |
||
196 | jnz .lp1 |
||
197 | mov esi,edi |
||
198 | dec esi ;переход на символ конца строки @cur_dir_path |
||
199 | std |
||
1204 | Lrz | 200 | align 4 |
1108 | Lrz | 201 | .lp2: |
5881 | IgorA | 202 | lodsb |
203 | cmp al,'/' |
||
204 | jnz .lp2 |
||
205 | mov edi,esi |
||
206 | add edi,2 |
||
207 | cld |
||
208 | mov esi,@point_dir_name |
||
209 | test esi,esi |
||
1204 | Lrz | 210 | jz .str_lp4 |
1108 | Lrz | 211 | |
6245 | IgorA | 212 | ;проверка относительных путей c двумя точками '../' |
213 | cmp word[esi],'..' |
||
214 | jne .lp3 |
||
215 | dec edi ;для перехода на '/' |
||
216 | .lp6: |
||
217 | add esi,3 ;пропускаем одно поднятие '../' |
||
218 | .lp5: |
||
219 | dec edi ;идем по папкам |
||
220 | cmp byte[edi],'/' |
||
221 | jnz .lp5 |
||
222 | cmp word[esi],'..' |
||
223 | je .lp6 |
||
224 | inc edi ;для перехода на '/' |
||
225 | |||
226 | ;копирование относительного пути |
||
1204 | Lrz | 227 | align 4 |
1108 | Lrz | 228 | .lp3: |
5881 | IgorA | 229 | lodsb |
230 | stosb |
||
231 | test eax,eax |
||
232 | jnz .lp3 |
||
233 | dec edi |
||
1204 | Lrz | 234 | .str_lp4: |
235 | mov esi,@library_name |
||
236 | align 4 |
||
237 | .lp4: |
||
5881 | IgorA | 238 | lodsb |
239 | stosb |
||
240 | test eax,eax |
||
241 | jnz .lp4 |
||
242 | ret |
||
1108 | Lrz | 243 | } |
8083 | IgorA | 244 | ;--------------------------------------------------------------------- |
1108 | Lrz | 245 | |
1488 | IgorA | 246 | macro @use_library_mem mem_alloc,mem_free,mem_realloc,dll_load |
247 | { |
||
248 | @use_library |
||
249 | library_fun_memory_alloc equ mem_alloc |
||
250 | library_fun_memory_free equ mem_free |
||
251 | library_fun_memory_realloc equ mem_realloc |
||
252 | library_fun_dll_load equ dll_load |
||
253 | } |
||
254 | |||
1204 | Lrz | 255 | macro sys_load_library library_name__, cur_dir_path__, library_path__, system_path__, err_message_found_lib__, head_f_l__, myimport, err_message_import__, head_f_i__,point_dir_name__ |
1108 | Lrz | 256 | { |
8083 | IgorA | 257 | local i_begin |
258 | local i_error |
||
259 | local i_exit |
||
1108 | Lrz | 260 | |
8083 | IgorA | 261 | mcall 68,19,system_path__ ; load of sys directory |
262 | test eax,eax |
||
263 | jnz i_begin |
||
1108 | Lrz | 264 | |
1204 | Lrz | 265 | if point_dir_name__ eq |
8083 | IgorA | 266 | copy_path library_name__, cur_dir_path__, library_path__,0 |
1204 | Lrz | 267 | else |
8083 | IgorA | 268 | ;the macros making way /current path a program/ + name system library |
269 | copy_path library_name__, cur_dir_path__, library_path__,point_dir_name__ |
||
270 | end if |
||
271 | mcall 68,19,library_path__ ; load of alternative |
||
272 | test eax,eax |
||
273 | jnz i_begin |
||
274 | push eax |
||
275 | push dword err_message_found_lib__ |
||
276 | push dword head_f_l__ |
||
277 | jmp i_error |
||
1108 | Lrz | 278 | align 4 |
8083 | IgorA | 279 | i_begin: |
280 | import_boxlib myimport |
||
281 | test eax,eax |
||
282 | jz i_exit |
||
283 | push eax |
||
284 | push dword err_message_import__ |
||
285 | push dword head_f_i__ |
||
286 | i_error: |
||
287 | call l_lib_init_error_window |
||
288 | notify_window_run [arrea_xx] ; создаем окно @notify |
||
289 | i_exit: |
||
290 | } |
||
1108 | Lrz | 291 | ;--------------------------------------------------------------------- |
292 | |||
1204 | Lrz | 293 | macro load_library library_name__, cur_dir_path__, library_path__, system_path__, err_message_found_lib__, head_f_l__, myimport, err_message_import__, head_f_i__,point_dir_name__ |
1108 | Lrz | 294 | { |
8083 | IgorA | 295 | local i_begin |
296 | local i_error |
||
297 | local i_exit |
||
1108 | Lrz | 298 | |
1204 | Lrz | 299 | if point_dir_name__ eq |
8083 | IgorA | 300 | copy_path library_name__, cur_dir_path__, library_path__,0 |
1204 | Lrz | 301 | else |
8083 | IgorA | 302 | ;the macros making way /current path a program/ + name system library |
303 | copy_path library_name__, cur_dir_path__, library_path__,point_dir_name__ |
||
304 | end if |
||
305 | mcall 68,19,library_path__ ; load of alternative |
||
306 | test eax,eax |
||
307 | jnz i_begin |
||
1108 | Lrz | 308 | |
8083 | IgorA | 309 | mcall 68,19,system_path__ ; load of sys directory |
310 | test eax,eax |
||
311 | jnz i_begin |
||
312 | push eax |
||
313 | push dword err_message_found_lib__ |
||
314 | push dword head_f_l__ |
||
315 | jmp i_error |
||
1108 | Lrz | 316 | align 4 |
8083 | IgorA | 317 | i_begin: |
318 | import_boxlib myimport |
||
319 | test eax,eax |
||
320 | jz i_exit |
||
321 | push eax |
||
322 | push dword err_message_found_lib__ |
||
323 | push dword head_f_l__ |
||
324 | i_error: |
||
325 | call l_lib_init_error_window |
||
326 | notify_window_run [arrea_xx] ; создаем окно @notify |
||
327 | i_exit: |
||
1108 | Lrz | 328 | ;--------------------------------------------------------------------- |
329 | } |
||
8083 | IgorA | 330 | |
331 | ;description: |
||
332 | ; макрос загрузки библиотек из системной папки, если библиотека не найдена |
||
333 | ; тогда поиск идет в текущей папке с программой |
||
1108 | Lrz | 334 | macro sys_load_libraries _start,_end |
335 | { |
||
8083 | IgorA | 336 | local cycle0 |
1108 | Lrz | 337 | local end_steep |
8083 | IgorA | 338 | local cycle0n |
339 | local cycle1 |
||
340 | local cycle1n |
||
341 | local cycle1e |
||
1108 | Lrz | 342 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1127 | Lrz | 343 | library_name__ equ [ebp] |
344 | cur_dir_path__ equ [ebp+4] |
||
345 | library_path__ equ [ebp+8] |
||
346 | system_path__ equ [ebp+12] |
||
347 | err_message_found_lib__ equ [ebp+16] |
||
348 | head_f_l__ equ [ebp+20] |
||
1204 | Lrz | 349 | my_import equ [ebp+24] |
1127 | Lrz | 350 | err_message_import__ equ [ebp+28] |
351 | head_f_i__ equ [ebp+32] |
||
1204 | Lrz | 352 | point_dir_name__ equ [ebp+36] |
353 | adr_load_lib equ dword [ebp+40] |
||
354 | status_lib equ dword [ebp+44] |
||
1108 | Lrz | 355 | |
8083 | IgorA | 356 | mov ebp,_start |
357 | mov ecx,(_end-_start)/ll_struc_size |
||
1108 | Lrz | 358 | align 4 |
8083 | IgorA | 359 | cycle0: |
360 | push ecx |
||
1127 | Lrz | 361 | mcall 68,19,system_path__ ; load of sys directory |
1108 | Lrz | 362 | test eax,eax |
363 | jnz end_steep |
||
364 | |||
8083 | IgorA | 365 | ;the macros making way /current path a program/ + name system library |
366 | copy_path library_name__, cur_dir_path__, library_path__,point_dir_name__ |
||
1108 | Lrz | 367 | |
1127 | Lrz | 368 | mcall 68,19,library_path__ ; load of alternative |
1108 | Lrz | 369 | test eax,eax |
370 | jnz end_steep |
||
8083 | IgorA | 371 | or status_lib,1 ; status of code - enable error - not found library |
1108 | Lrz | 372 | |
8083 | IgorA | 373 | push eax |
374 | push dword err_message_found_lib__ |
||
375 | push dword head_f_l__ |
||
376 | call l_lib_init_error_window |
||
377 | jmp cycle0n |
||
1108 | Lrz | 378 | |
379 | align 4 |
||
8083 | IgorA | 380 | end_steep: |
381 | mov adr_load_lib,eax ;save adr lib in memory |
||
382 | import_boxlib my_import |
||
383 | test eax,eax |
||
384 | jz cycle0n |
||
385 | or status_lib,2 ; status of code - enable error - import error |
||
386 | push eax |
||
387 | push dword err_message_import__ |
||
388 | push dword head_f_i__ |
||
389 | call l_lib_init_error_window |
||
390 | cycle0n: |
||
391 | pop ecx |
||
392 | add ebp,ll_struc_size |
||
393 | dec ecx |
||
394 | jnz cycle0 |
||
1108 | Lrz | 395 | |
8083 | IgorA | 396 | ;вывод сообщения об ошибке при загрузке |
397 | mov ebp,_start |
||
398 | mov ecx,(_end-_start)/ll_struc_size |
||
1127 | Lrz | 399 | align 4 |
8083 | IgorA | 400 | cycle1: |
401 | mov eax,status_lib |
||
402 | test eax,eax |
||
403 | jz cycle1n |
||
404 | notify_window_run [arrea_xx] ; создаем окно @notify |
||
405 | mov eax,-1 |
||
406 | jmp cycle1e |
||
407 | align 4 |
||
408 | cycle1n: |
||
409 | add ebp,ll_struc_size |
||
410 | dec ecx |
||
411 | jnz cycle1 |
||
412 | cycle1e: |
||
1108 | Lrz | 413 | } |
414 | |||
8083 | IgorA | 415 | ;description: |
416 | ; макрос загрузки библиотек из текущей папки с программой, если библиотека не найдена |
||
417 | ; тогда поиск идет в системной папке |
||
1108 | Lrz | 418 | macro load_libraries _start,_end |
419 | { |
||
8083 | IgorA | 420 | local cycle0 |
1108 | Lrz | 421 | local end_steep |
8083 | IgorA | 422 | local cycle0n |
423 | local cycle1 |
||
424 | local cycle1n |
||
425 | local cycle1e |
||
1108 | Lrz | 426 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1127 | Lrz | 427 | library_name__ equ [ebp] |
428 | cur_dir_path__ equ [ebp+4] |
||
429 | library_path__ equ [ebp+8] |
||
430 | system_path__ equ [ebp+12] |
||
431 | err_message_found_lib__ equ [ebp+16] |
||
432 | head_f_l__ equ [ebp+20] |
||
1204 | Lrz | 433 | my_import equ [ebp+24] |
1127 | Lrz | 434 | err_message_import__ equ [ebp+28] |
435 | head_f_i__ equ [ebp+32] |
||
1204 | Lrz | 436 | point_dir_name__ equ [ebp+36] |
437 | adr_load_lib equ dword [ebp+40] |
||
438 | status_lib equ dword [ebp+44] |
||
1108 | Lrz | 439 | |
8083 | IgorA | 440 | mov ebp,_start |
441 | mov ecx,(_end-_start)/ll_struc_size |
||
1108 | Lrz | 442 | align 4 |
8083 | IgorA | 443 | cycle0: |
444 | push ecx |
||
1108 | Lrz | 445 | |
8083 | IgorA | 446 | ;the macros making way /current path a program/ + name system library |
447 | copy_path library_name__, cur_dir_path__, library_path__,point_dir_name__ |
||
1108 | Lrz | 448 | |
8083 | IgorA | 449 | mcall 68,19,library_path__ ; load of alternative |
450 | test eax,eax |
||
451 | jnz end_steep |
||
1108 | Lrz | 452 | |
8083 | IgorA | 453 | mcall 68,19,system_path__ ; load of sys directory |
454 | test eax,eax |
||
455 | jnz end_steep |
||
456 | or status_lib,1 ; status of code - enable error - not found library |
||
1108 | Lrz | 457 | |
8083 | IgorA | 458 | push eax |
459 | push dword err_message_found_lib__ |
||
460 | push dword head_f_l__ |
||
461 | call l_lib_init_error_window |
||
462 | jmp cycle0n |
||
1108 | Lrz | 463 | |
464 | align 4 |
||
8083 | IgorA | 465 | end_steep: |
466 | mov adr_load_lib,eax ;save adr lib in memory |
||
467 | import_boxlib my_import |
||
468 | test eax,eax |
||
469 | jz cycle0n |
||
470 | or status_lib,2 ; status of code - enable error - import error |
||
471 | push eax |
||
472 | push dword err_message_import__ |
||
473 | push dword head_f_i__ |
||
474 | call l_lib_init_error_window |
||
475 | cycle0n: |
||
476 | pop ecx |
||
477 | add ebp,ll_struc_size |
||
478 | dec ecx |
||
479 | jnz cycle0 |
||
1108 | Lrz | 480 | |
8083 | IgorA | 481 | ;вывод сообщения об ошибке при загрузке |
482 | mov ebp,_start |
||
483 | mov ecx,(_end-_start)/ll_struc_size |
||
1127 | Lrz | 484 | align 4 |
8083 | IgorA | 485 | cycle1: |
486 | mov eax,status_lib |
||
487 | test eax,eax |
||
488 | jz cycle1n |
||
489 | notify_window_run [arrea_xx] ; создаем окно @notify |
||
490 | mov eax,-1 |
||
491 | jmp cycle1e |
||
492 | align 4 |
||
493 | cycle1n: |
||
494 | add ebp,ll_struc_size |
||
495 | dec ecx |
||
496 | jnz cycle1 |
||
497 | cycle1e: |
||
1108 | Lrz | 498 | } |
499 | |||
500 | |||
1204 | Lrz | 501 | macro copy_path lib_name,dir_path,lib_path,point_dir_name |
1108 | Lrz | 502 | { |
6245 | IgorA | 503 | pushad ;save all registers |
504 | push dword lib_name |
||
505 | push dword dir_path |
||
506 | push dword lib_path |
||
507 | push dword point_dir_name |
||
508 | call @copy_path |
||
1108 | Lrz | 509 | |
6245 | IgorA | 510 | add esp,16 |
511 | ;notify_window_run lib_path ;unblok for test load path |
||
512 | popad ;restore all registers |
||
1108 | Lrz | 513 | } |
514 | |||
3374 | IgorA | 515 | ; включаем показ сообщения через @notify: |
516 | macro notify_window_run message |
||
517 | { |
||
518 | push eax ebx |
||
519 | mov eax,message ;параметры для командной строки |
||
7577 | IgorA | 520 | mov [run_notify_struct.Flags],eax |
3374 | IgorA | 521 | mov eax,70 ;run @notify |
522 | mov ebx,run_notify_struct |
||
523 | int 0x40 |
||
524 | pop ebx eax |
||
525 | } |
||
1108 | Lrz | 526 | |
3374 | IgorA | 527 | |
8083 | IgorA | 528 | ;input: |
529 | ; eax - адрес библиотеки в памяти |
||
530 | ; myimport - импортируемые функции |
||
531 | ;output: |
||
532 | ; eax - если удачно то 0 или указатель на имя функции которую не удалось загрузить |
||
533 | macro import_boxlib myimport |
||
1108 | Lrz | 534 | { |
535 | local import_loop |
||
536 | local import_find |
||
537 | local lp |
||
538 | local import_find_next |
||
539 | local import_found |
||
540 | local import_done |
||
541 | local exit |
||
542 | local import_not_found |
||
543 | ; initialize import |
||
544 | |||
545 | mov edx, eax |
||
546 | mov esi,myimport |
||
547 | import_loop: |
||
3374 | IgorA | 548 | lodsd ;mov eax,dword[esi] ;add esi,4 ;получаем в eax указатель на имя импортируемой функции |
1108 | Lrz | 549 | test eax, eax |
3374 | IgorA | 550 | jz import_done ;если указатель на имя функции = 0 (в пользовательской программе) |
551 | push edx ;сохраняем начало библиотечных указателей на функции |
||
1108 | Lrz | 552 | import_find: |
8083 | IgorA | 553 | mov ebx, [edx] |
1108 | Lrz | 554 | test ebx, ebx |
3374 | IgorA | 555 | jz import_not_found ;если указатель на имя функции = 0 (в библиотеке) |
556 | push eax ;eax - указатель на имя экспортируемой функции (в пользовательской программе) |
||
1108 | Lrz | 557 | lp: |
8083 | IgorA | 558 | mov cl, [eax] |
559 | cmp cl, [ebx] ;сравниваем имена функций в библиотеке и в пользовательской программе |
||
3374 | IgorA | 560 | jnz import_find_next ;если названия не совпали |
1108 | Lrz | 561 | test cl, cl |
3374 | IgorA | 562 | jz import_found ;если названия совпали, и уже конец строки (cl=0) |
1108 | Lrz | 563 | inc eax |
564 | inc ebx |
||
565 | jmp lp |
||
566 | import_find_next: |
||
567 | pop eax |
||
3374 | IgorA | 568 | add edx, 8 ;8 = 4 байта указатель на название и 4 байта указатель на функцию |
1108 | Lrz | 569 | jmp import_find |
570 | import_found: |
||
3374 | IgorA | 571 | pop ebx ;востанавливаем указатель на имя функции (который был в eax) и освобождаем стек |
8083 | IgorA | 572 | mov eax, [edx+4] ;eax = указатель на функцию (в библиотеке) |
3374 | IgorA | 573 | mov [esi-4], eax ;копируем указатель (на функцию) в программу, -4 ставим потому что esi было сдвинуто командой lodsd |
574 | pop edx ;устанавливаем edx на начало библиотечных функций |
||
575 | ;--- проверяем совпадает ли имя экспортированной функции с 'lib_init' |
||
1488 | IgorA | 576 | if library_fun_memory_alloc eq 0 |
577 | else |
||
578 | cmp dword[ebx],'lib_' |
||
579 | jne import_loop |
||
580 | cmp dword[ebx+4],'init' |
||
581 | jne import_loop |
||
3374 | IgorA | 582 | ;--- если имя функции совпало с 'lib_init' попадаем сюда |
583 | ;подключение функций для работы с памятью |
||
1488 | IgorA | 584 | ;push eax |
585 | ;call dll.Init |
||
586 | pushad |
||
587 | mov esi,eax |
||
588 | mov eax,library_fun_memory_alloc |
||
589 | mov ebx,library_fun_memory_free |
||
590 | mov ecx,library_fun_memory_realloc |
||
591 | mov edx,library_fun_dll_load |
||
592 | call dword esi |
||
593 | popad |
||
594 | end if |
||
1108 | Lrz | 595 | jmp import_loop |
596 | import_not_found: |
||
597 | add esp,4 |
||
8083 | IgorA | 598 | jmp exit |
1108 | Lrz | 599 | import_done: |
3374 | IgorA | 600 | xor eax,eax ;=0 все загрузилось удачно |
8083 | IgorA | 601 | exit: |
602 | } |
||
1108 | Lrz | 603 | ;--------------------------------------------------------------------- |
8083 | IgorA | 604 | |
1204 | Lrz | 605 | ll_struc_size = 48;($-library_name__) ; constant size of struct |
606 | struc l_libs library_name__, cur_dir_path__, library_path__, system_path__, err_message_found_lib__, head_f_l__, my_import, err_message_import__, head_f_i__,point_dir_name; struct for loading libraries |
||
1108 | Lrz | 607 | { |
3374 | IgorA | 608 | .library_name__ dd library_name__ ; имя загружаемой библиотеки |
609 | .cur_dir_path__ dd cur_dir_path__ ; указатель на буфер в котором содержиться путь от куда была запущена программа |
||
1127 | Lrz | 610 | |
3374 | IgorA | 611 | .library_path__ dd library_path__ ; указатель на буфер в котором будет софоримирован путь к библиотеки, если нужно вычислить путь до либы с места запуска программы, обычно нужно, в случаях, если либа расположена в той же папке |
612 | .complete_path dd system_path__ ; путь который четко содержит путь |
||
1127 | Lrz | 613 | |
614 | .err_message_found_lib__ dd err_message_found_lib__ |
||
615 | .head_f_l__ dd head_f_l__ |
||
1204 | Lrz | 616 | .my_import dd my_import |
1127 | Lrz | 617 | .err_message_import__ dd err_message_import__ |
618 | .head_f_i__ dd head_f_i__ |
||
1204 | Lrz | 619 | if point_dir_name eq |
8083 | IgorA | 620 | .point_dir_name__ dd 0 |
1204 | Lrz | 621 | else |
3374 | IgorA | 622 | .point_dir_name__ dd point_dir_name ; имя вложенной дирректории в кторой храняться подгружаемые модули. |
1204 | Lrz | 623 | end if |
8083 | IgorA | 624 | .adr_load_lib dd 0 |
625 | .status_lib dd 0 ;status of load library |
||
1108 | Lrz | 626 | ; |
627 | } |