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