Subversion Repositories Kolibri OS

Rev

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

  1. ;
  2. ;  KolibriOS Dll load support
  3. ;
  4. ;  (C) 2020-2021 Coldy 
  5. ;  Thank's you for use this code and software based on it!
  6. ;  I will glad if it's will be helpful.
  7. ;
  8. ;  Distributed under terms of GPL
  9. ;
  10. format MS COFF
  11. public @EXPORT as 'EXPORTS'
  12.  
  13. include '../../../proc32.inc'
  14. include '../../../macros.inc'
  15.  
  16. section '.flat' code readable align 16
  17.  
  18. app_version       equ word[8]
  19. i_table_min_size  =   1
  20.  
  21. APP_START_THUNK:
  22.     ; First make shure that app
  23.     ; have header version 2.0 or more
  24.     cmp app_version,2
  25.     jl .denied
  26.    
  27.     ; Then make shure that we first
  28.     mov eax, @EXPORT
  29.     cmp dword[eax-4],0
  30.     je .denied
  31.    
  32.     ; Don't allow second time
  33.     mov dword[eax-4],0 
  34.    
  35.    ; Early app initialization
  36.    
  37.    ; Test import table 
  38.    mov  eax, [0x24] ; i_table_ptr
  39.    test eax, eax
  40.    jz  @f
  41.    mov esi, [0x10]
  42.    cmp esi, eax
  43.    jbe @f           ; i_table_ptr >= img_size ?
  44.    mov ebx, eax
  45.    add ebx, i_table_min_size
  46.    cmp esi, ebx
  47.    jbe @f           ; i_table_ptr + i_table_min_size >= img_size ?
  48.    
  49.    ; Link app import table with DLL's exoport table      
  50.    stdcall dll.Load,eax
  51.    test eax, eax
  52.    jnz  @f  
  53.    ; Start of app code
  54.    mov  eax, [0x0C]
  55.    ; TODO: test start_ptr + min_code_size < img_size   
  56.    call eax
  57. @@:
  58.    mov eax, -1
  59.    int 0x40
  60. .denied:
  61.    ret
  62. ; } APP_START_THUNK
  63.  
  64.  
  65. ; WARNING! This code must be after app initialization thunk!
  66. include '../../../dll.inc'
  67. align 4
  68. ;dd 0xdeadbeef
  69. dd APP_START_THUNK
  70. @EXPORT:
  71. export                              \
  72.     dll.Load,           'dll_load',  \
  73.     dll.Link,           'dll_link',  \
  74.     dll.GetProcAddress, 'dll_sym' ;