Subversion Repositories Kolibri OS

Rev

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

  1.  
  2. align 4
  3.  
  4. proc load_PE stdcall, file_name:dword
  5.            locals
  6.              image  dd ?
  7.            endl
  8.  
  9.            stdcall load_file, [file_name]
  10.            test eax, eax
  11.            jz .fail
  12.  
  13.            mov [image], eax
  14.  
  15.            mov edx, [eax+60]
  16.  
  17.            stdcall kernel_alloc, [eax+80+edx]
  18.            test eax, eax
  19.            jz .cleanup
  20.  
  21.            stdcall map_PE, eax, [image]
  22.            ret
  23. .cleanup:
  24.            stdcall kernel_free,[image]
  25. .fail:
  26.            xor eax, eax
  27.            ret
  28. endp
  29.  
  30.  
  31. align 4
  32. map_PE:                    ;stdcall base:dword, image:dword
  33.            cld
  34.            push    ebp
  35.            push    edi
  36.            push    esi
  37.            push    ebx
  38.            sub     esp, 44
  39.  
  40.            mov     ebp, [esp+68]
  41.            mov     ebx, [esp+64]
  42.            mov     edx, ebp
  43.            mov     esi, ebp
  44.            add     edx, [ebp+60]
  45.            mov     edi, ebx
  46.            mov     [esp+32], edx
  47.  
  48.            mov     ecx, [edx+84]
  49.            shr     ecx, 2
  50.            rep     movsd
  51.  
  52.            movzx   eax, word [edx+6]
  53.            mov     dword [esp+36], 0
  54.            mov     [esp+28], eax
  55.            jmp     .L6
  56. .L7:
  57.            mov     eax, [edx+264]
  58.            test    eax, eax
  59.            je      .L8
  60.  
  61.            mov     esi, ebp
  62.            mov     edi, ebx
  63.            add     esi, [edx+268]
  64.            mov     ecx, eax
  65.            add     edi, [edx+260]
  66.  
  67.            shr     ecx, 2
  68.            rep     movsd
  69.  
  70. .L8:
  71.            mov     ecx, [edx+256]
  72.            add     ecx, 4095
  73.            and     ecx, -4096
  74.            cmp     ecx, eax
  75.            jbe     .L10
  76.  
  77.            sub     ecx, eax
  78.            add     eax, [edx+260]
  79.            lea     edi, [eax+ebx]
  80.  
  81.            xor     eax, eax
  82.            rep     stosb
  83.  
  84. .L10:
  85.            inc     dword [esp+36]
  86.            add     edx, 40
  87. .L6:
  88.            mov     esi, [esp+28]
  89.            cmp     [esp+36], esi
  90.            jne     .L7
  91.  
  92.            mov     edi, [esp+32]
  93.            cmp     dword [edi+164], 0
  94.            je      .L13
  95.  
  96.            mov     eax, [esp+32]
  97.            mov     edi, ebx
  98.            mov     ecx, ebx
  99.            sub     edi, [eax+52]
  100.            add     ecx, [eax+160]
  101.  
  102.            mov     edx, edi
  103.            shr     edx, 16
  104.            mov     [esp+20], edx
  105.            jmp     .L15
  106. .L16:
  107.            lea     esi, [eax-8]
  108.            xor     ebp, ebp
  109.            shr     esi, 1
  110.            jmp     .L17
  111. .L18:
  112.            movzx   eax, word [ecx+8+ebp*2]
  113.            mov     edx, eax
  114.            shr     eax, 12
  115.            and     edx, 4095
  116.            add     edx, [ecx]
  117.            cmp     ax, 2
  118.            je      .L21
  119.  
  120.            cmp     ax, 3
  121.            je      .L22
  122.  
  123.            dec     ax
  124.            jne     .L19
  125.  
  126.            mov     eax, [esp+20]
  127.            add     [edx+ebx], ax
  128. .L21:
  129.            add     [edx+ebx], di
  130. .L22:
  131.            add     [edx+ebx], edi
  132. .L19:
  133.            inc     ebp
  134. .L17:
  135.            cmp     ebp, esi
  136.            jne     .L18
  137.  
  138.            add     ecx, [ecx+4]
  139. .L15:
  140.            mov     eax, [ecx+4]
  141.            test    eax, eax
  142.            jne     .L16
  143. .L13:
  144.            mov     edx, [esp+32]
  145.            cmp     dword [edx+132], 0
  146.            je      .L24
  147.  
  148.            mov     eax, ebx
  149.            add     eax, [edx+128]
  150.            lea     esi, [eax+20]
  151. .L26:
  152.            cmp     dword [esi-16], 0
  153.            jne     .L27
  154.  
  155.            cmp     dword [esi-8], 0
  156.            je      .L24
  157. .L27:
  158.            mov     ecx, [esi-20]
  159.            mov     ebp, ebx
  160.            add     ebp,  [esi-4]
  161.            add     ecx, ebx
  162.            mov     [esp+40], ecx
  163. .L29:
  164.            mov     edi, [esp+40]
  165.            mov     eax, [edi]
  166.            test    eax, eax
  167.            je      .L30
  168.  
  169.            test    eax, eax
  170.            js      .L30
  171.  
  172.            lea     eax, [eax+2+ebx]
  173.            mov     edi, kernel_export
  174.            mov     [ebp], dword -1
  175.            mov     [esp+24], eax
  176. .L33:
  177.            push    ecx
  178.            push    16
  179.            push    dword [edi]
  180.            push    dword [esp+36]
  181.            call    strncmp
  182.            pop     edx
  183.            test    eax, eax
  184.            jne     .L34
  185.            mov     eax, [edi+4]
  186.            mov     [ebp], eax
  187.            jmp     .L36
  188. .L34:
  189.            add     edi, 8
  190.            cmp     dword [edi], 0
  191.            jne     .L33
  192. .L36:
  193.            add     dword [esp+40], 4
  194.            add     ebp, 4
  195.            jmp     .L29
  196. .L30:
  197.            add     esi, 20
  198.            jmp     .L26
  199. .L24:
  200.            mov     eax, [esp+32]
  201.            add     ebx, [eax+40]
  202.            add     esp, 44
  203.            mov     eax, ebx
  204.            pop     ebx
  205.            pop     esi
  206.            pop     edi
  207.            pop     ebp
  208.            ret     8
  209.  
  210.