Rev 3481 | Rev 4421 | 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: 3761 $ |
||
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 | |||
88 | shr ecx, 2 |
||
89 | rep movsd |
||
90 | |||
91 | L4: |
||
92 | mov ecx, DWORD PTR [edx+256] |
||
93 | add ecx, 4095 |
||
94 | and ecx, -4096 |
||
95 | cmp ecx, eax |
||
96 | jbe L6 |
||
97 | sub ecx, eax |
||
98 | add eax, DWORD PTR [edx+260] |
||
99 | lea edi, [eax+ebp] |
||
100 | |||
101 | xor eax, eax |
||
102 | rep stosb |
||
103 | |||
104 | L6: |
||
105 | inc DWORD PTR [esp+36] |
||
106 | add edx, 40 |
||
107 | L2: |
||
108 | mov esi, DWORD PTR [esp+16] |
||
109 | cmp DWORD PTR [esp+36], esi |
||
110 | jne L3 |
||
111 | mov edi, DWORD PTR [esp+32] |
||
112 | cmp DWORD PTR [edi+164], 0 |
||
113 | je L9 |
||
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 |
||
120 | mov DWORD PTR [esp+12], eax |
||
121 | jmp L11 |
||
122 | L12: |
||
123 | lea ebx, [eax-8] |
||
124 | xor edi, edi |
||
125 | shr ebx, 1 |
||
126 | jmp L13 |
||
127 | L14: |
||
128 | movzx eax, WORD PTR [ecx+8+edi*2] |
||
129 | mov edx, eax |
||
130 | shr eax, 12 |
||
131 | and edx, 4095 |
||
132 | add edx, DWORD PTR [ecx] |
||
133 | cmp ax, 2 |
||
134 | je L17 |
||
135 | cmp ax, 3 |
||
136 | je L18 |
||
137 | dec ax |
||
138 | jne L15 |
||
139 | mov eax, DWORD PTR [esp+12] |
||
140 | add WORD PTR [edx+ebp], ax |
||
141 | L17: |
||
142 | add WORD PTR [edx+ebp], si |
||
143 | L18: |
||
144 | add DWORD PTR [edx+ebp], esi |
||
145 | L15: |
||
146 | inc edi |
||
147 | L13: |
||
148 | cmp edi, ebx |
||
149 | jne L14 |
||
150 | add ecx, DWORD PTR [ecx+4] |
||
151 | L11: |
||
152 | mov eax, DWORD PTR [ecx+4] |
||
153 | test eax, eax |
||
154 | jne L12 |
||
155 | L9: |
||
156 | mov edx, DWORD PTR [esp+32] |
||
157 | cmp DWORD PTR [edx+132], 0 |
||
158 | je L20 |
||
159 | mov eax, ebp |
||
160 | add eax, DWORD PTR [edx+128] |
||
161 | mov DWORD PTR [esp+40], 0 |
||
162 | add eax, 20 |
||
163 | mov DWORD PTR [esp+56], eax |
||
164 | L22: |
||
165 | mov ecx, DWORD PTR [esp+56] |
||
166 | cmp DWORD PTR [ecx-16], 0 |
||
167 | jne L23 |
||
168 | cmp DWORD PTR [ecx-8], 0 |
||
169 | je L25 |
||
170 | L23: |
||
171 | mov edi, DWORD PTR [__exports+32] |
||
172 | mov esi, DWORD PTR [__exports+28] |
||
173 | mov eax, DWORD PTR [esp+56] |
||
174 | mov DWORD PTR [esp+20], edi |
||
175 | add edi, OS_BASE |
||
176 | add esi, OS_BASE |
||
177 | mov DWORD PTR [esp+44], esi |
||
178 | mov ecx, DWORD PTR [eax-4] |
||
179 | mov DWORD PTR [esp+48], edi |
||
180 | mov edx, DWORD PTR [eax-20] |
||
181 | mov DWORD PTR [esp+52], 0 |
||
182 | add ecx, ebp |
||
183 | add edx, ebp |
||
184 | mov DWORD PTR [esp+24], edx |
||
185 | mov DWORD PTR [esp+28], ecx |
||
186 | L26: |
||
187 | mov esi, DWORD PTR [esp+52] |
||
188 | mov edi, DWORD PTR [esp+24] |
||
189 | mov eax, DWORD PTR [edi+esi*4] |
||
190 | test eax, eax |
||
191 | je L27 |
||
192 | test eax, eax |
||
193 | js L27 |
||
194 | lea edi, [ebp+eax] |
||
195 | mov eax, DWORD PTR [esp+28] |
||
196 | mov DWORD PTR [eax+esi*4], 0 |
||
197 | lea esi, [edi+2] |
||
198 | push eax |
||
199 | push 32 |
||
200 | movzx eax, WORD PTR [edi] |
||
201 | mov edx, DWORD PTR [esp+56] |
||
202 | mov eax, DWORD PTR [edx+eax*4] |
||
203 | add eax, OS_BASE |
||
204 | push eax |
||
205 | push esi |
||
206 | call strncmp |
||
207 | pop ebx |
||
208 | xor ebx, ebx |
||
209 | test eax, eax |
||
210 | jne L32 |
||
211 | jmp L30 |
||
212 | L33: |
||
213 | push ecx |
||
214 | push 32 |
||
215 | mov ecx, DWORD PTR [esp+28] |
||
216 | mov eax, DWORD PTR [ecx+OS_BASE+ebx*4] |
||
217 | add eax, OS_BASE |
||
218 | push eax |
||
219 | push esi |
||
220 | call strncmp |
||
221 | pop edx |
||
222 | test eax, eax |
||
223 | jne L34 |
||
224 | mov esi, DWORD PTR [esp+44] |
||
225 | mov edx, DWORD PTR [esp+52] |
||
226 | mov ecx, DWORD PTR [esp+28] |
||
227 | mov eax, DWORD PTR [esi+ebx*4] |
||
228 | add eax, OS_BASE |
||
229 | mov DWORD PTR [ecx+edx*4], eax |
||
230 | jmp L36 |
||
231 | L34: |
||
232 | inc ebx |
||
233 | L32: |
||
234 | cmp ebx, DWORD PTR [__exports+24] |
||
235 | jb L33 |
||
236 | L36: |
||
237 | cmp ebx, DWORD PTR [__exports+24] |
||
238 | jne L37 |
||
239 | |||
240 | mov esi, msg_unresolved |
||
241 | call sys_msg_board_str |
||
242 | lea esi, [edi+2] |
||
243 | call sys_msg_board_str |
||
244 | mov esi, msg_CR |
||
245 | call sys_msg_board_str |
||
246 | |||
247 | mov DWORD PTR [esp+40], 1 |
||
248 | jmp L37 |
||
249 | L30: |
||
250 | movzx eax, WORD PTR [edi] |
||
251 | mov esi, DWORD PTR [esp+44] |
||
252 | mov edi, DWORD PTR [esp+52] |
||
253 | mov edx, DWORD PTR [esp+28] |
||
254 | mov eax, DWORD PTR [esi+eax*4] |
||
255 | add eax, OS_BASE |
||
256 | mov DWORD PTR [edx+edi*4], eax |
||
257 | L37: |
||
258 | inc DWORD PTR [esp+52] |
||
259 | jmp L26 |
||
260 | L27: |
||
261 | add DWORD PTR [esp+56], 20 |
||
262 | jmp L22 |
||
263 | L25: |
||
264 | xor eax, eax |
||
265 | cmp DWORD PTR [esp+40], 0 |
||
266 | jne L40 |
||
267 | L20: |
||
268 | mov ecx, DWORD PTR [esp+32] |
||
269 | mov eax, ebp |
||
270 | add eax, DWORD PTR [ecx+40] |
||
271 | L40: |
||
272 | add esp, 60 |
||
273 | pop ebx |
||
274 | pop esi |
||
275 | pop edi |
||
276 | pop ebp |
||
277 | ret 8 |