Subversion Repositories Kolibri OS

Rev

Rev 668 | Rev 740 | 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. .L8:
  70.            mov     ecx, [edx+256]
  71.            add     ecx, 4095
  72.            and     ecx, -4096
  73.            cmp     ecx, eax
  74.            jbe     .L10
  75.  
  76.            sub     ecx, eax
  77.            add     eax, [edx+260]
  78.            lea     edi, [eax+ebx]
  79.  
  80.            xor     eax, eax
  81.            rep     stosb
  82. .L10:
  83.            inc     dword [esp+36]
  84.            add     edx, 40
  85. .L6:
  86.            mov     esi, [esp+28]
  87.            cmp     [esp+36], esi
  88.            jne     .L7
  89.  
  90.            mov     edi, [esp+32]
  91.            cmp     dword [edi+164], 0
  92.            je      .L13
  93.  
  94.            mov     eax, [esp+32]
  95.            mov     edi, ebx
  96.            mov     ecx, ebx
  97.            sub     edi, [eax+52]
  98.            add     ecx, [eax+160]
  99.  
  100.            mov     edx, edi
  101.            shr     edx, 16
  102.            mov     [esp+20], edx
  103.            jmp     .L15
  104. .L16:
  105.            lea     esi, [eax-8]
  106.            xor     ebp, ebp
  107.            shr     esi, 1
  108.            jmp     .L17
  109. .L18:
  110.            movzx   eax, word [ecx+8+ebp*2]
  111.            mov     edx, eax
  112.            shr     eax, 12
  113.            and     edx, 4095
  114.            add     edx, [ecx]
  115.            cmp     ax, 2
  116.            je      .L21
  117.  
  118.            cmp     ax, 3
  119.            je      .L22
  120.  
  121.            dec     ax
  122.            jne     .L19
  123.  
  124.            mov     eax, [esp+20]
  125.            add     [edx+ebx], ax
  126. .L21:
  127.            add     [edx+ebx], di
  128. .L22:
  129.            add     [edx+ebx], edi
  130. .L19:
  131.            inc     ebp
  132. .L17:
  133.            cmp     ebp, esi
  134.            jne     .L18
  135.  
  136.            add     ecx, [ecx+4]
  137. .L15:
  138.            mov     eax, [ecx+4]
  139.            test    eax, eax
  140.            jne     .L16
  141. .L13:
  142.            mov     edx, [esp+32]
  143.            cmp     dword [edx+132], 0
  144.            je      .L24
  145.  
  146.            mov     eax, ebx
  147.            add     eax, [edx+128]
  148.            lea     esi, [eax+20]
  149. .L26:
  150.            cmp     dword [esi-16], 0
  151.            jne     .L27
  152.  
  153.            cmp     dword [esi-8], 0
  154.            je      .L24
  155. .L27:
  156.            mov     ecx, [esi-20]
  157.            mov     ebp, ebx
  158.            add     ebp,  [esi-4]
  159.            add     ecx, ebx
  160.            mov     [esp+40], ecx
  161. .L29:
  162.            mov     edi, [esp+40]
  163.            mov     eax, [edi]
  164.            test    eax, eax
  165.            je      .L30
  166.  
  167.            test    eax, eax
  168.            js      .L30
  169.  
  170.            lea     eax, [eax+2+ebx]
  171.            mov     edi, kernel_export
  172.            mov     [ebp], dword -1
  173.            mov     [esp+24], eax
  174. .L33:
  175.            push    ecx
  176.            push    16
  177.            push    dword [edi]
  178.            push    dword [esp+36]
  179.            call    strncmp
  180.            pop     edx
  181.            test    eax, eax
  182.            jne     .L34
  183.            mov     eax, [edi+4]
  184.            mov     [ebp], eax
  185.            jmp     .L36
  186. .L34:
  187.            add     edi, 8
  188.            cmp     dword [edi], 0
  189.            jne     .L33
  190. .L36:
  191.            add     dword [esp+40], 4
  192.            add     ebp, 4
  193.            jmp     .L29
  194. .L30:
  195.            add     esi, 20
  196.            jmp     .L26
  197. .L24:
  198.            mov     eax, [esp+32]
  199.            add     ebx, [eax+40]
  200.            add     esp, 44
  201.            mov     eax, ebx
  202.            pop     ebx
  203.            pop     esi
  204.            pop     edi
  205.            pop     ebp
  206.            ret     8
  207.  
  208.