Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. use32
  3.  
  4. LIBC_VERSION     =  1
  5. DLL_ENTRY        =  1
  6.  
  7. db 'MENUET02'
  8. dd 1
  9. dd start
  10. dd i_end
  11. dd mem
  12. dd mem
  13. dd cmdline
  14. dd path
  15. dd 0
  16.  
  17. align 4
  18. start:
  19.            mov eax, LIBC_VERSION
  20.            mov ecx, sz_libc
  21.            mov edx, libc
  22.            call load_library
  23.            test eax, eax
  24.            jz .fail
  25.  
  26.            push dword 0                ; no environment
  27.            push cmdline
  28.            push path
  29.            push (my_app_end - my_app)
  30.            push my_app
  31.            call [libc.imp_exec]
  32.  
  33.            ret
  34. .fail:
  35.            or eax, -1
  36.            int 0x40
  37.  
  38. align 4
  39. load_library:    ;eax=VERSION ecx=library path edx=import section
  40.  
  41.            sub esp, 16
  42.            mov [esp+8], edx
  43.            mov [esp+12], eax
  44.  
  45.            mov  eax, 68
  46.            mov  ebx, 19
  47.            int  0x40
  48.            test eax, eax
  49.            jz   .fail
  50.  
  51.            mov [esp+4], eax
  52.            mov  esi, edx                ;import section
  53.            mov  edx, eax                ;export section
  54. .import_loop:
  55.            lodsd
  56.            test eax, eax
  57.            jz   .import_done
  58. .import_find:
  59.            mov ebx, [edx]
  60.            test ebx, ebx
  61.            jz .fail                     ;import_not_found
  62.  
  63.            mov [esp], eax               ;import name
  64. @@:
  65.            mov cl, [eax]
  66.            cmp cl, [ebx]
  67.            jnz .import_find_next
  68.  
  69.            test cl, cl
  70.            jz .import_found
  71.  
  72.            inc eax
  73.            inc ebx
  74.            jmp @b
  75.  
  76. .import_find_next:
  77.            mov eax, [esp]
  78.            add edx, 8
  79.            jmp .import_find
  80.  
  81. .import_found:
  82.            mov eax, [edx+4]
  83.            mov [esi-4], eax
  84.            mov edx, [esp+4]
  85.            jmp .import_loop
  86. .import_done:
  87.  
  88.            mov edx, [esp+8]
  89.            mov eax, [esp+12]
  90.  
  91.            cmp word [edx+4], ax
  92.            jb .fail
  93.            cmp word [edx+6], ax
  94.            ja .fail
  95.  
  96.            push DLL_ENTRY
  97.            call dword [edx]
  98. .fail:
  99.            add esp, 16
  100.            ret
  101.  
  102.  
  103. sz_libc    db  '/sys/lib/libc.obj',0
  104.  
  105. szStart    db  'START',0
  106. szVersion  db  'version',0
  107. szExec     db  'exec',0
  108.  
  109. libc:
  110.  
  111. .imp_start      dd  szStart
  112. .imp_ver        dd  szVersion
  113. .imp_exec       dd  szExec
  114.                 dd  0
  115.  
  116. ; keep this aligned
  117. align 16
  118. my_app:
  119.            file 'myapp.exe'
  120. my_app_end:
  121.  
  122.  
  123. ; keep this aligned
  124. align 4
  125. i_end:
  126.  
  127. path       rb 1024
  128. cmdline    rb 256
  129.            rb 128   ;required stack
  130. ; keep this aligned
  131. align 4096
  132. mem:
  133.  
  134.