Subversion Repositories Kolibri OS

Rev

Rev 8088 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ; The macros for load any library/libraries:
  2. ; Copyright (c) 2009, <Lrz>
  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 <organization> nor 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 <Lrz> ''AS IS'' AND ANY
  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 <copyright holder> BE LIABLE FOR ANY
  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:
  28. ; <Lrz> - Alexey Teplov / €«¥ªá¥© ’¥¯«®¢
  29. ; Mario79, Mario - Marat Zakiyanov / Œ à â ‡ ª¨ï­®¢
  30. ; Diamondz - Evgeny Grechnikov / …¢£¥­¨© ƒà¥ç­¨ª®¢
  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
  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__
  57. ;-if return code =-1 then exit, else normally work
  58. ;        cmp     eax,-1
  59. ;        jz      exit
  60. ;- Well, if you get
  61. ;
  62. ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  63. ;DATA ¤ ­­ë¥
  64. ;‚ᥣ¤  ᮡ«î¤ âì ¯®á«¥¤®¢ â¥«ì­®áâì ¢ ¨¬¥­¨.
  65. ;system_path__      db '/sys/lib/'
  66. ;library_name__     db 'box_lib.obj',0
  67. ; …᫨ ¥áâì ¦¥« ­¨¥ ࠧꥤ¨­¨âì, â® ­ã¦­® ¨á¯®«ì§®¢ âì á«¥¤ãîé¨î ª®­áâàãªæ¨î
  68. ;system_path__      db '/sys/lib/box_lib.obj',0
  69. ;... «î¡ ï ¯®á«¥¤®¢ â¥«ì­®áâì ¤àã£¨å ª®¬ ­¤ ¨ ®¯à¥¤¥«¥­¨©.
  70. ;library_name__     db 'box_lib.obj',0
  71. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  72.  
  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
  77.  
  78. ;myimport:  
  79. ;
  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
  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.  
  92. macro @use_library mem_alloc,mem_free,mem_realloc,dll_load
  93. {
  94. local lp1
  95. local lp2
  96. local lp3
  97. local lp4
  98. local lp5
  99. local lp6
  100. local file_name
  101.  
  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
  106.  
  107. align 4
  108. arrea_xx dd 0
  109. file_name db '/sys/@notify',0
  110.  
  111. align 4
  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
  120.  
  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.  
  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
  136. align 4
  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
  185. @copy_path:
  186.         mov     esi,@cur_dir_path
  187.         mov     edi,@library_path
  188.         xor     eax,eax
  189.         cld
  190. align 4
  191. .lp1:
  192.         lodsb
  193.         stosb
  194.         test    eax,eax
  195.         jnz     .lp1
  196.         mov     esi,edi
  197.         dec     esi ;¯¥à¥å®¤ ­  ᨬ¢®« ª®­æ  áâப¨ @cur_dir_path
  198.         std
  199. align 4
  200. .lp2:
  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
  209.         jz      .str_lp4
  210.  
  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.         ;ª®¯¨à®¢ ­¨¥ ®â­®á¨â¥«ì­®£® ¯ãâ¨
  226. align 4
  227. .lp3:
  228.         lodsb
  229.         stosb
  230.         test    eax,eax
  231.         jnz     .lp3
  232.         dec     edi
  233. .str_lp4:
  234.         mov     esi,@library_name
  235. align 4
  236. .lp4:
  237.         lodsb
  238.         stosb
  239.         test    eax,eax
  240.         jnz     .lp4
  241.         ret
  242. }
  243. ;---------------------------------------------------------------------
  244.  
  245. macro @use_library_mem mem_alloc,mem_free,mem_realloc,dll_load
  246. {
  247. @use_library mem_alloc,mem_free,mem_realloc,dll_load
  248. }
  249.  
  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__
  251. {
  252. local i_begin
  253. local i_error
  254. local i_exit
  255.  
  256.         mcall   68,19,system_path__   ; load of sys directory
  257.         test    eax,eax
  258.         jnz             i_begin
  259.  
  260. if point_dir_name__ eq
  261.                 copy_path   library_name__, [32], library_path__,0
  262. else
  263.                 ;the macros making way /current path a program/ + name system library
  264.                 copy_path   library_name__, [32], library_path__,point_dir_name__
  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
  273. align 4
  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. }
  286. ;---------------------------------------------------------------------
  287.  
  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__
  289. {
  290. local i_begin
  291. local i_error
  292. local i_exit
  293.  
  294. if point_dir_name__ eq
  295.                 copy_path   library_name__, [32], library_path__,0
  296. else
  297.                 ;the macros making way /current path a program/ + name system library
  298.                 copy_path   library_name__, [32], library_path__,point_dir_name__
  299. end if
  300.                 mcall   68,19,library_path__ ; load of alternative
  301.                 test    eax,eax
  302.                 jnz             i_begin
  303.  
  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
  311. align 4
  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:
  323. ;---------------------------------------------------------------------
  324. }
  325.  
  326. ;description:
  327. ; ¬ ªà®á § £à㧪¨ ¡¨¡«¨®â¥ª ¨§ á¨á⥬­®© ¯ ¯ª¨, ¥á«¨ ¡¨¡«¨®â¥ª  ­¥ ­ ©¤¥­ 
  328. ; ⮣¤  ¯®¨áª ¨¤¥â ¢ ⥪ã饩 ¯ ¯ª¥ á ¯à®£à ¬¬®©
  329. macro sys_load_libraries _start,_end
  330. {
  331. local cycle0
  332. local end_steep
  333. local cycle0n
  334. local cycle1
  335. local cycle1n
  336. local cycle1e
  337. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  338. library_name__            equ [ebp]
  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]
  349.  
  350.         mov     ebp,_start
  351.         mov     ecx,(_end-_start)/ll_struc_size
  352. align 4
  353.         cycle0:
  354.                 push    ecx
  355.         mcall   68,19,system_path__   ; load of sys directory
  356.         test    eax,eax
  357.         jnz     end_steep
  358.  
  359.         ;the macros making way /current path a program/ + name system library
  360.                 copy_path  library_name__, [32], library_path__,point_dir_name__
  361.        
  362.         mcall   68,19,library_path__ ; load of alternative
  363.         test    eax,eax
  364.         jnz     end_steep
  365.         or      status_lib,1          ; status of code - enable error - not found library
  366.  
  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
  372.  
  373. align 4
  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
  389.  
  390.         ;¢ë¢®¤ á®®¡é¥­¨ï ®¡ ®è¨¡ª¥ ¯à¨ § £à㧪¥
  391.         mov     ebp,_start
  392.         mov     ecx,(_end-_start)/ll_struc_size
  393. align 4
  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:
  407. }
  408.  
  409. ;description:
  410. ; ¬ ªà®á § £à㧪¨ ¡¨¡«¨®â¥ª ¨§ ⥪ã饩 ¯ ¯ª¨ á ¯à®£à ¬¬®©, ¥á«¨ ¡¨¡«¨®â¥ª  ­¥ ­ ©¤¥­ 
  411. ; ⮣¤  ¯®¨áª ¨¤¥â ¢ á¨á⥬­®© ¯ ¯ª¥
  412. macro load_libraries _start,_end
  413. {
  414. local cycle0
  415. local end_steep
  416. local cycle0n
  417. local cycle1
  418. local cycle1n
  419. local cycle1e
  420. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  421. library_name__            equ [ebp]
  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]
  432.  
  433.         mov     ebp,_start
  434.         mov     ecx,(_end-_start)/ll_struc_size
  435. align 4
  436.         cycle0:
  437.                 push    ecx
  438.  
  439.                 ;the macros making way /current path a program/ + name system library
  440.                 copy_path    library_name__, [32], library_path__,point_dir_name__
  441.  
  442.                 mcall   68,19,library_path__  ; load of alternative
  443.                 test    eax,eax
  444.                 jnz             end_steep
  445.  
  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
  450.  
  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
  456.  
  457. align 4
  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
  473.  
  474.         ;¢ë¢®¤ á®®¡é¥­¨ï ®¡ ®è¨¡ª¥ ¯à¨ § £à㧪¥
  475.         mov     ebp,_start
  476.         mov     ecx,(_end-_start)/ll_struc_size
  477. align 4
  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:
  491. }
  492.  
  493.  
  494. macro copy_path lib_name,dir_path,lib_path,point_dir_name
  495. {
  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
  502.  
  503.         add  esp,16
  504.         ;notify_window_run lib_path ;unblok for test load path
  505. popad   ;restore all registers
  506. }
  507.  
  508. ; ¢ª«îç ¥¬ ¯®ª § á®®¡é¥­¨ï ç¥à¥§ @notify:
  509. macro notify_window_run message
  510. {
  511. push eax ebx
  512.         mov eax,message ;¯ à ¬¥âàë ¤«ï ª®¬ ­¤­®© áâப¨
  513.         mov [run_notify_struct.Flags],eax
  514.         mov eax,70 ;run @notify
  515.         mov ebx,run_notify_struct
  516.         int 0x40
  517. pop ebx eax
  518. }
  519.  
  520.  
  521. ;input:
  522. ; eax -  ¤à¥á ¡¨¡«¨®â¥ª¨ ¢ ¯ ¬ïâ¨
  523. ; myimport - ¨¬¯®àâ¨àã¥¬ë¥ ä㭪樨
  524. ;output:
  525. ; eax - ¥á«¨ 㤠筮 â® 0 ¨«¨ 㪠§ â¥«ì ­  ¨¬ï ä㭪樨 ª®â®àãî ­¥ 㤠«®áì § £à㧨âì
  526. macro import_boxlib myimport
  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:
  541.         lodsd   ;mov eax,dword[esi] ;add esi,4 ;¯®«ãç ¥¬ ¢ eax 㪠§ â¥«ì ­  ¨¬ï ¨¬¯®àâ¨à㥬®© ä㭪樨
  542.         test    eax, eax
  543.         jz      import_done ;¥á«¨ 㪠§ â¥«ì ­  ¨¬ï ä㭪樨 = 0 (¢ ¯®«ì§®¢ â¥«ì᪮© ¯à®£à ¬¬¥)
  544.         push    edx ;á®å࠭塞 ­ ç «® ¡¨¡«¨®â¥ç­ëå 㪠§ â¥«¥© ­  ä㭪樨
  545. import_find:
  546.         mov     ebx, [edx]
  547.         test    ebx, ebx
  548.         jz      import_not_found ;¥á«¨ 㪠§ â¥«ì ­  ¨¬ï ä㭪樨 = 0 (¢ ¡¨¡«¨®â¥ª¥)
  549.         push    eax ;eax - 㪠§ â¥«ì ­  ¨¬ï íªá¯®àâ¨à㥬®© ä㭪樨 (¢ ¯®«ì§®¢ â¥«ì᪮© ¯à®£à ¬¬¥)
  550. lp:
  551.         mov     cl, [eax]
  552.         cmp     cl, [ebx] ;áà ¢­¨¢ ¥¬ ¨¬¥­  ä㭪権 ¢ ¡¨¡«¨®â¥ª¥ ¨ ¢ ¯®«ì§®¢ â¥«ì᪮© ¯à®£à ¬¬¥
  553.         jnz     import_find_next ;¥á«¨ ­ §¢ ­¨ï ­¥ ᮢ¯ «¨
  554.         test    cl, cl
  555.         jz      import_found ;¥á«¨ ­ §¢ ­¨ï ᮢ¯ «¨, ¨ 㦥 ª®­¥æ áâப¨ (cl=0)
  556.         inc     eax
  557.         inc     ebx
  558.         jmp     lp
  559. import_find_next:
  560.         pop     eax
  561.         add     edx, 8 ;8 = 4 ¡ ©â  㪠§ â¥«ì ­  ­ §¢ ­¨¥ ¨ 4 ¡ ©â  㪠§ â¥«ì ­  äã­ªæ¨î
  562.         jmp     import_find
  563. import_found:
  564.         pop     ebx ;¢®áâ ­ ¢«¨¢ ¥¬ 㪠§ â¥«ì ­  ¨¬ï ä㭪樨 (ª®â®àë© ¡ë« ¢ eax) ¨ ®á¢®¡®¦¤ ¥¬ á⥪
  565.         mov     eax, [edx+4] ;eax = 㪠§ â¥«ì ­  äã­ªæ¨î (¢ ¡¨¡«¨®â¥ª¥)
  566.         mov     [esi-4], eax ;ª®¯¨à㥬 㪠§ â¥«ì (­  äã­ªæ¨î) ¢ ¯à®£à ¬¬ã, -4 áâ ¢¨¬ ¯®â®¬ã çâ® esi ¡ë«® ᤢ¨­ãâ® ª®¬ ­¤®© lodsd
  567.         pop     edx ;ãáâ ­ ¢«¨¢ ¥¬ edx ­  ­ ç «® ¡¨¡«¨®â¥ç­ëå ä㭪権
  568. ;--- ¯à®¢¥à塞 ᮢ¯ ¤ ¥â «¨ ¨¬ï íªá¯®àâ¨à®¢ ­­®© ä㭪樨 á 'lib_init'
  569. if library_fun_memory_alloc eq
  570. else
  571.                 cmp dword[ebx],'lib_'
  572.                 jne             import_loop
  573.                 cmp dword[ebx+4],'init'
  574.                 jne             import_loop
  575. ;--- ¥á«¨ ¨¬ï ä㭪樨 ᮢ¯ «® á 'lib_init' ¯®¯ ¤ ¥¬ á
  576.                 ;¯®¤ª«î祭¨¥ ä㭪権 ¤«ï à ¡®âë á ¯ ¬ïâìî
  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
  588.         jmp     import_loop
  589. import_not_found:
  590.         add     esp,4
  591.         jmp     exit
  592. import_done:
  593.         xor     eax,eax ;=0 ¢á¥ § £à㧨«®áì 㤠筮
  594. exit:
  595. }
  596. ;---------------------------------------------------------------------
  597.  
  598. ll_struc_size = 44;($-library_name__)    ; constant   size of struct
  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
  600. {        
  601. .library_name__           dd library_name__        ; ¨¬ï § £à㦠¥¬®© ¡¨¡«¨®â¥ª¨
  602.                        
  603. .library_path__           dd library_path__        ; 㪠§ â¥«ì ­  ¡ãä¥à ¢ ª®â®à®¬ ¡ã¤¥â á®ä®à¨¬¨à®¢ ­ ¯ãâì ª ¡¨¡«¨®â¥ª¨, ¥á«¨ ­ã¦­® ¢ëç¨á«¨âì ¯ãâì ¤® «¨¡ë á ¬¥áâ  § ¯ã᪠ ¯à®£à ¬¬ë, ®¡ëç­® ­ã¦­®, ¢ á«ãç ïå, ¥á«¨ «¨¡  à á¯®«®¦¥­  ¢ ⮩ ¦¥ ¯ ¯ª¥
  604. .complete_path            dd system_path__         ; ¯ãâì ª®â®àë© ç¥âª® ᮤ¥à¦¨â ¯ãâì
  605.  
  606. .err_message_found_lib__  dd err_message_found_lib__
  607. .head_f_l__               dd head_f_l__
  608. .my_import                dd my_import
  609. .err_message_import__     dd err_message_import__
  610. .head_f_i__               dd head_f_i__
  611. if point_dir_name eq
  612. .point_dir_name__       dd 0
  613. else
  614. .point_dir_name__       dd point_dir_name          ; ¨¬ï ¢«®¦¥­­®© ¤¨à४â®à¨¨ ¢ ªâ®à®© åà ­ïâìáï ¯®¤£à㦠¥¬ë¥ ¬®¤ã«¨.
  615. end if
  616. .adr_load_lib           dd 0
  617. .status_lib             dd 0          ;status of load library
  618. ;
  619. }
  620.