Rev 4418 | Rev 5039 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2288 | clevermous | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
2455 | mario79 | 3 | ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;; |
2288 | clevermous | 4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
||
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
7 | |||
8 | $Revision: 4421 $ |
||
9 | |||
10 | include 'export.inc' |
||
11 | |||
12 | align 4 |
||
13 | |||
14 | proc load_PE stdcall, file_name:dword |
||
15 | locals |
||
16 | image dd ? |
||
17 | entry dd ? |
||
18 | base dd ? |
||
19 | endl |
||
20 | |||
21 | stdcall load_file, [file_name] |
||
22 | test eax, eax |
||
23 | jz .fail |
||
24 | |||
25 | mov [image], eax |
||
26 | |||
27 | mov edx, [eax+60] |
||
28 | |||
29 | stdcall kernel_alloc, [eax+80+edx] |
||
30 | test eax, eax |
||
31 | jz .cleanup |
||
32 | |||
33 | mov [base], eax |
||
34 | |||
35 | stdcall map_PE, eax, [image] |
||
36 | |||
37 | mov [entry], eax |
||
38 | test eax, eax |
||
39 | jnz .cleanup |
||
40 | |||
41 | stdcall kernel_free, [base] |
||
42 | .cleanup: |
||
43 | stdcall kernel_free, [image] |
||
44 | mov eax, [entry] |
||
45 | ret |
||
46 | .fail: |
||
47 | xor eax, eax |
||
48 | ret |
||
49 | endp |
||
50 | |||
51 | DWORD equ dword |
||
52 | PTR equ |
||
53 | |||
54 | align 4 |
||
55 | map_PE: ;stdcall base:dword, image:dword |
||
56 | cld |
||
57 | push ebp |
||
58 | push edi |
||
59 | push esi |
||
60 | push ebx |
||
61 | sub esp, 60 |
||
62 | mov ebx, DWORD PTR [esp+84] |
||
63 | mov ebp, DWORD PTR [esp+80] |
||
64 | mov edx, ebx |
||
65 | mov esi, ebx |
||
66 | add edx, DWORD PTR [ebx+60] |
||
67 | mov edi, ebp |
||
68 | mov DWORD PTR [esp+32], edx |
||
69 | mov ecx, DWORD PTR [edx+84] |
||
70 | |||
71 | shr ecx, 2 |
||
72 | rep movsd |
||
73 | |||
74 | movzx eax, WORD PTR [edx+6] |
||
75 | mov DWORD PTR [esp+36], 0 |
||
76 | mov DWORD PTR [esp+16], eax |
||
77 | jmp L2 |
||
78 | L3: |
||
79 | mov eax, DWORD PTR [edx+264] |
||
80 | test eax, eax |
||
81 | je L4 |
||
82 | mov esi, ebx |
||
83 | mov edi, ebp |
||
84 | add esi, DWORD PTR [edx+268] |
||
85 | mov ecx, eax |
||
86 | add edi, DWORD PTR [edx+260] |
||
87 | |||
4418 | clevermous | 88 | add ecx, 3 |
2288 | clevermous | 89 | shr ecx, 2 |
90 | rep movsd |
||
91 | |||
92 | L4: |
||
93 | mov ecx, DWORD PTR [edx+256] |
||
94 | cmp ecx, eax |
||
95 | jbe L6 |
||
96 | sub ecx, eax |
||
97 | add eax, DWORD PTR [edx+260] |
||
98 | lea edi, [eax+ebp] |
||
99 | |||
100 | xor eax, eax |
||
101 | rep stosb |
||
102 | |||
103 | L6: |
||
104 | inc DWORD PTR [esp+36] |
||
105 | add edx, 40 |
||
106 | L2: |
||
107 | mov esi, DWORD PTR [esp+16] |
||
108 | cmp DWORD PTR [esp+36], esi |
||
109 | jne L3 |
||
110 | mov edi, DWORD PTR [esp+32] |
||
111 | cmp DWORD PTR [edi+164], 0 |
||
112 | je L9 |
||
4421 | clevermous | 113 | pushd [edi+164] |
2288 | clevermous | 114 | mov esi, ebp |
115 | mov ecx, ebp |
||
116 | sub esi, DWORD PTR [edi+52] |
||
117 | add ecx, DWORD PTR [edi+160] |
||
118 | mov eax, esi |
||
119 | shr eax, 16 |
||
4421 | clevermous | 120 | mov DWORD PTR [esp+16], eax |
2288 | clevermous | 121 | L12: |
4421 | clevermous | 122 | mov eax, [ecx+4] |
123 | sub [esp], eax |
||
2288 | clevermous | 124 | lea ebx, [eax-8] |
125 | xor edi, edi |
||
126 | shr ebx, 1 |
||
127 | jmp L13 |
||
128 | L14: |
||
129 | movzx eax, WORD PTR [ecx+8+edi*2] |
||
130 | mov edx, eax |
||
131 | shr eax, 12 |
||
132 | and edx, 4095 |
||
133 | add edx, DWORD PTR [ecx] |
||
134 | cmp ax, 2 |
||
135 | je L17 |
||
136 | cmp ax, 3 |
||
137 | je L18 |
||
138 | dec ax |
||
139 | jne L15 |
||
4421 | clevermous | 140 | mov eax, DWORD PTR [esp+16] |
2288 | clevermous | 141 | add WORD PTR [edx+ebp], ax |
142 | L17: |
||
143 | add WORD PTR [edx+ebp], si |
||
144 | L18: |
||
145 | add DWORD PTR [edx+ebp], esi |
||
146 | L15: |
||
147 | inc edi |
||
148 | L13: |
||
149 | cmp edi, ebx |
||
150 | jne L14 |
||
151 | add ecx, DWORD PTR [ecx+4] |
||
152 | L11: |
||
4421 | clevermous | 153 | cmp dword [esp], 0 |
154 | jg L12 |
||
155 | pop eax |
||
2288 | clevermous | 156 | L9: |
157 | mov edx, DWORD PTR [esp+32] |
||
158 | cmp DWORD PTR [edx+132], 0 |
||
159 | je L20 |
||
160 | mov eax, ebp |
||
161 | add eax, DWORD PTR [edx+128] |
||
162 | mov DWORD PTR [esp+40], 0 |
||
163 | add eax, 20 |
||
164 | mov DWORD PTR [esp+56], eax |
||
165 | L22: |
||
166 | mov ecx, DWORD PTR [esp+56] |
||
167 | cmp DWORD PTR [ecx-16], 0 |
||
168 | jne L23 |
||
169 | cmp DWORD PTR [ecx-8], 0 |
||
170 | je L25 |
||
171 | L23: |
||
172 | mov edi, DWORD PTR [__exports+32] |
||
173 | mov esi, DWORD PTR [__exports+28] |
||
174 | mov eax, DWORD PTR [esp+56] |
||
175 | mov DWORD PTR [esp+20], edi |
||
176 | add edi, OS_BASE |
||
177 | add esi, OS_BASE |
||
178 | mov DWORD PTR [esp+44], esi |
||
179 | mov ecx, DWORD PTR [eax-4] |
||
180 | mov DWORD PTR [esp+48], edi |
||
181 | mov edx, DWORD PTR [eax-20] |
||
4418 | clevermous | 182 | test edx, edx |
183 | jnz @f |
||
184 | mov edx, ecx |
||
185 | @@: |
||
2288 | clevermous | 186 | mov DWORD PTR [esp+52], 0 |
187 | add ecx, ebp |
||
188 | add edx, ebp |
||
189 | mov DWORD PTR [esp+24], edx |
||
190 | mov DWORD PTR [esp+28], ecx |
||
191 | L26: |
||
192 | mov esi, DWORD PTR [esp+52] |
||
193 | mov edi, DWORD PTR [esp+24] |
||
194 | mov eax, DWORD PTR [edi+esi*4] |
||
195 | test eax, eax |
||
196 | je L27 |
||
197 | test eax, eax |
||
198 | js L27 |
||
199 | lea edi, [ebp+eax] |
||
200 | mov eax, DWORD PTR [esp+28] |
||
201 | mov DWORD PTR [eax+esi*4], 0 |
||
202 | lea esi, [edi+2] |
||
203 | push eax |
||
204 | push 32 |
||
205 | movzx eax, WORD PTR [edi] |
||
206 | mov edx, DWORD PTR [esp+56] |
||
207 | mov eax, DWORD PTR [edx+eax*4] |
||
208 | add eax, OS_BASE |
||
209 | push eax |
||
210 | push esi |
||
211 | call strncmp |
||
212 | pop ebx |
||
213 | xor ebx, ebx |
||
214 | test eax, eax |
||
215 | jne L32 |
||
216 | jmp L30 |
||
217 | L33: |
||
218 | push ecx |
||
219 | push 32 |
||
220 | mov ecx, DWORD PTR [esp+28] |
||
221 | mov eax, DWORD PTR [ecx+OS_BASE+ebx*4] |
||
222 | add eax, OS_BASE |
||
223 | push eax |
||
224 | push esi |
||
225 | call strncmp |
||
226 | pop edx |
||
227 | test eax, eax |
||
228 | jne L34 |
||
229 | mov esi, DWORD PTR [esp+44] |
||
230 | mov edx, DWORD PTR [esp+52] |
||
231 | mov ecx, DWORD PTR [esp+28] |
||
232 | mov eax, DWORD PTR [esi+ebx*4] |
||
233 | add eax, OS_BASE |
||
234 | mov DWORD PTR [ecx+edx*4], eax |
||
235 | jmp L36 |
||
236 | L34: |
||
237 | inc ebx |
||
238 | L32: |
||
239 | cmp ebx, DWORD PTR [__exports+24] |
||
240 | jb L33 |
||
241 | L36: |
||
242 | cmp ebx, DWORD PTR [__exports+24] |
||
243 | jne L37 |
||
244 | |||
245 | mov esi, msg_unresolved |
||
246 | call sys_msg_board_str |
||
247 | lea esi, [edi+2] |
||
248 | call sys_msg_board_str |
||
249 | mov esi, msg_CR |
||
250 | call sys_msg_board_str |
||
251 | |||
252 | mov DWORD PTR [esp+40], 1 |
||
253 | jmp L37 |
||
254 | L30: |
||
255 | movzx eax, WORD PTR [edi] |
||
256 | mov esi, DWORD PTR [esp+44] |
||
257 | mov edi, DWORD PTR [esp+52] |
||
258 | mov edx, DWORD PTR [esp+28] |
||
259 | mov eax, DWORD PTR [esi+eax*4] |
||
260 | add eax, OS_BASE |
||
261 | mov DWORD PTR [edx+edi*4], eax |
||
262 | L37: |
||
263 | inc DWORD PTR [esp+52] |
||
264 | jmp L26 |
||
265 | L27: |
||
266 | add DWORD PTR [esp+56], 20 |
||
267 | jmp L22 |
||
268 | L25: |
||
269 | xor eax, eax |
||
270 | cmp DWORD PTR [esp+40], 0 |
||
271 | jne L40 |
||
272 | L20: |
||
273 | mov ecx, DWORD PTR [esp+32] |
||
274 | mov eax, ebp |
||
275 | add eax, DWORD PTR [ecx+40] |
||
276 | L40: |
||
277 | add esp, 60 |
||
278 | pop ebx |
||
279 | pop esi |
||
280 | pop edi |
||
281 | pop ebp |
||
282 | ret 8 |