2010-10-01 13:21:55 +04:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2012-03-15 16:41:29 +04:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
|
2010-10-01 13:21:55 +04:00
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
$Revision$
|
|
|
|
|
|
|
|
include 'export.inc'
|
|
|
|
|
|
|
|
align 4
|
|
|
|
|
|
|
|
proc load_PE stdcall, file_name:dword
|
|
|
|
locals
|
|
|
|
image dd ?
|
|
|
|
entry dd ?
|
|
|
|
base dd ?
|
|
|
|
endl
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
stdcall load_file, [file_name]
|
|
|
|
test eax, eax
|
|
|
|
jz .fail
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
mov [image], eax
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
mov edx, [eax+60]
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
stdcall kernel_alloc, [eax+80+edx]
|
|
|
|
test eax, eax
|
|
|
|
jz .cleanup
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
mov [base], eax
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
stdcall map_PE, eax, [image]
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
mov [entry], eax
|
|
|
|
test eax, eax
|
|
|
|
jnz .cleanup
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
stdcall kernel_free, [base]
|
2010-10-01 13:21:55 +04:00
|
|
|
.cleanup:
|
2012-03-08 12:33:38 +04:00
|
|
|
stdcall kernel_free, [image]
|
|
|
|
mov eax, [entry]
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
.fail:
|
2012-03-08 12:33:38 +04:00
|
|
|
xor eax, eax
|
|
|
|
ret
|
2010-10-01 13:21:55 +04:00
|
|
|
endp
|
|
|
|
|
|
|
|
DWORD equ dword
|
|
|
|
PTR equ
|
|
|
|
|
|
|
|
align 4
|
|
|
|
map_PE: ;stdcall base:dword, image:dword
|
2012-03-08 12:33:38 +04:00
|
|
|
cld
|
2010-10-01 13:21:55 +04:00
|
|
|
push ebp
|
2012-03-08 12:33:38 +04:00
|
|
|
push edi
|
|
|
|
push esi
|
|
|
|
push ebx
|
|
|
|
sub esp, 60
|
|
|
|
mov ebx, DWORD PTR [esp+84]
|
|
|
|
mov ebp, DWORD PTR [esp+80]
|
|
|
|
mov edx, ebx
|
|
|
|
mov esi, ebx
|
|
|
|
add edx, DWORD PTR [ebx+60]
|
|
|
|
mov edi, ebp
|
|
|
|
mov DWORD PTR [esp+32], edx
|
|
|
|
mov ecx, DWORD PTR [edx+84]
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
shr ecx, 2
|
|
|
|
rep movsd
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
movzx eax, WORD PTR [edx+6]
|
|
|
|
mov DWORD PTR [esp+36], 0
|
|
|
|
mov DWORD PTR [esp+16], eax
|
|
|
|
jmp L2
|
2010-10-01 13:21:55 +04:00
|
|
|
L3:
|
2012-03-08 12:33:38 +04:00
|
|
|
mov eax, DWORD PTR [edx+264]
|
|
|
|
test eax, eax
|
|
|
|
je L4
|
|
|
|
mov esi, ebx
|
|
|
|
mov edi, ebp
|
|
|
|
add esi, DWORD PTR [edx+268]
|
|
|
|
mov ecx, eax
|
|
|
|
add edi, DWORD PTR [edx+260]
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2014-01-02 01:16:27 +04:00
|
|
|
add ecx, 3
|
2012-03-08 12:33:38 +04:00
|
|
|
shr ecx, 2
|
|
|
|
rep movsd
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
L4:
|
2012-03-08 12:33:38 +04:00
|
|
|
mov ecx, DWORD PTR [edx+256]
|
|
|
|
cmp ecx, eax
|
|
|
|
jbe L6
|
|
|
|
sub ecx, eax
|
|
|
|
add eax, DWORD PTR [edx+260]
|
|
|
|
lea edi, [eax+ebp]
|
2010-10-01 13:21:55 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
xor eax, eax
|
|
|
|
rep stosb
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
L6:
|
2012-03-08 12:33:38 +04:00
|
|
|
inc DWORD PTR [esp+36]
|
|
|
|
add edx, 40
|
2010-10-01 13:21:55 +04:00
|
|
|
L2:
|
2012-03-08 12:33:38 +04:00
|
|
|
mov esi, DWORD PTR [esp+16]
|
|
|
|
cmp DWORD PTR [esp+36], esi
|
|
|
|
jne L3
|
|
|
|
mov edi, DWORD PTR [esp+32]
|
|
|
|
cmp DWORD PTR [edi+164], 0
|
|
|
|
je L9
|
2014-01-02 01:16:27 +04:00
|
|
|
pushd [edi+164]
|
2012-03-08 12:33:38 +04:00
|
|
|
mov esi, ebp
|
|
|
|
mov ecx, ebp
|
|
|
|
sub esi, DWORD PTR [edi+52]
|
|
|
|
add ecx, DWORD PTR [edi+160]
|
|
|
|
mov eax, esi
|
|
|
|
shr eax, 16
|
2014-01-02 01:16:27 +04:00
|
|
|
mov DWORD PTR [esp+16], eax
|
2010-10-01 13:21:55 +04:00
|
|
|
L12:
|
2014-01-02 01:16:27 +04:00
|
|
|
mov eax, [ecx+4]
|
|
|
|
sub [esp], eax
|
2012-03-08 12:33:38 +04:00
|
|
|
lea ebx, [eax-8]
|
|
|
|
xor edi, edi
|
|
|
|
shr ebx, 1
|
|
|
|
jmp L13
|
2010-10-01 13:21:55 +04:00
|
|
|
L14:
|
2012-03-08 12:33:38 +04:00
|
|
|
movzx eax, WORD PTR [ecx+8+edi*2]
|
|
|
|
mov edx, eax
|
|
|
|
shr eax, 12
|
|
|
|
and edx, 4095
|
|
|
|
add edx, DWORD PTR [ecx]
|
|
|
|
cmp ax, 2
|
|
|
|
je L17
|
|
|
|
cmp ax, 3
|
|
|
|
je L18
|
|
|
|
dec ax
|
|
|
|
jne L15
|
2014-01-02 01:16:27 +04:00
|
|
|
mov eax, DWORD PTR [esp+16]
|
2012-03-08 12:33:38 +04:00
|
|
|
add WORD PTR [edx+ebp], ax
|
2010-10-01 13:21:55 +04:00
|
|
|
L17:
|
2012-03-08 12:33:38 +04:00
|
|
|
add WORD PTR [edx+ebp], si
|
2010-10-01 13:21:55 +04:00
|
|
|
L18:
|
2012-03-08 12:33:38 +04:00
|
|
|
add DWORD PTR [edx+ebp], esi
|
2010-10-01 13:21:55 +04:00
|
|
|
L15:
|
2012-03-08 12:33:38 +04:00
|
|
|
inc edi
|
2010-10-01 13:21:55 +04:00
|
|
|
L13:
|
2012-03-08 12:33:38 +04:00
|
|
|
cmp edi, ebx
|
|
|
|
jne L14
|
|
|
|
add ecx, DWORD PTR [ecx+4]
|
2010-10-01 13:21:55 +04:00
|
|
|
L11:
|
2014-01-02 01:16:27 +04:00
|
|
|
cmp dword [esp], 0
|
|
|
|
jg L12
|
|
|
|
pop eax
|
2010-10-01 13:21:55 +04:00
|
|
|
L9:
|
2012-03-08 12:33:38 +04:00
|
|
|
mov edx, DWORD PTR [esp+32]
|
|
|
|
cmp DWORD PTR [edx+132], 0
|
|
|
|
je L20
|
|
|
|
mov eax, ebp
|
|
|
|
add eax, DWORD PTR [edx+128]
|
|
|
|
mov DWORD PTR [esp+40], 0
|
|
|
|
add eax, 20
|
|
|
|
mov DWORD PTR [esp+56], eax
|
2010-10-01 13:21:55 +04:00
|
|
|
L22:
|
2012-03-08 12:33:38 +04:00
|
|
|
mov ecx, DWORD PTR [esp+56]
|
|
|
|
cmp DWORD PTR [ecx-16], 0
|
|
|
|
jne L23
|
|
|
|
cmp DWORD PTR [ecx-8], 0
|
|
|
|
je L25
|
2010-10-01 13:21:55 +04:00
|
|
|
L23:
|
|
|
|
mov edi, DWORD PTR [__exports+32]
|
|
|
|
mov esi, DWORD PTR [__exports+28]
|
2012-03-08 12:33:38 +04:00
|
|
|
mov eax, DWORD PTR [esp+56]
|
|
|
|
mov DWORD PTR [esp+20], edi
|
2010-10-01 13:21:55 +04:00
|
|
|
add edi, OS_BASE
|
|
|
|
add esi, OS_BASE
|
2012-03-08 12:33:38 +04:00
|
|
|
mov DWORD PTR [esp+44], esi
|
|
|
|
mov ecx, DWORD PTR [eax-4]
|
|
|
|
mov DWORD PTR [esp+48], edi
|
|
|
|
mov edx, DWORD PTR [eax-20]
|
2014-01-02 01:16:27 +04:00
|
|
|
test edx, edx
|
|
|
|
jnz @f
|
|
|
|
mov edx, ecx
|
|
|
|
@@:
|
2012-03-08 12:33:38 +04:00
|
|
|
mov DWORD PTR [esp+52], 0
|
|
|
|
add ecx, ebp
|
|
|
|
add edx, ebp
|
|
|
|
mov DWORD PTR [esp+24], edx
|
|
|
|
mov DWORD PTR [esp+28], ecx
|
2010-10-01 13:21:55 +04:00
|
|
|
L26:
|
2012-03-08 12:33:38 +04:00
|
|
|
mov esi, DWORD PTR [esp+52]
|
|
|
|
mov edi, DWORD PTR [esp+24]
|
|
|
|
mov eax, DWORD PTR [edi+esi*4]
|
|
|
|
test eax, eax
|
|
|
|
je L27
|
|
|
|
test eax, eax
|
|
|
|
js L27
|
|
|
|
lea edi, [ebp+eax]
|
|
|
|
mov eax, DWORD PTR [esp+28]
|
|
|
|
mov DWORD PTR [eax+esi*4], 0
|
|
|
|
lea esi, [edi+2]
|
|
|
|
push eax
|
|
|
|
push 32
|
|
|
|
movzx eax, WORD PTR [edi]
|
|
|
|
mov edx, DWORD PTR [esp+56]
|
|
|
|
mov eax, DWORD PTR [edx+eax*4]
|
2010-10-01 13:21:55 +04:00
|
|
|
add eax, OS_BASE
|
2012-03-08 12:33:38 +04:00
|
|
|
push eax
|
|
|
|
push esi
|
|
|
|
call strncmp
|
|
|
|
pop ebx
|
|
|
|
xor ebx, ebx
|
|
|
|
test eax, eax
|
|
|
|
jne L32
|
|
|
|
jmp L30
|
2010-10-01 13:21:55 +04:00
|
|
|
L33:
|
2012-03-08 12:33:38 +04:00
|
|
|
push ecx
|
|
|
|
push 32
|
|
|
|
mov ecx, DWORD PTR [esp+28]
|
2010-10-01 13:21:55 +04:00
|
|
|
mov eax, DWORD PTR [ecx+OS_BASE+ebx*4]
|
|
|
|
add eax, OS_BASE
|
2012-03-08 12:33:38 +04:00
|
|
|
push eax
|
|
|
|
push esi
|
|
|
|
call strncmp
|
|
|
|
pop edx
|
|
|
|
test eax, eax
|
|
|
|
jne L34
|
|
|
|
mov esi, DWORD PTR [esp+44]
|
|
|
|
mov edx, DWORD PTR [esp+52]
|
|
|
|
mov ecx, DWORD PTR [esp+28]
|
|
|
|
mov eax, DWORD PTR [esi+ebx*4]
|
2010-10-01 13:21:55 +04:00
|
|
|
add eax, OS_BASE
|
2012-03-08 12:33:38 +04:00
|
|
|
mov DWORD PTR [ecx+edx*4], eax
|
|
|
|
jmp L36
|
2010-10-01 13:21:55 +04:00
|
|
|
L34:
|
2012-03-08 12:33:38 +04:00
|
|
|
inc ebx
|
2010-10-01 13:21:55 +04:00
|
|
|
L32:
|
|
|
|
cmp ebx, DWORD PTR [__exports+24]
|
2012-03-08 12:33:38 +04:00
|
|
|
jb L33
|
2010-10-01 13:21:55 +04:00
|
|
|
L36:
|
|
|
|
cmp ebx, DWORD PTR [__exports+24]
|
2012-03-08 12:33:38 +04:00
|
|
|
jne L37
|
2010-10-01 13:21:55 +04:00
|
|
|
|
|
|
|
mov esi, msg_unresolved
|
|
|
|
call sys_msg_board_str
|
2012-03-08 12:33:38 +04:00
|
|
|
lea esi, [edi+2]
|
2010-10-01 13:21:55 +04:00
|
|
|
call sys_msg_board_str
|
|
|
|
mov esi, msg_CR
|
|
|
|
call sys_msg_board_str
|
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
mov DWORD PTR [esp+40], 1
|
|
|
|
jmp L37
|
2010-10-01 13:21:55 +04:00
|
|
|
L30:
|
2012-03-08 12:33:38 +04:00
|
|
|
movzx eax, WORD PTR [edi]
|
|
|
|
mov esi, DWORD PTR [esp+44]
|
|
|
|
mov edi, DWORD PTR [esp+52]
|
|
|
|
mov edx, DWORD PTR [esp+28]
|
|
|
|
mov eax, DWORD PTR [esi+eax*4]
|
2010-10-01 13:21:55 +04:00
|
|
|
add eax, OS_BASE
|
2012-03-08 12:33:38 +04:00
|
|
|
mov DWORD PTR [edx+edi*4], eax
|
2010-10-01 13:21:55 +04:00
|
|
|
L37:
|
2012-03-08 12:33:38 +04:00
|
|
|
inc DWORD PTR [esp+52]
|
|
|
|
jmp L26
|
2010-10-01 13:21:55 +04:00
|
|
|
L27:
|
2012-03-08 12:33:38 +04:00
|
|
|
add DWORD PTR [esp+56], 20
|
|
|
|
jmp L22
|
2010-10-01 13:21:55 +04:00
|
|
|
L25:
|
2012-03-08 12:33:38 +04:00
|
|
|
xor eax, eax
|
|
|
|
cmp DWORD PTR [esp+40], 0
|
|
|
|
jne L40
|
2010-10-01 13:21:55 +04:00
|
|
|
L20:
|
2012-03-08 12:33:38 +04:00
|
|
|
mov ecx, DWORD PTR [esp+32]
|
|
|
|
mov eax, ebp
|
|
|
|
add eax, DWORD PTR [ecx+40]
|
2010-10-01 13:21:55 +04:00
|
|
|
L40:
|
2012-03-08 12:33:38 +04:00
|
|
|
add esp, 60
|
|
|
|
pop ebx
|
|
|
|
pop esi
|
|
|
|
pop edi
|
|
|
|
pop ebp
|
2010-10-01 13:21:55 +04:00
|
|
|
ret 8
|