Subversion Repositories Kolibri OS

Rev

Rev 8083 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;13.03.2013 - use @notify
  2. ;08.06.2010 - new macros @use_library_mem
  3. ;08.05.2009 - bugfix
  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, <Lrz>
  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 <organization> nor 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 <Lrz> ''AS IS'' AND ANY
  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 <copyright holder> BE LIABLE FOR ANY
  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:
  32. ; <Lrz> - Alexey Teplov / €«¥ªá¥© ’¥¯«®¢
  33. ; Mario79, Mario - Marat Zakiyanov / Œ à â ‡ ª¨ï­®¢
  34. ; Diamondz - Evgeny Grechnikov / …¢£¥­¨© ƒà¥ç­¨ª®¢
  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
  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__
  61. ;-if return code =-1 then exit, else normally work
  62. ;        cmp     eax,-1
  63. ;        jz      exit
  64. ;- Well, if you get
  65. ;
  66. ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  67. ;DATA ¤ ­­ë¥
  68. ;‚ᥣ¤  ᮡ«î¤ âì ¯®á«¥¤®¢ â¥«ì­®áâì ¢ ¨¬¥­¨.
  69. ;system_path__      db '/sys/lib/'
  70. ;library_name__     db 'box_lib.obj',0
  71. ; …᫨ ¥áâì ¦¥« ­¨¥ ࠧꥤ¨­¨âì, â® ­ã¦­® ¨á¯®«ì§®¢ âì á«¥¤ãîé¨î ª®­áâàãªæ¨î
  72. ;system_path__      db '/sys/lib/box_lib.obj',0
  73. ;... «î¡ ï ¯®á«¥¤®¢ â¥«ì­®áâì ¤àã£¨å ª®¬ ­¤ ¨ ®¯à¥¤¥«¥­¨©.
  74. ;library_name__     db 'box_lib.obj',0
  75. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  76.  
  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
  81.  
  82. ;myimport:  
  83. ;
  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
  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. {
  98. local lp1
  99. local lp2
  100. local lp3
  101. local lp4
  102. local lp5
  103. local lp6
  104. local file_name
  105.  
  106. library_fun_memory_alloc equ 0 ;­¥ ¨á¯®«ì§®¢ âì ¢ ¬ ªà®á å ¯à®¢¥àªã ­  ä㭪樨 'lib_init'
  107.  
  108. align 4
  109. arrea_xx dd 0
  110. file_name db '/sys/@notify',0
  111.  
  112. align 4
  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
  121.  
  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.  
  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
  137. align 4
  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
  186. @copy_path:
  187.         mov     esi,@cur_dir_path
  188.         mov     edi,@library_path
  189.         xor     eax,eax
  190.         cld
  191. align 4
  192. .lp1:
  193.         lodsb
  194.         stosb
  195.         test    eax,eax
  196.         jnz     .lp1
  197.         mov     esi,edi
  198.         dec     esi ;¯¥à¥å®¤ ­  ᨬ¢®« ª®­æ  áâப¨ @cur_dir_path
  199.         std
  200. align 4
  201. .lp2:
  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
  210.         jz      .str_lp4
  211.  
  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.         ;ª®¯¨à®¢ ­¨¥ ®â­®á¨â¥«ì­®£® ¯ãâ¨
  227. align 4
  228. .lp3:
  229.         lodsb
  230.         stosb
  231.         test    eax,eax
  232.         jnz     .lp3
  233.         dec     edi
  234. .str_lp4:
  235.         mov     esi,@library_name
  236. align 4
  237. .lp4:
  238.         lodsb
  239.         stosb
  240.         test    eax,eax
  241.         jnz     .lp4
  242.         ret
  243. }
  244. ;---------------------------------------------------------------------
  245.  
  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.  
  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__
  256. {
  257. local i_begin
  258. local i_error
  259. local i_exit
  260.  
  261.         mcall   68,19,system_path__   ; load of sys directory
  262.         test    eax,eax
  263.         jnz             i_begin
  264.  
  265. if point_dir_name__ eq
  266.                 copy_path   library_name__, cur_dir_path__, library_path__,0
  267. else
  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
  278. align 4
  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. }
  291. ;---------------------------------------------------------------------
  292.  
  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__
  294. {
  295. local i_begin
  296. local i_error
  297. local i_exit
  298.  
  299. if point_dir_name__ eq
  300.                 copy_path   library_name__, cur_dir_path__, library_path__,0
  301. else
  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
  308.  
  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
  316. align 4
  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:
  328. ;---------------------------------------------------------------------
  329. }
  330.  
  331. ;description:
  332. ; ¬ ªà®á § £à㧪¨ ¡¨¡«¨®â¥ª ¨§ á¨á⥬­®© ¯ ¯ª¨, ¥á«¨ ¡¨¡«¨®â¥ª  ­¥ ­ ©¤¥­ 
  333. ; ⮣¤  ¯®¨áª ¨¤¥â ¢ ⥪ã饩 ¯ ¯ª¥ á ¯à®£à ¬¬®©
  334. macro sys_load_libraries _start,_end
  335. {
  336. local cycle0
  337. local end_steep
  338. local cycle0n
  339. local cycle1
  340. local cycle1n
  341. local cycle1e
  342. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  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]
  349. my_import                 equ [ebp+24]
  350. err_message_import__      equ [ebp+28]
  351. head_f_i__                equ [ebp+32]
  352. point_dir_name__          equ [ebp+36]
  353. adr_load_lib              equ dword [ebp+40]
  354. status_lib                equ dword [ebp+44]
  355.  
  356.         mov     ebp,_start
  357.         mov     ecx,(_end-_start)/ll_struc_size
  358. align 4
  359.         cycle0:
  360.                 push    ecx
  361.         mcall   68,19,system_path__   ; load of sys directory
  362.         test    eax,eax
  363.         jnz     end_steep
  364.  
  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__
  367.        
  368.         mcall   68,19,library_path__ ; load of alternative
  369.         test    eax,eax
  370.         jnz     end_steep
  371.         or      status_lib,1          ; status of code - enable error - not found library
  372.  
  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
  378.  
  379. align 4
  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
  395.  
  396.         ;¢ë¢®¤ á®®¡é¥­¨ï ®¡ ®è¨¡ª¥ ¯à¨ § £à㧪¥
  397.         mov     ebp,_start
  398.         mov     ecx,(_end-_start)/ll_struc_size
  399. align 4
  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:
  413. }
  414.  
  415. ;description:
  416. ; ¬ ªà®á § £à㧪¨ ¡¨¡«¨®â¥ª ¨§ ⥪ã饩 ¯ ¯ª¨ á ¯à®£à ¬¬®©, ¥á«¨ ¡¨¡«¨®â¥ª  ­¥ ­ ©¤¥­ 
  417. ; ⮣¤  ¯®¨áª ¨¤¥â ¢ á¨á⥬­®© ¯ ¯ª¥
  418. macro load_libraries _start,_end
  419. {
  420. local cycle0
  421. local end_steep
  422. local cycle0n
  423. local cycle1
  424. local cycle1n
  425. local cycle1e
  426. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  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]
  433. my_import                 equ [ebp+24]
  434. err_message_import__      equ [ebp+28]
  435. head_f_i__                equ [ebp+32]
  436. point_dir_name__          equ [ebp+36]
  437. adr_load_lib              equ dword [ebp+40]
  438. status_lib                equ dword [ebp+44]
  439.  
  440.         mov     ebp,_start
  441.         mov     ecx,(_end-_start)/ll_struc_size
  442. align 4
  443.         cycle0:
  444.                 push    ecx
  445.  
  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__
  448.  
  449.                 mcall   68,19,library_path__  ; load of alternative
  450.                 test    eax,eax
  451.                 jnz             end_steep
  452.  
  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
  457.  
  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
  463.  
  464. align 4
  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
  480.  
  481.         ;¢ë¢®¤ á®®¡é¥­¨ï ®¡ ®è¨¡ª¥ ¯à¨ § £à㧪¥
  482.         mov     ebp,_start
  483.         mov     ecx,(_end-_start)/ll_struc_size
  484. align 4
  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:
  498. }
  499.  
  500.  
  501. macro copy_path lib_name,dir_path,lib_path,point_dir_name
  502. {
  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
  509.  
  510.         add  esp,16
  511.         ;notify_window_run lib_path ;unblok for test load path
  512. popad   ;restore all registers
  513. }
  514.  
  515. ; ¢ª«îç ¥¬ ¯®ª § á®®¡é¥­¨ï ç¥à¥§ @notify:
  516. macro notify_window_run message
  517. {
  518. push eax ebx
  519.         mov eax,message ;¯ à ¬¥âàë ¤«ï ª®¬ ­¤­®© áâப¨
  520.         mov [run_notify_struct.Flags],eax
  521.         mov eax,70 ;run @notify
  522.         mov ebx,run_notify_struct
  523.         int 0x40
  524. pop ebx eax
  525. }
  526.  
  527.  
  528. ;input:
  529. ; eax -  ¤à¥á ¡¨¡«¨®â¥ª¨ ¢ ¯ ¬ïâ¨
  530. ; myimport - ¨¬¯®àâ¨àã¥¬ë¥ ä㭪樨
  531. ;output:
  532. ; eax - ¥á«¨ 㤠筮 â® 0 ¨«¨ 㪠§ â¥«ì ­  ¨¬ï ä㭪樨 ª®â®àãî ­¥ 㤠«®áì § £à㧨âì
  533. macro import_boxlib myimport
  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:
  548.         lodsd   ;mov eax,dword[esi] ;add esi,4 ;¯®«ãç ¥¬ ¢ eax 㪠§ â¥«ì ­  ¨¬ï ¨¬¯®àâ¨à㥬®© ä㭪樨
  549.         test    eax, eax
  550.         jz      import_done ;¥á«¨ 㪠§ â¥«ì ­  ¨¬ï ä㭪樨 = 0 (¢ ¯®«ì§®¢ â¥«ì᪮© ¯à®£à ¬¬¥)
  551.         push    edx ;á®å࠭塞 ­ ç «® ¡¨¡«¨®â¥ç­ëå 㪠§ â¥«¥© ­  ä㭪樨
  552. import_find:
  553.         mov     ebx, [edx]
  554.         test    ebx, ebx
  555.         jz      import_not_found ;¥á«¨ 㪠§ â¥«ì ­  ¨¬ï ä㭪樨 = 0 (¢ ¡¨¡«¨®â¥ª¥)
  556.         push    eax ;eax - 㪠§ â¥«ì ­  ¨¬ï íªá¯®àâ¨à㥬®© ä㭪樨 (¢ ¯®«ì§®¢ â¥«ì᪮© ¯à®£à ¬¬¥)
  557. lp:
  558.         mov     cl, [eax]
  559.         cmp     cl, [ebx] ;áà ¢­¨¢ ¥¬ ¨¬¥­  ä㭪権 ¢ ¡¨¡«¨®â¥ª¥ ¨ ¢ ¯®«ì§®¢ â¥«ì᪮© ¯à®£à ¬¬¥
  560.         jnz     import_find_next ;¥á«¨ ­ §¢ ­¨ï ­¥ ᮢ¯ «¨
  561.         test    cl, cl
  562.         jz      import_found ;¥á«¨ ­ §¢ ­¨ï ᮢ¯ «¨, ¨ 㦥 ª®­¥æ áâப¨ (cl=0)
  563.         inc     eax
  564.         inc     ebx
  565.         jmp     lp
  566. import_find_next:
  567.         pop     eax
  568.         add     edx, 8 ;8 = 4 ¡ ©â  㪠§ â¥«ì ­  ­ §¢ ­¨¥ ¨ 4 ¡ ©â  㪠§ â¥«ì ­  äã­ªæ¨î
  569.         jmp     import_find
  570. import_found:
  571.         pop     ebx ;¢®áâ ­ ¢«¨¢ ¥¬ 㪠§ â¥«ì ­  ¨¬ï ä㭪樨 (ª®â®àë© ¡ë« ¢ eax) ¨ ®á¢®¡®¦¤ ¥¬ á⥪
  572.         mov     eax, [edx+4] ;eax = 㪠§ â¥«ì ­  äã­ªæ¨î (¢ ¡¨¡«¨®â¥ª¥)
  573.         mov     [esi-4], eax ;ª®¯¨à㥬 㪠§ â¥«ì (­  äã­ªæ¨î) ¢ ¯à®£à ¬¬ã, -4 áâ ¢¨¬ ¯®â®¬ã çâ® esi ¡ë«® ᤢ¨­ãâ® ª®¬ ­¤®© lodsd
  574.         pop     edx ;ãáâ ­ ¢«¨¢ ¥¬ edx ­  ­ ç «® ¡¨¡«¨®â¥ç­ëå ä㭪権
  575. ;--- ¯à®¢¥à塞 ᮢ¯ ¤ ¥â «¨ ¨¬ï íªá¯®àâ¨à®¢ ­­®© ä㭪樨 á 'lib_init'
  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
  582. ;--- ¥á«¨ ¨¬ï ä㭪樨 ᮢ¯ «® á 'lib_init' ¯®¯ ¤ ¥¬ á
  583.                 ;¯®¤ª«î祭¨¥ ä㭪権 ¤«ï à ¡®âë á ¯ ¬ïâìî
  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
  595.         jmp     import_loop
  596. import_not_found:
  597.         add     esp,4
  598.         jmp     exit
  599. import_done:
  600.         xor     eax,eax ;=0 ¢á¥ § £à㧨«®áì 㤠筮
  601. exit:
  602. }
  603. ;---------------------------------------------------------------------
  604.  
  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
  607. {        
  608. .library_name__           dd library_name__        ; ¨¬ï § £à㦠¥¬®© ¡¨¡«¨®â¥ª¨
  609. .cur_dir_path__           dd cur_dir_path__        ; 㪠§ â¥«ì ­  ¡ãä¥à ¢ ª®â®à®¬ ᮤ¥à¦¨âìáï ¯ãâì ®â ªã¤  ¡ë«  § ¯ã饭  ¯à®£à ¬¬ 
  610.                        
  611. .library_path__           dd library_path__        ; 㪠§ â¥«ì ­  ¡ãä¥à ¢ ª®â®à®¬ ¡ã¤¥â á®ä®à¨¬¨à®¢ ­ ¯ãâì ª ¡¨¡«¨®â¥ª¨, ¥á«¨ ­ã¦­® ¢ëç¨á«¨âì ¯ãâì ¤® «¨¡ë á ¬¥áâ  § ¯ã᪠ ¯à®£à ¬¬ë, ®¡ëç­® ­ã¦­®, ¢ á«ãç ïå, ¥á«¨ «¨¡  à á¯®«®¦¥­  ¢ ⮩ ¦¥ ¯ ¯ª¥
  612. .complete_path            dd system_path__         ; ¯ãâì ª®â®àë© ç¥âª® ᮤ¥à¦¨â ¯ãâì
  613.  
  614. .err_message_found_lib__  dd err_message_found_lib__
  615. .head_f_l__               dd head_f_l__
  616. .my_import                dd my_import
  617. .err_message_import__     dd err_message_import__
  618. .head_f_i__               dd head_f_i__
  619. if point_dir_name eq
  620. .point_dir_name__       dd 0
  621. else
  622. .point_dir_name__       dd point_dir_name          ; ¨¬ï ¢«®¦¥­­®© ¤¨à४â®à¨¨ ¢ ªâ®à®© åà ­ïâìáï ¯®¤£à㦠¥¬ë¥ ¬®¤ã«¨.
  623. end if
  624. .adr_load_lib           dd 0
  625. .status_lib             dd 0          ;status of load library
  626. ;
  627. }
  628.