1 ; The macros for load any library/libraries:
\r
2 ; Copyright (c) 2009, <Lrz>
\r
3 ; All rights reserved.
\r
7 macro @use_library mem_alloc,mem_free,mem_realloc,dll_load
\r
21 library_fun_memory_alloc equ mem_alloc
\r
22 library_fun_memory_free equ mem_free
\r
23 library_fun_memory_realloc equ mem_realloc
\r
24 library_fun_dll_load equ dll_load
\r
28 file_name db '/sys/@notify',0
\r
31 l_lib_m1 db '"‘¨á⥬ ï ®è¨¡ª ',13,10,'�¥ ©¤¥ ¡¨¡«¨®â¥ª ',39,0
\r
32 l_lib_m2 db '"‘¨á⥬ ï ®è¨¡ª ',13,10,'Žè¨¡ª ¯à¨ ¨¬¯®à⥠¡¨¡«¨®â¥ª¨ ',39,0
\r
33 l_lib_m3 db 39,13,10,'¥ ©¤¥ äãªæ¨ï ',39,0
\r
34 l_lib_m4 db 39,'" -tE',0
\r
36 l_lib_m1 db '"Errore di sistema',13,10,'Non trovato ',39,0
\r
37 l_lib_m2 db '"Errore di sistema',13,10,'Import errato ',39,0
\r
38 l_lib_m3 db 39,13,10,'funzione non trovata ',39,0
\r
39 l_lib_m4 db 39,'" -tE',0
\r
41 l_lib_m1 db '"System error',13,10,'Sorry I cannot found library ',39,0
\r
42 l_lib_m2 db '"System error',13,10,'Error on load import library ',39,0
\r
43 l_lib_m3 db 39,13,10,'cannot found function ',39,0
\r
44 l_lib_m4 db 39,'" -tE',0
\r
55 .FileName dd file_name
\r
58 ; £®â®¢¨¬ ⥪áâ ¤«ï ¯®ª § ç¥à¥§ @notify:
\r
59 ; 1) ¢ë¤¥«ï¥¬ ¯ ¬ïâì ¢ [arrea_xx] ® ¥ ¡®«ìè¥ ®¤®£® à §
\r
60 ; 2) ª®¯¨à㥬 § £®«®¢®ª (¥á«¨ ¥áâì ¨¬ï äãªæ¨¨ â® ¤®¡ ¢«ï¥¬ ¥£® ª § £®«®¢ªã) ¨ ⥪áâ á®®¡é¥¨ï ¢ [arrea_xx]
\r
62 ; ebp+8 - library name
\r
63 ; ebp+12 - 0 ¨«¨ ¨¬ï äãªæ¨¨, ª®â®àãî ¥ 㤠«®áì íªá¯®àâ¨à®¢ âì
\r
67 l_lib_init_error_window:
\r
70 cmp dword[arrea_xx],0
\r
71 jne .no_msg ;¥á«¨ à ìè¥ ¡ë«® ᮧ¤ ® ¤à㣮¥ á®®¡é¥¨¥
\r
74 mcall SF_SYS_MISC,SSF_HEAP_INIT
\r
75 mcall SF_SYS_MISC,SSF_MEM_ALLOC,4096
\r
79 mov esi,l_lib_m2 ;á®®¡é¥¨¥ ¥á«¨ ¥ 㤠«®áì ¨¬¯®àâ¨à®¢ âì äãªæ¨î
\r
82 mov esi,l_lib_m1 ;á®®¡é¥¨¥ ¥á«¨ ¥ 㤠«®áì § £à㧨âì ¡¨¡«¨®â¥ªã
\r
88 ;¤®¡ ¢«ï¥¬ ¨¬ï ¡¨¡«¨®â¥ª¨
\r
98 ;¤®¡ ¢«ï¥¬ á¥à¥¤¨ã á®®¡é¥¨ï
\r
105 ;¤®¡ ¢«ï¥¬ ¨¬ï äãªæ¨¨
\r
113 .lp1: ;á®®¡é¥¨¥ ¥á«¨ ¥ 㤠«®áì § £à㧨âì ¡¨¡«¨®â¥ªã
\r
114 ;¤®¡ ¢«ï¥¬ ª®¥æ á®®¡é¥¨ï
\r
129 @library_name equ dword [esp+16]
\r
130 @cur_dir_path equ dword [esp+12]
\r
131 @library_path equ dword [esp+8]
\r
132 @point_dir_name equ dword [esp+4]
\r
136 mov esi,@cur_dir_path
\r
137 mov edi,@library_path
\r
147 dec esi ;¯¥à¥å®¤ ᨬ¢®« ª®æ áâப¨ @cur_dir_path
\r
157 mov esi,@point_dir_name
\r
161 ;¯à®¢¥àª ®â®á¨â¥«ìëå ¯ã⥩ c ¤¢ã¬ï â®çª ¬¨ '../'
\r
164 dec edi ;¤«ï ¯¥à¥å®¤ '/'
\r
166 add esi,3 ;¯à®¯ã᪠¥¬ ®¤® ¯®¤ï⨥ '../'
\r
168 dec edi ;¨¤¥¬ ¯® ¯ ¯ª ¬
\r
173 inc edi ;¤«ï ¯¥à¥å®¤ '/'
\r
175 ;ª®¯¨à®¢ ¨¥ ®â®á¨â¥«ì®£® ¯ãâ¨
\r
184 mov esi,@library_name
\r
193 ;---------------------------------------------------------------------
\r
195 macro sys_load_library library_name__, library_path__, system_path__, myimport, point_dir_name__
\r
201 mcall SF_SYS_MISC,SSF_LOAD_DLL,system_path__ ; load of sys directory
\r
205 if point_dir_name__ eq
\r
206 copy_path library_name__, [32], library_path__,0
\r
208 ;the macros making way /current path a program/ + name system library
\r
209 copy_path library_name__, [32], library_path__,point_dir_name__
\r
211 mcall SF_SYS_MISC,SSF_LOAD_DLL,library_path__ ; load of alternative
\r
217 import_boxlib myimport
\r
222 push dword library_name__
\r
223 call l_lib_init_error_window
\r
224 notify_window_run [arrea_xx] ; ᮧ¤ ¥¬ ®ª® @notify
\r
228 ;---------------------------------------------------------------------
\r
231 ; eax - ¥á«¨ ã¤ ç® â® 0
\r
232 macro load_library library_name__, library_path__, system_path__, myimport, point_dir_name__
\r
238 if point_dir_name__ eq
\r
239 copy_path library_name__, [32], library_path__,0
\r
241 ;the macros making way /current path a program/ + name system library
\r
242 copy_path library_name__, [32], library_path__,point_dir_name__
\r
244 mcall SF_SYS_MISC,SSF_LOAD_DLL,library_path__ ; load of alternative
\r
248 mcall SF_SYS_MISC,SSF_LOAD_DLL,system_path__ ; load of sys directory
\r
254 import_boxlib myimport
\r
259 push dword library_name__
\r
260 call l_lib_init_error_window
\r
261 notify_window_run [arrea_xx] ; ᮧ¤ ¥¬ ®ª® @notify
\r
264 ;---------------------------------------------------------------------
\r
268 ; ¬ ªà®á § £à㧪¨ ¡¨¡«¨®â¥ª ¨§ á¨á⥬®© ¯ ¯ª¨, ¥á«¨ ¡¨¡«¨®â¥ª ¥ ©¤¥
\r
269 ; ⮣¤ ¯®¨áª ¨¤¥â ¢ ⥪ã饩 ¯ ¯ª¥ á ¯à®£à ¬¬®©
\r
270 macro sys_load_libraries _start,_end
\r
278 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
\r
279 library_name__ equ [ebp]
\r
280 library_path__ equ [ebp+4]
\r
281 system_path__ equ [ebp+8]
\r
282 my_import equ [ebp+12]
\r
283 point_dir_name__ equ [ebp+16]
\r
284 adr_load_lib equ dword [ebp+20]
\r
285 status_lib equ dword [ebp+24]
\r
288 mov ecx,(_end-_start)/ll_struc_size
\r
292 mcall SF_SYS_MISC,SSF_LOAD_DLL,system_path__ ; load of sys directory
\r
296 ;the macros making way /current path a program/ + name system library
\r
297 copy_path library_name__, [32], library_path__,point_dir_name__
\r
299 mcall SF_SYS_MISC,SSF_LOAD_DLL,library_path__ ; load of alternative
\r
302 or status_lib,1 ; status of code - enable error - not found library
\r
305 push dword library_name__
\r
306 call l_lib_init_error_window
\r
311 mov adr_load_lib,eax ;save adr lib in memory
\r
312 import_boxlib my_import
\r
315 or status_lib,2 ; status of code - enable error - import error
\r
317 push dword library_name__
\r
318 call l_lib_init_error_window
\r
321 add ebp,ll_struc_size
\r
325 ;¢ë¢®¤ á®®¡é¥¨ï ®¡ ®è¨¡ª¥ ¯à¨ § £à㧪¥
\r
327 mov ecx,(_end-_start)/ll_struc_size
\r
333 notify_window_run [arrea_xx] ; ᮧ¤ ¥¬ ®ª® @notify
\r
338 add ebp,ll_struc_size
\r
345 ; ¬ ªà®á § £à㧪¨ ¡¨¡«¨®â¥ª ¨§ ⥪ã饩 ¯ ¯ª¨ á ¯à®£à ¬¬®©, ¥á«¨ ¡¨¡«¨®â¥ª ¥ ©¤¥
\r
346 ; ⮣¤ ¯®¨áª ¨¤¥â ¢ á¨á⥬®© ¯ ¯ª¥
\r
347 macro load_libraries _start,_end
\r
355 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
\r
356 library_name__ equ [ebp]
\r
357 library_path__ equ [ebp+4]
\r
358 system_path__ equ [ebp+8]
\r
359 my_import equ [ebp+12]
\r
360 point_dir_name__ equ [ebp+16]
\r
361 adr_load_lib equ dword [ebp+20]
\r
362 status_lib equ dword [ebp+24]
\r
365 mov ecx,(_end-_start)/ll_struc_size
\r
370 ;the macros making way /current path a program/ + name system library
\r
371 copy_path library_name__, [32], library_path__,point_dir_name__
\r
373 mcall SF_SYS_MISC,SSF_LOAD_DLL,library_path__ ; load of alternative
\r
377 mcall SF_SYS_MISC,SSF_LOAD_DLL,system_path__ ; load of sys directory
\r
380 or status_lib,1 ; status of code - enable error - not found library
\r
383 push dword library_name__
\r
384 call l_lib_init_error_window
\r
389 mov adr_load_lib,eax ;save adr lib in memory
\r
390 import_boxlib my_import
\r
393 or status_lib,2 ; status of code - enable error - import error
\r
395 push dword library_name__
\r
396 call l_lib_init_error_window
\r
399 add ebp,ll_struc_size
\r
403 ;¢ë¢®¤ á®®¡é¥¨ï ®¡ ®è¨¡ª¥ ¯à¨ § £à㧪¥
\r
405 mov ecx,(_end-_start)/ll_struc_size
\r
411 notify_window_run [arrea_xx] ; ᮧ¤ ¥¬ ®ª® @notify
\r
416 add ebp,ll_struc_size
\r
423 macro copy_path lib_name,dir_path,lib_path,point_dir_name
\r
425 pushad ;save all registers
\r
426 push dword lib_name
\r
427 push dword dir_path
\r
428 push dword lib_path
\r
429 push dword point_dir_name
\r
433 ;notify_window_run lib_path ;unblok for test load path
\r
434 popad ;restore all registers
\r
437 ; ¢ª«îç ¥¬ ¯®ª § á®®¡é¥¨ï ç¥à¥§ @notify:
\r
438 macro notify_window_run message
\r
441 mov eax,message ;¯ à ¬¥âàë ¤«ï ª®¬ ¤®© áâப¨
\r
442 mov [run_notify_struct.Flags],eax
\r
443 mcall SF_FILE,run_notify_struct
\r
449 ; eax - ¤à¥á ¡¨¡«¨®â¥ª¨ ¢ ¯ ¬ïâ¨
\r
450 ; myimport - ¨¬¯®àâ¨àã¥¬ë¥ äãªæ¨¨
\r
452 ; eax - ¥á«¨ ã¤ ç® â® 0 ¨«¨ 㪠§ â¥«ì ¨¬ï äãªæ¨¨ ª®â®àãî ¥ 㤠«®áì § £à㧨âì
\r
453 ; ebx - à §àãè ¥âáï
\r
454 macro import_boxlib myimport
\r
459 local import_find_next
\r
463 local import_not_found
\r
464 ; initialize import
\r
470 lodsd ;mov eax,dword[esi] ;add esi,4 ;¯®«ãç ¥¬ ¢ eax 㪠§ â¥«ì ¨¬ï ¨¬¯®àâ¨à㥬®© äãªæ¨¨
\r
472 jz import_done ;¥á«¨ 㪠§ â¥«ì ¨¬ï äãªæ¨¨ = 0 (¢ ¯®«ì§®¢ ⥫ì᪮© ¯à®£à ¬¬¥)
\r
473 push edx ;á®åà 塞 ç «® ¡¨¡«¨®â¥çëå 㪠§ ⥫¥© äãªæ¨¨
\r
477 jz import_not_found ;¥á«¨ 㪠§ â¥«ì ¨¬ï äãªæ¨¨ = 0 (¢ ¡¨¡«¨®â¥ª¥)
\r
478 push eax ;eax - 㪠§ â¥«ì ¨¬ï íªá¯®àâ¨à㥬®© äãªæ¨¨ (¢ ¯®«ì§®¢ ⥫ì᪮© ¯à®£à ¬¬¥)
\r
482 cmp cl, [ebx] ;áà ¢¨¢ ¥¬ ¨¬¥ äãªæ¨© ¢ ¡¨¡«¨®â¥ª¥ ¨ ¢ ¯®«ì§®¢ ⥫ì᪮© ¯à®£à ¬¬¥
\r
483 jnz import_find_next ;¥á«¨ §¢ ¨ï ¥ ᮢ¯ «¨
\r
485 jz import_found ;¥á«¨ §¢ ¨ï ᮢ¯ «¨, ¨ 㦥 ª®¥æ áâப¨ (cl=0)
\r
491 add edx, 8 ;8 = 4 ¡ ©â 㪠§ â¥«ì §¢ ¨¥ ¨ 4 ¡ ©â 㪠§ ⥫ì äãªæ¨î
\r
494 pop ebx ;¢®áâ ¢«¨¢ ¥¬ 㪠§ â¥«ì ¨¬ï äãªæ¨¨ (ª®â®àë© ¡ë« ¢ eax) ¨ ®á¢®¡®¦¤ ¥¬ á⥪
\r
495 mov eax, [edx+4] ;eax = 㪠§ ⥫ì äãªæ¨î (¢ ¡¨¡«¨®â¥ª¥)
\r
496 mov [esi-4], eax ;ª®¯¨à㥬 㪠§ ⥫ì ( äãªæ¨î) ¢ ¯à®£à ¬¬ã, -4 áâ ¢¨¬ ¯®â®¬ã çâ® esi ¡ë«® ᤢ¨ãâ® ª®¬ ¤®© lodsd
\r
497 pop edx ;ãáâ ¢«¨¢ ¥¬ edx ç «® ¡¨¡«¨®â¥çëå äãªæ¨©
\r
498 ;--- ¯à®¢¥à塞 ᮢ¯ ¤ ¥â «¨ ¨¬ï íªá¯®àâ¨à®¢ ®© äãªæ¨¨ á 'lib_init'
\r
499 if library_fun_memory_alloc eq
\r
501 cmp dword[ebx],'lib_'
\r
503 cmp dword[ebx+4],'init'
\r
507 ;--- ¥á«¨ ¨¬ï äãªæ¨¨ ᮢ¯ «® á 'lib_init' ¯®¯ ¤ ¥¬ áî¤
\r
508 ;¯®¤ª«î票¥ äãªæ¨© ¤«ï à ¡®âë á ¯ ¬ïâìî
\r
513 mov eax,library_fun_memory_alloc
\r
514 mov ebx,library_fun_memory_free
\r
515 mov ecx,library_fun_memory_realloc
\r
516 mov edx,library_fun_dll_load
\r
525 xor eax,eax ;=0 ¢á¥ § £à㧨«®áì 㤠ç®
\r
529 ;---------------------------------------------------------------------
\r
531 ll_struc_size = 28;($-library_name__) ; constant size of struct
\r
532 struc l_libs library_name__, library_path__, system_path__, my_import, point_dir_name; struct for loading libraries
\r
534 .library_name__ dd library_name__ ; ¨¬ï § £à㦠¥¬®© ¡¨¡«¨®â¥ª¨
\r
536 .library_path__ dd library_path__ ; 㪠§ â¥«ì ¡ãä¥à ¢ ª®â®à®¬ ¡ã¤¥â á®ä®à¨¬¨à®¢ ¯ãâì ª ¡¨¡«¨®â¥ª¨, ¥á«¨ 㦮 ¢ëç¨á«¨âì ¯ãâì ¤® «¨¡ë á ¬¥áâ § ¯ã᪠¯à®£à ¬¬ë, ®¡ëç® ã¦®, ¢ á«ãç ïå, ¥á«¨ «¨¡ à ᯮ«®¦¥ ¢ ⮩ ¦¥ ¯ ¯ª¥
\r
537 .complete_path dd system_path__ ; ¯ãâì ª®â®àë© ç¥âª® ᮤ¥à¦¨â ¯ãâì
\r
538 .my_import dd my_import
\r
539 if point_dir_name eq
\r
540 .point_dir_name__ dd 0
\r
542 .point_dir_name__ dd point_dir_name ; ¨¬ï ¢«®¦¥®© ¤¨à४â®à¨¨ ¢ ªâ®à®© åà ïâìáï ¯®¤£à㦠¥¬ë¥ ¬®¤ã«¨.
\r
545 .status_lib dd 0 ;status of load library
\r