Rev 7859 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7859 | Rev 9459 | ||
---|---|---|---|
1 | ; flat assembler core |
1 | ; flat assembler core |
2 | ; Copyright (c) 1999-2020, Tomasz Grysztar. |
2 | ; Copyright (c) 1999-2021, Tomasz Grysztar. |
3 | ; All rights reserved. |
3 | ; All rights reserved. |
4 | 4 | ||
5 | formatter: |
5 | formatter: |
6 | mov [current_offset],edi |
6 | mov [current_offset],edi |
7 | cmp [output_file],0 |
7 | cmp [output_file],0 |
8 | jne output_path_ok |
8 | jne output_path_ok |
9 | mov esi,[input_file] |
9 | mov esi,[input_file] |
10 | mov edi,[free_additional_memory] |
10 | mov edi,[free_additional_memory] |
11 | duplicate_output_path: |
11 | duplicate_output_path: |
12 | lods byte [esi] |
12 | lods byte [esi] |
13 | cmp edi,[structures_buffer] |
13 | cmp edi,[structures_buffer] |
14 | jae out_of_memory |
14 | jae out_of_memory |
15 | stos byte [edi] |
15 | stos byte [edi] |
16 | or al,al |
16 | or al,al |
17 | jnz duplicate_output_path |
17 | jnz duplicate_output_path |
18 | dec edi |
18 | dec edi |
19 | mov eax,edi |
19 | mov eax,edi |
20 | find_extension: |
20 | find_extension: |
21 | dec eax |
21 | dec eax |
22 | cmp eax,[free_additional_memory] |
22 | cmp eax,[free_additional_memory] |
23 | jb extension_found |
23 | jb extension_found |
24 | cmp byte [eax],'\' |
24 | cmp byte [eax],'\' |
25 | je extension_found |
25 | je extension_found |
26 | cmp byte [eax],'/' |
26 | cmp byte [eax],'/' |
27 | je extension_found |
27 | je extension_found |
28 | cmp byte [eax],'.' |
28 | cmp byte [eax],'.' |
29 | jne find_extension |
29 | jne find_extension |
30 | mov edi,eax |
30 | mov edi,eax |
31 | extension_found: |
31 | extension_found: |
32 | lea eax,[edi+9] |
32 | lea eax,[edi+9] |
33 | cmp eax,[structures_buffer] |
33 | cmp eax,[structures_buffer] |
34 | jae out_of_memory |
34 | jae out_of_memory |
35 | cmp [file_extension],0 |
35 | cmp [file_extension],0 |
36 | jne extension_specified |
36 | jne extension_specified |
37 | mov al,[output_format] |
37 | mov al,[output_format] |
38 | cmp al,2 |
38 | cmp al,2 |
39 | je exe_extension |
39 | je exe_extension |
40 | jb bin_extension |
40 | jb bin_extension |
41 | cmp al,4 |
41 | cmp al,4 |
42 | je obj_extension |
42 | je obj_extension |
43 | cmp al,5 |
43 | cmp al,5 |
44 | je o_extension |
44 | je o_extension |
45 | cmp al,3 |
45 | cmp al,3 |
46 | jne no_extension |
46 | jne no_extension |
47 | cmp [subsystem],1 |
47 | cmp [subsystem],1 |
48 | je sys_extension |
48 | je sys_extension |
49 | cmp [subsystem],10 |
49 | cmp [subsystem],10 |
50 | jae efi_extension |
50 | jae efi_extension |
51 | bt [format_flags],8 |
51 | bt [format_flags],8 |
52 | jnc exe_extension |
52 | jnc exe_extension |
53 | mov eax,'.dll' |
53 | mov eax,'.dll' |
54 | jmp make_extension |
54 | jmp make_extension |
55 | sys_extension: |
55 | sys_extension: |
56 | mov eax,'.sys' |
56 | mov eax,'.sys' |
57 | jmp make_extension |
57 | jmp make_extension |
58 | efi_extension: |
58 | efi_extension: |
59 | mov eax,'.efi' |
59 | mov eax,'.efi' |
60 | jmp make_extension |
60 | jmp make_extension |
61 | bin_extension: |
61 | bin_extension: |
62 | mov eax,'.bin' |
62 | mov eax,'.bin' |
63 | bt [format_flags],0 |
63 | bt [format_flags],0 |
64 | jnc make_extension |
64 | jnc make_extension |
65 | mov eax,'.com' |
65 | mov eax,'.com' |
66 | jmp make_extension |
66 | jmp make_extension |
67 | obj_extension: |
67 | obj_extension: |
68 | mov eax,'.obj' |
68 | mov eax,'.obj' |
69 | jmp make_extension |
69 | jmp make_extension |
70 | o_extension: |
70 | o_extension: |
71 | mov eax,'.o' |
71 | mov eax,'.o' |
72 | bt [format_flags],0 |
72 | bt [format_flags],0 |
73 | jnc make_extension |
73 | jnc make_extension |
74 | no_extension: |
74 | no_extension: |
75 | xor eax,eax |
75 | xor eax,eax |
76 | jmp make_extension |
76 | jmp make_extension |
77 | exe_extension: |
77 | exe_extension: |
78 | mov eax,'.exe' |
78 | mov eax,'.exe' |
79 | make_extension: |
79 | make_extension: |
80 | xchg eax,[edi] |
80 | xchg eax,[edi] |
81 | scas dword [edi] |
81 | scas dword [edi] |
82 | mov byte [edi],0 |
82 | mov byte [edi],0 |
83 | scas byte [edi] |
83 | scas byte [edi] |
84 | mov esi,edi |
84 | mov esi,edi |
85 | stos dword [edi] |
85 | stos dword [edi] |
86 | sub edi,9 |
86 | sub edi,9 |
87 | xor eax,eax |
87 | xor eax,eax |
88 | mov ebx,characters |
88 | mov ebx,characters |
89 | adapt_case: |
89 | adapt_case: |
90 | mov al,[esi] |
90 | mov al,[esi] |
91 | or al,al |
91 | or al,al |
92 | jz adapt_next |
92 | jz adapt_next |
93 | xlat byte [ebx] |
93 | xlat byte [ebx] |
94 | cmp al,[esi] |
94 | cmp al,[esi] |
95 | je adapt_ok |
95 | je adapt_ok |
96 | sub byte [edi],20h |
96 | sub byte [edi],20h |
97 | adapt_ok: |
97 | adapt_ok: |
98 | inc esi |
98 | inc esi |
99 | adapt_next: |
99 | adapt_next: |
100 | inc edi |
100 | inc edi |
101 | cmp byte [edi],0 |
101 | cmp byte [edi],0 |
102 | jne adapt_case |
102 | jne adapt_case |
103 | jmp extension_ok |
103 | jmp extension_ok |
104 | extension_specified: |
104 | extension_specified: |
105 | mov al,'.' |
105 | mov al,'.' |
106 | stos byte [edi] |
106 | stos byte [edi] |
107 | mov esi,[file_extension] |
107 | mov esi,[file_extension] |
108 | copy_extension: |
108 | copy_extension: |
109 | lods byte [esi] |
109 | lods byte [esi] |
110 | stos byte [edi] |
110 | stos byte [edi] |
111 | test al,al |
111 | test al,al |
112 | jnz copy_extension |
112 | jnz copy_extension |
113 | dec edi |
113 | dec edi |
114 | extension_ok: |
114 | extension_ok: |
115 | mov esi,edi |
115 | mov esi,edi |
116 | lea ecx,[esi+1] |
116 | lea ecx,[esi+1] |
117 | sub ecx,[free_additional_memory] |
117 | sub ecx,[free_additional_memory] |
118 | mov edi,[structures_buffer] |
118 | mov edi,[structures_buffer] |
119 | dec edi |
119 | dec edi |
120 | std |
120 | std |
121 | rep movs byte [edi],[esi] |
121 | rep movs byte [edi],[esi] |
122 | cld |
122 | cld |
123 | inc edi |
123 | inc edi |
124 | mov [structures_buffer],edi |
124 | mov [structures_buffer],edi |
125 | mov [output_file],edi |
125 | mov [output_file],edi |
126 | output_path_ok: |
126 | output_path_ok: |
127 | cmp [symbols_file],0 |
127 | cmp [symbols_file],0 |
128 | je labels_table_ok |
128 | je labels_table_ok |
129 | mov ecx,[memory_end] |
129 | mov ecx,[memory_end] |
130 | sub ecx,[labels_list] |
130 | sub ecx,[labels_list] |
131 | mov edi,[tagged_blocks] |
131 | mov edi,[tagged_blocks] |
132 | sub edi,8 |
132 | sub edi,8 |
133 | mov [edi],ecx |
133 | mov [edi],ecx |
134 | or dword [edi+4],-1 |
134 | or dword [edi+4],-1 |
135 | sub edi,ecx |
135 | sub edi,ecx |
136 | cmp edi,[current_offset] |
136 | cmp edi,[current_offset] |
137 | jbe out_of_memory |
137 | jbe out_of_memory |
138 | mov [tagged_blocks],edi |
138 | mov [tagged_blocks],edi |
139 | mov esi,[memory_end] |
139 | mov esi,[memory_end] |
140 | copy_labels: |
140 | copy_labels: |
141 | sub esi,32 |
141 | sub esi,32 |
142 | cmp esi,[labels_list] |
142 | cmp esi,[labels_list] |
143 | jb labels_table_ok |
143 | jb labels_table_ok |
144 | mov ecx,32 shr 2 |
144 | mov ecx,32 shr 2 |
145 | rep movs dword [edi],[esi] |
145 | rep movs dword [edi],[esi] |
146 | sub esi,32 |
146 | sub esi,32 |
147 | jmp copy_labels |
147 | jmp copy_labels |
148 | labels_table_ok: |
148 | labels_table_ok: |
149 | mov edi,[current_offset] |
149 | mov edi,[current_offset] |
150 | cmp [output_format],4 |
150 | cmp [output_format],4 |
151 | je coff_formatter |
151 | je coff_formatter |
152 | cmp [output_format],5 |
152 | cmp [output_format],5 |
153 | jne common_formatter |
153 | jne common_formatter |
154 | bt [format_flags],0 |
154 | bt [format_flags],0 |
155 | jnc elf_formatter |
155 | jnc elf_formatter |
156 | common_formatter: |
156 | common_formatter: |
157 | mov eax,edi |
157 | mov eax,edi |
158 | sub eax,[code_start] |
158 | sub eax,[code_start] |
159 | mov [real_code_size],eax |
159 | mov [real_code_size],eax |
160 | cmp edi,[undefined_data_end] |
160 | cmp edi,[undefined_data_end] |
161 | jne calculate_code_size |
161 | jne calculate_code_size |
162 | mov edi,[undefined_data_start] |
162 | mov edi,[undefined_data_start] |
163 | calculate_code_size: |
163 | calculate_code_size: |
164 | mov [current_offset],edi |
164 | mov [current_offset],edi |
165 | sub edi,[code_start] |
165 | sub edi,[code_start] |
166 | mov [code_size],edi |
166 | mov [code_size],edi |
167 | and [written_size],0 |
167 | and [written_size],0 |
168 | mov edx,[output_file] |
168 | mov edx,[output_file] |
169 | call create |
169 | call create |
170 | jc write_failed |
170 | jc write_failed |
171 | cmp [output_format],3 |
171 | cmp [output_format],3 |
172 | jne stub_written |
172 | jne stub_written |
173 | mov edx,[code_start] |
173 | mov edx,[code_start] |
174 | mov ecx,[stub_size] |
174 | mov ecx,[stub_size] |
175 | sub edx,ecx |
175 | sub edx,ecx |
176 | add [written_size],ecx |
176 | add [written_size],ecx |
177 | call write |
177 | call write |
178 | stub_written: |
178 | stub_written: |
179 | cmp [output_format],2 |
179 | cmp [output_format],2 |
180 | jne write_output |
180 | jne write_output |
181 | call write_mz_header |
181 | call write_mz_header |
182 | write_output: |
182 | write_output: |
183 | call write_code |
183 | call write_code |
184 | output_written: |
184 | output_written: |
185 | call close |
185 | call close |
186 | cmp [symbols_file],0 |
186 | cmp [symbols_file],0 |
187 | jne dump_symbols |
187 | jne dump_symbols |
188 | ret |
188 | ret |
189 | write_code: |
189 | write_code: |
190 | mov eax,[written_size] |
190 | mov eax,[written_size] |
191 | mov [headers_size],eax |
191 | mov [headers_size],eax |
192 | mov edx,[code_start] |
192 | mov edx,[code_start] |
193 | mov ecx,[code_size] |
193 | mov ecx,[code_size] |
194 | add [written_size],ecx |
194 | add [written_size],ecx |
195 | lea eax,[edx+ecx] |
195 | lea eax,[edx+ecx] |
196 | call write |
196 | call write |
197 | jc write_failed |
197 | jc write_failed |
198 | ret |
198 | ret |
199 | format_directive: |
199 | format_directive: |
200 | cmp edi,[code_start] |
200 | cmp edi,[code_start] |
201 | jne unexpected_instruction |
201 | jne unexpected_instruction |
202 | mov ebp,[addressing_space] |
202 | mov ebp,[addressing_space] |
203 | test byte [ds:ebp+0Ah],1 |
203 | test byte [ds:ebp+0Ah],1 |
204 | jnz unexpected_instruction |
204 | jnz unexpected_instruction |
205 | cmp [output_format],0 |
205 | cmp [output_format],0 |
206 | jne unexpected_instruction |
206 | jne unexpected_instruction |
207 | lods byte [esi] |
207 | lods byte [esi] |
208 | cmp al,1Ch |
208 | cmp al,1Ch |
209 | je format_prefix |
209 | je format_prefix |
210 | cmp al,18h |
210 | cmp al,18h |
211 | jne invalid_argument |
211 | jne invalid_argument |
212 | lods byte [esi] |
212 | lods byte [esi] |
213 | select_format: |
213 | select_format: |
214 | mov dl,al |
214 | mov dl,al |
215 | shr al,4 |
215 | shr al,4 |
216 | mov [output_format],al |
216 | mov [output_format],al |
217 | and edx,0Fh |
217 | and edx,0Fh |
218 | or [format_flags],edx |
218 | or [format_flags],edx |
219 | cmp al,2 |
219 | cmp al,2 |
220 | je format_mz |
220 | je format_mz |
221 | cmp al,3 |
221 | cmp al,3 |
222 | je format_pe |
222 | je format_pe |
223 | cmp al,4 |
223 | cmp al,4 |
224 | je format_coff |
224 | je format_coff |
225 | cmp al,5 |
225 | cmp al,5 |
226 | je format_elf |
226 | je format_elf |
227 | format_defined: |
227 | format_defined: |
228 | cmp byte [esi],86h |
228 | cmp byte [esi],86h |
229 | jne instruction_assembled |
229 | jne instruction_assembled |
230 | cmp word [esi+1],'(' |
230 | cmp word [esi+1],'(' |
231 | jne invalid_argument |
231 | jne invalid_argument |
232 | mov eax,[esi+3] |
232 | mov eax,[esi+3] |
233 | add esi,3+4 |
233 | add esi,3+4 |
234 | mov [file_extension],esi |
234 | mov [file_extension],esi |
235 | lea esi,[esi+eax+1] |
235 | lea esi,[esi+eax+1] |
236 | jmp instruction_assembled |
236 | jmp instruction_assembled |
237 | format_prefix: |
237 | format_prefix: |
238 | lods byte [esi] |
238 | lods byte [esi] |
239 | mov ah,al |
239 | mov ah,al |
240 | lods byte [esi] |
240 | lods byte [esi] |
241 | cmp al,18h |
241 | cmp al,18h |
242 | jne invalid_argument |
242 | jne invalid_argument |
243 | lods byte [esi] |
243 | lods byte [esi] |
244 | mov edx,eax |
244 | mov edx,eax |
245 | shr dl,4 |
245 | shr dl,4 |
246 | shr dh,4 |
246 | shr dh,4 |
247 | cmp dl,dh |
247 | cmp dl,dh |
248 | jne invalid_argument |
248 | jne invalid_argument |
249 | or al,ah |
249 | or al,ah |
250 | jmp select_format |
250 | jmp select_format |
251 | entry_directive: |
251 | entry_directive: |
252 | bts [format_flags],10h |
252 | bts [format_flags],10h |
253 | jc setting_already_specified |
253 | jc setting_already_specified |
254 | mov al,[output_format] |
254 | mov al,[output_format] |
255 | cmp al,2 |
255 | cmp al,2 |
256 | je mz_entry |
256 | je mz_entry |
257 | cmp al,3 |
257 | cmp al,3 |
258 | je pe_entry |
258 | je pe_entry |
259 | cmp al,5 |
259 | cmp al,5 |
260 | jne illegal_instruction |
260 | jne illegal_instruction |
261 | bt [format_flags],0 |
261 | bt [format_flags],0 |
262 | jc elf_entry |
262 | jc elf_entry |
263 | jmp illegal_instruction |
263 | jmp illegal_instruction |
264 | stack_directive: |
264 | stack_directive: |
265 | bts [format_flags],11h |
265 | bts [format_flags],11h |
266 | jc setting_already_specified |
266 | jc setting_already_specified |
267 | mov al,[output_format] |
267 | mov al,[output_format] |
268 | cmp al,2 |
268 | cmp al,2 |
269 | je mz_stack |
269 | je mz_stack |
270 | cmp al,3 |
270 | cmp al,3 |
271 | je pe_stack |
271 | je pe_stack |
272 | jmp illegal_instruction |
272 | jmp illegal_instruction |
273 | heap_directive: |
273 | heap_directive: |
274 | bts [format_flags],12h |
274 | bts [format_flags],12h |
275 | jc setting_already_specified |
275 | jc setting_already_specified |
276 | mov al,[output_format] |
276 | mov al,[output_format] |
277 | cmp al,2 |
277 | cmp al,2 |
278 | je mz_heap |
278 | je mz_heap |
279 | cmp al,3 |
279 | cmp al,3 |
280 | je pe_heap |
280 | je pe_heap |
281 | jmp illegal_instruction |
281 | jmp illegal_instruction |
282 | segment_directive: |
282 | segment_directive: |
283 | mov al,[output_format] |
283 | mov al,[output_format] |
284 | cmp al,2 |
284 | cmp al,2 |
285 | je mz_segment |
285 | je mz_segment |
286 | cmp al,5 |
286 | cmp al,5 |
287 | je elf_segment |
287 | je elf_segment |
288 | jmp illegal_instruction |
288 | jmp illegal_instruction |
289 | section_directive: |
289 | section_directive: |
290 | mov al,[output_format] |
290 | mov al,[output_format] |
291 | cmp al,3 |
291 | cmp al,3 |
292 | je pe_section |
292 | je pe_section |
293 | cmp al,4 |
293 | cmp al,4 |
294 | je coff_section |
294 | je coff_section |
295 | cmp al,5 |
295 | cmp al,5 |
296 | je elf_section |
296 | je elf_section |
297 | jmp illegal_instruction |
297 | jmp illegal_instruction |
298 | public_directive: |
298 | public_directive: |
299 | mov al,[output_format] |
299 | mov al,[output_format] |
300 | cmp al,4 |
300 | cmp al,4 |
301 | je public_allowed |
301 | je public_allowed |
302 | cmp al,5 |
302 | cmp al,5 |
303 | jne illegal_instruction |
303 | jne illegal_instruction |
304 | bt [format_flags],0 |
304 | bt [format_flags],0 |
305 | jc illegal_instruction |
305 | jc illegal_instruction |
306 | public_allowed: |
306 | public_allowed: |
307 | mov [base_code],0C0h |
307 | mov [base_code],0C0h |
308 | lods byte [esi] |
308 | lods byte [esi] |
309 | cmp al,2 |
309 | cmp al,2 |
310 | je public_label |
310 | je public_label |
311 | cmp al,1Dh |
311 | cmp al,1Dh |
312 | jne invalid_argument |
312 | jne invalid_argument |
313 | lods byte [esi] |
313 | lods byte [esi] |
314 | and al,7 |
314 | and al,7 |
315 | add [base_code],al |
315 | add [base_code],al |
316 | lods byte [esi] |
316 | lods byte [esi] |
317 | cmp al,2 |
317 | cmp al,2 |
318 | jne invalid_argument |
318 | jne invalid_argument |
319 | public_label: |
319 | public_label: |
320 | lods dword [esi] |
320 | lods dword [esi] |
321 | cmp eax,0Fh |
321 | cmp eax,0Fh |
322 | jb invalid_use_of_symbol |
322 | jb invalid_use_of_symbol |
323 | je reserved_word_used_as_symbol |
323 | je reserved_word_used_as_symbol |
324 | inc esi |
324 | inc esi |
325 | mov dx,[current_pass] |
325 | mov dx,[current_pass] |
326 | mov [eax+18],dx |
326 | mov [eax+18],dx |
327 | or byte [eax+8],8 |
327 | or byte [eax+8],8 |
328 | mov ebx,eax |
328 | mov ebx,eax |
329 | call store_label_reference |
329 | call store_label_reference |
330 | mov eax,ebx |
330 | mov eax,ebx |
331 | mov ebx,[free_additional_memory] |
331 | mov ebx,[free_additional_memory] |
332 | lea edx,[ebx+10h] |
332 | lea edx,[ebx+10h] |
333 | cmp edx,[structures_buffer] |
333 | cmp edx,[structures_buffer] |
334 | jae out_of_memory |
334 | jae out_of_memory |
335 | mov [free_additional_memory],edx |
335 | mov [free_additional_memory],edx |
336 | mov [ebx+8],eax |
336 | mov [ebx+8],eax |
337 | mov eax,[current_line] |
337 | mov eax,[current_line] |
338 | mov [ebx+0Ch],eax |
338 | mov [ebx+0Ch],eax |
339 | lods byte [esi] |
339 | lods byte [esi] |
340 | cmp al,86h |
340 | cmp al,86h |
341 | jne invalid_argument |
341 | jne invalid_argument |
342 | lods word [esi] |
342 | lods word [esi] |
343 | cmp ax,'(' |
343 | cmp ax,'(' |
344 | jne invalid_argument |
344 | jne invalid_argument |
345 | mov [ebx+4],esi |
345 | mov [ebx+4],esi |
346 | lods dword [esi] |
346 | lods dword [esi] |
347 | lea esi,[esi+eax+1] |
347 | lea esi,[esi+eax+1] |
348 | mov al,[base_code] |
348 | mov al,[base_code] |
349 | mov [ebx],al |
349 | mov [ebx],al |
350 | jmp instruction_assembled |
350 | jmp instruction_assembled |
351 | extrn_directive: |
351 | extrn_directive: |
352 | mov al,[output_format] |
352 | mov al,[output_format] |
353 | cmp al,4 |
353 | cmp al,4 |
354 | je extrn_allowed |
354 | je extrn_allowed |
355 | cmp al,5 |
355 | cmp al,5 |
356 | jne illegal_instruction |
356 | jne illegal_instruction |
357 | bt [format_flags],0 |
357 | bt [format_flags],0 |
358 | jc illegal_instruction |
358 | jc illegal_instruction |
359 | extrn_allowed: |
359 | extrn_allowed: |
360 | lods word [esi] |
360 | lods word [esi] |
361 | cmp ax,'(' |
361 | cmp ax,'(' |
362 | jne invalid_argument |
362 | jne invalid_argument |
363 | mov ebx,esi |
363 | mov ebx,esi |
364 | lods dword [esi] |
364 | lods dword [esi] |
365 | lea esi,[esi+eax+1] |
365 | lea esi,[esi+eax+1] |
366 | mov edx,[free_additional_memory] |
366 | mov edx,[free_additional_memory] |
367 | lea eax,[edx+0Ch] |
367 | lea eax,[edx+0Ch] |
368 | cmp eax,[structures_buffer] |
368 | cmp eax,[structures_buffer] |
369 | jae out_of_memory |
369 | jae out_of_memory |
370 | mov [free_additional_memory],eax |
370 | mov [free_additional_memory],eax |
371 | mov byte [edx],80h |
371 | mov byte [edx],80h |
372 | mov [edx+4],ebx |
372 | mov [edx+4],ebx |
373 | lods byte [esi] |
373 | lods byte [esi] |
374 | cmp al,86h |
374 | cmp al,86h |
375 | jne invalid_argument |
375 | jne invalid_argument |
376 | lods byte [esi] |
376 | lods byte [esi] |
377 | cmp al,2 |
377 | cmp al,2 |
378 | jne invalid_argument |
378 | jne invalid_argument |
379 | lods dword [esi] |
379 | lods dword [esi] |
380 | cmp eax,0Fh |
380 | cmp eax,0Fh |
381 | jb invalid_use_of_symbol |
381 | jb invalid_use_of_symbol |
382 | je reserved_word_used_as_symbol |
382 | je reserved_word_used_as_symbol |
383 | inc esi |
383 | inc esi |
384 | mov ebx,eax |
384 | mov ebx,eax |
385 | xor ah,ah |
385 | xor ah,ah |
386 | lods byte [esi] |
386 | lods byte [esi] |
387 | cmp al,':' |
387 | cmp al,':' |
388 | je get_extrn_size |
388 | je get_extrn_size |
389 | dec esi |
389 | dec esi |
390 | cmp al,11h |
390 | cmp al,11h |
391 | jne extrn_size_ok |
391 | jne extrn_size_ok |
392 | get_extrn_size: |
392 | get_extrn_size: |
393 | lods word [esi] |
393 | lods word [esi] |
394 | cmp al,11h |
394 | cmp al,11h |
395 | jne invalid_argument |
395 | jne invalid_argument |
396 | extrn_size_ok: |
396 | extrn_size_ok: |
397 | mov [address_symbol],edx |
397 | mov [address_symbol],edx |
398 | mov [label_size],ah |
398 | mov [label_size],ah |
399 | movzx ecx,ah |
399 | movzx ecx,ah |
400 | mov [edx+8],ecx |
400 | mov [edx+8],ecx |
401 | xor eax,eax |
401 | xor eax,eax |
402 | xor edx,edx |
402 | xor edx,edx |
403 | xor ebp,ebp |
403 | xor ebp,ebp |
404 | mov [address_sign],0 |
404 | mov [address_sign],0 |
405 | mov ch,2 |
405 | mov ch,2 |
406 | test [format_flags],8 |
406 | test [format_flags],8 |
407 | jz make_free_label |
407 | jz make_free_label |
408 | mov ch,4 |
408 | mov ch,4 |
409 | jmp make_free_label |
409 | jmp make_free_label |
410 | mark_relocation: |
410 | mark_relocation: |
411 | cmp [value_type],0 |
411 | cmp [value_type],0 |
412 | je relocation_ok |
412 | je relocation_ok |
413 | mov ebp,[addressing_space] |
413 | mov ebp,[addressing_space] |
414 | test byte [ds:ebp+0Ah],1 |
414 | test byte [ds:ebp+0Ah],1 |
415 | jnz relocation_ok |
415 | jnz relocation_ok |
416 | cmp [output_format],2 |
416 | cmp [output_format],2 |
417 | je mark_mz_relocation |
417 | je mark_mz_relocation |
418 | cmp [output_format],3 |
418 | cmp [output_format],3 |
419 | je mark_pe_relocation |
419 | je mark_pe_relocation |
420 | cmp [output_format],4 |
420 | cmp [output_format],4 |
421 | je mark_coff_relocation |
421 | je mark_coff_relocation |
422 | cmp [output_format],5 |
422 | cmp [output_format],5 |
423 | je mark_elf_relocation |
423 | je mark_elf_relocation |
424 | relocation_ok: |
424 | relocation_ok: |
425 | ret |
425 | ret |
426 | close_pass: |
426 | close_pass: |
427 | mov al,[output_format] |
427 | mov al,[output_format] |
428 | cmp al,3 |
428 | cmp al,3 |
429 | je close_pe |
429 | je close_pe |
430 | cmp al,4 |
430 | cmp al,4 |
431 | je close_coff |
431 | je close_coff |
432 | cmp al,5 |
432 | cmp al,5 |
433 | je close_elf |
433 | je close_elf |
434 | ret |
434 | ret |
435 | 435 | ||
436 | format_mz: |
436 | format_mz: |
437 | mov edx,[additional_memory] |
437 | mov edx,[additional_memory] |
438 | push edi |
438 | push edi |
439 | mov edi,edx |
439 | mov edi,edx |
440 | mov ecx,1Ch shr 2 |
440 | mov ecx,1Ch shr 2 |
441 | xor eax,eax |
441 | xor eax,eax |
442 | rep stos dword [edi] |
442 | rep stos dword [edi] |
443 | mov [free_additional_memory],edi |
443 | mov [free_additional_memory],edi |
444 | pop edi |
444 | pop edi |
445 | mov word [edx+0Ch],0FFFFh |
445 | mov word [edx+0Ch],0FFFFh |
446 | mov word [edx+10h],1000h |
446 | mov word [edx+10h],1000h |
447 | mov [code_type],16 |
447 | mov [code_type],16 |
448 | jmp format_defined |
448 | jmp format_defined |
449 | mark_mz_relocation: |
449 | mark_mz_relocation: |
450 | push eax ebx |
450 | push eax ebx |
451 | inc word [number_of_relocations] |
451 | inc word [number_of_relocations] |
452 | jz format_limitations_exceeded |
452 | jz format_limitations_exceeded |
453 | mov ebx,[free_additional_memory] |
453 | mov ebx,[free_additional_memory] |
454 | mov eax,edi |
454 | mov eax,edi |
455 | sub eax,[code_start] |
455 | sub eax,[code_start] |
456 | mov [ebx],ax |
456 | mov [ebx],ax |
457 | shr eax,16 |
457 | shr eax,16 |
458 | shl ax,12 |
458 | shl ax,12 |
459 | mov [ebx+2],ax |
459 | mov [ebx+2],ax |
460 | cmp word [ebx],0FFFFh |
460 | cmp word [ebx],0FFFFh |
461 | jne mz_relocation_ok |
461 | jne mz_relocation_ok |
462 | inc word [ebx+2] |
462 | inc word [ebx+2] |
463 | sub word [ebx],10h |
463 | sub word [ebx],10h |
464 | mz_relocation_ok: |
464 | mz_relocation_ok: |
465 | add ebx,4 |
465 | add ebx,4 |
466 | cmp ebx,[structures_buffer] |
466 | cmp ebx,[structures_buffer] |
467 | jae out_of_memory |
467 | jae out_of_memory |
468 | mov [free_additional_memory],ebx |
468 | mov [free_additional_memory],ebx |
469 | pop ebx eax |
469 | pop ebx eax |
470 | ret |
470 | ret |
471 | mz_segment: |
471 | mz_segment: |
472 | lods byte [esi] |
472 | lods byte [esi] |
473 | cmp al,2 |
473 | cmp al,2 |
474 | jne invalid_argument |
474 | jne invalid_argument |
475 | lods dword [esi] |
475 | lods dword [esi] |
476 | cmp eax,0Fh |
476 | cmp eax,0Fh |
477 | jb invalid_use_of_symbol |
477 | jb invalid_use_of_symbol |
478 | je reserved_word_used_as_symbol |
478 | je reserved_word_used_as_symbol |
479 | inc esi |
479 | inc esi |
480 | mov ebx,eax |
480 | mov ebx,eax |
481 | mov eax,edi |
481 | mov eax,edi |
482 | sub eax,[code_start] |
482 | sub eax,[code_start] |
483 | mov ecx,0Fh |
483 | mov ecx,0Fh |
484 | add eax,0Fh |
484 | add eax,0Fh |
485 | and eax,1111b |
485 | and eax,1111b |
486 | sub ecx,eax |
486 | sub ecx,eax |
487 | mov edx,edi |
487 | mov edx,edi |
488 | xor eax,eax |
488 | xor eax,eax |
489 | rep stos byte [edi] |
489 | rep stos byte [edi] |
490 | mov eax,edx |
490 | mov eax,edx |
491 | call undefined_data |
491 | call undefined_data |
492 | push ebx |
492 | push ebx |
493 | call create_addressing_space |
493 | call create_addressing_space |
494 | pop ebx |
494 | pop ebx |
495 | mov eax,edi |
495 | mov eax,edi |
496 | sub eax,[code_start] |
496 | sub eax,[code_start] |
497 | shr eax,4 |
497 | shr eax,4 |
498 | cmp eax,10000h |
498 | cmp eax,10000h |
499 | jae value_out_of_range |
499 | jae value_out_of_range |
500 | mov edx,eax |
500 | mov edx,eax |
501 | mov al,16 |
501 | mov al,16 |
502 | cmp byte [esi],13h |
502 | cmp byte [esi],13h |
503 | jne segment_type_ok |
503 | jne segment_type_ok |
504 | inc esi |
504 | inc esi |
505 | lods byte [esi] |
505 | lods byte [esi] |
506 | segment_type_ok: |
506 | segment_type_ok: |
507 | mov [code_type],al |
507 | mov [code_type],al |
508 | mov eax,edx |
508 | mov eax,edx |
509 | mov ch,1 |
509 | mov ch,1 |
510 | mov [address_sign],0 |
510 | mov [address_sign],0 |
511 | xor edx,edx |
511 | xor edx,edx |
512 | xor ebp,ebp |
512 | xor ebp,ebp |
513 | mov [label_size],0 |
513 | mov [label_size],0 |
514 | mov [address_symbol],edx |
514 | mov [address_symbol],edx |
515 | jmp make_free_label |
515 | jmp make_free_label |
516 | mz_entry: |
516 | mz_entry: |
517 | lods byte [esi] |
517 | lods byte [esi] |
518 | cmp al,'(' |
518 | cmp al,'(' |
519 | jne invalid_argument |
519 | jne invalid_argument |
520 | call get_word_value |
520 | call get_word_value |
521 | cmp [value_type],1 |
521 | cmp [value_type],1 |
522 | je initial_cs_ok |
522 | je initial_cs_ok |
523 | call recoverable_invalid_address |
523 | call recoverable_invalid_address |
524 | initial_cs_ok: |
524 | initial_cs_ok: |
525 | mov edx,[additional_memory] |
525 | mov edx,[additional_memory] |
526 | mov [edx+16h],ax |
526 | mov [edx+16h],ax |
527 | lods byte [esi] |
527 | lods byte [esi] |
528 | cmp al,':' |
528 | cmp al,':' |
529 | jne invalid_argument |
529 | jne invalid_argument |
530 | lods byte [esi] |
530 | lods byte [esi] |
531 | cmp al,'(' |
531 | cmp al,'(' |
532 | jne invalid_argument |
532 | jne invalid_argument |
533 | ja invalid_address |
533 | ja invalid_address |
534 | call get_word_value |
534 | call get_word_value |
535 | cmp [value_type],0 |
535 | cmp [value_type],0 |
536 | jne invalid_use_of_symbol |
536 | jne invalid_use_of_symbol |
537 | mov edx,[additional_memory] |
537 | mov edx,[additional_memory] |
538 | mov [edx+14h],ax |
538 | mov [edx+14h],ax |
539 | jmp instruction_assembled |
539 | jmp instruction_assembled |
540 | recoverable_invalid_address: |
540 | recoverable_invalid_address: |
541 | cmp [error_line],0 |
541 | cmp [error_line],0 |
542 | jne ignore_invalid_address |
542 | jne ignore_invalid_address |
543 | push [current_line] |
543 | push [current_line] |
544 | pop [error_line] |
544 | pop [error_line] |
545 | mov [error],invalid_address |
545 | mov [error],invalid_address |
546 | ignore_invalid_address: |
546 | ignore_invalid_address: |
547 | ret |
547 | ret |
548 | mz_stack: |
548 | mz_stack: |
549 | lods byte [esi] |
549 | lods byte [esi] |
550 | cmp al,'(' |
550 | cmp al,'(' |
551 | jne invalid_argument |
551 | jne invalid_argument |
552 | call get_word_value |
552 | call get_word_value |
553 | cmp byte [esi],':' |
553 | cmp byte [esi],':' |
554 | je stack_pointer |
554 | je stack_pointer |
555 | cmp ax,10h |
555 | cmp ax,10h |
556 | jb invalid_value |
556 | jb invalid_value |
557 | cmp [value_type],0 |
557 | cmp [value_type],0 |
558 | jne invalid_use_of_symbol |
558 | jne invalid_use_of_symbol |
559 | mov edx,[additional_memory] |
559 | mov edx,[additional_memory] |
560 | mov [edx+10h],ax |
560 | mov [edx+10h],ax |
561 | jmp instruction_assembled |
561 | jmp instruction_assembled |
562 | stack_pointer: |
562 | stack_pointer: |
563 | cmp [value_type],1 |
563 | cmp [value_type],1 |
564 | je initial_ss_ok |
564 | je initial_ss_ok |
565 | call recoverable_invalid_address |
565 | call recoverable_invalid_address |
566 | initial_ss_ok: |
566 | initial_ss_ok: |
567 | mov edx,[additional_memory] |
567 | mov edx,[additional_memory] |
568 | mov [edx+0Eh],ax |
568 | mov [edx+0Eh],ax |
569 | lods byte [esi] |
569 | lods byte [esi] |
570 | cmp al,':' |
570 | cmp al,':' |
571 | jne invalid_argument |
571 | jne invalid_argument |
572 | lods byte [esi] |
572 | lods byte [esi] |
573 | cmp al,'(' |
573 | cmp al,'(' |
574 | jne invalid_argument |
574 | jne invalid_argument |
575 | call get_word_value |
575 | call get_word_value |
576 | cmp [value_type],0 |
576 | cmp [value_type],0 |
577 | jne invalid_use_of_symbol |
577 | jne invalid_use_of_symbol |
578 | mov edx,[additional_memory] |
578 | mov edx,[additional_memory] |
579 | mov [edx+10h],ax |
579 | mov [edx+10h],ax |
580 | bts [format_flags],4 |
580 | bts [format_flags],4 |
581 | jmp instruction_assembled |
581 | jmp instruction_assembled |
582 | mz_heap: |
582 | mz_heap: |
583 | cmp [output_format],2 |
583 | cmp [output_format],2 |
584 | jne illegal_instruction |
584 | jne illegal_instruction |
585 | lods byte [esi] |
585 | lods byte [esi] |
586 | call get_size_operator |
586 | call get_size_operator |
587 | cmp ah,1 |
587 | cmp ah,1 |
588 | je invalid_value |
588 | je invalid_value |
589 | cmp ah,2 |
589 | cmp ah,2 |
590 | ja invalid_value |
590 | ja invalid_value |
591 | cmp al,'(' |
591 | cmp al,'(' |
592 | jne invalid_argument |
592 | jne invalid_argument |
593 | call get_word_value |
593 | call get_word_value |
594 | cmp [value_type],0 |
594 | cmp [value_type],0 |
595 | jne invalid_use_of_symbol |
595 | jne invalid_use_of_symbol |
596 | mov edx,[additional_memory] |
596 | mov edx,[additional_memory] |
597 | mov [edx+0Ch],ax |
597 | mov [edx+0Ch],ax |
598 | jmp instruction_assembled |
598 | jmp instruction_assembled |
599 | write_mz_header: |
599 | write_mz_header: |
600 | mov edx,[additional_memory] |
600 | mov edx,[additional_memory] |
601 | bt [format_flags],4 |
601 | bt [format_flags],4 |
602 | jc mz_stack_ok |
602 | jc mz_stack_ok |
603 | mov eax,[real_code_size] |
603 | mov eax,[real_code_size] |
604 | dec eax |
604 | dec eax |
605 | shr eax,4 |
605 | shr eax,4 |
606 | inc eax |
606 | inc eax |
607 | mov [edx+0Eh],ax |
607 | mov [edx+0Eh],ax |
608 | shl eax,4 |
608 | shl eax,4 |
609 | movzx ecx,word [edx+10h] |
609 | movzx ecx,word [edx+10h] |
610 | add eax,ecx |
610 | add eax,ecx |
611 | mov [real_code_size],eax |
611 | mov [real_code_size],eax |
612 | mz_stack_ok: |
612 | mz_stack_ok: |
613 | mov edi,[free_additional_memory] |
613 | mov edi,[free_additional_memory] |
614 | mov eax,[number_of_relocations] |
614 | mov eax,[number_of_relocations] |
615 | shl eax,2 |
615 | shl eax,2 |
616 | add eax,1Ch |
616 | add eax,1Ch |
617 | sub edi,eax |
617 | sub edi,eax |
618 | xchg edi,[free_additional_memory] |
618 | xchg edi,[free_additional_memory] |
619 | mov ecx,0Fh |
619 | mov ecx,0Fh |
620 | add eax,0Fh |
620 | add eax,0Fh |
621 | and eax,1111b |
621 | and eax,1111b |
622 | sub ecx,eax |
622 | sub ecx,eax |
623 | xor al,al |
623 | xor al,al |
624 | rep stos byte [edi] |
624 | rep stos byte [edi] |
625 | sub edi,[free_additional_memory] |
625 | sub edi,[free_additional_memory] |
626 | mov ecx,edi |
626 | mov ecx,edi |
627 | shr edi,4 |
627 | shr edi,4 |
628 | mov word [edx],'MZ' ; signature |
628 | mov word [edx],'MZ' ; signature |
629 | mov [edx+8],di ; header size in paragraphs |
629 | mov [edx+8],di ; header size in paragraphs |
630 | mov eax,[number_of_relocations] |
630 | mov eax,[number_of_relocations] |
631 | mov [edx+6],ax ; number of relocation entries |
631 | mov [edx+6],ax ; number of relocation entries |
632 | mov eax,[code_size] |
632 | mov eax,[code_size] |
633 | add eax,ecx |
633 | add eax,ecx |
634 | mov esi,eax |
634 | mov esi,eax |
635 | shr esi,9 |
635 | shr esi,9 |
636 | and eax,1FFh |
636 | and eax,1FFh |
637 | inc si |
637 | inc si |
638 | or ax,ax |
638 | or ax,ax |
639 | jnz mz_size_ok |
639 | jnz mz_size_ok |
640 | dec si |
640 | dec si |
641 | mz_size_ok: |
641 | mz_size_ok: |
642 | mov [edx+2],ax ; number of bytes in last page |
642 | mov [edx+2],ax ; number of bytes in last page |
643 | mov [edx+4],si ; number of pages |
643 | mov [edx+4],si ; number of pages |
644 | mov eax,[real_code_size] |
644 | mov eax,[real_code_size] |
645 | dec eax |
645 | dec eax |
646 | shr eax,4 |
646 | shr eax,4 |
647 | inc eax |
647 | inc eax |
648 | mov esi,[code_size] |
648 | mov esi,[code_size] |
649 | dec esi |
649 | dec esi |
650 | shr esi,4 |
650 | shr esi,4 |
651 | inc esi |
651 | inc esi |
652 | sub eax,esi |
652 | sub eax,esi |
653 | mov [edx+0Ah],ax ; minimum memory in addition to code |
653 | mov [edx+0Ah],ax ; minimum memory in addition to code |
654 | add [edx+0Ch],ax ; maximum memory in addition to code |
654 | add [edx+0Ch],ax ; maximum memory in addition to code |
655 | salc |
655 | salc |
656 | mov ah,al |
656 | mov ah,al |
657 | or [edx+0Ch],ax |
657 | or [edx+0Ch],ax |
658 | mov word [edx+18h],1Ch ; offset of relocation table |
658 | mov word [edx+18h],1Ch ; offset of relocation table |
659 | add [written_size],ecx |
659 | add [written_size],ecx |
660 | call write |
660 | call write |
661 | jc write_failed |
661 | jc write_failed |
662 | ret |
662 | ret |
663 | 663 | ||
664 | make_stub: |
664 | make_stub: |
665 | mov [stub_file],edx |
665 | mov [stub_file],edx |
666 | or edx,edx |
666 | or edx,edx |
667 | jnz stub_from_file |
667 | jnz stub_from_file |
668 | push esi |
668 | push esi |
669 | mov edx,edi |
669 | mov edx,edi |
670 | xor eax,eax |
670 | xor eax,eax |
671 | mov ecx,20h |
671 | mov ecx,20h |
672 | rep stos dword [edi] |
672 | rep stos dword [edi] |
673 | mov eax,40h+default_stub_end-default_stub |
673 | mov eax,40h+default_stub_end-default_stub |
674 | mov cx,100h+default_stub_end-default_stub |
674 | mov cx,100h+default_stub_end-default_stub |
675 | mov word [edx],'MZ' |
675 | mov word [edx],'MZ' |
676 | mov byte [edx+4],1 |
676 | mov byte [edx+4],1 |
677 | mov word [edx+2],ax |
677 | mov word [edx+2],ax |
678 | mov byte [edx+8],4 |
678 | mov byte [edx+8],4 |
679 | mov byte [edx+0Ah],10h |
679 | mov byte [edx+0Ah],10h |
680 | mov word [edx+0Ch],0FFFFh |
680 | mov word [edx+0Ch],0FFFFh |
681 | mov word [edx+10h],cx |
681 | mov word [edx+10h],cx |
682 | mov word [edx+3Ch],ax |
682 | mov word [edx+3Ch],ax |
683 | mov byte [edx+18h],40h |
683 | mov byte [edx+18h],40h |
684 | lea edi,[edx+40h] |
684 | lea edi,[edx+40h] |
685 | mov esi,default_stub |
685 | mov esi,default_stub |
686 | mov ecx,default_stub_end-default_stub |
686 | mov ecx,default_stub_end-default_stub |
687 | rep movs byte [edi],[esi] |
687 | rep movs byte [edi],[esi] |
688 | pop esi |
688 | pop esi |
689 | jmp stub_ok |
689 | jmp stub_ok |
690 | default_stub: |
690 | default_stub: |
691 | use16 |
691 | use16 |
692 | push cs |
692 | push cs |
693 | pop ds |
693 | pop ds |
694 | mov dx,stub_message-default_stub |
694 | mov dx,stub_message-default_stub |
695 | mov ah,9 |
695 | mov ah,9 |
696 | int 21h |
696 | int 21h |
697 | mov ax,4C01h |
697 | mov ax,4C01h |
698 | int 21h |
698 | int 21h |
699 | stub_message db 'This program cannot be run in DOS mode.',0Dh,0Ah,24h |
699 | stub_message db 'This program cannot be run in DOS mode.',0Dh,0Ah,24h |
700 | rq 1 |
700 | rq 1 |
701 | default_stub_end: |
701 | default_stub_end: |
702 | use32 |
702 | use32 |
703 | stub_from_file: |
703 | stub_from_file: |
704 | push esi |
704 | push esi |
705 | mov esi,edx |
705 | mov esi,edx |
706 | call open_binary_file |
706 | call open_binary_file |
707 | mov edx,edi |
707 | mov edx,edi |
708 | mov ecx,1Ch |
708 | mov ecx,1Ch |
709 | mov esi,edx |
709 | mov esi,edx |
710 | call read |
710 | call read |
711 | jc binary_stub |
711 | jc binary_stub |
712 | cmp word [esi],'MZ' |
712 | cmp word [esi],'MZ' |
713 | jne binary_stub |
713 | jne binary_stub |
714 | add edi,1Ch |
714 | add edi,1Ch |
715 | movzx ecx,word [esi+6] |
715 | movzx ecx,word [esi+6] |
716 | add ecx,11b |
716 | add ecx,11b |
717 | and ecx,not 11b |
717 | and ecx,not 11b |
718 | add ecx,(40h-1Ch) shr 2 |
718 | add ecx,(40h-1Ch) shr 2 |
719 | lea eax,[edi+ecx*4] |
719 | lea eax,[edi+ecx*4] |
720 | cmp edi,[tagged_blocks] |
720 | cmp edi,[tagged_blocks] |
721 | jae out_of_memory |
721 | jae out_of_memory |
722 | xor eax,eax |
722 | xor eax,eax |
723 | rep stos dword [edi] |
723 | rep stos dword [edi] |
724 | mov edx,40h |
724 | mov edx,40h |
725 | xchg dx,[esi+18h] |
725 | xchg dx,[esi+18h] |
726 | xor al,al |
726 | xor al,al |
727 | call lseek |
727 | call lseek |
728 | movzx ecx,word [esi+6] |
728 | movzx ecx,word [esi+6] |
729 | shl ecx,2 |
729 | shl ecx,2 |
730 | lea edx,[esi+40h] |
730 | lea edx,[esi+40h] |
731 | call read |
731 | call read |
732 | mov edx,edi |
732 | mov edx,edi |
733 | sub edx,esi |
733 | sub edx,esi |
734 | shr edx,4 |
734 | shr edx,4 |
735 | xchg dx,[esi+8] |
735 | xchg dx,[esi+8] |
736 | shl edx,4 |
736 | shl edx,4 |
737 | xor al,al |
737 | xor al,al |
738 | call lseek |
738 | call lseek |
739 | movzx ecx,word [esi+4] |
739 | movzx ecx,word [esi+4] |
740 | dec ecx |
740 | dec ecx |
741 | shl ecx,9 |
741 | shl ecx,9 |
742 | movzx edx,word [esi+2] |
742 | movzx edx,word [esi+2] |
743 | test edx,edx |
743 | test edx,edx |
744 | jnz stub_header_size_ok |
744 | jnz stub_header_size_ok |
745 | mov dx,200h |
745 | mov dx,200h |
746 | stub_header_size_ok: |
746 | stub_header_size_ok: |
747 | add ecx,edx |
747 | add ecx,edx |
748 | mov edx,edi |
748 | mov edx,edi |
749 | sub ecx,eax |
749 | sub ecx,eax |
750 | je read_stub_code |
750 | je read_stub_code |
751 | jb stub_code_ok |
751 | jb stub_code_ok |
752 | push ecx |
752 | push ecx |
753 | dec ecx |
753 | dec ecx |
754 | shr ecx,3 |
754 | shr ecx,3 |
755 | inc ecx |
755 | inc ecx |
756 | shl ecx,1 |
756 | shl ecx,1 |
757 | lea eax,[edi+ecx*4] |
757 | lea eax,[edi+ecx*4] |
758 | cmp eax,[tagged_blocks] |
758 | cmp eax,[tagged_blocks] |
759 | jae out_of_memory |
759 | jae out_of_memory |
760 | xor eax,eax |
760 | xor eax,eax |
761 | rep stos dword [edi] |
761 | rep stos dword [edi] |
762 | pop ecx |
762 | pop ecx |
763 | read_stub_code: |
763 | read_stub_code: |
764 | call read |
764 | call read |
765 | stub_code_ok: |
765 | stub_code_ok: |
766 | call close |
766 | call close |
767 | mov edx,edi |
767 | mov edx,edi |
768 | sub edx,esi |
768 | sub edx,esi |
769 | mov ax,dx |
769 | mov ax,dx |
770 | and ax,1FFh |
770 | and ax,1FFh |
771 | mov [esi+2],ax |
771 | mov [esi+2],ax |
772 | dec edx |
772 | dec edx |
773 | shr edx,9 |
773 | shr edx,9 |
774 | inc edx |
774 | inc edx |
775 | mov [esi+4],dx |
775 | mov [esi+4],dx |
776 | mov eax,edi |
776 | mov eax,edi |
777 | sub eax,esi |
777 | sub eax,esi |
778 | mov [esi+3Ch],eax |
778 | mov [esi+3Ch],eax |
779 | pop esi |
779 | pop esi |
780 | stub_ok: |
780 | stub_ok: |
781 | ret |
781 | ret |
782 | binary_stub: |
782 | binary_stub: |
783 | mov esi,edi |
783 | mov esi,edi |
784 | mov ecx,40h shr 2 |
784 | mov ecx,40h shr 2 |
785 | xor eax,eax |
785 | xor eax,eax |
786 | rep stos dword [edi] |
786 | rep stos dword [edi] |
787 | mov al,2 |
787 | mov al,2 |
788 | xor edx,edx |
788 | xor edx,edx |
789 | call lseek |
789 | call lseek |
790 | push eax |
790 | push eax |
791 | xor al,al |
791 | xor al,al |
792 | xor edx,edx |
792 | xor edx,edx |
793 | call lseek |
793 | call lseek |
794 | mov ecx,[esp] |
794 | mov ecx,[esp] |
795 | add ecx,40h+111b |
795 | add ecx,40h+111b |
796 | and ecx,not 111b |
796 | and ecx,not 111b |
797 | mov ax,cx |
797 | mov ax,cx |
798 | and ax,1FFh |
798 | and ax,1FFh |
799 | mov [esi+2],ax |
799 | mov [esi+2],ax |
800 | lea eax,[ecx+1FFh] |
800 | lea eax,[ecx+1FFh] |
801 | shr eax,9 |
801 | shr eax,9 |
802 | mov [esi+4],ax |
802 | mov [esi+4],ax |
803 | mov [esi+3Ch],ecx |
803 | mov [esi+3Ch],ecx |
804 | sub ecx,40h |
804 | sub ecx,40h |
805 | mov eax,10000h |
805 | mov eax,10000h |
806 | sub eax,ecx |
806 | sub eax,ecx |
807 | jbe binary_heap_ok |
807 | jbe binary_heap_ok |
808 | shr eax,4 |
808 | shr eax,4 |
809 | mov [esi+0Ah],ax |
809 | mov [esi+0Ah],ax |
810 | binary_heap_ok: |
810 | binary_heap_ok: |
811 | mov word [esi],'MZ' |
811 | mov word [esi],'MZ' |
812 | mov byte [esi+8],4 |
812 | mov byte [esi+8],4 |
813 | mov ax,0FFFFh |
813 | mov ax,0FFFFh |
814 | mov [esi+0Ch],ax |
814 | mov [esi+0Ch],ax |
815 | dec ax |
815 | dec ax |
816 | mov [esi+10h],ax |
816 | mov [esi+10h],ax |
817 | sub ax,0Eh |
817 | sub ax,0Eh |
818 | mov [esi+0Eh],ax |
818 | mov [esi+0Eh],ax |
819 | mov [esi+16h],ax |
819 | mov [esi+16h],ax |
820 | mov word [esi+14h],100h |
820 | mov word [esi+14h],100h |
821 | mov byte [esi+18h],40h |
821 | mov byte [esi+18h],40h |
822 | mov eax,[tagged_blocks] |
822 | mov eax,[tagged_blocks] |
823 | sub eax,ecx |
823 | sub eax,ecx |
824 | cmp edi,eax |
824 | cmp edi,eax |
825 | jae out_of_memory |
825 | jae out_of_memory |
826 | mov edx,edi |
826 | mov edx,edi |
827 | shr ecx,2 |
827 | shr ecx,2 |
828 | xor eax,eax |
828 | xor eax,eax |
829 | rep stos dword [edi] |
829 | rep stos dword [edi] |
830 | pop ecx |
830 | pop ecx |
831 | call read |
831 | call read |
832 | call close |
832 | call close |
833 | pop esi |
833 | pop esi |
834 | ret |
834 | ret |
835 | 835 | ||
836 | format_pe: |
836 | format_pe: |
837 | xor edx,edx |
837 | xor edx,edx |
838 | mov [machine],14Ch |
838 | mov [machine],14Ch |
839 | mov [subsystem],3 |
839 | mov [subsystem],3 |
840 | mov [subsystem_version],3 + 10 shl 16 |
840 | mov [subsystem_version],3 + 10 shl 16 |
841 | mov [image_base],400000h |
841 | mov [image_base],400000h |
842 | and [image_base_high],0 |
842 | and [image_base_high],0 |
843 | test [format_flags],8 |
843 | test [format_flags],8 |
844 | jz pe_settings |
844 | jz pe_settings |
845 | mov [machine],8664h |
845 | mov [machine],8664h |
846 | mov [subsystem_version],5 + 0 shl 16 |
846 | mov [subsystem_version],5 + 0 shl 16 |
847 | pe_settings: |
847 | pe_settings: |
848 | cmp byte [esi],84h |
848 | cmp byte [esi],84h |
849 | je get_stub_name |
849 | je get_stub_name |
850 | cmp byte [esi],80h |
850 | cmp byte [esi],80h |
851 | je get_pe_base |
851 | je get_pe_base |
852 | cmp byte [esi],1Bh |
852 | cmp byte [esi],1Bh |
853 | jne pe_settings_ok |
853 | jne pe_settings_ok |
854 | lods byte [esi] |
854 | lods byte [esi] |
855 | lods byte [esi] |
855 | lods byte [esi] |
856 | test al,80h+40h |
856 | test al,80h+40h |
857 | jz subsystem_setting |
857 | jz subsystem_setting |
858 | cmp al,80h |
858 | cmp al,80h |
859 | je dll_flag |
859 | je dll_flag |
860 | cmp al,81h |
860 | cmp al,81h |
861 | je wdm_flag |
861 | je wdm_flag |
862 | cmp al,82h |
862 | cmp al,82h |
863 | je large_flag |
863 | je large_flag |
864 | cmp al,83h |
864 | cmp al,83h |
865 | je nx_flag |
865 | je nx_flag |
866 | jmp pe_settings |
866 | jmp pe_settings |
867 | dll_flag: |
867 | dll_flag: |
868 | bts [format_flags],8 |
868 | bts [format_flags],8 |
869 | jc setting_already_specified |
869 | jc setting_already_specified |
870 | jmp pe_settings |
870 | jmp pe_settings |
871 | wdm_flag: |
871 | wdm_flag: |
872 | bts [format_flags],9 |
872 | bts [format_flags],9 |
873 | jc setting_already_specified |
873 | jc setting_already_specified |
874 | jmp pe_settings |
874 | jmp pe_settings |
875 | large_flag: |
875 | large_flag: |
876 | bts [format_flags],11 |
876 | bts [format_flags],11 |
877 | jc setting_already_specified |
877 | jc setting_already_specified |
878 | test [format_flags],8 |
878 | test [format_flags],8 |
879 | jnz invalid_argument |
879 | jnz invalid_argument |
880 | jmp pe_settings |
880 | jmp pe_settings |
881 | nx_flag: |
881 | nx_flag: |
882 | bts [format_flags],12 |
882 | bts [format_flags],12 |
883 | jc setting_already_specified |
883 | jc setting_already_specified |
884 | jmp pe_settings |
884 | jmp pe_settings |
885 | subsystem_setting: |
885 | subsystem_setting: |
886 | bts [format_flags],7 |
886 | bts [format_flags],7 |
887 | jc setting_already_specified |
887 | jc setting_already_specified |
888 | and ax,3Fh |
888 | and ax,3Fh |
889 | mov [subsystem],ax |
889 | mov [subsystem],ax |
890 | cmp ax,10 |
890 | cmp ax,10 |
891 | jb subsystem_type_ok |
891 | jb subsystem_type_ok |
892 | or [format_flags],4 |
892 | or [format_flags],4 |
893 | subsystem_type_ok: |
893 | subsystem_type_ok: |
894 | cmp byte [esi],'(' |
894 | cmp byte [esi],'(' |
895 | jne pe_settings |
895 | jne pe_settings |
896 | inc esi |
896 | inc esi |
897 | cmp byte [esi],'.' |
897 | cmp byte [esi],'.' |
898 | jne invalid_value |
898 | jne invalid_value |
899 | inc esi |
899 | inc esi |
900 | push edx |
900 | push edx |
901 | cmp byte [esi+11],0 |
901 | cmp byte [esi+11],0 |
902 | jne invalid_value |
902 | jne invalid_value |
903 | cmp byte [esi+10],2 |
903 | cmp byte [esi+10],2 |
904 | ja invalid_value |
904 | ja invalid_value |
905 | mov dx,[esi+8] |
905 | mov dx,[esi+8] |
906 | cmp dx,8000h |
906 | cmp dx,8000h |
907 | je zero_version |
907 | je zero_version |
908 | mov eax,[esi+4] |
908 | mov eax,[esi+4] |
909 | cmp dx,7 |
909 | cmp dx,7 |
910 | jg invalid_value |
910 | jg invalid_value |
911 | mov cx,7 |
911 | mov cx,7 |
912 | sub cx,dx |
912 | sub cx,dx |
913 | mov eax,[esi+4] |
913 | mov eax,[esi+4] |
914 | shr eax,cl |
914 | shr eax,cl |
915 | mov ebx,eax |
915 | mov ebx,eax |
916 | shr ebx,24 |
916 | shr ebx,24 |
917 | cmp bl,100 |
917 | cmp bl,100 |
918 | jae invalid_value |
918 | jae invalid_value |
919 | and eax,0FFFFFFh |
919 | and eax,0FFFFFFh |
920 | mov ecx,100 |
920 | mov ecx,100 |
921 | mul ecx |
921 | mul ecx |
922 | shrd eax,edx,24 |
922 | shrd eax,edx,24 |
923 | jnc version_value_ok |
923 | jnc version_value_ok |
924 | inc eax |
924 | inc eax |
925 | version_value_ok: |
925 | version_value_ok: |
926 | shl eax,16 |
926 | shl eax,16 |
927 | mov ax,bx |
927 | mov ax,bx |
928 | jmp subsystem_version_ok |
928 | jmp subsystem_version_ok |
929 | zero_version: |
929 | zero_version: |
930 | xor eax,eax |
930 | xor eax,eax |
931 | subsystem_version_ok: |
931 | subsystem_version_ok: |
932 | pop edx |
932 | pop edx |
933 | add esi,13 |
933 | add esi,13 |
934 | mov [subsystem_version],eax |
934 | mov [subsystem_version],eax |
935 | jmp pe_settings |
935 | jmp pe_settings |
936 | get_pe_base: |
936 | get_pe_base: |
937 | bts [format_flags],10 |
937 | bts [format_flags],10 |
938 | jc setting_already_specified |
938 | jc setting_already_specified |
939 | lods word [esi] |
939 | lods word [esi] |
940 | cmp ah,'(' |
940 | cmp ah,'(' |
941 | jne invalid_argument |
941 | jne invalid_argument |
942 | cmp byte [esi],'.' |
942 | cmp byte [esi],'.' |
943 | je invalid_value |
943 | je invalid_value |
944 | push edx edi |
944 | push edx edi |
945 | add edi,[stub_size] |
945 | add edi,[stub_size] |
946 | test [format_flags],4 |
946 | test [format_flags],4 |
947 | jnz get_peplus_base |
947 | jnz get_peplus_base |
948 | call get_dword_value |
948 | call get_dword_value |
949 | mov [image_base],eax |
949 | mov [image_base],eax |
950 | jmp pe_base_ok |
950 | jmp pe_base_ok |
951 | get_peplus_base: |
951 | get_peplus_base: |
952 | call get_qword_value |
952 | call get_qword_value |
953 | mov [image_base],eax |
953 | mov [image_base],eax |
954 | mov [image_base_high],edx |
954 | mov [image_base_high],edx |
955 | pe_base_ok: |
955 | pe_base_ok: |
956 | pop edi edx |
956 | pop edi edx |
957 | cmp [value_type],0 |
957 | cmp [value_type],0 |
958 | jne invalid_use_of_symbol |
958 | jne invalid_use_of_symbol |
959 | cmp byte [esi],84h |
959 | cmp byte [esi],84h |
960 | jne pe_settings_ok |
960 | jne pe_settings_ok |
961 | get_stub_name: |
961 | get_stub_name: |
962 | lods byte [esi] |
962 | lods byte [esi] |
963 | lods word [esi] |
963 | lods word [esi] |
964 | cmp ax,'(' |
964 | cmp ax,'(' |
965 | jne invalid_argument |
965 | jne invalid_argument |
966 | lods dword [esi] |
966 | lods dword [esi] |
967 | mov edx,esi |
967 | mov edx,esi |
968 | add esi,eax |
968 | add esi,eax |
969 | inc esi |
969 | inc esi |
970 | pe_settings_ok: |
970 | pe_settings_ok: |
971 | mov ebp,[stub_size] |
971 | mov ebp,[stub_size] |
972 | or ebp,ebp |
972 | or ebp,ebp |
973 | jz make_pe_stub |
973 | jz make_pe_stub |
974 | cmp edx,[stub_file] |
974 | cmp edx,[stub_file] |
975 | je pe_stub_ok |
975 | je pe_stub_ok |
976 | sub edi,[stub_size] |
976 | sub edi,[stub_size] |
977 | mov [code_start],edi |
977 | mov [code_start],edi |
978 | make_pe_stub: |
978 | make_pe_stub: |
979 | call make_stub |
979 | call make_stub |
980 | mov eax,edi |
980 | mov eax,edi |
981 | sub eax,[code_start] |
981 | sub eax,[code_start] |
982 | mov [stub_size],eax |
982 | mov [stub_size],eax |
983 | mov [code_start],edi |
983 | mov [code_start],edi |
984 | mov ebp,eax |
984 | mov ebp,eax |
985 | pe_stub_ok: |
985 | pe_stub_ok: |
986 | mov edx,edi |
986 | mov edx,edi |
987 | mov ecx,18h+0E0h |
987 | mov ecx,18h+0E0h |
988 | test [format_flags],4 |
988 | test [format_flags],4 |
989 | jz zero_pe_header |
989 | jz zero_pe_header |
990 | add ecx,10h |
990 | add ecx,10h |
991 | zero_pe_header: |
991 | zero_pe_header: |
992 | add ebp,ecx |
992 | add ebp,ecx |
993 | shr ecx,2 |
993 | shr ecx,2 |
994 | xor eax,eax |
994 | xor eax,eax |
995 | rep stos dword [edi] |
995 | rep stos dword [edi] |
996 | mov word [edx],'PE' ; signature |
996 | mov word [edx],'PE' ; signature |
997 | mov ax,[machine] |
997 | mov ax,[machine] |
998 | mov word [edx+4],ax |
998 | mov word [edx+4],ax |
999 | mov byte [edx+38h+1],10h ; section alignment |
999 | mov byte [edx+38h+1],10h ; section alignment |
1000 | mov byte [edx+3Ch+1],2 ; file alignment |
1000 | mov byte [edx+3Ch+1],2 ; file alignment |
1001 | mov byte [edx+40h],1 ; OS version |
1001 | mov byte [edx+40h],1 ; OS version |
1002 | mov eax,[subsystem_version] |
1002 | mov eax,[subsystem_version] |
1003 | mov [edx+48h],eax |
1003 | mov [edx+48h],eax |
1004 | mov ax,[subsystem] |
1004 | mov ax,[subsystem] |
1005 | mov [edx+5Ch],ax |
1005 | mov [edx+5Ch],ax |
1006 | cmp ax,1 |
1006 | cmp ax,1 |
1007 | jne pe_alignment_ok |
1007 | jne pe_alignment_ok |
1008 | mov eax,20h |
1008 | mov eax,20h |
1009 | mov dword [edx+38h],eax |
1009 | mov dword [edx+38h],eax |
1010 | mov dword [edx+3Ch],eax |
1010 | mov dword [edx+3Ch],eax |
1011 | pe_alignment_ok: |
1011 | pe_alignment_ok: |
1012 | mov word [edx+1Ah],VERSION_MAJOR + VERSION_MINOR shl 8 |
1012 | mov word [edx+1Ah],VERSION_MAJOR + VERSION_MINOR shl 8 |
1013 | test [format_flags],4 |
1013 | test [format_flags],4 |
1014 | jnz init_peplus_specific |
1014 | jnz init_peplus_specific |
1015 | mov byte [edx+14h],0E0h ; size of optional header |
1015 | mov byte [edx+14h],0E0h ; size of optional header |
1016 | mov dword [edx+16h],10B010Fh; flags and magic value |
1016 | mov dword [edx+16h],10B010Fh; flags and magic value |
1017 | mov eax,[image_base] |
1017 | mov eax,[image_base] |
1018 | mov [edx+34h],eax |
1018 | mov [edx+34h],eax |
1019 | mov byte [edx+60h+1],10h ; stack reserve |
1019 | mov byte [edx+60h+1],10h ; stack reserve |
1020 | mov byte [edx+64h+1],10h ; stack commit |
1020 | mov byte [edx+64h+1],10h ; stack commit |
1021 | mov byte [edx+68h+2],1 ; heap reserve |
1021 | mov byte [edx+68h+2],1 ; heap reserve |
1022 | mov byte [edx+74h],16 ; number of directories |
1022 | mov byte [edx+74h],16 ; number of directories |
1023 | jmp pe_header_ok |
1023 | jmp pe_header_ok |
1024 | init_peplus_specific: |
1024 | init_peplus_specific: |
1025 | mov byte [edx+14h],0F0h ; size of optional header |
1025 | mov byte [edx+14h],0F0h ; size of optional header |
1026 | mov dword [edx+16h],20B002Fh; flags and magic value |
1026 | mov dword [edx+16h],20B002Fh; flags and magic value |
1027 | mov eax,[image_base] |
1027 | mov eax,[image_base] |
1028 | mov [edx+30h],eax |
1028 | mov [edx+30h],eax |
1029 | mov eax,[image_base_high] |
1029 | mov eax,[image_base_high] |
1030 | mov [edx+34h],eax |
1030 | mov [edx+34h],eax |
1031 | mov byte [edx+60h+1],10h ; stack reserve |
1031 | mov byte [edx+60h+1],10h ; stack reserve |
1032 | mov byte [edx+68h+1],10h ; stack commit |
1032 | mov byte [edx+68h+1],10h ; stack commit |
1033 | mov byte [edx+70h+2],1 ; heap reserve |
1033 | mov byte [edx+70h+2],1 ; heap reserve |
1034 | mov byte [edx+84h],16 ; number of directories |
1034 | mov byte [edx+84h],16 ; number of directories |
1035 | pe_header_ok: |
1035 | pe_header_ok: |
1036 | bsf ecx,[edx+3Ch] |
1036 | bsf ecx,[edx+3Ch] |
1037 | imul ebx,[number_of_sections],28h |
1037 | imul ebx,[number_of_sections],28h |
1038 | or ebx,ebx |
1038 | or ebx,ebx |
1039 | jnz reserve_space_for_section_headers |
1039 | jnz reserve_space_for_section_headers |
1040 | mov ebx,28h |
1040 | mov ebx,28h |
1041 | reserve_space_for_section_headers: |
1041 | reserve_space_for_section_headers: |
1042 | add ebx,ebp |
1042 | add ebx,ebp |
1043 | dec ebx |
1043 | dec ebx |
1044 | shr ebx,cl |
1044 | shr ebx,cl |
1045 | inc ebx |
1045 | inc ebx |
1046 | shl ebx,cl |
1046 | shl ebx,cl |
1047 | sub ebx,ebp |
1047 | sub ebx,ebp |
1048 | mov ecx,ebx |
1048 | mov ecx,ebx |
1049 | mov eax,[tagged_blocks] |
1049 | mov eax,[tagged_blocks] |
1050 | sub eax,ecx |
1050 | sub eax,ecx |
1051 | cmp edi,eax |
1051 | cmp edi,eax |
1052 | jae out_of_memory |
1052 | jae out_of_memory |
1053 | shr ecx,2 |
1053 | shr ecx,2 |
1054 | xor eax,eax |
1054 | xor eax,eax |
1055 | rep stos dword [edi] |
1055 | rep stos dword [edi] |
1056 | mov eax,edi |
1056 | mov eax,edi |
1057 | sub eax,[code_start] |
1057 | sub eax,[code_start] |
1058 | add eax,[stub_size] |
1058 | add eax,[stub_size] |
1059 | mov [edx+54h],eax ; size of headers |
1059 | mov [edx+54h],eax ; size of headers |
1060 | mov ecx,[edx+38h] |
1060 | mov ecx,[edx+38h] |
1061 | dec ecx |
1061 | dec ecx |
1062 | add eax,ecx |
1062 | add eax,ecx |
1063 | not ecx |
1063 | not ecx |
1064 | and eax,ecx |
1064 | and eax,ecx |
1065 | bt [format_flags],8 |
1065 | bt [format_flags],8 |
1066 | jc pe_entry_init_ok |
1066 | jc pe_entry_init_ok |
1067 | mov [edx+28h],eax ; entry point rva |
1067 | mov [edx+28h],eax ; entry point rva |
1068 | pe_entry_init_ok: |
1068 | pe_entry_init_ok: |
1069 | and [number_of_sections],0 |
1069 | and [number_of_sections],0 |
1070 | movzx ebx,word [edx+14h] |
1070 | movzx ebx,word [edx+14h] |
1071 | lea ebx,[edx+18h+ebx] |
1071 | lea ebx,[edx+18h+ebx] |
1072 | mov [current_section],ebx |
1072 | mov [current_section],ebx |
1073 | mov dword [ebx],'.fla' |
1073 | mov dword [ebx],'.fla' |
1074 | mov dword [ebx+4],'t' |
1074 | mov dword [ebx+4],'t' |
1075 | mov [ebx+14h],edi |
1075 | mov [ebx+14h],edi |
1076 | mov [ebx+0Ch],eax |
1076 | mov [ebx+0Ch],eax |
1077 | mov dword [ebx+24h],0E0000060h |
1077 | mov dword [ebx+24h],0E0000060h |
1078 | xor ecx,ecx |
1078 | xor ecx,ecx |
1079 | xor bl,bl |
1079 | xor bl,bl |
1080 | not eax |
1080 | not eax |
1081 | not ecx |
1081 | not ecx |
1082 | not bl |
1082 | not bl |
1083 | add eax,1 |
1083 | add eax,1 |
1084 | adc ecx,0 |
1084 | adc ecx,0 |
1085 | adc bl,0 |
1085 | adc bl,0 |
1086 | add eax,edi |
1086 | add eax,edi |
1087 | adc ecx,0 |
1087 | adc ecx,0 |
1088 | adc bl,0 |
1088 | adc bl,0 |
1089 | test [format_flags],4 |
1089 | test [format_flags],4 |
1090 | jnz peplus_org |
1090 | jnz peplus_org |
1091 | sub eax,[edx+34h] |
1091 | sub eax,[edx+34h] |
1092 | sbb ecx,0 |
1092 | sbb ecx,0 |
1093 | sbb bl,0 |
1093 | sbb bl,0 |
1094 | jmp pe_org_ok |
1094 | jmp pe_org_ok |
1095 | peplus_org: |
1095 | peplus_org: |
1096 | sub eax,[edx+30h] |
1096 | sub eax,[edx+30h] |
1097 | sbb ecx,[edx+34h] |
1097 | sbb ecx,[edx+34h] |
1098 | sbb bl,0 |
1098 | sbb bl,0 |
1099 | pe_org_ok: |
1099 | pe_org_ok: |
1100 | test [format_flags],8 |
1100 | test [format_flags],8 |
1101 | jnz pe64_code |
1101 | jnz pe64_code |
1102 | mov bh,2 |
1102 | mov bh,2 |
1103 | mov [code_type],32 |
1103 | mov [code_type],32 |
1104 | jmp pe_code_type_ok |
1104 | jmp pe_code_type_ok |
1105 | pe64_code: |
1105 | pe64_code: |
1106 | mov bh,4 |
1106 | mov bh,4 |
1107 | mov [code_type],64 |
1107 | mov [code_type],64 |
1108 | pe_code_type_ok: |
1108 | pe_code_type_ok: |
1109 | bt [resolver_flags],0 |
1109 | bt [resolver_flags],0 |
1110 | jc pe_labels_type_ok |
1110 | jc pe_labels_type_ok |
1111 | xor bh,bh |
1111 | xor bh,bh |
1112 | pe_labels_type_ok: |
1112 | pe_labels_type_ok: |
1113 | push eax ebx |
1113 | push eax ebx |
1114 | call init_addressing_space |
1114 | call init_addressing_space |
1115 | mov ebp,ebx |
1115 | mov ebp,ebx |
1116 | pop ebx eax |
1116 | pop ebx eax |
1117 | mov [ds:ebp],eax |
1117 | mov [ds:ebp],eax |
1118 | mov [ds:ebp+4],ecx |
1118 | mov [ds:ebp+4],ecx |
1119 | mov [ds:ebp+8],bx |
1119 | mov [ds:ebp+8],bx |
1120 | mov [ds:ebp+18h],edi |
1120 | mov [ds:ebp+18h],edi |
1121 | bt [format_flags],8 |
1121 | bt [format_flags],8 |
1122 | jnc dll_flag_ok |
1122 | jnc dll_flag_ok |
1123 | or byte [edx+16h+1],20h |
1123 | or byte [edx+16h+1],20h |
1124 | dll_flag_ok: |
1124 | dll_flag_ok: |
1125 | bt [format_flags],9 |
1125 | bt [format_flags],9 |
1126 | jnc wdm_flag_ok |
1126 | jnc wdm_flag_ok |
1127 | or byte [edx+5Eh+1],20h |
1127 | or byte [edx+5Eh+1],20h |
1128 | wdm_flag_ok: |
1128 | wdm_flag_ok: |
1129 | bt [format_flags],11 |
1129 | bt [format_flags],11 |
1130 | jnc large_flag_ok |
1130 | jnc large_flag_ok |
1131 | or byte [edx+16h],20h |
1131 | or byte [edx+16h],20h |
1132 | large_flag_ok: |
1132 | large_flag_ok: |
1133 | bt [format_flags],12 |
1133 | bt [format_flags],12 |
1134 | jnc nx_ok |
1134 | jnc nx_ok |
1135 | or byte [edx+5Eh+1],1 |
1135 | or byte [edx+5Eh+1],1 |
1136 | nx_ok: |
1136 | nx_ok: |
1137 | jmp format_defined |
1137 | jmp format_defined |
1138 | pe_section: |
1138 | pe_section: |
1139 | call close_pe_section |
1139 | call close_pe_section |
1140 | push eax ebx |
1140 | push eax ebx |
1141 | call create_addressing_space |
1141 | call create_addressing_space |
1142 | mov ebp,ebx |
1142 | mov ebp,ebx |
1143 | pop ebx eax |
1143 | pop ebx eax |
1144 | bts [format_flags],5 |
1144 | bts [format_flags],5 |
1145 | lea ecx,[ebx+28h] |
1145 | lea ecx,[ebx+28h] |
1146 | add edx,[edx+54h] |
1146 | add edx,[edx+54h] |
1147 | sub edx,[stub_size] |
1147 | sub edx,[stub_size] |
1148 | cmp ecx,edx |
1148 | cmp ecx,edx |
1149 | jbe new_section |
1149 | jbe new_section |
1150 | lea ebx,[edx-28h] |
1150 | lea ebx,[edx-28h] |
1151 | or [next_pass_needed],-1 |
1151 | or [next_pass_needed],-1 |
1152 | push edi |
1152 | push edi |
1153 | mov edi,ebx |
1153 | mov edi,ebx |
1154 | mov ecx,28h shr 4 |
1154 | mov ecx,28h shr 4 |
1155 | xor eax,eax |
1155 | xor eax,eax |
1156 | rep stos dword [edi] |
1156 | rep stos dword [edi] |
1157 | pop edi |
1157 | pop edi |
1158 | new_section: |
1158 | new_section: |
1159 | mov [ebx+0Ch],eax |
1159 | mov [ebx+0Ch],eax |
1160 | lods word [esi] |
1160 | lods word [esi] |
1161 | cmp ax,'(' |
1161 | cmp ax,'(' |
1162 | jne invalid_argument |
1162 | jne invalid_argument |
1163 | lea edx,[esi+4] |
1163 | lea edx,[esi+4] |
1164 | mov ecx,[esi] |
1164 | mov ecx,[esi] |
1165 | lea esi,[esi+4+ecx+1] |
1165 | lea esi,[esi+4+ecx+1] |
1166 | cmp ecx,8 |
1166 | cmp ecx,8 |
1167 | ja name_too_long |
1167 | ja name_too_long |
1168 | xor eax,eax |
1168 | xor eax,eax |
1169 | mov [ebx],eax |
1169 | mov [ebx],eax |
1170 | mov [ebx+4],eax |
1170 | mov [ebx+4],eax |
1171 | push esi edi |
1171 | push esi edi |
1172 | mov edi,ebx |
1172 | mov edi,ebx |
1173 | mov esi,edx |
1173 | mov esi,edx |
1174 | rep movs byte [edi],[esi] |
1174 | rep movs byte [edi],[esi] |
1175 | pop edi esi |
1175 | pop edi esi |
1176 | and dword [ebx+24h],0 |
1176 | and dword [ebx+24h],0 |
1177 | mov [ebx+14h],edi |
1177 | mov [ebx+14h],edi |
1178 | mov edx,[code_start] |
1178 | mov edx,[code_start] |
1179 | mov eax,edi |
1179 | mov eax,edi |
1180 | xor ecx,ecx |
1180 | xor ecx,ecx |
1181 | sub eax,[ebx+0Ch] |
1181 | sub eax,[ebx+0Ch] |
1182 | sbb ecx,0 |
1182 | sbb ecx,0 |
1183 | sbb byte [ds:ebp+8],0 |
1183 | sbb byte [ds:ebp+8],0 |
1184 | mov byte [ds:ebp+9],2 |
1184 | mov byte [ds:ebp+9],2 |
1185 | mov [code_type],32 |
1185 | mov [code_type],32 |
1186 | test [format_flags],8 |
1186 | test [format_flags],8 |
1187 | jz pe_section_code_type_ok |
1187 | jz pe_section_code_type_ok |
1188 | mov byte [ds:ebp+9],4 |
1188 | mov byte [ds:ebp+9],4 |
1189 | mov [code_type],64 |
1189 | mov [code_type],64 |
1190 | pe_section_code_type_ok: |
1190 | pe_section_code_type_ok: |
1191 | test [format_flags],4 |
1191 | test [format_flags],4 |
1192 | jnz peplus_section_org |
1192 | jnz peplus_section_org |
1193 | sub eax,[edx+34h] |
1193 | sub eax,[edx+34h] |
1194 | sbb ecx,0 |
1194 | sbb ecx,0 |
1195 | sbb byte [ds:ebp+8],0 |
1195 | sbb byte [ds:ebp+8],0 |
1196 | bt [resolver_flags],0 |
1196 | bt [resolver_flags],0 |
1197 | jc pe_section_org_ok |
1197 | jc pe_section_org_ok |
1198 | mov byte [ds:ebp+9],0 |
1198 | mov byte [ds:ebp+9],0 |
1199 | jmp pe_section_org_ok |
1199 | jmp pe_section_org_ok |
1200 | peplus_section_org: |
1200 | peplus_section_org: |
1201 | sub eax,[edx+30h] |
1201 | sub eax,[edx+30h] |
1202 | sbb ecx,[edx+34h] |
1202 | sbb ecx,[edx+34h] |
1203 | sbb byte [ds:ebp+8],0 |
1203 | sbb byte [ds:ebp+8],0 |
1204 | bt [resolver_flags],0 |
1204 | bt [resolver_flags],0 |
1205 | jc pe_section_org_ok |
1205 | jc pe_section_org_ok |
1206 | mov byte [ds:ebp+9],0 |
1206 | mov byte [ds:ebp+9],0 |
1207 | pe_section_org_ok: |
1207 | pe_section_org_ok: |
1208 | mov [ds:ebp],eax |
1208 | mov [ds:ebp],eax |
1209 | mov [ds:ebp+4],ecx |
1209 | mov [ds:ebp+4],ecx |
1210 | mov [ds:ebp+18h],edi |
1210 | mov [ds:ebp+18h],edi |
1211 | get_section_flags: |
1211 | get_section_flags: |
1212 | lods byte [esi] |
1212 | lods byte [esi] |
1213 | cmp al,1Ah |
1213 | cmp al,1Ah |
1214 | je set_directory |
1214 | je set_directory |
1215 | cmp al,19h |
1215 | cmp al,19h |
1216 | je section_flag |
1216 | je section_flag |
1217 | dec esi |
1217 | dec esi |
1218 | jmp instruction_assembled |
1218 | jmp instruction_assembled |
1219 | set_directory: |
1219 | set_directory: |
1220 | movzx eax,byte [esi] |
1220 | movzx eax,byte [esi] |
1221 | inc esi |
1221 | inc esi |
1222 | mov ecx,ebx |
1222 | mov ecx,ebx |
1223 | test [format_flags],4 |
1223 | test [format_flags],4 |
1224 | jnz peplus_directory |
1224 | jnz peplus_directory |
1225 | xchg ecx,[edx+78h+eax*8] |
1225 | xchg ecx,[edx+78h+eax*8] |
1226 | mov dword [edx+78h+eax*8+4],-1 |
1226 | mov dword [edx+78h+eax*8+4],-1 |
1227 | jmp pe_directory_set |
1227 | jmp pe_directory_set |
1228 | peplus_directory: |
1228 | peplus_directory: |
1229 | xchg ecx,[edx+88h+eax*8] |
1229 | xchg ecx,[edx+88h+eax*8] |
1230 | mov dword [edx+88h+eax*8+4],-1 |
1230 | mov dword [edx+88h+eax*8+4],-1 |
1231 | pe_directory_set: |
1231 | pe_directory_set: |
1232 | or ecx,ecx |
1232 | or ecx,ecx |
1233 | jnz data_already_defined |
1233 | jnz data_already_defined |
1234 | push ebx edx |
1234 | push ebx edx |
1235 | call generate_pe_data |
1235 | call generate_pe_data |
1236 | pop edx ebx |
1236 | pop edx ebx |
1237 | jmp get_section_flags |
1237 | jmp get_section_flags |
1238 | section_flag: |
1238 | section_flag: |
1239 | lods byte [esi] |
1239 | lods byte [esi] |
1240 | cmp al,9 |
1240 | cmp al,9 |
1241 | je invalid_argument |
1241 | je invalid_argument |
1242 | cmp al,11 |
1242 | cmp al,11 |
1243 | je invalid_argument |
1243 | je invalid_argument |
1244 | mov cl,al |
1244 | mov cl,al |
1245 | mov eax,1 |
1245 | mov eax,1 |
1246 | shl eax,cl |
1246 | shl eax,cl |
1247 | test dword [ebx+24h],eax |
1247 | test dword [ebx+24h],eax |
1248 | jnz setting_already_specified |
1248 | jnz setting_already_specified |
1249 | or dword [ebx+24h],eax |
1249 | or dword [ebx+24h],eax |
1250 | jmp get_section_flags |
1250 | jmp get_section_flags |
1251 | close_pe_section: |
1251 | close_pe_section: |
1252 | mov ebx,[current_section] |
1252 | mov ebx,[current_section] |
1253 | mov edx,[code_start] |
1253 | mov edx,[code_start] |
1254 | mov eax,edi |
1254 | mov eax,edi |
1255 | sub eax,[ebx+14h] |
1255 | sub eax,[ebx+14h] |
1256 | jnz finish_section |
1256 | jnz finish_section |
1257 | bt [format_flags],5 |
1257 | bt [format_flags],5 |
1258 | jc finish_section |
1258 | jc finish_section |
1259 | mov eax,[ebx+0Ch] |
1259 | mov eax,[ebx+0Ch] |
1260 | ret |
1260 | ret |
1261 | finish_section: |
1261 | finish_section: |
1262 | mov [ebx+8],eax |
1262 | mov [ebx+8],eax |
1263 | cmp edi,[undefined_data_end] |
1263 | cmp edi,[undefined_data_end] |
1264 | jne align_section |
1264 | jne align_section |
1265 | cmp dword [edx+38h],1000h |
1265 | cmp dword [edx+38h],1000h |
1266 | jb align_section |
1266 | jb align_section |
1267 | mov edi,[undefined_data_start] |
1267 | mov edi,[undefined_data_start] |
1268 | align_section: |
1268 | align_section: |
1269 | and [undefined_data_end],0 |
1269 | and [undefined_data_end],0 |
1270 | mov ebp,edi |
1270 | mov ebp,edi |
1271 | sub ebp,[ebx+14h] |
1271 | sub ebp,[ebx+14h] |
1272 | mov ecx,[edx+3Ch] |
1272 | mov ecx,[edx+3Ch] |
1273 | dec ecx |
1273 | dec ecx |
1274 | lea eax,[ebp+ecx] |
1274 | lea eax,[ebp+ecx] |
1275 | not ecx |
1275 | not ecx |
1276 | and eax,ecx |
1276 | and eax,ecx |
1277 | mov [ebx+10h],eax |
1277 | mov [ebx+10h],eax |
1278 | sub eax,ebp |
1278 | sub eax,ebp |
1279 | mov ecx,eax |
1279 | mov ecx,eax |
1280 | xor al,al |
1280 | xor al,al |
1281 | rep stos byte [edi] |
1281 | rep stos byte [edi] |
1282 | mov eax,[code_start] |
1282 | mov eax,[code_start] |
1283 | sub eax,[stub_size] |
1283 | sub eax,[stub_size] |
1284 | sub [ebx+14h],eax |
1284 | sub [ebx+14h],eax |
1285 | mov ecx,[ebx+10h] |
1285 | mov ecx,[ebx+10h] |
1286 | test byte [ebx+24h],20h |
1286 | test byte [ebx+24h],20h |
1287 | jz pe_code_sum_ok |
1287 | jz pe_code_sum_ok |
1288 | add [edx+1Ch],ecx |
1288 | add [edx+1Ch],ecx |
1289 | cmp dword [edx+2Ch],0 |
1289 | cmp dword [edx+2Ch],0 |
1290 | jne pe_code_sum_ok |
1290 | jne pe_code_sum_ok |
1291 | mov eax,[ebx+0Ch] |
1291 | mov eax,[ebx+0Ch] |
1292 | mov [edx+2Ch],eax |
1292 | mov [edx+2Ch],eax |
1293 | pe_code_sum_ok: |
1293 | pe_code_sum_ok: |
1294 | test byte [ebx+24h],40h |
1294 | test byte [ebx+24h],40h |
1295 | jz pe_data_sum_ok |
1295 | jz pe_data_sum_ok |
1296 | add [edx+20h],ecx |
1296 | add [edx+20h],ecx |
1297 | test [format_flags],4 |
1297 | test [format_flags],4 |
1298 | jnz pe_data_sum_ok |
1298 | jnz pe_data_sum_ok |
1299 | cmp dword [edx+30h],0 |
1299 | cmp dword [edx+30h],0 |
1300 | jne pe_data_sum_ok |
1300 | jne pe_data_sum_ok |
1301 | mov eax,[ebx+0Ch] |
1301 | mov eax,[ebx+0Ch] |
1302 | mov [edx+30h],eax |
1302 | mov [edx+30h],eax |
1303 | pe_data_sum_ok: |
1303 | pe_data_sum_ok: |
1304 | mov eax,[ebx+8] |
1304 | mov eax,[ebx+8] |
1305 | or eax,eax |
1305 | or eax,eax |
1306 | jz udata_ok |
1306 | jz udata_ok |
1307 | cmp dword [ebx+10h],0 |
1307 | cmp dword [ebx+10h],0 |
1308 | jne udata_ok |
1308 | jne udata_ok |
1309 | or byte [ebx+24h],80h |
1309 | or byte [ebx+24h],80h |
1310 | add [edx+24h],ecx |
1310 | add [edx+24h],ecx |
1311 | udata_ok: |
1311 | udata_ok: |
1312 | mov ecx,[edx+38h] |
1312 | mov ecx,[edx+38h] |
1313 | dec ecx |
1313 | dec ecx |
1314 | add eax,ecx |
1314 | add eax,ecx |
1315 | not ecx |
1315 | not ecx |
1316 | and eax,ecx |
1316 | and eax,ecx |
1317 | add eax,[ebx+0Ch] |
1317 | add eax,[ebx+0Ch] |
1318 | add ebx,28h |
1318 | add ebx,28h |
1319 | mov [current_section],ebx |
1319 | mov [current_section],ebx |
1320 | inc word [number_of_sections] |
1320 | inc word [number_of_sections] |
1321 | jz format_limitations_exceeded |
1321 | jz format_limitations_exceeded |
1322 | ret |
1322 | ret |
1323 | data_directive: |
1323 | data_directive: |
1324 | cmp [output_format],3 |
1324 | cmp [output_format],3 |
1325 | jne illegal_instruction |
1325 | jne illegal_instruction |
1326 | lods byte [esi] |
1326 | lods byte [esi] |
1327 | cmp al,1Ah |
1327 | cmp al,1Ah |
1328 | je predefined_data_type |
1328 | je predefined_data_type |
1329 | cmp al,'(' |
1329 | cmp al,'(' |
1330 | jne invalid_argument |
1330 | jne invalid_argument |
1331 | call get_byte_value |
1331 | call get_byte_value |
1332 | cmp al,16 |
1332 | cmp al,16 |
1333 | jb data_type_ok |
1333 | jb data_type_ok |
1334 | jmp invalid_value |
1334 | jmp invalid_value |
1335 | predefined_data_type: |
1335 | predefined_data_type: |
1336 | movzx eax,byte [esi] |
1336 | movzx eax,byte [esi] |
1337 | inc esi |
1337 | inc esi |
1338 | data_type_ok: |
1338 | data_type_ok: |
1339 | mov ebx,[current_section] |
1339 | mov ebx,[current_section] |
1340 | mov ecx,edi |
1340 | mov ecx,edi |
1341 | sub ecx,[ebx+14h] |
1341 | sub ecx,[ebx+14h] |
1342 | add ecx,[ebx+0Ch] |
1342 | add ecx,[ebx+0Ch] |
1343 | mov edx,[code_start] |
1343 | mov edx,[code_start] |
1344 | test [format_flags],4 |
1344 | test [format_flags],4 |
1345 | jnz peplus_data |
1345 | jnz peplus_data |
1346 | xchg ecx,[edx+78h+eax*8] |
1346 | xchg ecx,[edx+78h+eax*8] |
1347 | jmp init_pe_data |
1347 | jmp init_pe_data |
1348 | peplus_data: |
1348 | peplus_data: |
1349 | xchg ecx,[edx+88h+eax*8] |
1349 | xchg ecx,[edx+88h+eax*8] |
1350 | init_pe_data: |
1350 | init_pe_data: |
1351 | or ecx,ecx |
1351 | or ecx,ecx |
1352 | jnz data_already_defined |
1352 | jnz data_already_defined |
1353 | call allocate_structure_data |
1353 | call allocate_structure_data |
1354 | mov word [ebx],data_directive-instruction_handler |
1354 | mov word [ebx],data_directive-instruction_handler |
1355 | mov [ebx+2],al |
1355 | mov [ebx+2],al |
1356 | mov edx,[current_line] |
1356 | mov edx,[current_line] |
1357 | mov [ebx+4],edx |
1357 | mov [ebx+4],edx |
1358 | call generate_pe_data |
1358 | call generate_pe_data |
1359 | jmp instruction_assembled |
1359 | jmp instruction_assembled |
1360 | end_data: |
1360 | end_data: |
1361 | cmp [output_format],3 |
1361 | cmp [output_format],3 |
1362 | jne illegal_instruction |
1362 | jne illegal_instruction |
1363 | call find_structure_data |
1363 | call find_structure_data |
1364 | jc unexpected_instruction |
1364 | jc unexpected_instruction |
1365 | movzx eax,byte [ebx+2] |
1365 | movzx eax,byte [ebx+2] |
1366 | mov edx,[current_section] |
1366 | mov edx,[current_section] |
1367 | mov ecx,edi |
1367 | mov ecx,edi |
1368 | sub ecx,[edx+14h] |
1368 | sub ecx,[edx+14h] |
1369 | add ecx,[edx+0Ch] |
1369 | add ecx,[edx+0Ch] |
1370 | mov edx,[code_start] |
1370 | mov edx,[code_start] |
1371 | test [format_flags],4 |
1371 | test [format_flags],4 |
1372 | jnz end_peplus_data |
1372 | jnz end_peplus_data |
1373 | sub ecx,[edx+78h+eax*8] |
1373 | sub ecx,[edx+78h+eax*8] |
1374 | mov [edx+78h+eax*8+4],ecx |
1374 | mov [edx+78h+eax*8+4],ecx |
1375 | jmp remove_structure_data |
1375 | jmp remove_structure_data |
1376 | end_peplus_data: |
1376 | end_peplus_data: |
1377 | sub ecx,[edx+88h+eax*8] |
1377 | sub ecx,[edx+88h+eax*8] |
1378 | mov [edx+88h+eax*8+4],ecx |
1378 | mov [edx+88h+eax*8+4],ecx |
1379 | jmp remove_structure_data |
1379 | jmp remove_structure_data |
1380 | pe_entry: |
1380 | pe_entry: |
1381 | lods byte [esi] |
1381 | lods byte [esi] |
1382 | cmp al,'(' |
1382 | cmp al,'(' |
1383 | jne invalid_argument |
1383 | jne invalid_argument |
1384 | cmp byte [esi],'.' |
1384 | cmp byte [esi],'.' |
1385 | je invalid_value |
1385 | je invalid_value |
1386 | test [format_flags],8 |
1386 | test [format_flags],8 |
1387 | jnz pe64_entry |
1387 | jnz pe64_entry |
1388 | call get_dword_value |
1388 | call get_dword_value |
1389 | mov bl,2 |
1389 | mov bl,2 |
1390 | bt [resolver_flags],0 |
1390 | bt [resolver_flags],0 |
1391 | jc check_pe_entry_label_type |
1391 | jc check_pe_entry_label_type |
1392 | xor bl,bl |
1392 | xor bl,bl |
1393 | check_pe_entry_label_type: |
1393 | check_pe_entry_label_type: |
1394 | cmp [value_type],bl |
1394 | cmp [value_type],bl |
1395 | je pe_entry_ok |
1395 | je pe_entry_ok |
1396 | call recoverable_invalid_address |
1396 | call recoverable_invalid_address |
1397 | pe_entry_ok: |
1397 | pe_entry_ok: |
1398 | cdq |
1398 | cdq |
1399 | test [format_flags],4 |
1399 | test [format_flags],4 |
1400 | jnz pe64_entry_type_ok |
1400 | jnz pe64_entry_type_ok |
1401 | mov edx,[code_start] |
1401 | mov edx,[code_start] |
1402 | sub eax,[edx+34h] |
1402 | sub eax,[edx+34h] |
1403 | mov [edx+28h],eax |
1403 | mov [edx+28h],eax |
1404 | jmp instruction_assembled |
1404 | jmp instruction_assembled |
1405 | pe64_entry: |
1405 | pe64_entry: |
1406 | call get_qword_value |
1406 | call get_qword_value |
1407 | mov bl,4 |
1407 | mov bl,4 |
1408 | bt [resolver_flags],0 |
1408 | bt [resolver_flags],0 |
1409 | jc check_pe64_entry_label_type |
1409 | jc check_pe64_entry_label_type |
1410 | xor bl,bl |
1410 | xor bl,bl |
1411 | check_pe64_entry_label_type: |
1411 | check_pe64_entry_label_type: |
1412 | cmp [value_type],bl |
1412 | cmp [value_type],bl |
1413 | je pe64_entry_type_ok |
1413 | je pe64_entry_type_ok |
1414 | call recoverable_invalid_address |
1414 | call recoverable_invalid_address |
1415 | pe64_entry_type_ok: |
1415 | pe64_entry_type_ok: |
1416 | mov ecx,[code_start] |
1416 | mov ecx,[code_start] |
1417 | sub eax,[ecx+30h] |
1417 | sub eax,[ecx+30h] |
1418 | sbb edx,[ecx+34h] |
1418 | sbb edx,[ecx+34h] |
1419 | jz pe64_entry_range_ok |
1419 | jz pe64_entry_range_ok |
1420 | call recoverable_overflow |
1420 | call recoverable_overflow |
1421 | pe64_entry_range_ok: |
1421 | pe64_entry_range_ok: |
1422 | mov [ecx+28h],eax |
1422 | mov [ecx+28h],eax |
1423 | jmp instruction_assembled |
1423 | jmp instruction_assembled |
1424 | pe_stack: |
1424 | pe_stack: |
1425 | lods byte [esi] |
1425 | lods byte [esi] |
1426 | cmp al,'(' |
1426 | cmp al,'(' |
1427 | jne invalid_argument |
1427 | jne invalid_argument |
1428 | cmp byte [esi],'.' |
1428 | cmp byte [esi],'.' |
1429 | je invalid_value |
1429 | je invalid_value |
1430 | test [format_flags],4 |
1430 | test [format_flags],4 |
1431 | jnz peplus_stack |
1431 | jnz peplus_stack |
1432 | call get_count_value |
1432 | call get_count_value |
1433 | mov edx,[code_start] |
1433 | mov edx,[code_start] |
1434 | mov [edx+60h],eax |
1434 | mov [edx+60h],eax |
1435 | cmp byte [esi],',' |
1435 | cmp byte [esi],',' |
1436 | jne default_stack_commit |
1436 | jne default_stack_commit |
1437 | lods byte [esi] |
1437 | lods byte [esi] |
1438 | lods byte [esi] |
1438 | lods byte [esi] |
1439 | cmp al,'(' |
1439 | cmp al,'(' |
1440 | jne invalid_argument |
1440 | jne invalid_argument |
1441 | cmp byte [esi],'.' |
1441 | cmp byte [esi],'.' |
1442 | je invalid_value |
1442 | je invalid_value |
1443 | call get_count_value |
1443 | call get_count_value |
1444 | mov edx,[code_start] |
1444 | mov edx,[code_start] |
1445 | mov [edx+64h],eax |
1445 | mov [edx+64h],eax |
1446 | cmp eax,[edx+60h] |
1446 | cmp eax,[edx+60h] |
1447 | ja value_out_of_range |
1447 | ja value_out_of_range |
1448 | jmp instruction_assembled |
1448 | jmp instruction_assembled |
1449 | default_stack_commit: |
1449 | default_stack_commit: |
1450 | mov dword [edx+64h],1000h |
1450 | mov dword [edx+64h],1000h |
1451 | mov eax,[edx+60h] |
1451 | mov eax,[edx+60h] |
1452 | cmp eax,1000h |
1452 | cmp eax,1000h |
1453 | ja instruction_assembled |
1453 | ja instruction_assembled |
1454 | mov dword [edx+64h],eax |
1454 | mov dword [edx+64h],eax |
1455 | jmp instruction_assembled |
1455 | jmp instruction_assembled |
1456 | peplus_stack: |
1456 | peplus_stack: |
1457 | call get_qword_value |
1457 | call get_qword_value |
1458 | cmp [value_type],0 |
1458 | cmp [value_type],0 |
1459 | jne invalid_use_of_symbol |
1459 | jne invalid_use_of_symbol |
1460 | mov ecx,[code_start] |
1460 | mov ecx,[code_start] |
1461 | mov [ecx+60h],eax |
1461 | mov [ecx+60h],eax |
1462 | mov [ecx+64h],edx |
1462 | mov [ecx+64h],edx |
1463 | cmp byte [esi],',' |
1463 | cmp byte [esi],',' |
1464 | jne default_peplus_stack_commit |
1464 | jne default_peplus_stack_commit |
1465 | lods byte [esi] |
1465 | lods byte [esi] |
1466 | lods byte [esi] |
1466 | lods byte [esi] |
1467 | cmp al,'(' |
1467 | cmp al,'(' |
1468 | jne invalid_argument |
1468 | jne invalid_argument |
1469 | cmp byte [esi],'.' |
1469 | cmp byte [esi],'.' |
1470 | je invalid_value |
1470 | je invalid_value |
1471 | call get_qword_value |
1471 | call get_qword_value |
1472 | cmp [value_type],0 |
1472 | cmp [value_type],0 |
1473 | jne invalid_use_of_symbol |
1473 | jne invalid_use_of_symbol |
1474 | mov ecx,[code_start] |
1474 | mov ecx,[code_start] |
1475 | mov [ecx+68h],eax |
1475 | mov [ecx+68h],eax |
1476 | mov [ecx+6Ch],edx |
1476 | mov [ecx+6Ch],edx |
1477 | cmp edx,[ecx+64h] |
1477 | cmp edx,[ecx+64h] |
1478 | ja value_out_of_range |
1478 | ja value_out_of_range |
1479 | jb instruction_assembled |
1479 | jb instruction_assembled |
1480 | cmp eax,[ecx+60h] |
1480 | cmp eax,[ecx+60h] |
1481 | ja value_out_of_range |
1481 | ja value_out_of_range |
1482 | jmp instruction_assembled |
1482 | jmp instruction_assembled |
1483 | default_peplus_stack_commit: |
1483 | default_peplus_stack_commit: |
1484 | mov dword [ecx+68h],1000h |
1484 | mov dword [ecx+68h],1000h |
1485 | cmp dword [ecx+64h],0 |
1485 | cmp dword [ecx+64h],0 |
1486 | jne instruction_assembled |
1486 | jne instruction_assembled |
1487 | mov eax,[ecx+60h] |
1487 | mov eax,[ecx+60h] |
1488 | cmp eax,1000h |
1488 | cmp eax,1000h |
1489 | ja instruction_assembled |
1489 | ja instruction_assembled |
1490 | mov dword [ecx+68h],eax |
1490 | mov dword [ecx+68h],eax |
1491 | jmp instruction_assembled |
1491 | jmp instruction_assembled |
1492 | pe_heap: |
1492 | pe_heap: |
1493 | lods byte [esi] |
1493 | lods byte [esi] |
1494 | cmp al,'(' |
1494 | cmp al,'(' |
1495 | jne invalid_argument |
1495 | jne invalid_argument |
1496 | cmp byte [esi],'.' |
1496 | cmp byte [esi],'.' |
1497 | je invalid_value |
1497 | je invalid_value |
1498 | test [format_flags],4 |
1498 | test [format_flags],4 |
1499 | jnz peplus_heap |
1499 | jnz peplus_heap |
1500 | call get_count_value |
1500 | call get_count_value |
1501 | mov edx,[code_start] |
1501 | mov edx,[code_start] |
1502 | mov [edx+68h],eax |
1502 | mov [edx+68h],eax |
1503 | cmp byte [esi],',' |
1503 | cmp byte [esi],',' |
1504 | jne instruction_assembled |
1504 | jne instruction_assembled |
1505 | lods byte [esi] |
1505 | lods byte [esi] |
1506 | lods byte [esi] |
1506 | lods byte [esi] |
1507 | cmp al,'(' |
1507 | cmp al,'(' |
1508 | jne invalid_argument |
1508 | jne invalid_argument |
1509 | cmp byte [esi],'.' |
1509 | cmp byte [esi],'.' |
1510 | je invalid_value |
1510 | je invalid_value |
1511 | call get_count_value |
1511 | call get_count_value |
1512 | mov edx,[code_start] |
1512 | mov edx,[code_start] |
1513 | mov [edx+6Ch],eax |
1513 | mov [edx+6Ch],eax |
1514 | cmp eax,[edx+68h] |
1514 | cmp eax,[edx+68h] |
1515 | ja value_out_of_range |
1515 | ja value_out_of_range |
1516 | jmp instruction_assembled |
1516 | jmp instruction_assembled |
1517 | peplus_heap: |
1517 | peplus_heap: |
1518 | call get_qword_value |
1518 | call get_qword_value |
1519 | cmp [value_type],0 |
1519 | cmp [value_type],0 |
1520 | jne invalid_use_of_symbol |
1520 | jne invalid_use_of_symbol |
1521 | mov ecx,[code_start] |
1521 | mov ecx,[code_start] |
1522 | mov [ecx+70h],eax |
1522 | mov [ecx+70h],eax |
1523 | mov [ecx+74h],edx |
1523 | mov [ecx+74h],edx |
1524 | cmp byte [esi],',' |
1524 | cmp byte [esi],',' |
1525 | jne instruction_assembled |
1525 | jne instruction_assembled |
1526 | lods byte [esi] |
1526 | lods byte [esi] |
1527 | lods byte [esi] |
1527 | lods byte [esi] |
1528 | cmp al,'(' |
1528 | cmp al,'(' |
1529 | jne invalid_argument |
1529 | jne invalid_argument |
1530 | cmp byte [esi],'.' |
1530 | cmp byte [esi],'.' |
1531 | je invalid_value |
1531 | je invalid_value |
1532 | call get_qword_value |
1532 | call get_qword_value |
1533 | cmp [value_type],0 |
1533 | cmp [value_type],0 |
1534 | jne invalid_use_of_symbol |
1534 | jne invalid_use_of_symbol |
1535 | mov ecx,[code_start] |
1535 | mov ecx,[code_start] |
1536 | mov [ecx+78h],eax |
1536 | mov [ecx+78h],eax |
1537 | mov [ecx+7Ch],edx |
1537 | mov [ecx+7Ch],edx |
1538 | cmp edx,[ecx+74h] |
1538 | cmp edx,[ecx+74h] |
1539 | ja value_out_of_range |
1539 | ja value_out_of_range |
1540 | jb instruction_assembled |
1540 | jb instruction_assembled |
1541 | cmp eax,[ecx+70h] |
1541 | cmp eax,[ecx+70h] |
1542 | ja value_out_of_range |
1542 | ja value_out_of_range |
1543 | jmp instruction_assembled |
1543 | jmp instruction_assembled |
1544 | mark_pe_relocation: |
1544 | mark_pe_relocation: |
1545 | push eax ebx |
1545 | push eax ebx |
1546 | test [format_flags],4 |
1546 | test [format_flags],4 |
1547 | jz check_standard_pe_relocation_type |
1547 | jz check_standard_pe_relocation_type |
1548 | cmp [value_type],4 |
1548 | cmp [value_type],4 |
1549 | je pe_relocation_type_ok |
1549 | je pe_relocation_type_ok |
1550 | check_standard_pe_relocation_type: |
1550 | check_standard_pe_relocation_type: |
1551 | cmp [value_type],2 |
1551 | cmp [value_type],2 |
1552 | je pe_relocation_type_ok |
1552 | je pe_relocation_type_ok |
1553 | call recoverable_misuse |
1553 | call recoverable_misuse |
1554 | pe_relocation_type_ok: |
1554 | pe_relocation_type_ok: |
1555 | mov ebx,[current_section] |
1555 | mov ebx,[current_section] |
1556 | mov eax,edi |
1556 | mov eax,edi |
1557 | sub eax,[ebx+14h] |
1557 | sub eax,[ebx+14h] |
1558 | add eax,[ebx+0Ch] |
1558 | add eax,[ebx+0Ch] |
1559 | mov ebx,[free_additional_memory] |
1559 | mov ebx,[free_additional_memory] |
1560 | inc [number_of_relocations] |
1560 | inc [number_of_relocations] |
1561 | add ebx,5 |
1561 | add ebx,5 |
1562 | cmp ebx,[structures_buffer] |
1562 | cmp ebx,[structures_buffer] |
1563 | jae out_of_memory |
1563 | jae out_of_memory |
1564 | mov [free_additional_memory],ebx |
1564 | mov [free_additional_memory],ebx |
1565 | mov [ebx-5],eax |
1565 | mov [ebx-5],eax |
1566 | cmp [value_type],2 |
1566 | cmp [value_type],2 |
1567 | je fixup_32bit |
1567 | je fixup_32bit |
1568 | mov byte [ebx-1],0Ah |
1568 | mov byte [ebx-1],0Ah |
1569 | jmp fixup_ok |
1569 | jmp fixup_ok |
1570 | fixup_32bit: |
1570 | fixup_32bit: |
1571 | mov byte [ebx-1],3 |
1571 | mov byte [ebx-1],3 |
1572 | fixup_ok: |
1572 | fixup_ok: |
1573 | pop ebx eax |
1573 | pop ebx eax |
1574 | ret |
1574 | ret |
1575 | generate_pe_data: |
1575 | generate_pe_data: |
1576 | cmp al,2 |
1576 | cmp al,2 |
1577 | je make_pe_resource |
1577 | je make_pe_resource |
1578 | cmp al,5 |
1578 | cmp al,5 |
1579 | je make_pe_fixups |
1579 | je make_pe_fixups |
1580 | ret |
1580 | ret |
1581 | make_pe_fixups: |
1581 | make_pe_fixups: |
1582 | mov edx,[code_start] |
1582 | mov edx,[code_start] |
1583 | and byte [edx+16h],not 1 |
1583 | and byte [edx+16h],not 1 |
1584 | or byte [edx+5Eh],40h |
1584 | or byte [edx+5Eh],40h |
1585 | bts [resolver_flags],0 |
1585 | bts [resolver_flags],0 |
1586 | jc fixups_ready |
1586 | jc fixups_ready |
1587 | or [next_pass_needed],-1 |
1587 | or [next_pass_needed],-1 |
1588 | fixups_ready: |
1588 | fixups_ready: |
1589 | and [last_fixup_base],0 |
1589 | and [last_fixup_base],0 |
1590 | call make_fixups |
1590 | call make_fixups |
1591 | xchg eax,[actual_fixups_size] |
1591 | xchg eax,[actual_fixups_size] |
1592 | sub eax,[actual_fixups_size] |
1592 | sub eax,[actual_fixups_size] |
1593 | ja reserve_forward_fixups |
1593 | ja reserve_forward_fixups |
1594 | xor eax,eax |
1594 | xor eax,eax |
1595 | reserve_forward_fixups: |
1595 | reserve_forward_fixups: |
1596 | mov [reserved_fixups],edi |
1596 | mov [reserved_fixups],edi |
1597 | add edi,eax |
1597 | add edi,eax |
1598 | mov [reserved_fixups_size],eax |
1598 | mov [reserved_fixups_size],eax |
1599 | ret |
1599 | ret |
1600 | make_fixups: |
1600 | make_fixups: |
1601 | push esi |
1601 | push esi |
1602 | xor ecx,ecx |
1602 | xor ecx,ecx |
1603 | xchg ecx,[number_of_relocations] |
1603 | xchg ecx,[number_of_relocations] |
1604 | mov esi,[free_additional_memory] |
1604 | mov esi,[free_additional_memory] |
1605 | lea eax,[ecx*5] |
1605 | lea eax,[ecx*5] |
1606 | sub esi,eax |
1606 | sub esi,eax |
1607 | mov [free_additional_memory],esi |
1607 | mov [free_additional_memory],esi |
1608 | mov edx,[last_fixup_base] |
1608 | mov edx,[last_fixup_base] |
1609 | mov ebx,[last_fixup_header] |
1609 | mov ebx,[last_fixup_header] |
1610 | mov ebp,edi |
1610 | mov ebp,edi |
1611 | jecxz fixups_done |
1611 | jecxz fixups_done |
1612 | make_fixup: |
1612 | make_fixup: |
1613 | cmp [esi],edx |
1613 | cmp [esi],edx |
1614 | jb store_fixup |
1614 | jb store_fixup |
1615 | mov eax,edi |
1615 | mov eax,edi |
1616 | sub eax,ebp |
1616 | sub eax,ebp |
1617 | test eax,11b |
1617 | test eax,11b |
1618 | jz fixups_block |
1618 | jz fixups_block |
1619 | xor ax,ax |
1619 | xor ax,ax |
1620 | stos word [edi] |
1620 | stos word [edi] |
1621 | add dword [ebx],2 |
1621 | add dword [ebx],2 |
1622 | fixups_block: |
1622 | fixups_block: |
1623 | mov eax,edx |
1623 | mov eax,edx |
1624 | add edx,1000h |
1624 | add edx,1000h |
1625 | cmp [esi],edx |
1625 | cmp [esi],edx |
1626 | jae fixups_block |
1626 | jae fixups_block |
1627 | stos dword [edi] |
1627 | stos dword [edi] |
1628 | mov ebx,edi |
1628 | mov ebx,edi |
1629 | mov eax,8 |
1629 | mov eax,8 |
1630 | stos dword [edi] |
1630 | stos dword [edi] |
1631 | store_fixup: |
1631 | store_fixup: |
1632 | add dword [ebx],2 |
1632 | add dword [ebx],2 |
1633 | mov ah,[esi+1] |
1633 | mov ah,[esi+1] |
1634 | and ah,0Fh |
1634 | and ah,0Fh |
1635 | mov al,[esi+4] |
1635 | mov al,[esi+4] |
1636 | shl al,4 |
1636 | shl al,4 |
1637 | or ah,al |
1637 | or ah,al |
1638 | mov al,[esi] |
1638 | mov al,[esi] |
1639 | stos word [edi] |
1639 | stos word [edi] |
1640 | add esi,5 |
1640 | add esi,5 |
1641 | loop make_fixup |
1641 | loop make_fixup |
1642 | fixups_done: |
1642 | fixups_done: |
1643 | mov [last_fixup_base],edx |
1643 | mov [last_fixup_base],edx |
1644 | mov [last_fixup_header],ebx |
1644 | mov [last_fixup_header],ebx |
1645 | pop esi |
1645 | pop esi |
1646 | mov eax,edi |
1646 | mov eax,edi |
1647 | sub eax,ebp |
1647 | sub eax,ebp |
1648 | ret |
1648 | ret |
1649 | make_pe_resource: |
1649 | make_pe_resource: |
1650 | cmp byte [esi],82h |
1650 | cmp byte [esi],82h |
1651 | jne resource_done |
1651 | jne resource_done |
1652 | inc esi |
1652 | inc esi |
1653 | lods word [esi] |
1653 | lods word [esi] |
1654 | cmp ax,'(' |
1654 | cmp ax,'(' |
1655 | jne invalid_argument |
1655 | jne invalid_argument |
1656 | lods dword [esi] |
1656 | lods dword [esi] |
1657 | mov edx,esi |
1657 | mov edx,esi |
1658 | lea esi,[esi+eax+1] |
1658 | lea esi,[esi+eax+1] |
1659 | cmp [next_pass_needed],0 |
1659 | cmp [next_pass_needed],0 |
1660 | je resource_from_file |
1660 | je resource_from_file |
1661 | cmp [current_pass],0 |
1661 | cmp [current_pass],0 |
1662 | jne reserve_space_for_resource |
1662 | jne reserve_space_for_resource |
1663 | and [resource_size],0 |
1663 | and [resource_size],0 |
1664 | reserve_space_for_resource: |
1664 | reserve_space_for_resource: |
1665 | add edi,[resource_size] |
1665 | add edi,[resource_size] |
1666 | cmp edi,[tagged_blocks] |
1666 | cmp edi,[tagged_blocks] |
1667 | ja out_of_memory |
1667 | ja out_of_memory |
1668 | jmp resource_done |
1668 | jmp resource_done |
1669 | resource_from_file: |
1669 | resource_from_file: |
1670 | push esi |
1670 | push esi |
1671 | mov esi,edx |
1671 | mov esi,edx |
1672 | call open_binary_file |
1672 | call open_binary_file |
1673 | push ebx |
1673 | push ebx |
1674 | mov esi,[free_additional_memory] |
1674 | mov esi,[free_additional_memory] |
1675 | lea eax,[esi+20h] |
1675 | lea eax,[esi+20h] |
1676 | cmp eax,[structures_buffer] |
1676 | cmp eax,[structures_buffer] |
1677 | ja out_of_memory |
1677 | ja out_of_memory |
1678 | mov edx,esi |
1678 | mov edx,esi |
1679 | mov ecx,20h |
1679 | mov ecx,20h |
1680 | call read |
1680 | call read |
1681 | jc invalid_file_format |
1681 | jc invalid_file_format |
1682 | xor eax,eax |
1682 | xor eax,eax |
1683 | cmp [esi],eax |
1683 | cmp [esi],eax |
1684 | jne invalid_file_format |
1684 | jne invalid_file_format |
1685 | mov ax,0FFFFh |
1685 | mov ax,0FFFFh |
1686 | cmp [esi+8],eax |
1686 | cmp [esi+8],eax |
1687 | jne invalid_file_format |
1687 | jne invalid_file_format |
1688 | cmp [esi+12],eax |
1688 | cmp [esi+12],eax |
1689 | jne invalid_file_format |
1689 | jne invalid_file_format |
1690 | mov eax,20h |
1690 | mov eax,20h |
1691 | cmp [esi+4],eax |
1691 | cmp [esi+4],eax |
1692 | jne invalid_file_format |
1692 | jne invalid_file_format |
1693 | read_resource_headers: |
1693 | read_resource_headers: |
1694 | test eax,11b |
1694 | test eax,11b |
1695 | jz resource_file_alignment_ok |
1695 | jz resource_file_alignment_ok |
1696 | mov edx,4 |
1696 | mov edx,4 |
1697 | and eax,11b |
1697 | and eax,11b |
1698 | sub edx,eax |
1698 | sub edx,eax |
1699 | mov al,1 |
1699 | mov al,1 |
1700 | call lseek |
1700 | call lseek |
1701 | jc resource_headers_ok |
1701 | jc resource_headers_ok |
1702 | resource_file_alignment_ok: |
1702 | resource_file_alignment_ok: |
1703 | mov [esi],eax |
1703 | mov [esi],eax |
1704 | lea edx,[esi+12] |
1704 | lea edx,[esi+12] |
1705 | mov ecx,8 |
1705 | mov ecx,8 |
1706 | call read |
1706 | call read |
1707 | jc resource_headers_ok |
1707 | jc resource_headers_ok |
1708 | mov ecx,[esi+16] |
1708 | mov ecx,[esi+16] |
1709 | add [esi],ecx |
1709 | add [esi],ecx |
1710 | lea edx,[esi+20] |
1710 | lea edx,[esi+20] |
1711 | sub ecx,8 |
1711 | sub ecx,8 |
1712 | mov [esi+16],ecx |
1712 | mov [esi+16],ecx |
1713 | lea eax,[edx+ecx] |
1713 | lea eax,[edx+ecx] |
1714 | cmp eax,[structures_buffer] |
1714 | cmp eax,[structures_buffer] |
1715 | ja out_of_memory |
1715 | ja out_of_memory |
1716 | call read |
1716 | call read |
1717 | jc invalid_file_format |
1717 | jc invalid_file_format |
1718 | mov edx,[esi] |
1718 | mov edx,[esi] |
1719 | add edx,[esi+12] |
1719 | add edx,[esi+12] |
1720 | mov eax,[esi+16] |
1720 | mov eax,[esi+16] |
1721 | lea ecx,[esi+20] |
1721 | lea ecx,[esi+20] |
1722 | lea esi,[ecx+eax] |
1722 | lea esi,[ecx+eax] |
1723 | add ecx,2 |
1723 | add ecx,2 |
1724 | cmp word [ecx-2],0FFFFh |
1724 | cmp word [ecx-2],0FFFFh |
1725 | je resource_header_type_ok |
1725 | je resource_header_type_ok |
1726 | check_resource_header_type: |
1726 | check_resource_header_type: |
1727 | cmp ecx,esi |
1727 | cmp ecx,esi |
1728 | jae invalid_file_format |
1728 | jae invalid_file_format |
1729 | cmp word [ecx],0 |
1729 | cmp word [ecx],0 |
1730 | je resource_header_type_ok |
1730 | je resource_header_type_ok |
1731 | add ecx,2 |
1731 | add ecx,2 |
1732 | jmp check_resource_header_type |
1732 | jmp check_resource_header_type |
1733 | resource_header_type_ok: |
1733 | resource_header_type_ok: |
1734 | add ecx,2 |
1734 | add ecx,2 |
1735 | cmp word [ecx],0FFFFh |
1735 | cmp word [ecx],0FFFFh |
1736 | je resource_header_name_ok |
1736 | je resource_header_name_ok |
1737 | check_resource_header_name: |
1737 | check_resource_header_name: |
1738 | cmp ecx,esi |
1738 | cmp ecx,esi |
1739 | jae invalid_file_format |
1739 | jae invalid_file_format |
1740 | cmp word [ecx],0 |
1740 | cmp word [ecx],0 |
1741 | je resource_header_name_ok |
1741 | je resource_header_name_ok |
1742 | add ecx,2 |
1742 | add ecx,2 |
1743 | jmp check_resource_header_name |
1743 | jmp check_resource_header_name |
1744 | resource_header_name_ok: |
1744 | resource_header_name_ok: |
1745 | xor al,al |
1745 | xor al,al |
1746 | call lseek |
1746 | call lseek |
1747 | jnc read_resource_headers |
1747 | jnc read_resource_headers |
1748 | resource_headers_ok: |
1748 | resource_headers_ok: |
1749 | cmp esi,[free_additional_memory] |
1749 | cmp esi,[free_additional_memory] |
1750 | je invalid_file_format |
1750 | je invalid_file_format |
1751 | xor eax,eax |
1751 | xor eax,eax |
1752 | mov [esi],eax |
1752 | mov [esi],eax |
1753 | mov [resource_data],edi |
1753 | mov [resource_data],edi |
1754 | lea eax,[edi+16] |
1754 | lea eax,[edi+16] |
1755 | cmp eax,[tagged_blocks] |
1755 | cmp eax,[tagged_blocks] |
1756 | jae out_of_memory |
1756 | jae out_of_memory |
1757 | xor eax,eax |
1757 | xor eax,eax |
1758 | stos dword [edi] |
1758 | stos dword [edi] |
1759 | call make_timestamp |
1759 | call make_timestamp |
1760 | stos dword [edi] |
1760 | stos dword [edi] |
1761 | xor eax,eax |
1761 | xor eax,eax |
1762 | stos dword [edi] |
1762 | stos dword [edi] |
1763 | stos dword [edi] |
1763 | stos dword [edi] |
1764 | xor ebx,ebx |
1764 | xor ebx,ebx |
1765 | make_type_name_directory: |
1765 | make_type_name_directory: |
1766 | mov esi,[free_additional_memory] |
1766 | mov esi,[free_additional_memory] |
1767 | xor edx,edx |
1767 | xor edx,edx |
1768 | find_type_name: |
1768 | find_type_name: |
1769 | cmp dword [esi],0 |
1769 | cmp dword [esi],0 |
1770 | je type_name_ok |
1770 | je type_name_ok |
1771 | add esi,20 |
1771 | add esi,20 |
1772 | cmp word [esi],0FFFFh |
1772 | cmp word [esi],0FFFFh |
1773 | je check_next_type_name |
1773 | je check_next_type_name |
1774 | or ebx,ebx |
1774 | or ebx,ebx |
1775 | jz check_this_type_name |
1775 | jz check_this_type_name |
1776 | xor ecx,ecx |
1776 | xor ecx,ecx |
1777 | compare_with_previous_type_name: |
1777 | compare_with_previous_type_name: |
1778 | mov ax,[esi+ecx] |
1778 | mov ax,[esi+ecx] |
1779 | cmp ax,[ebx+ecx] |
1779 | cmp ax,[ebx+ecx] |
1780 | ja check_this_type_name |
1780 | ja check_this_type_name |
1781 | jb check_next_type_name |
1781 | jb check_next_type_name |
1782 | add ecx,2 |
1782 | add ecx,2 |
1783 | mov ax,[esi+ecx] |
1783 | mov ax,[esi+ecx] |
1784 | or ax,[ebx+ecx] |
1784 | or ax,[ebx+ecx] |
1785 | jnz compare_with_previous_type_name |
1785 | jnz compare_with_previous_type_name |
1786 | jmp check_next_type_name |
1786 | jmp check_next_type_name |
1787 | check_this_type_name: |
1787 | check_this_type_name: |
1788 | or edx,edx |
1788 | or edx,edx |
1789 | jz type_name_found |
1789 | jz type_name_found |
1790 | xor ecx,ecx |
1790 | xor ecx,ecx |
1791 | compare_with_current_type_name: |
1791 | compare_with_current_type_name: |
1792 | mov ax,[esi+ecx] |
1792 | mov ax,[esi+ecx] |
1793 | cmp ax,[edx+ecx] |
1793 | cmp ax,[edx+ecx] |
1794 | ja check_next_type_name |
1794 | ja check_next_type_name |
1795 | jb type_name_found |
1795 | jb type_name_found |
1796 | add ecx,2 |
1796 | add ecx,2 |
1797 | mov ax,[esi+ecx] |
1797 | mov ax,[esi+ecx] |
1798 | or ax,[edx+ecx] |
1798 | or ax,[edx+ecx] |
1799 | jnz compare_with_current_type_name |
1799 | jnz compare_with_current_type_name |
1800 | jmp same_type_name |
1800 | jmp same_type_name |
1801 | type_name_found: |
1801 | type_name_found: |
1802 | mov edx,esi |
1802 | mov edx,esi |
1803 | same_type_name: |
1803 | same_type_name: |
1804 | mov [esi-16],edi |
1804 | mov [esi-16],edi |
1805 | check_next_type_name: |
1805 | check_next_type_name: |
1806 | mov eax,[esi-4] |
1806 | mov eax,[esi-4] |
1807 | add esi,eax |
1807 | add esi,eax |
1808 | jmp find_type_name |
1808 | jmp find_type_name |
1809 | type_name_ok: |
1809 | type_name_ok: |
1810 | or edx,edx |
1810 | or edx,edx |
1811 | jz type_name_directory_done |
1811 | jz type_name_directory_done |
1812 | mov ebx,edx |
1812 | mov ebx,edx |
1813 | make_type_name_entry: |
1813 | make_type_name_entry: |
1814 | mov eax,[resource_data] |
1814 | mov eax,[resource_data] |
1815 | inc word [eax+12] |
1815 | inc word [eax+12] |
1816 | lea eax,[edi+8] |
1816 | lea eax,[edi+8] |
1817 | cmp eax,[tagged_blocks] |
1817 | cmp eax,[tagged_blocks] |
1818 | jae out_of_memory |
1818 | jae out_of_memory |
1819 | mov eax,ebx |
1819 | mov eax,ebx |
1820 | stos dword [edi] |
1820 | stos dword [edi] |
1821 | xor eax,eax |
1821 | xor eax,eax |
1822 | stos dword [edi] |
1822 | stos dword [edi] |
1823 | jmp make_type_name_directory |
1823 | jmp make_type_name_directory |
1824 | type_name_directory_done: |
1824 | type_name_directory_done: |
1825 | mov ebx,-1 |
1825 | mov ebx,-1 |
1826 | make_type_id_directory: |
1826 | make_type_id_directory: |
1827 | mov esi,[free_additional_memory] |
1827 | mov esi,[free_additional_memory] |
1828 | mov edx,10000h |
1828 | mov edx,10000h |
1829 | find_type_id: |
1829 | find_type_id: |
1830 | cmp dword [esi],0 |
1830 | cmp dword [esi],0 |
1831 | je type_id_ok |
1831 | je type_id_ok |
1832 | add esi,20 |
1832 | add esi,20 |
1833 | cmp word [esi],0FFFFh |
1833 | cmp word [esi],0FFFFh |
1834 | jne check_next_type_id |
1834 | jne check_next_type_id |
1835 | movzx eax,word [esi+2] |
1835 | movzx eax,word [esi+2] |
1836 | cmp eax,ebx |
1836 | cmp eax,ebx |
1837 | jle check_next_type_id |
1837 | jle check_next_type_id |
1838 | cmp eax,edx |
1838 | cmp eax,edx |
1839 | jg check_next_type_id |
1839 | jg check_next_type_id |
1840 | mov edx,eax |
1840 | mov edx,eax |
1841 | mov [esi-16],edi |
1841 | mov [esi-16],edi |
1842 | check_next_type_id: |
1842 | check_next_type_id: |
1843 | mov eax,[esi-4] |
1843 | mov eax,[esi-4] |
1844 | add esi,eax |
1844 | add esi,eax |
1845 | jmp find_type_id |
1845 | jmp find_type_id |
1846 | type_id_ok: |
1846 | type_id_ok: |
1847 | cmp edx,10000h |
1847 | cmp edx,10000h |
1848 | je type_id_directory_done |
1848 | je type_id_directory_done |
1849 | mov ebx,edx |
1849 | mov ebx,edx |
1850 | make_type_id_entry: |
1850 | make_type_id_entry: |
1851 | mov eax,[resource_data] |
1851 | mov eax,[resource_data] |
1852 | inc word [eax+14] |
1852 | inc word [eax+14] |
1853 | lea eax,[edi+8] |
1853 | lea eax,[edi+8] |
1854 | cmp eax,[tagged_blocks] |
1854 | cmp eax,[tagged_blocks] |
1855 | jae out_of_memory |
1855 | jae out_of_memory |
1856 | mov eax,ebx |
1856 | mov eax,ebx |
1857 | stos dword [edi] |
1857 | stos dword [edi] |
1858 | xor eax,eax |
1858 | xor eax,eax |
1859 | stos dword [edi] |
1859 | stos dword [edi] |
1860 | jmp make_type_id_directory |
1860 | jmp make_type_id_directory |
1861 | type_id_directory_done: |
1861 | type_id_directory_done: |
1862 | mov esi,[resource_data] |
1862 | mov esi,[resource_data] |
1863 | add esi,10h |
1863 | add esi,10h |
1864 | mov ecx,[esi-4] |
1864 | mov ecx,[esi-4] |
1865 | or cx,cx |
1865 | or cx,cx |
1866 | jz resource_directories_ok |
1866 | jz resource_directories_ok |
1867 | make_resource_directories: |
1867 | make_resource_directories: |
1868 | push ecx |
1868 | push ecx |
1869 | push edi |
1869 | push edi |
1870 | mov edx,edi |
1870 | mov edx,edi |
1871 | sub edx,[resource_data] |
1871 | sub edx,[resource_data] |
1872 | bts edx,31 |
1872 | bts edx,31 |
1873 | mov [esi+4],edx |
1873 | mov [esi+4],edx |
1874 | lea eax,[edi+16] |
1874 | lea eax,[edi+16] |
1875 | cmp eax,[tagged_blocks] |
1875 | cmp eax,[tagged_blocks] |
1876 | jae out_of_memory |
1876 | jae out_of_memory |
1877 | xor eax,eax |
1877 | xor eax,eax |
1878 | stos dword [edi] |
1878 | stos dword [edi] |
1879 | call make_timestamp |
1879 | call make_timestamp |
1880 | stos dword [edi] |
1880 | stos dword [edi] |
1881 | xor eax,eax |
1881 | xor eax,eax |
1882 | stos dword [edi] |
1882 | stos dword [edi] |
1883 | stos dword [edi] |
1883 | stos dword [edi] |
1884 | mov ebp,esi |
1884 | mov ebp,esi |
1885 | xor ebx,ebx |
1885 | xor ebx,ebx |
1886 | make_resource_name_directory: |
1886 | make_resource_name_directory: |
1887 | mov esi,[free_additional_memory] |
1887 | mov esi,[free_additional_memory] |
1888 | xor edx,edx |
1888 | xor edx,edx |
1889 | find_resource_name: |
1889 | find_resource_name: |
1890 | cmp dword [esi],0 |
1890 | cmp dword [esi],0 |
1891 | je resource_name_ok |
1891 | je resource_name_ok |
1892 | push esi |
1892 | push esi |
1893 | cmp [esi+4],ebp |
1893 | cmp [esi+4],ebp |
1894 | jne check_next_resource_name |
1894 | jne check_next_resource_name |
1895 | add esi,20 |
1895 | add esi,20 |
1896 | call skip_resource_name |
1896 | call skip_resource_name |
1897 | cmp word [esi],0FFFFh |
1897 | cmp word [esi],0FFFFh |
1898 | je check_next_resource_name |
1898 | je check_next_resource_name |
1899 | or ebx,ebx |
1899 | or ebx,ebx |
1900 | jz check_this_resource_name |
1900 | jz check_this_resource_name |
1901 | xor ecx,ecx |
1901 | xor ecx,ecx |
1902 | compare_with_previous_resource_name: |
1902 | compare_with_previous_resource_name: |
1903 | mov ax,[esi+ecx] |
1903 | mov ax,[esi+ecx] |
1904 | cmp ax,[ebx+ecx] |
1904 | cmp ax,[ebx+ecx] |
1905 | ja check_this_resource_name |
1905 | ja check_this_resource_name |
1906 | jb check_next_resource_name |
1906 | jb check_next_resource_name |
1907 | add ecx,2 |
1907 | add ecx,2 |
1908 | mov ax,[esi+ecx] |
1908 | mov ax,[esi+ecx] |
1909 | or ax,[ebx+ecx] |
1909 | or ax,[ebx+ecx] |
1910 | jnz compare_with_previous_resource_name |
1910 | jnz compare_with_previous_resource_name |
1911 | jmp check_next_resource_name |
1911 | jmp check_next_resource_name |
1912 | skip_resource_name: |
1912 | skip_resource_name: |
1913 | cmp word [esi],0FFFFh |
1913 | cmp word [esi],0FFFFh |
1914 | jne skip_unicode_string |
1914 | jne skip_unicode_string |
1915 | add esi,4 |
1915 | add esi,4 |
1916 | ret |
1916 | ret |
1917 | skip_unicode_string: |
1917 | skip_unicode_string: |
1918 | add esi,2 |
1918 | add esi,2 |
1919 | cmp word [esi-2],0 |
1919 | cmp word [esi-2],0 |
1920 | jne skip_unicode_string |
1920 | jne skip_unicode_string |
1921 | ret |
1921 | ret |
1922 | check_this_resource_name: |
1922 | check_this_resource_name: |
1923 | or edx,edx |
1923 | or edx,edx |
1924 | jz resource_name_found |
1924 | jz resource_name_found |
1925 | xor ecx,ecx |
1925 | xor ecx,ecx |
1926 | compare_with_current_resource_name: |
1926 | compare_with_current_resource_name: |
1927 | mov ax,[esi+ecx] |
1927 | mov ax,[esi+ecx] |
1928 | cmp ax,[edx+ecx] |
1928 | cmp ax,[edx+ecx] |
1929 | ja check_next_resource_name |
1929 | ja check_next_resource_name |
1930 | jb resource_name_found |
1930 | jb resource_name_found |
1931 | add ecx,2 |
1931 | add ecx,2 |
1932 | mov ax,[esi+ecx] |
1932 | mov ax,[esi+ecx] |
1933 | or ax,[edx+ecx] |
1933 | or ax,[edx+ecx] |
1934 | jnz compare_with_current_resource_name |
1934 | jnz compare_with_current_resource_name |
1935 | jmp same_resource_name |
1935 | jmp same_resource_name |
1936 | resource_name_found: |
1936 | resource_name_found: |
1937 | mov edx,esi |
1937 | mov edx,esi |
1938 | same_resource_name: |
1938 | same_resource_name: |
1939 | mov eax,[esp] |
1939 | mov eax,[esp] |
1940 | mov [eax+8],edi |
1940 | mov [eax+8],edi |
1941 | check_next_resource_name: |
1941 | check_next_resource_name: |
1942 | pop esi |
1942 | pop esi |
1943 | mov eax,[esi+16] |
1943 | mov eax,[esi+16] |
1944 | lea esi,[esi+20+eax] |
1944 | lea esi,[esi+20+eax] |
1945 | jmp find_resource_name |
1945 | jmp find_resource_name |
1946 | resource_name_ok: |
1946 | resource_name_ok: |
1947 | or edx,edx |
1947 | or edx,edx |
1948 | jz resource_name_directory_done |
1948 | jz resource_name_directory_done |
1949 | mov ebx,edx |
1949 | mov ebx,edx |
1950 | make_resource_name_entry: |
1950 | make_resource_name_entry: |
1951 | mov eax,[esp] |
1951 | mov eax,[esp] |
1952 | inc word [eax+12] |
1952 | inc word [eax+12] |
1953 | lea eax,[edi+8] |
1953 | lea eax,[edi+8] |
1954 | cmp eax,[tagged_blocks] |
1954 | cmp eax,[tagged_blocks] |
1955 | jae out_of_memory |
1955 | jae out_of_memory |
1956 | mov eax,ebx |
1956 | mov eax,ebx |
1957 | stos dword [edi] |
1957 | stos dword [edi] |
1958 | xor eax,eax |
1958 | xor eax,eax |
1959 | stos dword [edi] |
1959 | stos dword [edi] |
1960 | jmp make_resource_name_directory |
1960 | jmp make_resource_name_directory |
1961 | resource_name_directory_done: |
1961 | resource_name_directory_done: |
1962 | mov ebx,-1 |
1962 | mov ebx,-1 |
1963 | make_resource_id_directory: |
1963 | make_resource_id_directory: |
1964 | mov esi,[free_additional_memory] |
1964 | mov esi,[free_additional_memory] |
1965 | mov edx,10000h |
1965 | mov edx,10000h |
1966 | find_resource_id: |
1966 | find_resource_id: |
1967 | cmp dword [esi],0 |
1967 | cmp dword [esi],0 |
1968 | je resource_id_ok |
1968 | je resource_id_ok |
1969 | push esi |
1969 | push esi |
1970 | cmp [esi+4],ebp |
1970 | cmp [esi+4],ebp |
1971 | jne check_next_resource_id |
1971 | jne check_next_resource_id |
1972 | add esi,20 |
1972 | add esi,20 |
1973 | call skip_resource_name |
1973 | call skip_resource_name |
1974 | cmp word [esi],0FFFFh |
1974 | cmp word [esi],0FFFFh |
1975 | jne check_next_resource_id |
1975 | jne check_next_resource_id |
1976 | movzx eax,word [esi+2] |
1976 | movzx eax,word [esi+2] |
1977 | cmp eax,ebx |
1977 | cmp eax,ebx |
1978 | jle check_next_resource_id |
1978 | jle check_next_resource_id |
1979 | cmp eax,edx |
1979 | cmp eax,edx |
1980 | jg check_next_resource_id |
1980 | jg check_next_resource_id |
1981 | mov edx,eax |
1981 | mov edx,eax |
1982 | mov eax,[esp] |
1982 | mov eax,[esp] |
1983 | mov [eax+8],edi |
1983 | mov [eax+8],edi |
1984 | check_next_resource_id: |
1984 | check_next_resource_id: |
1985 | pop esi |
1985 | pop esi |
1986 | mov eax,[esi+16] |
1986 | mov eax,[esi+16] |
1987 | lea esi,[esi+20+eax] |
1987 | lea esi,[esi+20+eax] |
1988 | jmp find_resource_id |
1988 | jmp find_resource_id |
1989 | resource_id_ok: |
1989 | resource_id_ok: |
1990 | cmp edx,10000h |
1990 | cmp edx,10000h |
1991 | je resource_id_directory_done |
1991 | je resource_id_directory_done |
1992 | mov ebx,edx |
1992 | mov ebx,edx |
1993 | make_resource_id_entry: |
1993 | make_resource_id_entry: |
1994 | mov eax,[esp] |
1994 | mov eax,[esp] |
1995 | inc word [eax+14] |
1995 | inc word [eax+14] |
1996 | lea eax,[edi+8] |
1996 | lea eax,[edi+8] |
1997 | cmp eax,[tagged_blocks] |
1997 | cmp eax,[tagged_blocks] |
1998 | jae out_of_memory |
1998 | jae out_of_memory |
1999 | mov eax,ebx |
1999 | mov eax,ebx |
2000 | stos dword [edi] |
2000 | stos dword [edi] |
2001 | xor eax,eax |
2001 | xor eax,eax |
2002 | stos dword [edi] |
2002 | stos dword [edi] |
2003 | jmp make_resource_id_directory |
2003 | jmp make_resource_id_directory |
2004 | resource_id_directory_done: |
2004 | resource_id_directory_done: |
2005 | pop eax |
2005 | pop eax |
2006 | mov esi,ebp |
2006 | mov esi,ebp |
2007 | pop ecx |
2007 | pop ecx |
2008 | add esi,8 |
2008 | add esi,8 |
2009 | dec cx |
2009 | dec cx |
2010 | jnz make_resource_directories |
2010 | jnz make_resource_directories |
2011 | resource_directories_ok: |
2011 | resource_directories_ok: |
2012 | shr ecx,16 |
2012 | shr ecx,16 |
2013 | jnz make_resource_directories |
2013 | jnz make_resource_directories |
2014 | mov esi,[resource_data] |
2014 | mov esi,[resource_data] |
2015 | add esi,10h |
2015 | add esi,10h |
2016 | movzx eax,word [esi-4] |
2016 | movzx eax,word [esi-4] |
2017 | movzx edx,word [esi-2] |
2017 | movzx edx,word [esi-2] |
2018 | add eax,edx |
2018 | add eax,edx |
2019 | lea esi,[esi+eax*8] |
2019 | lea esi,[esi+eax*8] |
2020 | push edi ; address of language directories |
2020 | push edi ; address of language directories |
2021 | update_resource_directories: |
2021 | update_resource_directories: |
2022 | cmp esi,[esp] |
2022 | cmp esi,[esp] |
2023 | je resource_directories_updated |
2023 | je resource_directories_updated |
2024 | add esi,10h |
2024 | add esi,10h |
2025 | mov ecx,[esi-4] |
2025 | mov ecx,[esi-4] |
2026 | or cx,cx |
2026 | or cx,cx |
2027 | jz language_directories_ok |
2027 | jz language_directories_ok |
2028 | make_language_directories: |
2028 | make_language_directories: |
2029 | push ecx |
2029 | push ecx |
2030 | push edi |
2030 | push edi |
2031 | mov edx,edi |
2031 | mov edx,edi |
2032 | sub edx,[resource_data] |
2032 | sub edx,[resource_data] |
2033 | bts edx,31 |
2033 | bts edx,31 |
2034 | mov [esi+4],edx |
2034 | mov [esi+4],edx |
2035 | lea eax,[edi+16] |
2035 | lea eax,[edi+16] |
2036 | cmp eax,[tagged_blocks] |
2036 | cmp eax,[tagged_blocks] |
2037 | jae out_of_memory |
2037 | jae out_of_memory |
2038 | xor eax,eax |
2038 | xor eax,eax |
2039 | stos dword [edi] |
2039 | stos dword [edi] |
2040 | call make_timestamp |
2040 | call make_timestamp |
2041 | stos dword [edi] |
2041 | stos dword [edi] |
2042 | xor eax,eax |
2042 | xor eax,eax |
2043 | stos dword [edi] |
2043 | stos dword [edi] |
2044 | stos dword [edi] |
2044 | stos dword [edi] |
2045 | mov ebp,esi |
2045 | mov ebp,esi |
2046 | mov ebx,-1 |
2046 | mov ebx,-1 |
2047 | make_language_id_directory: |
2047 | make_language_id_directory: |
2048 | mov esi,[free_additional_memory] |
2048 | mov esi,[free_additional_memory] |
2049 | mov edx,10000h |
2049 | mov edx,10000h |
2050 | find_language_id: |
2050 | find_language_id: |
2051 | cmp dword [esi],0 |
2051 | cmp dword [esi],0 |
2052 | je language_id_ok |
2052 | je language_id_ok |
2053 | push esi |
2053 | push esi |
2054 | cmp [esi+8],ebp |
2054 | cmp [esi+8],ebp |
2055 | jne check_next_language_id |
2055 | jne check_next_language_id |
2056 | add esi,20 |
2056 | add esi,20 |
2057 | mov eax,esi |
2057 | mov eax,esi |
2058 | call skip_resource_name |
2058 | call skip_resource_name |
2059 | call skip_resource_name |
2059 | call skip_resource_name |
2060 | neg eax |
2060 | neg eax |
2061 | add eax,esi |
2061 | add eax,esi |
2062 | and eax,11b |
2062 | and eax,11b |
2063 | add esi,eax |
2063 | add esi,eax |
2064 | get_language_id: |
2064 | get_language_id: |
2065 | movzx eax,word [esi+6] |
2065 | movzx eax,word [esi+6] |
2066 | cmp eax,ebx |
2066 | cmp eax,ebx |
2067 | jle check_next_language_id |
2067 | jle check_next_language_id |
2068 | cmp eax,edx |
2068 | cmp eax,edx |
2069 | jge check_next_language_id |
2069 | jge check_next_language_id |
2070 | mov edx,eax |
2070 | mov edx,eax |
2071 | mov eax,[esp] |
2071 | mov eax,[esp] |
2072 | mov dword [value],eax |
2072 | mov dword [value],eax |
2073 | check_next_language_id: |
2073 | check_next_language_id: |
2074 | pop esi |
2074 | pop esi |
2075 | mov eax,[esi+16] |
2075 | mov eax,[esi+16] |
2076 | lea esi,[esi+20+eax] |
2076 | lea esi,[esi+20+eax] |
2077 | jmp find_language_id |
2077 | jmp find_language_id |
2078 | language_id_ok: |
2078 | language_id_ok: |
2079 | cmp edx,10000h |
2079 | cmp edx,10000h |
2080 | je language_id_directory_done |
2080 | je language_id_directory_done |
2081 | mov ebx,edx |
2081 | mov ebx,edx |
2082 | make_language_id_entry: |
2082 | make_language_id_entry: |
2083 | mov eax,[esp] |
2083 | mov eax,[esp] |
2084 | inc word [eax+14] |
2084 | inc word [eax+14] |
2085 | lea eax,[edi+8] |
2085 | lea eax,[edi+8] |
2086 | cmp eax,[tagged_blocks] |
2086 | cmp eax,[tagged_blocks] |
2087 | jae out_of_memory |
2087 | jae out_of_memory |
2088 | mov eax,ebx |
2088 | mov eax,ebx |
2089 | stos dword [edi] |
2089 | stos dword [edi] |
2090 | mov eax,dword [value] |
2090 | mov eax,dword [value] |
2091 | stos dword [edi] |
2091 | stos dword [edi] |
2092 | jmp make_language_id_directory |
2092 | jmp make_language_id_directory |
2093 | language_id_directory_done: |
2093 | language_id_directory_done: |
2094 | pop eax |
2094 | pop eax |
2095 | mov esi,ebp |
2095 | mov esi,ebp |
2096 | pop ecx |
2096 | pop ecx |
2097 | add esi,8 |
2097 | add esi,8 |
2098 | dec cx |
2098 | dec cx |
2099 | jnz make_language_directories |
2099 | jnz make_language_directories |
2100 | language_directories_ok: |
2100 | language_directories_ok: |
2101 | shr ecx,16 |
2101 | shr ecx,16 |
2102 | jnz make_language_directories |
2102 | jnz make_language_directories |
2103 | jmp update_resource_directories |
2103 | jmp update_resource_directories |
2104 | resource_directories_updated: |
2104 | resource_directories_updated: |
2105 | mov esi,[resource_data] |
2105 | mov esi,[resource_data] |
2106 | push edi |
2106 | push edi |
2107 | make_name_strings: |
2107 | make_name_strings: |
2108 | add esi,10h |
2108 | add esi,10h |
2109 | movzx eax,word [esi-2] |
2109 | movzx eax,word [esi-2] |
2110 | movzx ecx,word [esi-4] |
2110 | movzx ecx,word [esi-4] |
2111 | add eax,ecx |
2111 | add eax,ecx |
2112 | lea eax,[esi+eax*8] |
2112 | lea eax,[esi+eax*8] |
2113 | push eax |
2113 | push eax |
2114 | or ecx,ecx |
2114 | or ecx,ecx |
2115 | jz string_entries_processed |
2115 | jz string_entries_processed |
2116 | process_string_entries: |
2116 | process_string_entries: |
2117 | push ecx |
2117 | push ecx |
2118 | mov edx,edi |
2118 | mov edx,edi |
2119 | sub edx,[resource_data] |
2119 | sub edx,[resource_data] |
2120 | bts edx,31 |
2120 | bts edx,31 |
2121 | xchg [esi],edx |
2121 | xchg [esi],edx |
2122 | mov ebx,edi |
2122 | mov ebx,edi |
2123 | xor ax,ax |
2123 | xor ax,ax |
2124 | stos word [edi] |
2124 | stos word [edi] |
2125 | copy_string_data: |
2125 | copy_string_data: |
2126 | lea eax,[edi+2] |
2126 | lea eax,[edi+2] |
2127 | cmp eax,[tagged_blocks] |
2127 | cmp eax,[tagged_blocks] |
2128 | jae out_of_memory |
2128 | jae out_of_memory |
2129 | mov ax,[edx] |
2129 | mov ax,[edx] |
2130 | or ax,ax |
2130 | or ax,ax |
2131 | jz string_data_copied |
2131 | jz string_data_copied |
2132 | stos word [edi] |
2132 | stos word [edi] |
2133 | inc word [ebx] |
2133 | inc word [ebx] |
2134 | add edx,2 |
2134 | add edx,2 |
2135 | jmp copy_string_data |
2135 | jmp copy_string_data |
2136 | string_data_copied: |
2136 | string_data_copied: |
2137 | add esi,8 |
2137 | add esi,8 |
2138 | pop ecx |
2138 | pop ecx |
2139 | loop process_string_entries |
2139 | loop process_string_entries |
2140 | string_entries_processed: |
2140 | string_entries_processed: |
2141 | pop esi |
2141 | pop esi |
2142 | cmp esi,[esp] |
2142 | cmp esi,[esp] |
2143 | jb make_name_strings |
2143 | jb make_name_strings |
2144 | mov eax,edi |
2144 | mov eax,edi |
2145 | sub eax,[resource_data] |
2145 | sub eax,[resource_data] |
2146 | test al,11b |
2146 | test al,11b |
2147 | jz resource_strings_alignment_ok |
2147 | jz resource_strings_alignment_ok |
2148 | xor ax,ax |
2148 | xor ax,ax |
2149 | stos word [edi] |
2149 | stos word [edi] |
2150 | resource_strings_alignment_ok: |
2150 | resource_strings_alignment_ok: |
2151 | pop edx |
2151 | pop edx |
2152 | pop ebx ; address of language directories |
2152 | pop ebx ; address of language directories |
2153 | mov ebp,edi |
2153 | mov ebp,edi |
2154 | update_language_directories: |
2154 | update_language_directories: |
2155 | add ebx,10h |
2155 | add ebx,10h |
2156 | movzx eax,word [ebx-2] |
2156 | movzx eax,word [ebx-2] |
2157 | movzx ecx,word [ebx-4] |
2157 | movzx ecx,word [ebx-4] |
2158 | add ecx,eax |
2158 | add ecx,eax |
2159 | make_data_records: |
2159 | make_data_records: |
2160 | push ecx |
2160 | push ecx |
2161 | mov esi,edi |
2161 | mov esi,edi |
2162 | sub esi,[resource_data] |
2162 | sub esi,[resource_data] |
2163 | xchg esi,[ebx+4] |
2163 | xchg esi,[ebx+4] |
2164 | lea eax,[edi+16] |
2164 | lea eax,[edi+16] |
2165 | cmp eax,[tagged_blocks] |
2165 | cmp eax,[tagged_blocks] |
2166 | jae out_of_memory |
2166 | jae out_of_memory |
2167 | mov eax,esi |
2167 | mov eax,esi |
2168 | stos dword [edi] |
2168 | stos dword [edi] |
2169 | mov eax,[esi+12] |
2169 | mov eax,[esi+12] |
2170 | stos dword [edi] |
2170 | stos dword [edi] |
2171 | xor eax,eax |
2171 | xor eax,eax |
2172 | stos dword [edi] |
2172 | stos dword [edi] |
2173 | stos dword [edi] |
2173 | stos dword [edi] |
2174 | pop ecx |
2174 | pop ecx |
2175 | add ebx,8 |
2175 | add ebx,8 |
2176 | loop make_data_records |
2176 | loop make_data_records |
2177 | cmp ebx,edx |
2177 | cmp ebx,edx |
2178 | jb update_language_directories |
2178 | jb update_language_directories |
2179 | pop ebx ; file handle |
2179 | pop ebx ; file handle |
2180 | mov esi,ebp |
2180 | mov esi,ebp |
2181 | mov ebp,edi |
2181 | mov ebp,edi |
2182 | update_data_records: |
2182 | update_data_records: |
2183 | push ebp |
2183 | push ebp |
2184 | mov ecx,edi |
2184 | mov ecx,edi |
2185 | mov eax,[current_section] |
2185 | mov eax,[current_section] |
2186 | sub ecx,[eax+14h] |
2186 | sub ecx,[eax+14h] |
2187 | add ecx,[eax+0Ch] |
2187 | add ecx,[eax+0Ch] |
2188 | xchg ecx,[esi] |
2188 | xchg ecx,[esi] |
2189 | mov edx,[ecx] |
2189 | mov edx,[ecx] |
2190 | xor al,al |
2190 | xor al,al |
2191 | call lseek |
2191 | call lseek |
2192 | mov edx,edi |
2192 | mov edx,edi |
2193 | mov ecx,[esi+4] |
2193 | mov ecx,[esi+4] |
2194 | add edi,ecx |
2194 | add edi,ecx |
2195 | cmp edi,[tagged_blocks] |
2195 | cmp edi,[tagged_blocks] |
2196 | ja out_of_memory |
2196 | ja out_of_memory |
2197 | call read |
2197 | call read |
2198 | mov eax,edi |
2198 | mov eax,edi |
2199 | sub eax,[resource_data] |
2199 | sub eax,[resource_data] |
2200 | and eax,11b |
2200 | and eax,11b |
2201 | jz resource_data_alignment_ok |
2201 | jz resource_data_alignment_ok |
2202 | mov ecx,4 |
2202 | mov ecx,4 |
2203 | sub ecx,eax |
2203 | sub ecx,eax |
2204 | xor al,al |
2204 | xor al,al |
2205 | rep stos byte [edi] |
2205 | rep stos byte [edi] |
2206 | resource_data_alignment_ok: |
2206 | resource_data_alignment_ok: |
2207 | pop ebp |
2207 | pop ebp |
2208 | add esi,16 |
2208 | add esi,16 |
2209 | cmp esi,ebp |
2209 | cmp esi,ebp |
2210 | jb update_data_records |
2210 | jb update_data_records |
2211 | pop esi |
2211 | pop esi |
2212 | call close |
2212 | call close |
2213 | mov eax,edi |
2213 | mov eax,edi |
2214 | sub eax,[resource_data] |
2214 | sub eax,[resource_data] |
2215 | mov [resource_size],eax |
2215 | mov [resource_size],eax |
2216 | resource_done: |
2216 | resource_done: |
2217 | ret |
2217 | ret |
2218 | close_pe: |
2218 | close_pe: |
2219 | call close_pe_section |
2219 | call close_pe_section |
2220 | mov edx,[code_start] |
2220 | mov edx,[code_start] |
2221 | mov [edx+50h],eax |
2221 | mov [edx+50h],eax |
2222 | call make_timestamp |
2222 | call make_timestamp |
2223 | mov edx,[code_start] |
2223 | mov edx,[code_start] |
2224 | mov [edx+8],eax |
2224 | mov [edx+8],eax |
2225 | mov eax,[number_of_sections] |
2225 | mov eax,[number_of_sections] |
2226 | mov [edx+6],ax |
2226 | mov [edx+6],ax |
2227 | imul eax,28h |
2227 | imul eax,28h |
2228 | movzx ecx,word [edx+14h] |
2228 | movzx ecx,word [edx+14h] |
2229 | lea eax,[eax+18h+ecx] |
2229 | lea eax,[eax+18h+ecx] |
2230 | add eax,[stub_size] |
2230 | add eax,[stub_size] |
2231 | mov ecx,[edx+3Ch] |
2231 | mov ecx,[edx+3Ch] |
2232 | dec ecx |
2232 | dec ecx |
2233 | add eax,ecx |
2233 | add eax,ecx |
2234 | not ecx |
2234 | not ecx |
2235 | and eax,ecx |
2235 | and eax,ecx |
2236 | cmp eax,[edx+54h] |
2236 | cmp eax,[edx+54h] |
2237 | je pe_sections_ok |
2237 | je pe_sections_ok |
2238 | or [next_pass_needed],-1 |
2238 | or [next_pass_needed],-1 |
2239 | pe_sections_ok: |
2239 | pe_sections_ok: |
2240 | xor ecx,ecx |
2240 | xor ecx,ecx |
2241 | add edx,78h |
2241 | add edx,78h |
2242 | test [format_flags],4 |
2242 | test [format_flags],4 |
2243 | jz process_directories |
2243 | jz process_directories |
2244 | add edx,10h |
2244 | add edx,10h |
2245 | process_directories: |
2245 | process_directories: |
2246 | mov eax,[edx+ecx*8] |
2246 | mov eax,[edx+ecx*8] |
2247 | or eax,eax |
2247 | or eax,eax |
2248 | jz directory_ok |
2248 | jz directory_ok |
2249 | cmp dword [edx+ecx*8+4],-1 |
2249 | cmp dword [edx+ecx*8+4],-1 |
2250 | jne directory_ok |
2250 | jne directory_ok |
2251 | section_data: |
2251 | section_data: |
2252 | mov ebx,[edx+ecx*8] |
2252 | mov ebx,[edx+ecx*8] |
2253 | mov eax,[ebx+0Ch] |
2253 | mov eax,[ebx+0Ch] |
2254 | mov [edx+ecx*8],eax ; directory rva |
2254 | mov [edx+ecx*8],eax ; directory rva |
2255 | mov eax,[ebx+8] |
2255 | mov eax,[ebx+8] |
2256 | mov [edx+ecx*8+4],eax ; directory size |
2256 | mov [edx+ecx*8+4],eax ; directory size |
2257 | directory_ok: |
2257 | directory_ok: |
2258 | inc cl |
2258 | inc cl |
2259 | cmp cl,10h |
2259 | cmp cl,10h |
2260 | jb process_directories |
2260 | jb process_directories |
2261 | cmp dword [edx+5*8],0 |
2261 | cmp dword [edx+5*8],0 |
2262 | jne finish_pe_relocations |
2262 | jne finish_pe_relocations |
2263 | mov eax,[number_of_relocations] |
2263 | mov eax,[number_of_relocations] |
2264 | shl eax,2 |
2264 | shl eax,2 |
2265 | sub [free_additional_memory],eax |
2265 | sub [free_additional_memory],eax |
2266 | btr [resolver_flags],0 |
2266 | btr [resolver_flags],0 |
2267 | jnc pe_relocations_ok |
2267 | jnc pe_relocations_ok |
2268 | or [next_pass_needed],-1 |
2268 | or [next_pass_needed],-1 |
2269 | jmp pe_relocations_ok |
2269 | jmp pe_relocations_ok |
2270 | finish_pe_relocations: |
2270 | finish_pe_relocations: |
2271 | push edi |
2271 | push edi |
2272 | mov edi,[reserved_fixups] |
2272 | mov edi,[reserved_fixups] |
2273 | call make_fixups |
2273 | call make_fixups |
2274 | pop edi |
2274 | pop edi |
2275 | add [actual_fixups_size],eax |
2275 | add [actual_fixups_size],eax |
2276 | cmp eax,[reserved_fixups_size] |
2276 | cmp eax,[reserved_fixups_size] |
2277 | je pe_relocations_ok |
2277 | je pe_relocations_ok |
2278 | or [next_pass_needed],-1 |
2278 | or [next_pass_needed],-1 |
2279 | pe_relocations_ok: |
2279 | pe_relocations_ok: |
2280 | mov ebx,[code_start] |
2280 | mov ebx,[code_start] |
2281 | sub ebx,[stub_size] |
2281 | sub ebx,[stub_size] |
2282 | mov ecx,edi |
2282 | mov ecx,edi |
2283 | sub ecx,ebx |
2283 | sub ecx,ebx |
2284 | mov ebp,ecx |
2284 | mov ebp,ecx |
2285 | shr ecx,1 |
2285 | shr ecx,1 |
2286 | xor eax,eax |
2286 | xor eax,eax |
2287 | cdq |
2287 | cdq |
2288 | calculate_checksum: |
2288 | calculate_checksum: |
2289 | mov dx,[ebx] |
2289 | mov dx,[ebx] |
2290 | add eax,edx |
2290 | add eax,edx |
2291 | mov dx,ax |
2291 | mov dx,ax |
2292 | shr eax,16 |
2292 | shr eax,16 |
2293 | add eax,edx |
2293 | add eax,edx |
2294 | add ebx,2 |
2294 | add ebx,2 |
2295 | loop calculate_checksum |
2295 | loop calculate_checksum |
2296 | add eax,ebp |
2296 | add eax,ebp |
2297 | mov ebx,[code_start] |
2297 | mov ebx,[code_start] |
2298 | mov [ebx+58h],eax |
2298 | mov [ebx+58h],eax |
2299 | ret |
2299 | ret |
2300 | 2300 | ||
2301 | format_coff: |
2301 | format_coff: |
2302 | mov eax,[additional_memory] |
2302 | mov eax,[additional_memory] |
2303 | mov [symbols_stream],eax |
2303 | mov [symbols_stream],eax |
2304 | mov ebx,eax |
2304 | mov ebx,eax |
2305 | add eax,20h |
2305 | add eax,20h |
2306 | cmp eax,[structures_buffer] |
2306 | cmp eax,[structures_buffer] |
2307 | jae out_of_memory |
2307 | jae out_of_memory |
2308 | mov [free_additional_memory],eax |
2308 | mov [free_additional_memory],eax |
2309 | xor eax,eax |
2309 | xor eax,eax |
2310 | mov [ebx],al |
2310 | mov [ebx],al |
2311 | mov [ebx+4],eax |
2311 | mov [ebx+4],eax |
2312 | mov [ebx+8],edi |
2312 | mov [ebx+8],edi |
2313 | mov al,4 |
2313 | mov al,4 |
2314 | mov [ebx+10h],eax |
2314 | mov [ebx+10h],eax |
2315 | mov al,60h |
2315 | mov al,60h |
2316 | bt [format_flags],0 |
2316 | bt [format_flags],0 |
2317 | jnc flat_section_flags_ok |
2317 | jnc flat_section_flags_ok |
2318 | or eax,0E0000000h |
2318 | or eax,0E0000000h |
2319 | flat_section_flags_ok: |
2319 | flat_section_flags_ok: |
2320 | mov dword [ebx+14h],eax |
2320 | mov dword [ebx+14h],eax |
2321 | mov [current_section],ebx |
2321 | mov [current_section],ebx |
2322 | xor eax,eax |
2322 | xor eax,eax |
2323 | mov [number_of_sections],eax |
2323 | mov [number_of_sections],eax |
2324 | mov edx,ebx |
2324 | mov edx,ebx |
2325 | call init_addressing_space |
2325 | call init_addressing_space |
2326 | mov [ebx+14h],edx |
2326 | mov [ebx+14h],edx |
2327 | mov byte [ebx+9],2 |
2327 | mov byte [ebx+9],2 |
2328 | mov [code_type],32 |
2328 | mov [code_type],32 |
2329 | test [format_flags],8 |
2329 | test [format_flags],8 |
2330 | jz format_defined |
2330 | jz format_defined |
2331 | mov byte [ebx+9],4 |
2331 | mov byte [ebx+9],4 |
2332 | mov [code_type],64 |
2332 | mov [code_type],64 |
2333 | jmp format_defined |
2333 | jmp format_defined |
2334 | coff_section: |
2334 | coff_section: |
2335 | call close_coff_section |
2335 | call close_coff_section |
2336 | mov ebx,[free_additional_memory] |
2336 | mov ebx,[free_additional_memory] |
2337 | lea eax,[ebx+20h] |
2337 | lea eax,[ebx+20h] |
2338 | cmp eax,[structures_buffer] |
2338 | cmp eax,[structures_buffer] |
2339 | jae out_of_memory |
2339 | jae out_of_memory |
2340 | mov [free_additional_memory],eax |
2340 | mov [free_additional_memory],eax |
2341 | mov [current_section],ebx |
2341 | mov [current_section],ebx |
2342 | inc [number_of_sections] |
2342 | inc [number_of_sections] |
2343 | xor eax,eax |
2343 | xor eax,eax |
2344 | mov [ebx],al |
2344 | mov [ebx],al |
2345 | mov [ebx+8],edi |
2345 | mov [ebx+8],edi |
2346 | mov [ebx+10h],eax |
2346 | mov [ebx+10h],eax |
2347 | mov [ebx+14h],eax |
2347 | mov [ebx+14h],eax |
2348 | mov edx,ebx |
2348 | mov edx,ebx |
2349 | call create_addressing_space |
2349 | call create_addressing_space |
2350 | xchg edx,ebx |
2350 | xchg edx,ebx |
2351 | mov [edx+14h],ebx |
2351 | mov [edx+14h],ebx |
2352 | mov byte [edx+9],2 |
2352 | mov byte [edx+9],2 |
2353 | test [format_flags],8 |
2353 | test [format_flags],8 |
2354 | jz coff_labels_type_ok |
2354 | jz coff_labels_type_ok |
2355 | mov byte [edx+9],4 |
2355 | mov byte [edx+9],4 |
2356 | coff_labels_type_ok: |
2356 | coff_labels_type_ok: |
2357 | lods word [esi] |
2357 | lods word [esi] |
2358 | cmp ax,'(' |
2358 | cmp ax,'(' |
2359 | jne invalid_argument |
2359 | jne invalid_argument |
2360 | mov [ebx+4],esi |
2360 | mov [ebx+4],esi |
2361 | mov ecx,[esi] |
2361 | mov ecx,[esi] |
2362 | lea esi,[esi+4+ecx+1] |
2362 | lea esi,[esi+4+ecx+1] |
2363 | cmp ecx,8 |
2363 | cmp ecx,8 |
2364 | ja name_too_long |
2364 | ja name_too_long |
2365 | coff_section_flags: |
2365 | coff_section_flags: |
2366 | cmp byte [esi],8Ch |
2366 | cmp byte [esi],8Ch |
2367 | je coff_section_alignment |
2367 | je coff_section_alignment |
2368 | cmp byte [esi],19h |
2368 | cmp byte [esi],19h |
2369 | jne coff_section_settings_ok |
2369 | jne coff_section_settings_ok |
2370 | inc esi |
2370 | inc esi |
2371 | lods byte [esi] |
2371 | lods byte [esi] |
2372 | bt [format_flags],0 |
2372 | bt [format_flags],0 |
2373 | jc coff_section_flag_ok |
2373 | jc coff_section_flag_ok |
2374 | cmp al,7 |
2374 | cmp al,7 |
2375 | ja invalid_argument |
2375 | ja invalid_argument |
2376 | coff_section_flag_ok: |
2376 | coff_section_flag_ok: |
2377 | mov cl,al |
2377 | mov cl,al |
2378 | mov eax,1 |
2378 | mov eax,1 |
2379 | shl eax,cl |
2379 | shl eax,cl |
2380 | test dword [ebx+14h],eax |
2380 | test dword [ebx+14h],eax |
2381 | jnz setting_already_specified |
2381 | jnz setting_already_specified |
2382 | or dword [ebx+14h],eax |
2382 | or dword [ebx+14h],eax |
2383 | jmp coff_section_flags |
2383 | jmp coff_section_flags |
2384 | coff_section_alignment: |
2384 | coff_section_alignment: |
2385 | bt [format_flags],0 |
2385 | bt [format_flags],0 |
2386 | jnc invalid_argument |
2386 | jnc invalid_argument |
2387 | inc esi |
2387 | inc esi |
2388 | lods byte [esi] |
2388 | lods byte [esi] |
2389 | cmp al,'(' |
2389 | cmp al,'(' |
2390 | jne invalid_argument |
2390 | jne invalid_argument |
2391 | cmp byte [esi],'.' |
2391 | cmp byte [esi],'.' |
2392 | je invalid_value |
2392 | je invalid_value |
2393 | push ebx |
2393 | push ebx |
2394 | call get_count_value |
2394 | call get_count_value |
2395 | pop ebx |
2395 | pop ebx |
2396 | mov edx,eax |
2396 | mov edx,eax |
2397 | dec edx |
2397 | dec edx |
2398 | test eax,edx |
2398 | test eax,edx |
2399 | jnz invalid_value |
2399 | jnz invalid_value |
2400 | or eax,eax |
2400 | or eax,eax |
2401 | jz invalid_value |
2401 | jz invalid_value |
2402 | cmp eax,2000h |
2402 | cmp eax,2000h |
2403 | ja invalid_value |
2403 | ja invalid_value |
2404 | bsf edx,eax |
2404 | bsf edx,eax |
2405 | inc edx |
2405 | inc edx |
2406 | shl edx,20 |
2406 | shl edx,20 |
2407 | or [ebx+14h],edx |
2407 | or [ebx+14h],edx |
2408 | xchg [ebx+10h],eax |
2408 | xchg [ebx+10h],eax |
2409 | or eax,eax |
2409 | or eax,eax |
2410 | jnz setting_already_specified |
2410 | jnz setting_already_specified |
2411 | jmp coff_section_flags |
2411 | jmp coff_section_flags |
2412 | coff_section_settings_ok: |
2412 | coff_section_settings_ok: |
2413 | cmp dword [ebx+10h],0 |
2413 | cmp dword [ebx+10h],0 |
2414 | jne instruction_assembled |
2414 | jne instruction_assembled |
2415 | mov dword [ebx+10h],4 |
2415 | mov dword [ebx+10h],4 |
2416 | bt [format_flags],0 |
2416 | bt [format_flags],0 |
2417 | jnc instruction_assembled |
2417 | jnc instruction_assembled |
2418 | or dword [ebx+14h],300000h |
2418 | or dword [ebx+14h],300000h |
2419 | jmp instruction_assembled |
2419 | jmp instruction_assembled |
2420 | close_coff_section: |
2420 | close_coff_section: |
2421 | mov ebx,[current_section] |
2421 | mov ebx,[current_section] |
2422 | mov eax,edi |
2422 | mov eax,edi |
2423 | mov edx,[ebx+8] |
2423 | mov edx,[ebx+8] |
2424 | sub eax,edx |
2424 | sub eax,edx |
2425 | mov [ebx+0Ch],eax |
2425 | mov [ebx+0Ch],eax |
2426 | xor eax,eax |
2426 | xor eax,eax |
2427 | xchg [undefined_data_end],eax |
2427 | xchg [undefined_data_end],eax |
2428 | cmp eax,edi |
2428 | cmp eax,edi |
2429 | jne coff_section_ok |
2429 | jne coff_section_ok |
2430 | cmp edx,[undefined_data_start] |
2430 | cmp edx,[undefined_data_start] |
2431 | jne coff_section_ok |
2431 | jne coff_section_ok |
2432 | mov edi,edx |
2432 | mov edi,edx |
2433 | or byte [ebx+14h],80h |
2433 | or byte [ebx+14h],80h |
2434 | coff_section_ok: |
2434 | coff_section_ok: |
2435 | ret |
2435 | ret |
2436 | mark_coff_relocation: |
2436 | mark_coff_relocation: |
2437 | cmp [value_type],3 |
2437 | cmp [value_type],3 |
2438 | je coff_relocation_relative |
2438 | je coff_relocation_relative |
2439 | push ebx eax |
2439 | push ebx eax |
2440 | test [format_flags],8 |
2440 | test [format_flags],8 |
2441 | jnz coff_64bit_relocation |
2441 | jnz coff_64bit_relocation |
2442 | mov al,6 |
2442 | mov al,6 |
2443 | cmp [value_type],2 |
2443 | cmp [value_type],2 |
2444 | je coff_relocation |
2444 | je coff_relocation |
2445 | cmp [value_type],5 |
2445 | cmp [value_type],5 |
2446 | jne invalid_use_of_symbol |
2446 | jne invalid_use_of_symbol |
2447 | inc al |
2447 | inc al |
2448 | jmp coff_relocation |
2448 | jmp coff_relocation |
2449 | coff_64bit_relocation: |
2449 | coff_64bit_relocation: |
2450 | mov al,1 |
2450 | mov al,1 |
2451 | cmp [value_type],4 |
2451 | cmp [value_type],4 |
2452 | je coff_relocation |
2452 | je coff_relocation |
2453 | mov al,2 |
2453 | mov al,2 |
2454 | cmp [value_type],2 |
2454 | cmp [value_type],2 |
2455 | je coff_relocation |
2455 | je coff_relocation |
2456 | cmp [value_type],5 |
2456 | cmp [value_type],5 |
2457 | jne invalid_use_of_symbol |
2457 | jne invalid_use_of_symbol |
2458 | inc al |
2458 | inc al |
2459 | jmp coff_relocation |
2459 | jmp coff_relocation |
2460 | coff_relocation_relative: |
2460 | coff_relocation_relative: |
2461 | push ebx |
2461 | push ebx |
2462 | bt [format_flags],0 |
2462 | bt [format_flags],0 |
2463 | jnc relative_ok |
2463 | jnc relative_ok |
2464 | mov ebx,[current_section] |
2464 | mov ebx,[current_section] |
2465 | mov ebx,[ebx+8] |
2465 | mov ebx,[ebx+8] |
2466 | sub ebx,edi |
2466 | sub ebx,edi |
2467 | sub eax,ebx |
2467 | sub eax,ebx |
2468 | add eax,4 |
2468 | add eax,4 |
2469 | relative_ok: |
2469 | relative_ok: |
2470 | mov ebx,[addressing_space] |
2470 | mov ebx,[addressing_space] |
2471 | push eax |
2471 | push eax |
2472 | mov al,20 |
2472 | mov al,20 |
2473 | test [format_flags],8 |
2473 | test [format_flags],8 |
2474 | jnz relative_coff_64bit_relocation |
2474 | jnz relative_coff_64bit_relocation |
2475 | cmp byte [ebx+9],2 |
2475 | cmp byte [ebx+9],2 |
2476 | jne invalid_use_of_symbol |
2476 | jne invalid_use_of_symbol |
2477 | jmp coff_relocation |
2477 | jmp coff_relocation |
2478 | relative_coff_64bit_relocation: |
2478 | relative_coff_64bit_relocation: |
2479 | mov al,4 |
2479 | mov al,4 |
2480 | cmp byte [ebx+9],4 |
2480 | cmp byte [ebx+9],4 |
2481 | jne invalid_use_of_symbol |
2481 | jne invalid_use_of_symbol |
2482 | coff_relocation: |
2482 | coff_relocation: |
2483 | mov ebx,[free_additional_memory] |
2483 | mov ebx,[free_additional_memory] |
2484 | add ebx,0Ch |
2484 | add ebx,0Ch |
2485 | cmp ebx,[structures_buffer] |
2485 | cmp ebx,[structures_buffer] |
2486 | jae out_of_memory |
2486 | jae out_of_memory |
2487 | mov [free_additional_memory],ebx |
2487 | mov [free_additional_memory],ebx |
2488 | mov byte [ebx-0Ch],al |
2488 | mov byte [ebx-0Ch],al |
2489 | mov eax,[current_section] |
2489 | mov eax,[current_section] |
2490 | mov eax,[eax+8] |
2490 | mov eax,[eax+8] |
2491 | neg eax |
2491 | neg eax |
2492 | add eax,edi |
2492 | add eax,edi |
2493 | mov [ebx-0Ch+4],eax |
2493 | mov [ebx-0Ch+4],eax |
2494 | mov eax,[symbol_identifier] |
2494 | mov eax,[symbol_identifier] |
2495 | mov [ebx-0Ch+8],eax |
2495 | mov [ebx-0Ch+8],eax |
2496 | pop eax ebx |
2496 | pop eax ebx |
2497 | ret |
2497 | ret |
2498 | close_coff: |
2498 | close_coff: |
2499 | call close_coff_section |
2499 | call close_coff_section |
2500 | cmp [next_pass_needed],0 |
2500 | cmp [next_pass_needed],0 |
2501 | je coff_closed |
2501 | je coff_closed |
2502 | mov eax,[symbols_stream] |
2502 | mov eax,[symbols_stream] |
2503 | mov [free_additional_memory],eax |
2503 | mov [free_additional_memory],eax |
2504 | coff_closed: |
2504 | coff_closed: |
2505 | ret |
2505 | ret |
2506 | coff_formatter: |
2506 | coff_formatter: |
2507 | sub edi,[code_start] |
2507 | sub edi,[code_start] |
2508 | mov [code_size],edi |
2508 | mov [code_size],edi |
2509 | call prepare_default_section |
2509 | call prepare_default_section |
2510 | mov edi,[free_additional_memory] |
2510 | mov edi,[free_additional_memory] |
2511 | mov ebx,edi |
2511 | mov ebx,edi |
2512 | mov ecx,28h shr 2 |
2512 | mov ecx,28h shr 2 |
2513 | imul ecx,[number_of_sections] |
2513 | imul ecx,[number_of_sections] |
2514 | add ecx,14h shr 2 |
2514 | add ecx,14h shr 2 |
2515 | lea eax,[edi+ecx*4] |
2515 | lea eax,[edi+ecx*4] |
2516 | cmp eax,[structures_buffer] |
2516 | cmp eax,[structures_buffer] |
2517 | jae out_of_memory |
2517 | jae out_of_memory |
2518 | xor eax,eax |
2518 | xor eax,eax |
2519 | rep stos dword [edi] |
2519 | rep stos dword [edi] |
2520 | mov word [ebx],14Ch |
2520 | mov word [ebx],14Ch |
2521 | test [format_flags],8 |
2521 | test [format_flags],8 |
2522 | jz coff_magic_ok |
2522 | jz coff_magic_ok |
2523 | mov word [ebx],8664h |
2523 | mov word [ebx],8664h |
2524 | coff_magic_ok: |
2524 | coff_magic_ok: |
2525 | mov word [ebx+12h],104h |
2525 | mov word [ebx+12h],104h |
2526 | bt [format_flags],0 |
2526 | bt [format_flags],0 |
2527 | jnc coff_flags_ok |
2527 | jnc coff_flags_ok |
2528 | or byte [ebx+12h],80h |
2528 | or byte [ebx+12h],80h |
2529 | coff_flags_ok: |
2529 | coff_flags_ok: |
2530 | push ebx |
2530 | push ebx |
2531 | call make_timestamp |
2531 | call make_timestamp |
2532 | pop ebx |
2532 | pop ebx |
2533 | mov [ebx+4],eax |
2533 | mov [ebx+4],eax |
2534 | mov eax,[number_of_sections] |
2534 | mov eax,[number_of_sections] |
2535 | mov [ebx+2],ax |
2535 | mov [ebx+2],ax |
2536 | mov esi,[symbols_stream] |
2536 | mov esi,[symbols_stream] |
2537 | xor eax,eax |
2537 | xor eax,eax |
2538 | xor ecx,ecx |
2538 | xor ecx,ecx |
2539 | enumerate_symbols: |
2539 | enumerate_symbols: |
2540 | cmp esi,[free_additional_memory] |
2540 | cmp esi,[free_additional_memory] |
2541 | je symbols_enumerated |
2541 | je symbols_enumerated |
2542 | mov dl,[esi] |
2542 | mov dl,[esi] |
2543 | or dl,dl |
2543 | or dl,dl |
2544 | jz enumerate_section |
2544 | jz enumerate_section |
2545 | cmp dl,0C0h |
2545 | cmp dl,0C0h |
2546 | jae enumerate_public |
2546 | jae enumerate_public |
2547 | cmp dl,80h |
2547 | cmp dl,80h |
2548 | jae enumerate_extrn |
2548 | jae enumerate_extrn |
2549 | add esi,0Ch |
2549 | add esi,0Ch |
2550 | jmp enumerate_symbols |
2550 | jmp enumerate_symbols |
2551 | enumerate_section: |
2551 | enumerate_section: |
2552 | mov edx,eax |
2552 | mov edx,eax |
2553 | shl edx,8 |
2553 | shl edx,8 |
2554 | mov [esi],edx |
2554 | mov [esi],edx |
2555 | inc eax |
2555 | inc eax |
2556 | inc ecx |
2556 | inc ecx |
2557 | mov [esi+1Eh],cx |
2557 | mov [esi+1Eh],cx |
2558 | add esi,20h |
2558 | add esi,20h |
2559 | jmp enumerate_symbols |
2559 | jmp enumerate_symbols |
2560 | enumerate_public: |
2560 | enumerate_public: |
2561 | mov edx,eax |
2561 | mov edx,eax |
2562 | shl edx,8 |
2562 | shl edx,8 |
2563 | mov dl,[esi] |
2563 | mov dl,[esi] |
2564 | mov [esi],edx |
2564 | mov [esi],edx |
2565 | mov edx,[esi+8] |
2565 | mov edx,[esi+8] |
2566 | add esi,10h |
2566 | add esi,10h |
2567 | inc eax |
2567 | inc eax |
2568 | cmp byte [edx+11],0 |
2568 | cmp byte [edx+11],0 |
2569 | je enumerate_symbols |
2569 | je enumerate_symbols |
2570 | mov edx,[edx+20] |
2570 | mov edx,[edx+20] |
2571 | cmp byte [edx],0C0h |
2571 | cmp byte [edx],0C0h |
2572 | jae enumerate_symbols |
2572 | jae enumerate_symbols |
2573 | cmp byte [edx],80h |
2573 | cmp byte [edx],80h |
2574 | jb enumerate_symbols |
2574 | jb enumerate_symbols |
2575 | inc eax |
2575 | inc eax |
2576 | jmp enumerate_symbols |
2576 | jmp enumerate_symbols |
2577 | enumerate_extrn: |
2577 | enumerate_extrn: |
2578 | mov edx,eax |
2578 | mov edx,eax |
2579 | shl edx,8 |
2579 | shl edx,8 |
2580 | mov dl,[esi] |
2580 | mov dl,[esi] |
2581 | mov [esi],edx |
2581 | mov [esi],edx |
2582 | add esi,0Ch |
2582 | add esi,0Ch |
2583 | inc eax |
2583 | inc eax |
2584 | jmp enumerate_symbols |
2584 | jmp enumerate_symbols |
2585 | prepare_default_section: |
2585 | prepare_default_section: |
2586 | mov ebx,[symbols_stream] |
2586 | mov ebx,[symbols_stream] |
2587 | cmp dword [ebx+0Ch],0 |
2587 | cmp dword [ebx+0Ch],0 |
2588 | jne default_section_ok |
2588 | jne default_section_ok |
2589 | cmp [number_of_sections],0 |
2589 | cmp [number_of_sections],0 |
2590 | je default_section_ok |
2590 | je default_section_ok |
2591 | mov edx,ebx |
2591 | mov edx,ebx |
2592 | find_references_to_default_section: |
2592 | find_references_to_default_section: |
2593 | cmp ebx,[free_additional_memory] |
2593 | cmp ebx,[free_additional_memory] |
2594 | jne check_reference |
2594 | jne check_reference |
2595 | add [symbols_stream],20h |
2595 | add [symbols_stream],20h |
2596 | ret |
2596 | ret |
2597 | check_reference: |
2597 | check_reference: |
2598 | mov al,[ebx] |
2598 | mov al,[ebx] |
2599 | or al,al |
2599 | or al,al |
2600 | jz skip_other_section |
2600 | jz skip_other_section |
2601 | cmp al,0C0h |
2601 | cmp al,0C0h |
2602 | jae check_public_reference |
2602 | jae check_public_reference |
2603 | cmp al,80h |
2603 | cmp al,80h |
2604 | jae next_reference |
2604 | jae next_reference |
2605 | cmp edx,[ebx+8] |
2605 | cmp edx,[ebx+8] |
2606 | je default_section_ok |
2606 | je default_section_ok |
2607 | next_reference: |
2607 | next_reference: |
2608 | add ebx,0Ch |
2608 | add ebx,0Ch |
2609 | jmp find_references_to_default_section |
2609 | jmp find_references_to_default_section |
2610 | check_public_reference: |
2610 | check_public_reference: |
2611 | mov eax,[ebx+8] |
2611 | mov eax,[ebx+8] |
2612 | add ebx,10h |
2612 | add ebx,10h |
2613 | test byte [eax+8],1 |
2613 | test byte [eax+8],1 |
2614 | jz find_references_to_default_section |
2614 | jz find_references_to_default_section |
2615 | mov cx,[current_pass] |
2615 | mov cx,[current_pass] |
2616 | cmp cx,[eax+16] |
2616 | cmp cx,[eax+16] |
2617 | jne find_references_to_default_section |
2617 | jne find_references_to_default_section |
2618 | cmp edx,[eax+20] |
2618 | cmp edx,[eax+20] |
2619 | je default_section_ok |
2619 | je default_section_ok |
2620 | jmp find_references_to_default_section |
2620 | jmp find_references_to_default_section |
2621 | skip_other_section: |
2621 | skip_other_section: |
2622 | add ebx,20h |
2622 | add ebx,20h |
2623 | jmp find_references_to_default_section |
2623 | jmp find_references_to_default_section |
2624 | default_section_ok: |
2624 | default_section_ok: |
2625 | inc [number_of_sections] |
2625 | inc [number_of_sections] |
2626 | ret |
2626 | ret |
2627 | symbols_enumerated: |
2627 | symbols_enumerated: |
2628 | mov [ebx+0Ch],eax |
2628 | mov [ebx+0Ch],eax |
2629 | mov ebp,edi |
2629 | mov ebp,edi |
2630 | sub ebp,ebx |
2630 | sub ebp,ebx |
2631 | push ebp |
2631 | push ebp |
2632 | lea edi,[ebx+14h] |
2632 | lea edi,[ebx+14h] |
2633 | mov esi,[symbols_stream] |
2633 | mov esi,[symbols_stream] |
2634 | find_section: |
2634 | find_section: |
2635 | cmp esi,[free_additional_memory] |
2635 | cmp esi,[free_additional_memory] |
2636 | je sections_finished |
2636 | je sections_finished |
2637 | mov al,[esi] |
2637 | mov al,[esi] |
2638 | or al,al |
2638 | or al,al |
2639 | jz section_found |
2639 | jz section_found |
2640 | add esi,0Ch |
2640 | add esi,0Ch |
2641 | cmp al,0C0h |
2641 | cmp al,0C0h |
2642 | jb find_section |
2642 | jb find_section |
2643 | add esi,4 |
2643 | add esi,4 |
2644 | jmp find_section |
2644 | jmp find_section |
2645 | section_found: |
2645 | section_found: |
2646 | push esi edi |
2646 | push esi edi |
2647 | mov esi,[esi+4] |
2647 | mov esi,[esi+4] |
2648 | or esi,esi |
2648 | or esi,esi |
2649 | jz default_section |
2649 | jz default_section |
2650 | mov ecx,[esi] |
2650 | mov ecx,[esi] |
2651 | add esi,4 |
2651 | add esi,4 |
2652 | rep movs byte [edi],[esi] |
2652 | rep movs byte [edi],[esi] |
2653 | jmp section_name_ok |
2653 | jmp section_name_ok |
2654 | default_section: |
2654 | default_section: |
2655 | mov al,'.' |
2655 | mov al,'.' |
2656 | stos byte [edi] |
2656 | stos byte [edi] |
2657 | mov eax,'flat' |
2657 | mov eax,'flat' |
2658 | stos dword [edi] |
2658 | stos dword [edi] |
2659 | section_name_ok: |
2659 | section_name_ok: |
2660 | pop edi esi |
2660 | pop edi esi |
2661 | mov eax,[esi+0Ch] |
2661 | mov eax,[esi+0Ch] |
2662 | mov [edi+10h],eax |
2662 | mov [edi+10h],eax |
2663 | mov eax,[esi+14h] |
2663 | mov eax,[esi+14h] |
2664 | mov [edi+24h],eax |
2664 | mov [edi+24h],eax |
2665 | test al,80h |
2665 | test al,80h |
2666 | jnz section_ptr_ok |
2666 | jnz section_ptr_ok |
2667 | mov eax,[esi+8] |
2667 | mov eax,[esi+8] |
2668 | sub eax,[code_start] |
2668 | sub eax,[code_start] |
2669 | add eax,ebp |
2669 | add eax,ebp |
2670 | mov [edi+14h],eax |
2670 | mov [edi+14h],eax |
2671 | section_ptr_ok: |
2671 | section_ptr_ok: |
2672 | mov ebx,[code_start] |
2672 | mov ebx,[code_start] |
2673 | mov edx,[code_size] |
2673 | mov edx,[code_size] |
2674 | add ebx,edx |
2674 | add ebx,edx |
2675 | add edx,ebp |
2675 | add edx,ebp |
2676 | xor ecx,ecx |
2676 | xor ecx,ecx |
2677 | add esi,20h |
2677 | add esi,20h |
2678 | find_relocations: |
2678 | find_relocations: |
2679 | cmp esi,[free_additional_memory] |
2679 | cmp esi,[free_additional_memory] |
2680 | je section_relocations_done |
2680 | je section_relocations_done |
2681 | mov al,[esi] |
2681 | mov al,[esi] |
2682 | or al,al |
2682 | or al,al |
2683 | jz section_relocations_done |
2683 | jz section_relocations_done |
2684 | cmp al,80h |
2684 | cmp al,80h |
2685 | jb add_relocation |
2685 | jb add_relocation |
2686 | cmp al,0C0h |
2686 | cmp al,0C0h |
2687 | jb next_relocation |
2687 | jb next_relocation |
2688 | add esi,10h |
2688 | add esi,10h |
2689 | jmp find_relocations |
2689 | jmp find_relocations |
2690 | add_relocation: |
2690 | add_relocation: |
2691 | lea eax,[ebx+0Ah] |
2691 | lea eax,[ebx+0Ah] |
2692 | cmp eax,[tagged_blocks] |
2692 | cmp eax,[tagged_blocks] |
2693 | ja out_of_memory |
2693 | ja out_of_memory |
2694 | mov eax,[esi+4] |
2694 | mov eax,[esi+4] |
2695 | mov [ebx],eax |
2695 | mov [ebx],eax |
2696 | mov eax,[esi+8] |
2696 | mov eax,[esi+8] |
2697 | mov eax,[eax] |
2697 | mov eax,[eax] |
2698 | shr eax,8 |
2698 | shr eax,8 |
2699 | mov [ebx+4],eax |
2699 | mov [ebx+4],eax |
2700 | movzx ax,byte [esi] |
2700 | movzx ax,byte [esi] |
2701 | mov [ebx+8],ax |
2701 | mov [ebx+8],ax |
2702 | add ebx,0Ah |
2702 | add ebx,0Ah |
2703 | inc ecx |
2703 | inc ecx |
2704 | next_relocation: |
2704 | next_relocation: |
2705 | add esi,0Ch |
2705 | add esi,0Ch |
2706 | jmp find_relocations |
2706 | jmp find_relocations |
2707 | section_relocations_done: |
2707 | section_relocations_done: |
2708 | cmp ecx,10000h |
2708 | cmp ecx,10000h |
2709 | jb section_relocations_count_16bit |
2709 | jb section_relocations_count_16bit |
2710 | bt [format_flags],0 |
2710 | bt [format_flags],0 |
2711 | jnc format_limitations_exceeded |
2711 | jnc format_limitations_exceeded |
2712 | mov word [edi+20h],0FFFFh |
2712 | mov word [edi+20h],0FFFFh |
2713 | or dword [edi+24h],1000000h |
2713 | or dword [edi+24h],1000000h |
2714 | mov [edi+18h],edx |
2714 | mov [edi+18h],edx |
2715 | push esi edi |
2715 | push esi edi |
2716 | push ecx |
2716 | push ecx |
2717 | lea esi,[ebx-1] |
2717 | lea esi,[ebx-1] |
2718 | add ebx,0Ah |
2718 | add ebx,0Ah |
2719 | lea edi,[ebx-1] |
2719 | lea edi,[ebx-1] |
2720 | imul ecx,0Ah |
2720 | imul ecx,0Ah |
2721 | std |
2721 | std |
2722 | rep movs byte [edi],[esi] |
2722 | rep movs byte [edi],[esi] |
2723 | cld |
2723 | cld |
2724 | pop ecx |
2724 | pop ecx |
2725 | inc esi |
2725 | inc esi |
2726 | inc ecx |
2726 | inc ecx |
2727 | mov [esi],ecx |
2727 | mov [esi],ecx |
2728 | xor eax,eax |
2728 | xor eax,eax |
2729 | mov [esi+4],eax |
2729 | mov [esi+4],eax |
2730 | mov [esi+8],ax |
2730 | mov [esi+8],ax |
2731 | pop edi esi |
2731 | pop edi esi |
2732 | jmp section_relocations_ok |
2732 | jmp section_relocations_ok |
2733 | section_relocations_count_16bit: |
2733 | section_relocations_count_16bit: |
2734 | mov [edi+20h],cx |
2734 | mov [edi+20h],cx |
2735 | jcxz section_relocations_ok |
2735 | jcxz section_relocations_ok |
2736 | mov [edi+18h],edx |
2736 | mov [edi+18h],edx |
2737 | section_relocations_ok: |
2737 | section_relocations_ok: |
2738 | sub ebx,[code_start] |
2738 | sub ebx,[code_start] |
2739 | mov [code_size],ebx |
2739 | mov [code_size],ebx |
2740 | add edi,28h |
2740 | add edi,28h |
2741 | jmp find_section |
2741 | jmp find_section |
2742 | sections_finished: |
2742 | sections_finished: |
2743 | mov edx,[free_additional_memory] |
2743 | mov edx,[free_additional_memory] |
2744 | mov ebx,[code_size] |
2744 | mov ebx,[code_size] |
2745 | add ebp,ebx |
2745 | add ebp,ebx |
2746 | mov [edx+8],ebp |
2746 | mov [edx+8],ebp |
2747 | add ebx,[code_start] |
2747 | add ebx,[code_start] |
2748 | mov edi,ebx |
2748 | mov edi,ebx |
2749 | mov ecx,[edx+0Ch] |
2749 | mov ecx,[edx+0Ch] |
2750 | imul ecx,12h shr 1 |
2750 | imul ecx,12h shr 1 |
2751 | xor eax,eax |
2751 | xor eax,eax |
2752 | shr ecx,1 |
2752 | shr ecx,1 |
2753 | jnc zero_symbols_table |
2753 | jnc zero_symbols_table |
2754 | stos word [edi] |
2754 | stos word [edi] |
2755 | zero_symbols_table: |
2755 | zero_symbols_table: |
2756 | rep stos dword [edi] |
2756 | rep stos dword [edi] |
2757 | mov edx,edi |
2757 | mov edx,edi |
2758 | stos dword [edi] |
2758 | stos dword [edi] |
2759 | mov esi,[symbols_stream] |
2759 | mov esi,[symbols_stream] |
2760 | make_symbols_table: |
2760 | make_symbols_table: |
2761 | cmp esi,[free_additional_memory] |
2761 | cmp esi,[free_additional_memory] |
2762 | je symbols_table_ok |
2762 | je symbols_table_ok |
2763 | mov al,[esi] |
2763 | mov al,[esi] |
2764 | cmp al,0C0h |
2764 | cmp al,0C0h |
2765 | jae add_public_symbol |
2765 | jae add_public_symbol |
2766 | cmp al,80h |
2766 | cmp al,80h |
2767 | jae add_extrn_symbol |
2767 | jae add_extrn_symbol |
2768 | or al,al |
2768 | or al,al |
2769 | jz add_section_symbol |
2769 | jz add_section_symbol |
2770 | add esi,0Ch |
2770 | add esi,0Ch |
2771 | jmp make_symbols_table |
2771 | jmp make_symbols_table |
2772 | add_section_symbol: |
2772 | add_section_symbol: |
2773 | call store_symbol_name |
2773 | call store_symbol_name |
2774 | movzx eax,word [esi+1Eh] |
2774 | movzx eax,word [esi+1Eh] |
2775 | mov [ebx+0Ch],ax |
2775 | mov [ebx+0Ch],ax |
2776 | mov byte [ebx+10h],3 |
2776 | mov byte [ebx+10h],3 |
2777 | add esi,20h |
2777 | add esi,20h |
2778 | add ebx,12h |
2778 | add ebx,12h |
2779 | jmp make_symbols_table |
2779 | jmp make_symbols_table |
2780 | add_extrn_symbol: |
2780 | add_extrn_symbol: |
2781 | call store_symbol_name |
2781 | call store_symbol_name |
2782 | mov byte [ebx+10h],2 |
2782 | mov byte [ebx+10h],2 |
2783 | add esi,0Ch |
2783 | add esi,0Ch |
2784 | add ebx,12h |
2784 | add ebx,12h |
2785 | jmp make_symbols_table |
2785 | jmp make_symbols_table |
2786 | add_public_symbol: |
2786 | add_public_symbol: |
2787 | call store_symbol_name |
2787 | call store_symbol_name |
2788 | mov eax,[esi+0Ch] |
2788 | mov eax,[esi+0Ch] |
2789 | mov [current_line],eax |
2789 | mov [current_line],eax |
2790 | mov eax,[esi+8] |
2790 | mov eax,[esi+8] |
2791 | test byte [eax+8],1 |
2791 | test byte [eax+8],1 |
2792 | jz undefined_coff_public |
2792 | jz undefined_coff_public |
2793 | mov cx,[current_pass] |
2793 | mov cx,[current_pass] |
2794 | cmp cx,[eax+16] |
2794 | cmp cx,[eax+16] |
2795 | jne undefined_coff_public |
2795 | jne undefined_coff_public |
2796 | mov cl,[eax+11] |
2796 | mov cl,[eax+11] |
2797 | or cl,cl |
2797 | or cl,cl |
2798 | jz public_constant |
2798 | jz public_constant |
2799 | test [format_flags],8 |
2799 | test [format_flags],8 |
2800 | jnz check_64bit_public_symbol |
2800 | jnz check_64bit_public_symbol |
2801 | cmp cl,2 |
2801 | cmp cl,2 |
2802 | je public_symbol_type_ok |
2802 | je public_symbol_type_ok |
2803 | jmp invalid_use_of_symbol |
2803 | jmp invalid_use_of_symbol |
2804 | undefined_coff_public: |
2804 | undefined_coff_public: |
2805 | mov [error_info],eax |
2805 | mov [error_info],eax |
2806 | jmp undefined_symbol |
2806 | jmp undefined_symbol |
2807 | check_64bit_public_symbol: |
2807 | check_64bit_public_symbol: |
2808 | cmp cl,4 |
2808 | cmp cl,4 |
2809 | jne invalid_use_of_symbol |
2809 | jne invalid_use_of_symbol |
2810 | public_symbol_type_ok: |
2810 | public_symbol_type_ok: |
2811 | mov ecx,[eax+20] |
2811 | mov ecx,[eax+20] |
2812 | cmp byte [ecx],80h |
2812 | cmp byte [ecx],80h |
2813 | je alias_symbol |
2813 | je alias_symbol |
2814 | cmp byte [ecx],0 |
2814 | cmp byte [ecx],0 |
2815 | jne invalid_use_of_symbol |
2815 | jne invalid_use_of_symbol |
2816 | mov cx,[ecx+1Eh] |
2816 | mov cx,[ecx+1Eh] |
2817 | mov [ebx+0Ch],cx |
2817 | mov [ebx+0Ch],cx |
2818 | public_symbol_section_ok: |
2818 | public_symbol_section_ok: |
2819 | movzx ecx,byte [eax+9] |
2819 | movzx ecx,byte [eax+9] |
2820 | shr cl,1 |
2820 | shr cl,1 |
2821 | and cl,1 |
2821 | and cl,1 |
2822 | neg ecx |
2822 | neg ecx |
2823 | cmp ecx,[eax+4] |
2823 | cmp ecx,[eax+4] |
2824 | jne value_out_of_range |
2824 | jne value_out_of_range |
2825 | xor ecx,[eax] |
2825 | xor ecx,[eax] |
2826 | js value_out_of_range |
2826 | js value_out_of_range |
2827 | mov eax,[eax] |
2827 | mov eax,[eax] |
2828 | mov [ebx+8],eax |
2828 | mov [ebx+8],eax |
2829 | mov al,2 |
2829 | mov al,2 |
2830 | cmp byte [esi],0C0h |
2830 | cmp byte [esi],0C0h |
2831 | je store_symbol_class |
2831 | je store_symbol_class |
2832 | inc al |
2832 | inc al |
2833 | cmp byte [esi],0C1h |
2833 | cmp byte [esi],0C1h |
2834 | je store_symbol_class |
2834 | je store_symbol_class |
2835 | mov al,105 |
2835 | mov al,105 |
2836 | store_symbol_class: |
2836 | store_symbol_class: |
2837 | mov byte [ebx+10h],al |
2837 | mov byte [ebx+10h],al |
2838 | add esi,10h |
2838 | add esi,10h |
2839 | add ebx,12h |
2839 | add ebx,12h |
2840 | jmp make_symbols_table |
2840 | jmp make_symbols_table |
2841 | alias_symbol: |
2841 | alias_symbol: |
2842 | bt [format_flags],0 |
2842 | bt [format_flags],0 |
2843 | jnc invalid_use_of_symbol |
2843 | jnc invalid_use_of_symbol |
2844 | mov ecx,[eax] |
2844 | mov ecx,[eax] |
2845 | or ecx,[eax+4] |
2845 | or ecx,[eax+4] |
2846 | jnz invalid_use_of_symbol |
2846 | jnz invalid_use_of_symbol |
2847 | mov byte [ebx+10h],69h |
2847 | mov byte [ebx+10h],69h |
2848 | mov byte [ebx+11h],1 |
2848 | mov byte [ebx+11h],1 |
2849 | add ebx,12h |
2849 | add ebx,12h |
2850 | mov ecx,[eax+20] |
2850 | mov ecx,[eax+20] |
2851 | mov ecx,[ecx] |
2851 | mov ecx,[ecx] |
2852 | shr ecx,8 |
2852 | shr ecx,8 |
2853 | mov [ebx],ecx |
2853 | mov [ebx],ecx |
2854 | mov byte [ebx+4],3 |
2854 | mov byte [ebx+4],3 |
2855 | add esi,10h |
2855 | add esi,10h |
2856 | add ebx,12h |
2856 | add ebx,12h |
2857 | jmp make_symbols_table |
2857 | jmp make_symbols_table |
2858 | public_constant: |
2858 | public_constant: |
2859 | mov word [ebx+0Ch],0FFFFh |
2859 | mov word [ebx+0Ch],0FFFFh |
2860 | jmp public_symbol_section_ok |
2860 | jmp public_symbol_section_ok |
2861 | symbols_table_ok: |
2861 | symbols_table_ok: |
2862 | mov eax,edi |
2862 | mov eax,edi |
2863 | sub eax,edx |
2863 | sub eax,edx |
2864 | mov [edx],eax |
2864 | mov [edx],eax |
2865 | sub edi,[code_start] |
2865 | sub edi,[code_start] |
2866 | mov [code_size],edi |
2866 | mov [code_size],edi |
2867 | and [written_size],0 |
2867 | and [written_size],0 |
2868 | mov edx,[output_file] |
2868 | mov edx,[output_file] |
2869 | call create |
2869 | call create |
2870 | jc write_failed |
2870 | jc write_failed |
2871 | mov edx,[free_additional_memory] |
2871 | mov edx,[free_additional_memory] |
2872 | pop ecx |
2872 | pop ecx |
2873 | add [written_size],ecx |
2873 | add [written_size],ecx |
2874 | call write |
2874 | call write |
2875 | jc write_failed |
2875 | jc write_failed |
2876 | jmp write_output |
2876 | jmp write_output |
2877 | store_symbol_name: |
2877 | store_symbol_name: |
2878 | push esi |
2878 | push esi |
2879 | mov esi,[esi+4] |
2879 | mov esi,[esi+4] |
2880 | or esi,esi |
2880 | or esi,esi |
2881 | jz default_name |
2881 | jz default_name |
2882 | lods dword [esi] |
2882 | lods dword [esi] |
2883 | mov ecx,eax |
2883 | mov ecx,eax |
2884 | cmp ecx,8 |
2884 | cmp ecx,8 |
2885 | ja add_string |
2885 | ja add_string |
2886 | push edi |
2886 | push edi |
2887 | mov edi,ebx |
2887 | mov edi,ebx |
2888 | rep movs byte [edi],[esi] |
2888 | rep movs byte [edi],[esi] |
2889 | pop edi esi |
2889 | pop edi esi |
2890 | ret |
2890 | ret |
2891 | default_name: |
2891 | default_name: |
2892 | mov dword [ebx],'.fla' |
2892 | mov dword [ebx],'.fla' |
2893 | mov dword [ebx+4],'t' |
2893 | mov dword [ebx+4],'t' |
2894 | pop esi |
2894 | pop esi |
2895 | ret |
2895 | ret |
2896 | add_string: |
2896 | add_string: |
2897 | mov eax,edi |
2897 | mov eax,edi |
2898 | sub eax,edx |
2898 | sub eax,edx |
2899 | mov [ebx+4],eax |
2899 | mov [ebx+4],eax |
2900 | inc ecx |
2900 | inc ecx |
2901 | rep movs byte [edi],[esi] |
2901 | rep movs byte [edi],[esi] |
2902 | pop esi |
2902 | pop esi |
2903 | ret |
2903 | ret |
2904 | 2904 | ||
2905 | format_elf: |
2905 | format_elf: |
2906 | test [format_flags],8 |
2906 | test [format_flags],8 |
2907 | jnz format_elf64 |
2907 | jnz format_elf64 |
2908 | mov edx,edi |
2908 | mov edx,edi |
2909 | mov ecx,34h shr 2 |
2909 | mov ecx,34h shr 2 |
2910 | lea eax,[edi+ecx*4] |
2910 | lea eax,[edi+ecx*4] |
2911 | cmp eax,[tagged_blocks] |
2911 | cmp eax,[tagged_blocks] |
2912 | jae out_of_memory |
2912 | jae out_of_memory |
2913 | xor eax,eax |
2913 | xor eax,eax |
2914 | rep stos dword [edi] |
2914 | rep stos dword [edi] |
2915 | mov dword [edx],7Fh + 'ELF' shl 8 |
2915 | mov dword [edx],7Fh + 'ELF' shl 8 |
2916 | mov al,1 |
2916 | mov al,1 |
2917 | mov [edx+4],al |
2917 | mov [edx+4],al |
2918 | mov [edx+5],al |
2918 | mov [edx+5],al |
2919 | mov [edx+6],al |
2919 | mov [edx+6],al |
2920 | mov [edx+14h],al |
2920 | mov [edx+14h],al |
2921 | mov byte [edx+12h],3 |
2921 | mov byte [edx+12h],3 |
2922 | mov byte [edx+28h],34h |
2922 | mov byte [edx+28h],34h |
2923 | mov byte [edx+2Eh],28h |
2923 | mov byte [edx+2Eh],28h |
2924 | mov [code_type],32 |
2924 | mov [code_type],32 |
2925 | mov byte [edx+10h],2 |
2925 | mov byte [edx+10h],2 |
2926 | cmp word [esi],1D19h |
2926 | cmp word [esi],1D19h |
2927 | je format_elf_exe |
2927 | je format_elf_exe |
2928 | mov byte [edx+10h],3 |
2928 | mov byte [edx+10h],3 |
2929 | cmp word [esi],021Eh |
2929 | cmp word [esi],021Eh |
2930 | je format_elf_exe |
2930 | je format_elf_exe |
2931 | elf_header_ok: |
2931 | elf_header_ok: |
2932 | mov byte [edx+10h],1 |
2932 | mov byte [edx+10h],1 |
2933 | mov eax,[additional_memory] |
2933 | mov eax,[additional_memory] |
2934 | mov [symbols_stream],eax |
2934 | mov [symbols_stream],eax |
2935 | mov ebx,eax |
2935 | mov ebx,eax |
2936 | add eax,20h |
2936 | add eax,20h |
2937 | cmp eax,[structures_buffer] |
2937 | cmp eax,[structures_buffer] |
2938 | jae out_of_memory |
2938 | jae out_of_memory |
2939 | mov [free_additional_memory],eax |
2939 | mov [free_additional_memory],eax |
2940 | xor eax,eax |
2940 | xor eax,eax |
2941 | mov [current_section],ebx |
2941 | mov [current_section],ebx |
2942 | mov [number_of_sections],eax |
2942 | mov [number_of_sections],eax |
2943 | mov [ebx],al |
2943 | mov [ebx],al |
2944 | mov [ebx+4],eax |
2944 | mov [ebx+4],eax |
2945 | mov [ebx+8],edi |
2945 | mov [ebx+8],edi |
2946 | mov al,111b |
2946 | mov al,111b |
2947 | mov [ebx+14h],eax |
2947 | mov [ebx+14h],eax |
2948 | mov al,4 |
2948 | mov al,4 |
2949 | mov [ebx+10h],eax |
2949 | mov [ebx+10h],eax |
2950 | mov edx,ebx |
2950 | mov edx,ebx |
2951 | call init_addressing_space |
2951 | call init_addressing_space |
2952 | xchg edx,ebx |
2952 | xchg edx,ebx |
2953 | mov [edx+14h],ebx |
2953 | mov [edx+14h],ebx |
2954 | mov byte [edx+9],2 |
2954 | mov byte [edx+9],2 |
2955 | test [format_flags],8 |
2955 | test [format_flags],8 |
2956 | jz format_defined |
2956 | jz format_defined |
2957 | mov byte [edx+9],4 |
2957 | mov byte [edx+9],4 |
2958 | mov byte [ebx+10h],8 |
2958 | mov byte [ebx+10h],8 |
2959 | jmp format_defined |
2959 | jmp format_defined |
2960 | format_elf64: |
2960 | format_elf64: |
2961 | mov edx,edi |
2961 | mov edx,edi |
2962 | mov ecx,40h shr 2 |
2962 | mov ecx,40h shr 2 |
2963 | lea eax,[edi+ecx*4] |
2963 | lea eax,[edi+ecx*4] |
2964 | cmp eax,[tagged_blocks] |
2964 | cmp eax,[tagged_blocks] |
2965 | jae out_of_memory |
2965 | jae out_of_memory |
2966 | xor eax,eax |
2966 | xor eax,eax |
2967 | rep stos dword [edi] |
2967 | rep stos dword [edi] |
2968 | mov dword [edx],7Fh + 'ELF' shl 8 |
2968 | mov dword [edx],7Fh + 'ELF' shl 8 |
2969 | mov al,1 |
2969 | mov al,1 |
2970 | mov [edx+5],al |
2970 | mov [edx+5],al |
2971 | mov [edx+6],al |
2971 | mov [edx+6],al |
2972 | mov [edx+14h],al |
2972 | mov [edx+14h],al |
2973 | mov byte [edx+4],2 |
2973 | mov byte [edx+4],2 |
2974 | mov byte [edx+12h],62 |
2974 | mov byte [edx+12h],62 |
2975 | mov byte [edx+34h],40h |
2975 | mov byte [edx+34h],40h |
2976 | mov byte [edx+3Ah],40h |
2976 | mov byte [edx+3Ah],40h |
2977 | mov [code_type],64 |
2977 | mov [code_type],64 |
2978 | mov byte [edx+10h],2 |
2978 | mov byte [edx+10h],2 |
2979 | cmp word [esi],1D19h |
2979 | cmp word [esi],1D19h |
2980 | je format_elf64_exe |
2980 | je format_elf64_exe |
2981 | mov byte [edx+10h],3 |
2981 | mov byte [edx+10h],3 |
2982 | cmp word [esi],021Eh |
2982 | cmp word [esi],021Eh |
2983 | je format_elf64_exe |
2983 | je format_elf64_exe |
2984 | jmp elf_header_ok |
2984 | jmp elf_header_ok |
2985 | elf_section: |
2985 | elf_section: |
2986 | bt [format_flags],0 |
2986 | bt [format_flags],0 |
2987 | jc illegal_instruction |
2987 | jc illegal_instruction |
2988 | call close_coff_section |
2988 | call close_coff_section |
2989 | mov ebx,[free_additional_memory] |
2989 | mov ebx,[free_additional_memory] |
2990 | lea eax,[ebx+20h] |
2990 | lea eax,[ebx+20h] |
2991 | cmp eax,[structures_buffer] |
2991 | cmp eax,[structures_buffer] |
2992 | jae out_of_memory |
2992 | jae out_of_memory |
2993 | mov [free_additional_memory],eax |
2993 | mov [free_additional_memory],eax |
2994 | mov [current_section],ebx |
2994 | mov [current_section],ebx |
2995 | inc word [number_of_sections] |
2995 | inc word [number_of_sections] |
2996 | jz format_limitations_exceeded |
2996 | jz format_limitations_exceeded |
2997 | xor eax,eax |
2997 | xor eax,eax |
2998 | mov [ebx],al |
2998 | mov [ebx],al |
2999 | mov [ebx+8],edi |
2999 | mov [ebx+8],edi |
3000 | mov [ebx+10h],eax |
3000 | mov [ebx+10h],eax |
3001 | mov al,10b |
3001 | mov al,10b |
3002 | mov [ebx+14h],eax |
3002 | mov [ebx+14h],eax |
3003 | mov edx,ebx |
3003 | mov edx,ebx |
3004 | call create_addressing_space |
3004 | call create_addressing_space |
3005 | xchg edx,ebx |
3005 | xchg edx,ebx |
3006 | mov [edx+14h],ebx |
3006 | mov [edx+14h],ebx |
3007 | mov byte [edx+9],2 |
3007 | mov byte [edx+9],2 |
3008 | test [format_flags],8 |
3008 | test [format_flags],8 |
3009 | jz elf_labels_type_ok |
3009 | jz elf_labels_type_ok |
3010 | mov byte [edx+9],4 |
3010 | mov byte [edx+9],4 |
3011 | elf_labels_type_ok: |
3011 | elf_labels_type_ok: |
3012 | lods word [esi] |
3012 | lods word [esi] |
3013 | cmp ax,'(' |
3013 | cmp ax,'(' |
3014 | jne invalid_argument |
3014 | jne invalid_argument |
3015 | mov [ebx+4],esi |
3015 | mov [ebx+4],esi |
3016 | mov ecx,[esi] |
3016 | mov ecx,[esi] |
3017 | lea esi,[esi+4+ecx+1] |
3017 | lea esi,[esi+4+ecx+1] |
3018 | elf_section_flags: |
3018 | elf_section_flags: |
3019 | cmp byte [esi],8Ch |
3019 | cmp byte [esi],8Ch |
3020 | je elf_section_alignment |
3020 | je elf_section_alignment |
3021 | cmp byte [esi],19h |
3021 | cmp byte [esi],19h |
3022 | jne elf_section_settings_ok |
3022 | jne elf_section_settings_ok |
3023 | inc esi |
3023 | inc esi |
3024 | lods byte [esi] |
3024 | lods byte [esi] |
3025 | sub al,28 |
3025 | sub al,28 |
3026 | xor al,11b |
3026 | xor al,11b |
3027 | test al,not 10b |
3027 | test al,not 10b |
3028 | jnz invalid_argument |
3028 | jnz invalid_argument |
3029 | mov cl,al |
3029 | mov cl,al |
3030 | mov al,1 |
3030 | mov al,1 |
3031 | shl al,cl |
3031 | shl al,cl |
3032 | test byte [ebx+14h],al |
3032 | test byte [ebx+14h],al |
3033 | jnz setting_already_specified |
3033 | jnz setting_already_specified |
3034 | or byte [ebx+14h],al |
3034 | or byte [ebx+14h],al |
3035 | jmp elf_section_flags |
3035 | jmp elf_section_flags |
3036 | elf_section_alignment: |
3036 | elf_section_alignment: |
3037 | inc esi |
3037 | inc esi |
3038 | lods byte [esi] |
3038 | lods byte [esi] |
3039 | cmp al,'(' |
3039 | cmp al,'(' |
3040 | jne invalid_argument |
3040 | jne invalid_argument |
3041 | cmp byte [esi],'.' |
3041 | cmp byte [esi],'.' |
3042 | je invalid_value |
3042 | je invalid_value |
3043 | push ebx |
3043 | push ebx |
3044 | call get_count_value |
3044 | call get_count_value |
3045 | pop ebx |
3045 | pop ebx |
3046 | mov edx,eax |
3046 | mov edx,eax |
3047 | dec edx |
3047 | dec edx |
3048 | test eax,edx |
3048 | test eax,edx |
3049 | jnz invalid_value |
3049 | jnz invalid_value |
3050 | or eax,eax |
3050 | or eax,eax |
3051 | jz invalid_value |
3051 | jz invalid_value |
3052 | xchg [ebx+10h],eax |
3052 | xchg [ebx+10h],eax |
3053 | or eax,eax |
3053 | or eax,eax |
3054 | jnz setting_already_specified |
3054 | jnz setting_already_specified |
3055 | jmp elf_section_flags |
3055 | jmp elf_section_flags |
3056 | elf_section_settings_ok: |
3056 | elf_section_settings_ok: |
3057 | cmp dword [ebx+10h],0 |
3057 | cmp dword [ebx+10h],0 |
3058 | jne instruction_assembled |
3058 | jne instruction_assembled |
3059 | mov dword [ebx+10h],4 |
3059 | mov dword [ebx+10h],4 |
3060 | test [format_flags],8 |
3060 | test [format_flags],8 |
3061 | jz instruction_assembled |
3061 | jz instruction_assembled |
3062 | mov byte [ebx+10h],8 |
3062 | mov byte [ebx+10h],8 |
3063 | jmp instruction_assembled |
3063 | jmp instruction_assembled |
3064 | mark_elf_relocation: |
3064 | mark_elf_relocation: |
3065 | test [format_flags],1 |
3065 | test [format_flags],1 |
3066 | jnz invalid_use_of_symbol |
3066 | jnz invalid_use_of_symbol |
3067 | push ebx |
3067 | push ebx |
3068 | mov ebx,[addressing_space] |
3068 | mov ebx,[addressing_space] |
3069 | cmp [value_type],3 |
3069 | cmp [value_type],3 |
3070 | je elf_relocation_relative |
3070 | je elf_relocation_relative |
3071 | cmp [value_type],7 |
3071 | cmp [value_type],7 |
3072 | je elf_relocation_relative |
3072 | je elf_relocation_relative |
3073 | push eax |
3073 | push eax |
3074 | cmp [value_type],5 |
3074 | cmp [value_type],5 |
3075 | je elf_gotoff_relocation |
3075 | je elf_gotoff_relocation |
3076 | ja invalid_use_of_symbol |
3076 | ja invalid_use_of_symbol |
3077 | mov al,1 ; R_386_32 / R_AMD64_64 |
3077 | mov al,1 ; R_386_32 / R_AMD64_64 |
3078 | test [format_flags],8 |
3078 | test [format_flags],8 |
3079 | jz coff_relocation |
3079 | jz coff_relocation |
3080 | cmp [value_type],4 |
3080 | cmp [value_type],4 |
3081 | je coff_relocation |
3081 | je coff_relocation |
3082 | mov al,11 ; R_AMD64_32S |
3082 | mov al,11 ; R_AMD64_32S |
3083 | jmp coff_relocation |
3083 | jmp coff_relocation |
3084 | elf_gotoff_relocation: |
3084 | elf_gotoff_relocation: |
3085 | test [format_flags],8 |
3085 | test [format_flags],8 |
3086 | jnz invalid_use_of_symbol |
3086 | jnz invalid_use_of_symbol |
3087 | mov al,9 ; R_386_GOTOFF |
3087 | mov al,9 ; R_386_GOTOFF |
3088 | jmp coff_relocation |
3088 | jmp coff_relocation |
3089 | elf_relocation_relative: |
3089 | elf_relocation_relative: |
3090 | cmp byte [ebx+9],0 |
3090 | cmp byte [ebx+9],0 |
3091 | je invalid_use_of_symbol |
3091 | je invalid_use_of_symbol |
3092 | mov ebx,[current_section] |
3092 | mov ebx,[current_section] |
3093 | mov ebx,[ebx+8] |
3093 | mov ebx,[ebx+8] |
3094 | sub ebx,edi |
3094 | sub ebx,edi |
3095 | sub eax,ebx |
3095 | sub eax,ebx |
3096 | push eax |
3096 | push eax |
3097 | mov al,2 ; R_386_PC32 / R_AMD64_PC32 |
3097 | mov al,2 ; R_386_PC32 / R_AMD64_PC32 |
3098 | cmp [value_type],3 |
3098 | cmp [value_type],3 |
3099 | je coff_relocation |
3099 | je coff_relocation |
3100 | mov al,4 ; R_386_PLT32 / R_AMD64_PLT32 |
3100 | mov al,4 ; R_386_PLT32 / R_AMD64_PLT32 |
3101 | jmp coff_relocation |
3101 | jmp coff_relocation |
3102 | close_elf: |
3102 | close_elf: |
3103 | bt [format_flags],0 |
3103 | bt [format_flags],0 |
3104 | jc close_elf_exe |
3104 | jc close_elf_exe |
3105 | call close_coff_section |
3105 | call close_coff_section |
3106 | cmp [next_pass_needed],0 |
3106 | cmp [next_pass_needed],0 |
3107 | je elf_closed |
3107 | je elf_closed |
3108 | mov eax,[symbols_stream] |
3108 | mov eax,[symbols_stream] |
3109 | mov [free_additional_memory],eax |
3109 | mov [free_additional_memory],eax |
3110 | elf_closed: |
3110 | elf_closed: |
3111 | ret |
3111 | ret |
3112 | elf_formatter: |
3112 | elf_formatter: |
3113 | mov ecx,edi |
3113 | mov ecx,edi |
3114 | sub ecx,[code_start] |
3114 | sub ecx,[code_start] |
3115 | neg ecx |
3115 | neg ecx |
3116 | and ecx,111b |
3116 | and ecx,111b |
3117 | test [format_flags],8 |
3117 | test [format_flags],8 |
3118 | jnz align_elf_structures |
3118 | jnz align_elf_structures |
3119 | and ecx,11b |
3119 | and ecx,11b |
3120 | align_elf_structures: |
3120 | align_elf_structures: |
3121 | xor al,al |
3121 | xor al,al |
3122 | rep stos byte [edi] |
3122 | rep stos byte [edi] |
3123 | push edi |
3123 | push edi |
3124 | call prepare_default_section |
3124 | call prepare_default_section |
3125 | mov esi,[symbols_stream] |
3125 | mov esi,[symbols_stream] |
3126 | mov edi,[free_additional_memory] |
3126 | mov edi,[free_additional_memory] |
3127 | xor eax,eax |
3127 | xor eax,eax |
3128 | mov ecx,4 |
3128 | mov ecx,4 |
3129 | rep stos dword [edi] |
3129 | rep stos dword [edi] |
3130 | test [format_flags],8 |
3130 | test [format_flags],8 |
3131 | jz find_first_section |
3131 | jz find_first_section |
3132 | mov ecx,2 |
3132 | mov ecx,2 |
3133 | rep stos dword [edi] |
3133 | rep stos dword [edi] |
3134 | find_first_section: |
3134 | find_first_section: |
3135 | mov al,[esi] |
3135 | mov al,[esi] |
3136 | or al,al |
3136 | or al,al |
3137 | jz first_section_found |
3137 | jz first_section_found |
3138 | cmp al,0C0h |
3138 | cmp al,0C0h |
3139 | jb skip_other_symbol |
3139 | jb skip_other_symbol |
3140 | add esi,4 |
3140 | add esi,4 |
3141 | skip_other_symbol: |
3141 | skip_other_symbol: |
3142 | add esi,0Ch |
3142 | add esi,0Ch |
3143 | jmp find_first_section |
3143 | jmp find_first_section |
3144 | first_section_found: |
3144 | first_section_found: |
3145 | mov ebx,esi |
3145 | mov ebx,esi |
3146 | mov ebp,esi |
3146 | mov ebp,esi |
3147 | add esi,20h |
3147 | add esi,20h |
3148 | xor ecx,ecx |
3148 | xor ecx,ecx |
3149 | xor edx,edx |
3149 | xor edx,edx |
3150 | find_next_section: |
3150 | find_next_section: |
3151 | cmp esi,[free_additional_memory] |
3151 | cmp esi,[free_additional_memory] |
3152 | je make_section_symbol |
3152 | je make_section_symbol |
3153 | mov al,[esi] |
3153 | mov al,[esi] |
3154 | or al,al |
3154 | or al,al |
3155 | jz make_section_symbol |
3155 | jz make_section_symbol |
3156 | cmp al,0C0h |
3156 | cmp al,0C0h |
3157 | jae skip_public |
3157 | jae skip_public |
3158 | cmp al,80h |
3158 | cmp al,80h |
3159 | jae skip_extrn |
3159 | jae skip_extrn |
3160 | or byte [ebx+14h],40h |
3160 | or byte [ebx+14h],40h |
3161 | skip_extrn: |
3161 | skip_extrn: |
3162 | add esi,0Ch |
3162 | add esi,0Ch |
3163 | jmp find_next_section |
3163 | jmp find_next_section |
3164 | skip_public: |
3164 | skip_public: |
3165 | add esi,10h |
3165 | add esi,10h |
3166 | jmp find_next_section |
3166 | jmp find_next_section |
3167 | make_section_symbol: |
3167 | make_section_symbol: |
3168 | mov eax,edi |
3168 | mov eax,edi |
3169 | xchg eax,[ebx+4] |
3169 | xchg eax,[ebx+4] |
3170 | stos dword [edi] |
3170 | stos dword [edi] |
3171 | test [format_flags],8 |
3171 | test [format_flags],8 |
3172 | jnz elf64_section_symbol |
3172 | jnz elf64_section_symbol |
3173 | xor eax,eax |
3173 | xor eax,eax |
3174 | stos dword [edi] |
3174 | stos dword [edi] |
3175 | stos dword [edi] |
3175 | stos dword [edi] |
3176 | call store_section_index |
3176 | call store_section_index |
3177 | jmp section_symbol_ok |
3177 | jmp section_symbol_ok |
3178 | store_section_index: |
3178 | store_section_index: |
3179 | inc ecx |
3179 | inc ecx |
3180 | mov eax,ecx |
3180 | mov eax,ecx |
3181 | shl eax,8 |
3181 | shl eax,8 |
3182 | mov [ebx],eax |
3182 | mov [ebx],eax |
3183 | inc dx |
3183 | inc dx |
3184 | jz format_limitations_exceeded |
3184 | jz format_limitations_exceeded |
3185 | mov eax,edx |
3185 | mov eax,edx |
3186 | shl eax,16 |
3186 | shl eax,16 |
3187 | mov al,3 |
3187 | mov al,3 |
3188 | test byte [ebx+14h],40h |
3188 | test byte [ebx+14h],40h |
3189 | jz section_index_ok |
3189 | jz section_index_ok |
3190 | or ah,-1 |
3190 | or ah,-1 |
3191 | inc dx |
3191 | inc dx |
3192 | jz format_limitations_exceeded |
3192 | jz format_limitations_exceeded |
3193 | section_index_ok: |
3193 | section_index_ok: |
3194 | stos dword [edi] |
3194 | stos dword [edi] |
3195 | ret |
3195 | ret |
3196 | elf64_section_symbol: |
3196 | elf64_section_symbol: |
3197 | call store_section_index |
3197 | call store_section_index |
3198 | xor eax,eax |
3198 | xor eax,eax |
3199 | stos dword [edi] |
3199 | stos dword [edi] |
3200 | stos dword [edi] |
3200 | stos dword [edi] |
3201 | stos dword [edi] |
3201 | stos dword [edi] |
3202 | stos dword [edi] |
3202 | stos dword [edi] |
3203 | section_symbol_ok: |
3203 | section_symbol_ok: |
3204 | mov ebx,esi |
3204 | mov ebx,esi |
3205 | add esi,20h |
3205 | add esi,20h |
3206 | cmp ebx,[free_additional_memory] |
3206 | cmp ebx,[free_additional_memory] |
3207 | jne find_next_section |
3207 | jne find_next_section |
3208 | inc dx |
3208 | inc dx |
3209 | jz format_limitations_exceeded |
3209 | jz format_limitations_exceeded |
3210 | mov [current_section],edx |
3210 | mov [current_section],edx |
3211 | mov esi,[symbols_stream] |
3211 | mov esi,[symbols_stream] |
3212 | find_other_symbols: |
3212 | find_other_symbols: |
3213 | cmp esi,[free_additional_memory] |
3213 | cmp esi,[free_additional_memory] |
3214 | je elf_symbol_table_ok |
3214 | je elf_symbol_table_ok |
3215 | mov al,[esi] |
3215 | mov al,[esi] |
3216 | or al,al |
3216 | or al,al |
3217 | jz skip_section |
3217 | jz skip_section |
3218 | cmp al,0C0h |
3218 | cmp al,0C0h |
3219 | jae make_public_symbol |
3219 | jae make_public_symbol |
3220 | cmp al,80h |
3220 | cmp al,80h |
3221 | jae make_extrn_symbol |
3221 | jae make_extrn_symbol |
3222 | add esi,0Ch |
3222 | add esi,0Ch |
3223 | jmp find_other_symbols |
3223 | jmp find_other_symbols |
3224 | skip_section: |
3224 | skip_section: |
3225 | add esi,20h |
3225 | add esi,20h |
3226 | jmp find_other_symbols |
3226 | jmp find_other_symbols |
3227 | make_public_symbol: |
3227 | make_public_symbol: |
3228 | mov eax,[esi+0Ch] |
3228 | mov eax,[esi+0Ch] |
3229 | mov [current_line],eax |
3229 | mov [current_line],eax |
3230 | cmp byte [esi],0C0h |
3230 | cmp byte [esi],0C0h |
3231 | jne invalid_argument |
3231 | jne invalid_argument |
3232 | mov ebx,[esi+8] |
3232 | mov ebx,[esi+8] |
3233 | test byte [ebx+8],1 |
3233 | test byte [ebx+8],1 |
3234 | jz undefined_public |
3234 | jz undefined_public |
3235 | mov ax,[current_pass] |
3235 | mov ax,[current_pass] |
3236 | cmp ax,[ebx+16] |
3236 | cmp ax,[ebx+16] |
3237 | jne undefined_public |
3237 | jne undefined_public |
3238 | mov dl,[ebx+11] |
3238 | mov dl,[ebx+11] |
3239 | or dl,dl |
3239 | or dl,dl |
3240 | jz public_absolute |
3240 | jz public_absolute |
3241 | mov eax,[ebx+20] |
3241 | mov eax,[ebx+20] |
3242 | cmp byte [eax],0 |
3242 | cmp byte [eax],0 |
3243 | jne invalid_use_of_symbol |
3243 | jne invalid_use_of_symbol |
3244 | mov eax,[eax+4] |
3244 | mov eax,[eax+4] |
3245 | test [format_flags],8 |
3245 | test [format_flags],8 |
3246 | jnz elf64_public |
3246 | jnz elf64_public |
3247 | cmp dl,2 |
3247 | cmp dl,2 |
3248 | jne invalid_use_of_symbol |
3248 | jne invalid_use_of_symbol |
3249 | mov dx,[eax+0Eh] |
3249 | mov dx,[eax+0Eh] |
3250 | jmp section_for_public_ok |
3250 | jmp section_for_public_ok |
3251 | undefined_public: |
3251 | undefined_public: |
3252 | mov [error_info],ebx |
3252 | mov [error_info],ebx |
3253 | jmp undefined_symbol |
3253 | jmp undefined_symbol |
3254 | elf64_public: |
3254 | elf64_public: |
3255 | cmp dl,4 |
3255 | cmp dl,4 |
3256 | jne invalid_use_of_symbol |
3256 | jne invalid_use_of_symbol |
3257 | mov dx,[eax+6] |
3257 | mov dx,[eax+6] |
3258 | jmp section_for_public_ok |
3258 | jmp section_for_public_ok |
3259 | public_absolute: |
3259 | public_absolute: |
3260 | mov dx,0FFF1h |
3260 | mov dx,0FFF1h |
3261 | section_for_public_ok: |
3261 | section_for_public_ok: |
3262 | mov eax,[esi+4] |
3262 | mov eax,[esi+4] |
3263 | stos dword [edi] |
3263 | stos dword [edi] |
3264 | test [format_flags],8 |
3264 | test [format_flags],8 |
3265 | jnz elf64_public_symbol |
3265 | jnz elf64_public_symbol |
3266 | movzx eax,byte [ebx+9] |
3266 | movzx eax,byte [ebx+9] |
3267 | shr al,1 |
3267 | shr al,1 |
3268 | and al,1 |
3268 | and al,1 |
3269 | neg eax |
3269 | neg eax |
3270 | cmp eax,[ebx+4] |
3270 | cmp eax,[ebx+4] |
3271 | jne value_out_of_range |
3271 | jne value_out_of_range |
3272 | xor eax,[ebx] |
3272 | xor eax,[ebx] |
3273 | js value_out_of_range |
3273 | js value_out_of_range |
3274 | mov eax,[ebx] |
3274 | mov eax,[ebx] |
3275 | stos dword [edi] |
3275 | stos dword [edi] |
3276 | xor eax,eax |
3276 | xor eax,eax |
3277 | mov al,[ebx+10] |
3277 | mov al,[ebx+10] |
3278 | stos dword [edi] |
3278 | stos dword [edi] |
3279 | mov eax,edx |
3279 | mov eax,edx |
3280 | shl eax,16 |
3280 | shl eax,16 |
3281 | mov al,10h |
3281 | mov al,10h |
3282 | cmp byte [ebx+10],0 |
3282 | cmp byte [ebx+10],0 |
3283 | je elf_public_function |
3283 | je elf_public_function |
3284 | or al,1 |
3284 | or al,1 |
3285 | jmp store_elf_public_info |
3285 | jmp store_elf_public_info |
3286 | elf_public_function: |
3286 | elf_public_function: |
3287 | or al,2 |
3287 | or al,2 |
3288 | store_elf_public_info: |
3288 | store_elf_public_info: |
3289 | stos dword [edi] |
3289 | stos dword [edi] |
3290 | jmp public_symbol_ok |
3290 | jmp public_symbol_ok |
3291 | elf64_public_symbol: |
3291 | elf64_public_symbol: |
3292 | mov eax,edx |
3292 | mov eax,edx |
3293 | shl eax,16 |
3293 | shl eax,16 |
3294 | mov al,10h |
3294 | mov al,10h |
3295 | cmp byte [ebx+10],0 |
3295 | cmp byte [ebx+10],0 |
3296 | je elf64_public_function |
3296 | je elf64_public_function |
3297 | or al,1 |
3297 | or al,1 |
3298 | jmp store_elf64_public_info |
3298 | jmp store_elf64_public_info |
3299 | elf64_public_function: |
3299 | elf64_public_function: |
3300 | or al,2 |
3300 | or al,2 |
3301 | store_elf64_public_info: |
3301 | store_elf64_public_info: |
3302 | stos dword [edi] |
3302 | stos dword [edi] |
3303 | mov al,[ebx+9] |
3303 | mov al,[ebx+9] |
3304 | shl eax,31-1 |
3304 | shl eax,31-1 |
3305 | xor eax,[ebx+4] |
3305 | xor eax,[ebx+4] |
3306 | js value_out_of_range |
3306 | js value_out_of_range |
3307 | mov eax,[ebx] |
3307 | mov eax,[ebx] |
3308 | stos dword [edi] |
3308 | stos dword [edi] |
3309 | mov eax,[ebx+4] |
3309 | mov eax,[ebx+4] |
3310 | stos dword [edi] |
3310 | stos dword [edi] |
3311 | mov al,[ebx+10] |
3311 | mov al,[ebx+10] |
3312 | stos dword [edi] |
3312 | stos dword [edi] |
3313 | xor al,al |
3313 | xor al,al |
3314 | stos dword [edi] |
3314 | stos dword [edi] |
3315 | public_symbol_ok: |
3315 | public_symbol_ok: |
3316 | inc ecx |
3316 | inc ecx |
3317 | mov eax,ecx |
3317 | mov eax,ecx |
3318 | shl eax,8 |
3318 | shl eax,8 |
3319 | mov al,0C0h |
3319 | mov al,0C0h |
3320 | mov [esi],eax |
3320 | mov [esi],eax |
3321 | add esi,10h |
3321 | add esi,10h |
3322 | jmp find_other_symbols |
3322 | jmp find_other_symbols |
3323 | make_extrn_symbol: |
3323 | make_extrn_symbol: |
3324 | mov eax,[esi+4] |
3324 | mov eax,[esi+4] |
3325 | stos dword [edi] |
3325 | stos dword [edi] |
3326 | test [format_flags],8 |
3326 | test [format_flags],8 |
3327 | jnz elf64_extrn_symbol |
3327 | jnz elf64_extrn_symbol |
3328 | xor eax,eax |
3328 | xor eax,eax |
3329 | stos dword [edi] |
3329 | stos dword [edi] |
3330 | mov eax,[esi+8] |
3330 | mov eax,[esi+8] |
3331 | stos dword [edi] |
3331 | stos dword [edi] |
3332 | mov eax,10h |
3332 | mov eax,10h |
3333 | stos dword [edi] |
3333 | stos dword [edi] |
3334 | jmp extrn_symbol_ok |
3334 | jmp extrn_symbol_ok |
3335 | elf64_extrn_symbol: |
3335 | elf64_extrn_symbol: |
3336 | mov eax,10h |
3336 | mov eax,10h |
3337 | stos dword [edi] |
3337 | stos dword [edi] |
3338 | xor al,al |
3338 | xor al,al |
3339 | stos dword [edi] |
3339 | stos dword [edi] |
3340 | stos dword [edi] |
3340 | stos dword [edi] |
3341 | mov eax,[esi+8] |
3341 | mov eax,[esi+8] |
3342 | stos dword [edi] |
3342 | stos dword [edi] |
3343 | xor eax,eax |
3343 | xor eax,eax |
3344 | stos dword [edi] |
3344 | stos dword [edi] |
3345 | extrn_symbol_ok: |
3345 | extrn_symbol_ok: |
3346 | inc ecx |
3346 | inc ecx |
3347 | mov eax,ecx |
3347 | mov eax,ecx |
3348 | shl eax,8 |
3348 | shl eax,8 |
3349 | mov al,80h |
3349 | mov al,80h |
3350 | mov [esi],eax |
3350 | mov [esi],eax |
3351 | add esi,0Ch |
3351 | add esi,0Ch |
3352 | jmp find_other_symbols |
3352 | jmp find_other_symbols |
3353 | elf_symbol_table_ok: |
3353 | elf_symbol_table_ok: |
3354 | mov edx,edi |
3354 | mov edx,edi |
3355 | mov ebx,[free_additional_memory] |
3355 | mov ebx,[free_additional_memory] |
3356 | xor al,al |
3356 | xor al,al |
3357 | stos byte [edi] |
3357 | stos byte [edi] |
3358 | add edi,16 |
3358 | add edi,16 |
3359 | mov [edx+1],edx |
3359 | mov [edx+1],edx |
3360 | add ebx,10h |
3360 | add ebx,10h |
3361 | test [format_flags],8 |
3361 | test [format_flags],8 |
3362 | jz make_string_table |
3362 | jz make_string_table |
3363 | add ebx,8 |
3363 | add ebx,8 |
3364 | make_string_table: |
3364 | make_string_table: |
3365 | cmp ebx,edx |
3365 | cmp ebx,edx |
3366 | je elf_string_table_ok |
3366 | je elf_string_table_ok |
3367 | test [format_flags],8 |
3367 | test [format_flags],8 |
3368 | jnz make_elf64_string |
3368 | jnz make_elf64_string |
3369 | cmp byte [ebx+0Dh],0 |
3369 | cmp byte [ebx+0Dh],0 |
3370 | je rel_prefix_ok |
3370 | je rel_prefix_ok |
3371 | mov byte [ebx+0Dh],0 |
3371 | mov byte [ebx+0Dh],0 |
3372 | mov eax,'.rel' |
3372 | mov eax,'.rel' |
3373 | stos dword [edi] |
3373 | stos dword [edi] |
3374 | rel_prefix_ok: |
3374 | rel_prefix_ok: |
3375 | mov esi,edi |
3375 | mov esi,edi |
3376 | sub esi,edx |
3376 | sub esi,edx |
3377 | xchg esi,[ebx] |
3377 | xchg esi,[ebx] |
3378 | add ebx,10h |
3378 | add ebx,10h |
3379 | make_elf_string: |
3379 | make_elf_string: |
3380 | or esi,esi |
3380 | or esi,esi |
3381 | jz default_string |
3381 | jz default_string |
3382 | lods dword [esi] |
3382 | lods dword [esi] |
3383 | mov ecx,eax |
3383 | mov ecx,eax |
3384 | rep movs byte [edi],[esi] |
3384 | rep movs byte [edi],[esi] |
3385 | xor al,al |
3385 | xor al,al |
3386 | stos byte [edi] |
3386 | stos byte [edi] |
3387 | jmp make_string_table |
3387 | jmp make_string_table |
3388 | make_elf64_string: |
3388 | make_elf64_string: |
3389 | cmp byte [ebx+5],0 |
3389 | cmp byte [ebx+5],0 |
3390 | je elf64_rel_prefix_ok |
3390 | je elf64_rel_prefix_ok |
3391 | mov byte [ebx+5],0 |
3391 | mov byte [ebx+5],0 |
3392 | mov eax,'.rel' |
3392 | mov eax,'.rel' |
3393 | stos dword [edi] |
3393 | stos dword [edi] |
3394 | mov al,'a' |
3394 | mov al,'a' |
3395 | stos byte [edi] |
3395 | stos byte [edi] |
3396 | elf64_rel_prefix_ok: |
3396 | elf64_rel_prefix_ok: |
3397 | mov esi,edi |
3397 | mov esi,edi |
3398 | sub esi,edx |
3398 | sub esi,edx |
3399 | xchg esi,[ebx] |
3399 | xchg esi,[ebx] |
3400 | add ebx,18h |
3400 | add ebx,18h |
3401 | jmp make_elf_string |
3401 | jmp make_elf_string |
3402 | default_string: |
3402 | default_string: |
3403 | mov eax,'.fla' |
3403 | mov eax,'.fla' |
3404 | stos dword [edi] |
3404 | stos dword [edi] |
3405 | mov ax,'t' |
3405 | mov ax,'t' |
3406 | stos word [edi] |
3406 | stos word [edi] |
3407 | jmp make_string_table |
3407 | jmp make_string_table |
3408 | elf_string_table_ok: |
3408 | elf_string_table_ok: |
3409 | mov [edx+1+8],edi |
3409 | mov [edx+1+8],edi |
3410 | mov ebx,[code_start] |
3410 | mov ebx,[code_start] |
3411 | mov eax,edi |
3411 | mov eax,edi |
3412 | sub eax,[free_additional_memory] |
3412 | sub eax,[free_additional_memory] |
3413 | xor ecx,ecx |
3413 | xor ecx,ecx |
3414 | sub ecx,eax |
3414 | sub ecx,eax |
3415 | test [format_flags],8 |
3415 | test [format_flags],8 |
3416 | jnz finish_elf64_header |
3416 | jnz finish_elf64_header |
3417 | and ecx,11b |
3417 | and ecx,11b |
3418 | add eax,ecx |
3418 | add eax,ecx |
3419 | mov [ebx+20h],eax |
3419 | mov [ebx+20h],eax |
3420 | mov eax,[current_section] |
3420 | mov eax,[current_section] |
3421 | inc ax |
3421 | inc ax |
3422 | jz format_limitations_exceeded |
3422 | jz format_limitations_exceeded |
3423 | mov [ebx+32h],ax |
3423 | mov [ebx+32h],ax |
3424 | inc ax |
3424 | inc ax |
3425 | jz format_limitations_exceeded |
3425 | jz format_limitations_exceeded |
3426 | mov [ebx+30h],ax |
3426 | mov [ebx+30h],ax |
3427 | jmp elf_header_finished |
3427 | jmp elf_header_finished |
3428 | finish_elf64_header: |
3428 | finish_elf64_header: |
3429 | and ecx,111b |
3429 | and ecx,111b |
3430 | add eax,ecx |
3430 | add eax,ecx |
3431 | mov [ebx+28h],eax |
3431 | mov [ebx+28h],eax |
3432 | mov eax,[current_section] |
3432 | mov eax,[current_section] |
3433 | inc ax |
3433 | inc ax |
3434 | jz format_limitations_exceeded |
3434 | jz format_limitations_exceeded |
3435 | mov [ebx+3Eh],ax |
3435 | mov [ebx+3Eh],ax |
3436 | inc ax |
3436 | inc ax |
3437 | jz format_limitations_exceeded |
3437 | jz format_limitations_exceeded |
3438 | mov [ebx+3Ch],ax |
3438 | mov [ebx+3Ch],ax |
3439 | elf_header_finished: |
3439 | elf_header_finished: |
3440 | xor eax,eax |
3440 | xor eax,eax |
3441 | add ecx,10*4 |
3441 | add ecx,10*4 |
3442 | rep stos byte [edi] |
3442 | rep stos byte [edi] |
3443 | test [format_flags],8 |
3443 | test [format_flags],8 |
3444 | jz elf_null_section_ok |
3444 | jz elf_null_section_ok |
3445 | mov ecx,6*4 |
3445 | mov ecx,6*4 |
3446 | rep stos byte [edi] |
3446 | rep stos byte [edi] |
3447 | elf_null_section_ok: |
3447 | elf_null_section_ok: |
3448 | mov esi,ebp |
3448 | mov esi,ebp |
3449 | xor ecx,ecx |
3449 | xor ecx,ecx |
3450 | make_section_entry: |
3450 | make_section_entry: |
3451 | mov ebx,edi |
3451 | mov ebx,edi |
3452 | mov eax,[esi+4] |
3452 | mov eax,[esi+4] |
3453 | mov eax,[eax] |
3453 | mov eax,[eax] |
3454 | stos dword [edi] |
3454 | stos dword [edi] |
3455 | mov eax,1 |
3455 | mov eax,1 |
3456 | cmp dword [esi+0Ch],0 |
3456 | cmp dword [esi+0Ch],0 |
3457 | je bss_section |
3457 | je bss_section |
3458 | test byte [esi+14h],80h |
3458 | test byte [esi+14h],80h |
3459 | jz section_type_ok |
3459 | jz section_type_ok |
3460 | bss_section: |
3460 | bss_section: |
3461 | mov al,8 |
3461 | mov al,8 |
3462 | section_type_ok: |
3462 | section_type_ok: |
3463 | stos dword [edi] |
3463 | stos dword [edi] |
3464 | mov eax,[esi+14h] |
3464 | mov eax,[esi+14h] |
3465 | and al,3Fh |
3465 | and al,3Fh |
3466 | call store_elf_machine_word |
3466 | call store_elf_machine_word |
3467 | xor eax,eax |
3467 | xor eax,eax |
3468 | call store_elf_machine_word |
3468 | call store_elf_machine_word |
3469 | mov eax,[esi+8] |
3469 | mov eax,[esi+8] |
3470 | mov [image_base],eax |
3470 | mov [image_base],eax |
3471 | sub eax,[code_start] |
3471 | sub eax,[code_start] |
3472 | call store_elf_machine_word |
3472 | call store_elf_machine_word |
3473 | mov eax,[esi+0Ch] |
3473 | mov eax,[esi+0Ch] |
3474 | call store_elf_machine_word |
3474 | call store_elf_machine_word |
3475 | xor eax,eax |
3475 | xor eax,eax |
3476 | stos dword [edi] |
3476 | stos dword [edi] |
3477 | stos dword [edi] |
3477 | stos dword [edi] |
3478 | mov eax,[esi+10h] |
3478 | mov eax,[esi+10h] |
3479 | call store_elf_machine_word |
3479 | call store_elf_machine_word |
3480 | xor eax,eax |
3480 | xor eax,eax |
3481 | call store_elf_machine_word |
3481 | call store_elf_machine_word |
3482 | inc ecx |
3482 | inc ecx |
3483 | add esi,20h |
3483 | add esi,20h |
3484 | xchg edi,[esp] |
3484 | xchg edi,[esp] |
3485 | mov ebp,edi |
3485 | mov ebp,edi |
3486 | convert_relocations: |
3486 | convert_relocations: |
3487 | cmp esi,[free_additional_memory] |
3487 | cmp esi,[free_additional_memory] |
3488 | je relocations_converted |
3488 | je relocations_converted |
3489 | mov al,[esi] |
3489 | mov al,[esi] |
3490 | or al,al |
3490 | or al,al |
3491 | jz relocations_converted |
3491 | jz relocations_converted |
3492 | cmp al,80h |
3492 | cmp al,80h |
3493 | jb make_relocation_entry |
3493 | jb make_relocation_entry |
3494 | cmp al,0C0h |
3494 | cmp al,0C0h |
3495 | jb relocation_entry_ok |
3495 | jb relocation_entry_ok |
3496 | add esi,10h |
3496 | add esi,10h |
3497 | jmp convert_relocations |
3497 | jmp convert_relocations |
3498 | make_relocation_entry: |
3498 | make_relocation_entry: |
3499 | test [format_flags],8 |
3499 | test [format_flags],8 |
3500 | jnz make_elf64_relocation_entry |
3500 | jnz make_elf64_relocation_entry |
3501 | mov eax,[esi+4] |
3501 | mov eax,[esi+4] |
3502 | stos dword [edi] |
3502 | stos dword [edi] |
3503 | mov eax,[esi+8] |
3503 | mov eax,[esi+8] |
3504 | mov eax,[eax] |
3504 | mov eax,[eax] |
3505 | mov al,[esi] |
3505 | mov al,[esi] |
3506 | stos dword [edi] |
3506 | stos dword [edi] |
3507 | jmp relocation_entry_ok |
3507 | jmp relocation_entry_ok |
3508 | make_elf64_relocation_entry: |
3508 | make_elf64_relocation_entry: |
3509 | mov eax,[esi+4] |
3509 | mov eax,[esi+4] |
3510 | stos dword [edi] |
3510 | stos dword [edi] |
3511 | xor eax,eax |
3511 | xor eax,eax |
3512 | stos dword [edi] |
3512 | stos dword [edi] |
3513 | movzx eax,byte [esi] |
3513 | movzx eax,byte [esi] |
3514 | stos dword [edi] |
3514 | stos dword [edi] |
3515 | mov eax,[esi+8] |
3515 | mov eax,[esi+8] |
3516 | mov eax,[eax] |
3516 | mov eax,[eax] |
3517 | shr eax,8 |
3517 | shr eax,8 |
3518 | stos dword [edi] |
3518 | stos dword [edi] |
3519 | xor eax,eax |
3519 | xor eax,eax |
3520 | push edx |
3520 | push edx |
3521 | mov edx,[esi+4] |
3521 | mov edx,[esi+4] |
3522 | add edx,[image_base] |
3522 | add edx,[image_base] |
3523 | xchg eax,[edx] |
3523 | xchg eax,[edx] |
3524 | stos dword [edi] |
3524 | stos dword [edi] |
3525 | cmp byte [esi],1 |
3525 | cmp byte [esi],1 |
3526 | je addend_64bit |
3526 | je addend_64bit |
3527 | pop edx |
3527 | pop edx |
3528 | sar eax,31 |
3528 | sar eax,31 |
3529 | stos dword [edi] |
3529 | stos dword [edi] |
3530 | jmp relocation_entry_ok |
3530 | jmp relocation_entry_ok |
3531 | addend_64bit: |
3531 | addend_64bit: |
3532 | xor eax,eax |
3532 | xor eax,eax |
3533 | xchg eax,[edx+4] |
3533 | xchg eax,[edx+4] |
3534 | stos dword [edi] |
3534 | stos dword [edi] |
3535 | pop edx |
3535 | pop edx |
3536 | relocation_entry_ok: |
3536 | relocation_entry_ok: |
3537 | add esi,0Ch |
3537 | add esi,0Ch |
3538 | jmp convert_relocations |
3538 | jmp convert_relocations |
3539 | store_elf_machine_word: |
3539 | store_elf_machine_word: |
3540 | stos dword [edi] |
3540 | stos dword [edi] |
3541 | test [format_flags],8 |
3541 | test [format_flags],8 |
3542 | jz elf_machine_word_ok |
3542 | jz elf_machine_word_ok |
3543 | and dword [edi],0 |
3543 | and dword [edi],0 |
3544 | add edi,4 |
3544 | add edi,4 |
3545 | elf_machine_word_ok: |
3545 | elf_machine_word_ok: |
3546 | ret |
3546 | ret |
3547 | relocations_converted: |
3547 | relocations_converted: |
3548 | cmp edi,ebp |
3548 | cmp edi,ebp |
3549 | xchg edi,[esp] |
3549 | xchg edi,[esp] |
3550 | je rel_section_ok |
3550 | je rel_section_ok |
3551 | mov eax,[ebx] |
3551 | mov eax,[ebx] |
3552 | sub eax,4 |
3552 | sub eax,4 |
3553 | test [format_flags],8 |
3553 | test [format_flags],8 |
3554 | jz store_relocations_name_offset |
3554 | jz store_relocations_name_offset |
3555 | dec eax |
3555 | dec eax |
3556 | store_relocations_name_offset: |
3556 | store_relocations_name_offset: |
3557 | stos dword [edi] |
3557 | stos dword [edi] |
3558 | test [format_flags],8 |
3558 | test [format_flags],8 |
3559 | jnz rela_section |
3559 | jnz rela_section |
3560 | mov eax,9 |
3560 | mov eax,9 |
3561 | jmp store_relocations_type |
3561 | jmp store_relocations_type |
3562 | rela_section: |
3562 | rela_section: |
3563 | mov eax,4 |
3563 | mov eax,4 |
3564 | store_relocations_type: |
3564 | store_relocations_type: |
3565 | stos dword [edi] |
3565 | stos dword [edi] |
3566 | xor al,al |
3566 | xor al,al |
3567 | call store_elf_machine_word |
3567 | call store_elf_machine_word |
3568 | call store_elf_machine_word |
3568 | call store_elf_machine_word |
3569 | mov eax,ebp |
3569 | mov eax,ebp |
3570 | sub eax,[code_start] |
3570 | sub eax,[code_start] |
3571 | call store_elf_machine_word |
3571 | call store_elf_machine_word |
3572 | mov eax,[esp] |
3572 | mov eax,[esp] |
3573 | sub eax,ebp |
3573 | sub eax,ebp |
3574 | call store_elf_machine_word |
3574 | call store_elf_machine_word |
3575 | mov eax,[current_section] |
3575 | mov eax,[current_section] |
3576 | stos dword [edi] |
3576 | stos dword [edi] |
3577 | mov eax,ecx |
3577 | mov eax,ecx |
3578 | stos dword [edi] |
3578 | stos dword [edi] |
3579 | inc ecx |
3579 | inc ecx |
3580 | test [format_flags],8 |
3580 | test [format_flags],8 |
3581 | jnz finish_elf64_rela_section |
3581 | jnz finish_elf64_rela_section |
3582 | mov eax,4 |
3582 | mov eax,4 |
3583 | stos dword [edi] |
3583 | stos dword [edi] |
3584 | mov al,8 |
3584 | mov al,8 |
3585 | stos dword [edi] |
3585 | stos dword [edi] |
3586 | jmp rel_section_ok |
3586 | jmp rel_section_ok |
3587 | finish_elf64_rela_section: |
3587 | finish_elf64_rela_section: |
3588 | mov eax,8 |
3588 | mov eax,8 |
3589 | stos dword [edi] |
3589 | stos dword [edi] |
3590 | xor al,al |
3590 | xor al,al |
3591 | stos dword [edi] |
3591 | stos dword [edi] |
3592 | mov al,24 |
3592 | mov al,24 |
3593 | stos dword [edi] |
3593 | stos dword [edi] |
3594 | xor al,al |
3594 | xor al,al |
3595 | stos dword [edi] |
3595 | stos dword [edi] |
3596 | rel_section_ok: |
3596 | rel_section_ok: |
3597 | cmp esi,[free_additional_memory] |
3597 | cmp esi,[free_additional_memory] |
3598 | jne make_section_entry |
3598 | jne make_section_entry |
3599 | pop eax |
3599 | pop eax |
3600 | mov ebx,[code_start] |
3600 | mov ebx,[code_start] |
3601 | sub eax,ebx |
3601 | sub eax,ebx |
3602 | mov [code_size],eax |
3602 | mov [code_size],eax |
3603 | mov ecx,20h |
3603 | mov ecx,20h |
3604 | test [format_flags],8 |
3604 | test [format_flags],8 |
3605 | jz adjust_elf_section_headers_offset |
3605 | jz adjust_elf_section_headers_offset |
3606 | mov ecx,28h |
3606 | mov ecx,28h |
3607 | adjust_elf_section_headers_offset: |
3607 | adjust_elf_section_headers_offset: |
3608 | add [ebx+ecx],eax |
3608 | add [ebx+ecx],eax |
3609 | mov eax,1 |
3609 | mov eax,1 |
3610 | stos dword [edi] |
3610 | stos dword [edi] |
3611 | mov al,2 |
3611 | mov al,2 |
3612 | stos dword [edi] |
3612 | stos dword [edi] |
3613 | xor al,al |
3613 | xor al,al |
3614 | call store_elf_machine_word |
3614 | call store_elf_machine_word |
3615 | call store_elf_machine_word |
3615 | call store_elf_machine_word |
3616 | mov eax,[code_size] |
3616 | mov eax,[code_size] |
3617 | call store_elf_machine_word |
3617 | call store_elf_machine_word |
3618 | mov eax,[edx+1] |
3618 | mov eax,[edx+1] |
3619 | sub eax,[free_additional_memory] |
3619 | sub eax,[free_additional_memory] |
3620 | call store_elf_machine_word |
3620 | call store_elf_machine_word |
3621 | mov eax,[current_section] |
3621 | mov eax,[current_section] |
3622 | inc eax |
3622 | inc eax |
3623 | stos dword [edi] |
3623 | stos dword [edi] |
3624 | mov eax,[number_of_sections] |
3624 | mov eax,[number_of_sections] |
3625 | inc eax |
3625 | inc eax |
3626 | stos dword [edi] |
3626 | stos dword [edi] |
3627 | test [format_flags],8 |
3627 | test [format_flags],8 |
3628 | jnz finish_elf64_sym_section |
3628 | jnz finish_elf64_sym_section |
3629 | mov eax,4 |
3629 | mov eax,4 |
3630 | stos dword [edi] |
3630 | stos dword [edi] |
3631 | mov al,10h |
3631 | mov al,10h |
3632 | stos dword [edi] |
3632 | stos dword [edi] |
3633 | jmp sym_section_ok |
3633 | jmp sym_section_ok |
3634 | finish_elf64_sym_section: |
3634 | finish_elf64_sym_section: |
3635 | mov eax,8 |
3635 | mov eax,8 |
3636 | stos dword [edi] |
3636 | stos dword [edi] |
3637 | xor al,al |
3637 | xor al,al |
3638 | stos dword [edi] |
3638 | stos dword [edi] |
3639 | mov al,18h |
3639 | mov al,18h |
3640 | stos dword [edi] |
3640 | stos dword [edi] |
3641 | xor al,al |
3641 | xor al,al |
3642 | stos dword [edi] |
3642 | stos dword [edi] |
3643 | sym_section_ok: |
3643 | sym_section_ok: |
3644 | mov al,1+8 |
3644 | mov al,1+8 |
3645 | stos dword [edi] |
3645 | stos dword [edi] |
3646 | mov al,3 |
3646 | mov al,3 |
3647 | stos dword [edi] |
3647 | stos dword [edi] |
3648 | xor al,al |
3648 | xor al,al |
3649 | call store_elf_machine_word |
3649 | call store_elf_machine_word |
3650 | call store_elf_machine_word |
3650 | call store_elf_machine_word |
3651 | mov eax,[edx+1] |
3651 | mov eax,[edx+1] |
3652 | sub eax,[free_additional_memory] |
3652 | sub eax,[free_additional_memory] |
3653 | add eax,[code_size] |
3653 | add eax,[code_size] |
3654 | call store_elf_machine_word |
3654 | call store_elf_machine_word |
3655 | mov eax,[edx+1+8] |
3655 | mov eax,[edx+1+8] |
3656 | sub eax,[edx+1] |
3656 | sub eax,[edx+1] |
3657 | call store_elf_machine_word |
3657 | call store_elf_machine_word |
3658 | xor eax,eax |
3658 | xor eax,eax |
3659 | stos dword [edi] |
3659 | stos dword [edi] |
3660 | stos dword [edi] |
3660 | stos dword [edi] |
3661 | mov al,1 |
3661 | mov al,1 |
3662 | call store_elf_machine_word |
3662 | call store_elf_machine_word |
3663 | xor eax,eax |
3663 | xor eax,eax |
3664 | call store_elf_machine_word |
3664 | call store_elf_machine_word |
3665 | mov eax,'tab' |
3665 | mov eax,'tab' |
3666 | mov dword [edx+1],'.sym' |
3666 | mov dword [edx+1],'.sym' |
3667 | mov [edx+1+4],eax |
3667 | mov [edx+1+4],eax |
3668 | mov dword [edx+1+8],'.str' |
3668 | mov dword [edx+1+8],'.str' |
3669 | mov [edx+1+8+4],eax |
3669 | mov [edx+1+8+4],eax |
3670 | mov [resource_data],edx |
3670 | mov [resource_data],edx |
3671 | mov [written_size],0 |
3671 | mov [written_size],0 |
3672 | mov edx,[output_file] |
3672 | mov edx,[output_file] |
3673 | call create |
3673 | call create |
3674 | jc write_failed |
3674 | jc write_failed |
3675 | call write_code |
3675 | call write_code |
3676 | mov ecx,edi |
3676 | mov ecx,edi |
3677 | mov edx,[free_additional_memory] |
3677 | mov edx,[free_additional_memory] |
3678 | sub ecx,edx |
3678 | sub ecx,edx |
3679 | add [written_size],ecx |
3679 | add [written_size],ecx |
3680 | call write |
3680 | call write |
3681 | jc write_failed |
3681 | jc write_failed |
3682 | jmp output_written |
3682 | jmp output_written |
3683 | 3683 | ||
3684 | format_elf_exe: |
3684 | format_elf_exe: |
3685 | add esi,2 |
3685 | add esi,2 |
3686 | or [format_flags],1 |
3686 | or [format_flags],1 |
3687 | cmp byte [esi],'(' |
3687 | cmp byte [esi],'(' |
3688 | jne elf_exe_brand_ok |
3688 | jne elf_exe_brand_ok |
3689 | inc esi |
3689 | inc esi |
3690 | cmp byte [esi],'.' |
3690 | cmp byte [esi],'.' |
3691 | je invalid_value |
3691 | je invalid_value |
3692 | push edx |
3692 | push edx |
3693 | call get_byte_value |
3693 | call get_byte_value |
3694 | cmp [value_type],0 |
3694 | cmp [value_type],0 |
3695 | jne invalid_use_of_symbol |
3695 | jne invalid_use_of_symbol |
3696 | pop edx |
3696 | pop edx |
3697 | mov [edx+7],al |
3697 | mov [edx+7],al |
3698 | elf_exe_brand_ok: |
3698 | elf_exe_brand_ok: |
3699 | mov [image_base],8048000h |
3699 | mov [image_base],8048000h |
3700 | cmp byte [esi],80h |
3700 | cmp byte [esi],80h |
3701 | jne elf_exe_base_ok |
3701 | jne elf_exe_base_ok |
3702 | lods word [esi] |
3702 | lods word [esi] |
3703 | cmp ah,'(' |
3703 | cmp ah,'(' |
3704 | jne invalid_argument |
3704 | jne invalid_argument |
3705 | cmp byte [esi],'.' |
3705 | cmp byte [esi],'.' |
3706 | je invalid_value |
3706 | je invalid_value |
3707 | push edx |
3707 | push edx |
3708 | call get_dword_value |
3708 | call get_dword_value |
3709 | cmp [value_type],0 |
3709 | cmp [value_type],0 |
3710 | jne invalid_use_of_symbol |
3710 | jne invalid_use_of_symbol |
3711 | mov [image_base],eax |
3711 | mov [image_base],eax |
3712 | pop edx |
3712 | pop edx |
3713 | elf_exe_base_ok: |
3713 | elf_exe_base_ok: |
3714 | mov byte [edx+2Ah],20h |
3714 | mov byte [edx+2Ah],20h |
3715 | mov ebx,edi |
3715 | mov ebx,edi |
3716 | mov ecx,20h shr 2 |
3716 | mov ecx,20h shr 2 |
3717 | cmp [current_pass],0 |
3717 | cmp [current_pass],0 |
3718 | je init_elf_segments |
3718 | je init_elf_segments |
3719 | imul ecx,[number_of_sections] |
3719 | imul ecx,[number_of_sections] |
3720 | init_elf_segments: |
3720 | init_elf_segments: |
3721 | xor eax,eax |
3721 | xor eax,eax |
3722 | rep stos dword [edi] |
3722 | rep stos dword [edi] |
3723 | and [number_of_sections],0 |
3723 | and [number_of_sections],0 |
3724 | mov byte [ebx],1 |
3724 | mov byte [ebx],1 |
3725 | mov word [ebx+1Ch],1000h |
3725 | mov word [ebx+1Ch],1000h |
3726 | mov byte [ebx+18h],111b |
3726 | mov byte [ebx+18h],111b |
3727 | mov ebp,[image_base] |
3727 | mov ebp,[image_base] |
3728 | and dword [ebx+4],0 |
3728 | and dword [ebx+4],0 |
3729 | mov [ebx+8],ebp |
3729 | mov [ebx+8],ebp |
3730 | mov [ebx+0Ch],ebp |
3730 | mov [ebx+0Ch],ebp |
3731 | mov eax,edi |
3731 | mov eax,edi |
3732 | sub eax,[code_start] |
3732 | sub eax,[code_start] |
3733 | add eax,ebp |
3733 | add eax,ebp |
3734 | mov [edx+18h],eax |
3734 | mov [edx+18h],eax |
3735 | and [image_base_high],0 |
3735 | and [image_base_high],0 |
3736 | elf_exe_addressing_setup: |
3736 | elf_exe_addressing_setup: |
3737 | call init_addressing_space |
3737 | call init_addressing_space |
3738 | call setup_elf_exe_labels_type |
3738 | call setup_elf_exe_labels_type |
3739 | mov eax,[code_start] |
3739 | mov eax,[code_start] |
3740 | xor edx,edx |
3740 | xor edx,edx |
3741 | xor cl,cl |
3741 | xor cl,cl |
3742 | sub eax,[image_base] |
3742 | sub eax,[image_base] |
3743 | sbb edx,[image_base_high] |
3743 | sbb edx,[image_base_high] |
3744 | sbb cl,0 |
3744 | sbb cl,0 |
3745 | mov [ebx],eax |
3745 | mov [ebx],eax |
3746 | mov [ebx+4],edx |
3746 | mov [ebx+4],edx |
3747 | mov [ebx+8],cl |
3747 | mov [ebx+8],cl |
3748 | mov [symbols_stream],edi |
3748 | mov [symbols_stream],edi |
3749 | jmp format_defined |
3749 | jmp format_defined |
3750 | format_elf64_exe: |
3750 | format_elf64_exe: |
3751 | add esi,2 |
3751 | add esi,2 |
3752 | or [format_flags],1 |
3752 | or [format_flags],1 |
3753 | cmp byte [esi],'(' |
3753 | cmp byte [esi],'(' |
3754 | jne elf64_exe_brand_ok |
3754 | jne elf64_exe_brand_ok |
3755 | inc esi |
3755 | inc esi |
3756 | cmp byte [esi],'.' |
3756 | cmp byte [esi],'.' |
3757 | je invalid_value |
3757 | je invalid_value |
3758 | push edx |
3758 | push edx |
3759 | call get_byte_value |
3759 | call get_byte_value |
3760 | cmp [value_type],0 |
3760 | cmp [value_type],0 |
3761 | jne invalid_use_of_symbol |
3761 | jne invalid_use_of_symbol |
3762 | pop edx |
3762 | pop edx |
3763 | mov [edx+7],al |
3763 | mov [edx+7],al |
3764 | elf64_exe_brand_ok: |
3764 | elf64_exe_brand_ok: |
3765 | mov [image_base],400000h |
3765 | mov [image_base],400000h |
3766 | and [image_base_high],0 |
3766 | and [image_base_high],0 |
3767 | cmp byte [esi],80h |
3767 | cmp byte [esi],80h |
3768 | jne elf64_exe_base_ok |
3768 | jne elf64_exe_base_ok |
3769 | lods word [esi] |
3769 | lods word [esi] |
3770 | cmp ah,'(' |
3770 | cmp ah,'(' |
3771 | jne invalid_argument |
3771 | jne invalid_argument |
3772 | cmp byte [esi],'.' |
3772 | cmp byte [esi],'.' |
3773 | je invalid_value |
3773 | je invalid_value |
3774 | push edx |
3774 | push edx |
3775 | call get_qword_value |
3775 | call get_qword_value |
3776 | cmp [value_type],0 |
3776 | cmp [value_type],0 |
3777 | jne invalid_use_of_symbol |
3777 | jne invalid_use_of_symbol |
3778 | mov [image_base],eax |
3778 | mov [image_base],eax |
3779 | mov [image_base_high],edx |
3779 | mov [image_base_high],edx |
3780 | pop edx |
3780 | pop edx |
3781 | elf64_exe_base_ok: |
3781 | elf64_exe_base_ok: |
3782 | mov byte [edx+36h],38h |
3782 | mov byte [edx+36h],38h |
3783 | mov ebx,edi |
3783 | mov ebx,edi |
3784 | mov ecx,38h shr 2 |
3784 | mov ecx,38h shr 2 |
3785 | cmp [current_pass],0 |
3785 | cmp [current_pass],0 |
3786 | je init_elf64_segments |
3786 | je init_elf64_segments |
3787 | imul ecx,[number_of_sections] |
3787 | imul ecx,[number_of_sections] |
3788 | init_elf64_segments: |
3788 | init_elf64_segments: |
3789 | xor eax,eax |
3789 | xor eax,eax |
3790 | rep stos dword [edi] |
3790 | rep stos dword [edi] |
3791 | and [number_of_sections],0 |
3791 | and [number_of_sections],0 |
3792 | mov byte [ebx],1 |
3792 | mov byte [ebx],1 |
3793 | mov word [ebx+30h],1000h |
3793 | mov word [ebx+30h],1000h |
3794 | mov byte [ebx+4],111b |
3794 | mov byte [ebx+4],111b |
3795 | mov ebp,[image_base] |
3795 | mov ebp,[image_base] |
3796 | mov ecx,[image_base_high] |
3796 | mov ecx,[image_base_high] |
3797 | and dword [ebx+8],0 |
3797 | and dword [ebx+8],0 |
3798 | mov [ebx+10h],ebp |
3798 | mov [ebx+10h],ebp |
3799 | mov [ebx+10h+4],ecx |
3799 | mov [ebx+10h+4],ecx |
3800 | mov [ebx+18h],ebp |
3800 | mov [ebx+18h],ebp |
3801 | mov [ebx+18h+4],ecx |
3801 | mov [ebx+18h+4],ecx |
3802 | mov eax,edi |
3802 | mov eax,edi |
3803 | sub eax,[code_start] |
3803 | sub eax,[code_start] |
3804 | add eax,ebp |
3804 | add eax,ebp |
3805 | adc ecx,0 |
3805 | adc ecx,0 |
3806 | mov [edx+18h],eax |
3806 | mov [edx+18h],eax |
3807 | mov [edx+18h+4],ecx |
3807 | mov [edx+18h+4],ecx |
3808 | jmp elf_exe_addressing_setup |
3808 | jmp elf_exe_addressing_setup |
3809 | setup_elf_exe_labels_type: |
3809 | setup_elf_exe_labels_type: |
3810 | mov eax,[code_start] |
3810 | mov eax,[code_start] |
3811 | cmp byte [eax+10h],3 |
3811 | cmp byte [eax+10h],3 |
3812 | jne elf_exe_labels_type_ok |
3812 | jne elf_exe_labels_type_ok |
3813 | mov byte [ebx+9],2 |
3813 | mov byte [ebx+9],2 |
3814 | test [format_flags],8 |
3814 | test [format_flags],8 |
3815 | jz elf_exe_labels_type_ok |
3815 | jz elf_exe_labels_type_ok |
3816 | mov byte [ebx+9],4 |
3816 | mov byte [ebx+9],4 |
3817 | elf_exe_labels_type_ok: |
3817 | elf_exe_labels_type_ok: |
3818 | ret |
3818 | ret |
3819 | elf_entry: |
3819 | elf_entry: |
3820 | lods byte [esi] |
3820 | lods byte [esi] |
3821 | cmp al,'(' |
3821 | cmp al,'(' |
3822 | jne invalid_argument |
3822 | jne invalid_argument |
3823 | cmp byte [esi],'.' |
3823 | cmp byte [esi],'.' |
3824 | je invalid_value |
3824 | je invalid_value |
3825 | test [format_flags],8 |
3825 | test [format_flags],8 |
3826 | jnz elf64_entry |
3826 | jnz elf64_entry |
3827 | call get_dword_value |
3827 | call get_dword_value |
3828 | mov edx,[code_start] |
3828 | mov edx,[code_start] |
3829 | mov [edx+18h],eax |
3829 | mov [edx+18h],eax |
3830 | jmp instruction_assembled |
3830 | jmp instruction_assembled |
3831 | elf64_entry: |
3831 | elf64_entry: |
3832 | call get_qword_value |
3832 | call get_qword_value |
3833 | mov ebx,[code_start] |
3833 | mov ebx,[code_start] |
3834 | mov [ebx+18h],eax |
3834 | mov [ebx+18h],eax |
3835 | mov [ebx+1Ch],edx |
3835 | mov [ebx+1Ch],edx |
3836 | jmp instruction_assembled |
3836 | jmp instruction_assembled |
3837 | elf_segment: |
3837 | elf_segment: |
3838 | bt [format_flags],0 |
3838 | bt [format_flags],0 |
3839 | jnc illegal_instruction |
3839 | jnc illegal_instruction |
3840 | test [format_flags],8 |
3840 | test [format_flags],8 |
3841 | jnz elf64_segment |
3841 | jnz elf64_segment |
3842 | call close_elf_segment |
3842 | call close_elf_segment |
3843 | push eax |
3843 | push eax |
3844 | call create_addressing_space |
3844 | call create_addressing_space |
3845 | call setup_elf_exe_labels_type |
3845 | call setup_elf_exe_labels_type |
3846 | mov ebp,ebx |
3846 | mov ebp,ebx |
3847 | mov ebx,[number_of_sections] |
3847 | mov ebx,[number_of_sections] |
3848 | shl ebx,5 |
3848 | shl ebx,5 |
3849 | add ebx,[code_start] |
3849 | add ebx,[code_start] |
3850 | add ebx,34h |
3850 | add ebx,34h |
3851 | cmp ebx,[symbols_stream] |
3851 | cmp ebx,[symbols_stream] |
3852 | jb new_elf_segment |
3852 | jb new_elf_segment |
3853 | mov ebx,[symbols_stream] |
3853 | mov ebx,[symbols_stream] |
3854 | sub ebx,20h |
3854 | sub ebx,20h |
3855 | or [next_pass_needed],-1 |
3855 | or [next_pass_needed],-1 |
3856 | new_elf_segment: |
3856 | new_elf_segment: |
3857 | mov byte [ebx],1 |
3857 | mov byte [ebx],1 |
3858 | and dword [ebx+18h],0 |
3858 | and dword [ebx+18h],0 |
3859 | mov word [ebx+1Ch],1000h |
3859 | mov word [ebx+1Ch],1000h |
3860 | elf_segment_flags: |
3860 | elf_segment_flags: |
3861 | cmp byte [esi],1Eh |
3861 | cmp byte [esi],1Eh |
3862 | je elf_segment_type |
3862 | je elf_segment_type |
3863 | cmp byte [esi],19h |
3863 | cmp byte [esi],19h |
3864 | jne elf_segment_flags_ok |
3864 | jne elf_segment_flags_ok |
3865 | lods word [esi] |
3865 | lods word [esi] |
3866 | sub ah,28 |
3866 | sub ah,28 |
3867 | jbe invalid_argument |
3867 | jbe invalid_argument |
3868 | cmp ah,1 |
3868 | cmp ah,1 |
3869 | je mark_elf_segment_flag |
3869 | je mark_elf_segment_flag |
3870 | cmp ah,3 |
3870 | cmp ah,3 |
3871 | ja invalid_argument |
3871 | ja invalid_argument |
3872 | xor ah,1 |
3872 | xor ah,1 |
3873 | cmp ah,2 |
3873 | cmp ah,2 |
3874 | je mark_elf_segment_flag |
3874 | je mark_elf_segment_flag |
3875 | inc ah |
3875 | inc ah |
3876 | mark_elf_segment_flag: |
3876 | mark_elf_segment_flag: |
3877 | test [ebx+18h],ah |
3877 | test [ebx+18h],ah |
3878 | jnz setting_already_specified |
3878 | jnz setting_already_specified |
3879 | or [ebx+18h],ah |
3879 | or [ebx+18h],ah |
3880 | jmp elf_segment_flags |
3880 | jmp elf_segment_flags |
3881 | elf_segment_type: |
3881 | elf_segment_type: |
3882 | cmp byte [ebx],1 |
3882 | cmp byte [ebx],1 |
3883 | jne setting_already_specified |
3883 | jne setting_already_specified |
3884 | lods word [esi] |
3884 | lods word [esi] |
3885 | mov ecx,[number_of_sections] |
3885 | mov ecx,[number_of_sections] |
3886 | jecxz elf_segment_type_ok |
3886 | jecxz elf_segment_type_ok |
3887 | mov edx,[code_start] |
3887 | mov edx,[code_start] |
3888 | add edx,34h |
3888 | add edx,34h |
3889 | scan_elf_segment_types: |
3889 | scan_elf_segment_types: |
3890 | cmp edx,[symbols_stream] |
3890 | cmp edx,[symbols_stream] |
3891 | jae elf_segment_type_ok |
3891 | jae elf_segment_type_ok |
3892 | cmp [edx],ah |
3892 | cmp [edx],ah |
3893 | je data_already_defined |
3893 | je data_already_defined |
3894 | add edx,20h |
3894 | add edx,20h |
3895 | loop scan_elf_segment_types |
3895 | loop scan_elf_segment_types |
3896 | elf_segment_type_ok: |
3896 | elf_segment_type_ok: |
3897 | mov [ebx],ah |
3897 | mov [ebx],ah |
3898 | mov word [ebx+1Ch],1 |
3898 | mov word [ebx+1Ch],1 |
3899 | cmp ah,50h |
3899 | cmp ah,50h |
3900 | jb elf_segment_flags |
3900 | jb elf_segment_flags |
3901 | or dword [ebx],6474E500h |
3901 | or dword [ebx],6474E500h |
3902 | jmp elf_segment_flags |
3902 | jmp elf_segment_flags |
3903 | elf_segment_flags_ok: |
3903 | elf_segment_flags_ok: |
3904 | pop edx |
3904 | pop edx |
3905 | cmp byte [ebx],1 |
3905 | cmp byte [ebx],1 |
3906 | jne no_elf_segment_merging |
3906 | jne no_elf_segment_merging |
3907 | cmp [merge_segment],0 |
3907 | cmp [merge_segment],0 |
3908 | jne merge_elf_segment |
3908 | jne merge_elf_segment |
3909 | no_elf_segment_merging: |
3909 | no_elf_segment_merging: |
3910 | mov eax,edi |
3910 | mov eax,edi |
3911 | sub eax,[code_start] |
3911 | sub eax,[code_start] |
3912 | mov [ebx+4],eax |
3912 | mov [ebx+4],eax |
3913 | and eax,0FFFh |
3913 | and eax,0FFFh |
3914 | add eax,edx |
3914 | add eax,edx |
3915 | mov [ebx+8],eax |
3915 | mov [ebx+8],eax |
3916 | mov [ebx+0Ch],eax |
3916 | mov [ebx+0Ch],eax |
3917 | xor edx,edx |
3917 | xor edx,edx |
3918 | elf_segment_addressing_setup: |
3918 | elf_segment_addressing_setup: |
3919 | xor cl,cl |
3919 | xor cl,cl |
3920 | not eax |
3920 | not eax |
3921 | not edx |
3921 | not edx |
3922 | not cl |
3922 | not cl |
3923 | add eax,1 |
3923 | add eax,1 |
3924 | adc edx,0 |
3924 | adc edx,0 |
3925 | adc cl,0 |
3925 | adc cl,0 |
3926 | add eax,edi |
3926 | add eax,edi |
3927 | adc edx,0 |
3927 | adc edx,0 |
3928 | adc cl,0 |
3928 | adc cl,0 |
3929 | mov [ds:ebp],eax |
3929 | mov [ds:ebp],eax |
3930 | mov [ds:ebp+4],edx |
3930 | mov [ds:ebp+4],edx |
3931 | mov [ds:ebp+8],cl |
3931 | mov [ds:ebp+8],cl |
3932 | inc [number_of_sections] |
3932 | inc [number_of_sections] |
3933 | jmp instruction_assembled |
3933 | jmp instruction_assembled |
3934 | merge_elf_segment: |
3934 | merge_elf_segment: |
3935 | xor ecx,ecx |
3935 | xor ecx,ecx |
3936 | xchg ecx,[merge_segment] |
3936 | xchg ecx,[merge_segment] |
3937 | cmp ecx,-1 |
3937 | cmp ecx,-1 |
3938 | je merge_elf_header |
3938 | je merge_elf_header |
3939 | mov eax,[ecx+8] |
3939 | mov eax,[ecx+8] |
3940 | mov ecx,[ecx+4] |
3940 | mov ecx,[ecx+4] |
3941 | elf_segment_separated_base: |
3941 | elf_segment_separated_base: |
3942 | mov [ebx+8],eax |
3942 | mov [ebx+8],eax |
3943 | mov [ebx+0Ch],eax |
3943 | mov [ebx+0Ch],eax |
3944 | mov [ebx+4],ecx |
3944 | mov [ebx+4],ecx |
3945 | sub eax,ecx |
3945 | sub eax,ecx |
3946 | add eax,edi |
3946 | add eax,edi |
3947 | sub eax,[code_start] |
3947 | sub eax,[code_start] |
3948 | xor edx,edx |
3948 | xor edx,edx |
3949 | jmp elf_segment_addressing_setup |
3949 | jmp elf_segment_addressing_setup |
3950 | merge_elf_header: |
3950 | merge_elf_header: |
3951 | mov eax,[image_base] |
3951 | mov eax,[image_base] |
3952 | xor ecx,ecx |
3952 | xor ecx,ecx |
3953 | jmp elf_segment_separated_base |
3953 | jmp elf_segment_separated_base |
3954 | close_elf_segment: |
3954 | close_elf_segment: |
3955 | cmp [number_of_sections],0 |
3955 | cmp [number_of_sections],0 |
3956 | jne finish_elf_segment |
3956 | jne finish_elf_segment |
3957 | cmp edi,[symbols_stream] |
3957 | cmp edi,[symbols_stream] |
3958 | jne first_elf_segment_ok |
3958 | jne first_elf_segment_ok |
3959 | or [merge_segment],-1 |
3959 | or [merge_segment],-1 |
3960 | mov eax,[image_base] |
3960 | mov eax,[image_base] |
3961 | ret |
3961 | ret |
3962 | first_elf_segment_ok: |
3962 | first_elf_segment_ok: |
3963 | and [merge_segment],0 |
3963 | and [merge_segment],0 |
3964 | inc [number_of_sections] |
3964 | inc [number_of_sections] |
3965 | finish_elf_segment: |
3965 | finish_elf_segment: |
3966 | mov ebx,[number_of_sections] |
3966 | mov ebx,[number_of_sections] |
3967 | dec ebx |
3967 | dec ebx |
3968 | shl ebx,5 |
3968 | shl ebx,5 |
3969 | add ebx,[code_start] |
3969 | add ebx,[code_start] |
3970 | add ebx,34h |
3970 | add ebx,34h |
3971 | mov eax,edi |
3971 | mov eax,edi |
3972 | sub eax,[code_start] |
3972 | sub eax,[code_start] |
3973 | sub eax,[ebx+4] |
3973 | sub eax,[ebx+4] |
3974 | mov edx,edi |
3974 | mov edx,edi |
3975 | cmp edi,[undefined_data_end] |
3975 | cmp edi,[undefined_data_end] |
3976 | jne elf_segment_size_ok |
3976 | jne elf_segment_size_ok |
3977 | cmp byte [ebx],1 |
3977 | cmp byte [ebx],1 |
3978 | jne elf_segment_size_ok |
3978 | jne elf_segment_size_ok |
3979 | mov edi,[undefined_data_start] |
3979 | mov edi,[undefined_data_start] |
3980 | elf_segment_size_ok: |
3980 | elf_segment_size_ok: |
3981 | mov [ebx+14h],eax |
3981 | mov [ebx+14h],eax |
3982 | add eax,edi |
3982 | add eax,edi |
3983 | sub eax,edx |
3983 | sub eax,edx |
3984 | mov [ebx+10h],eax |
3984 | mov [ebx+10h],eax |
3985 | and [undefined_data_end],0 |
3985 | and [undefined_data_end],0 |
3986 | mov eax,[ebx+8] |
3986 | mov eax,[ebx+8] |
3987 | cmp byte [ebx],1 |
3987 | cmp byte [ebx],1 |
3988 | je elf_segment_position_move_and_align |
3988 | je elf_segment_position_move_and_align |
3989 | cmp [merge_segment],0 |
3989 | cmp [merge_segment],0 |
3990 | jne elf_segment_position_move |
3990 | jne elf_segment_position_move |
3991 | cmp byte [ebx],4 |
3991 | cmp byte [ebx],4 |
3992 | je elf_segment_position_ok |
3992 | je elf_segment_position_ok |
3993 | cmp byte [ebx],51h |
3993 | cmp byte [ebx],51h |
3994 | je elf_segment_position_ok |
3994 | je elf_segment_position_ok |
3995 | mov [merge_segment],ebx |
3995 | mov [merge_segment],ebx |
3996 | elf_segment_position_move: |
3996 | elf_segment_position_move: |
3997 | add eax,[ebx+14h] |
3997 | add eax,[ebx+14h] |
3998 | jmp elf_segment_position_ok |
3998 | jmp elf_segment_position_ok |
3999 | elf_segment_position_move_and_align: |
3999 | elf_segment_position_move_and_align: |
4000 | add eax,[ebx+14h] |
4000 | add eax,[ebx+14h] |
4001 | add eax,0FFFh |
4001 | add eax,0FFFh |
4002 | elf_segment_position_ok: |
4002 | elf_segment_position_ok: |
4003 | and eax,not 0FFFh |
4003 | and eax,not 0FFFh |
4004 | ret |
4004 | ret |
4005 | elf64_segment: |
4005 | elf64_segment: |
4006 | call close_elf64_segment |
4006 | call close_elf64_segment |
4007 | push eax edx |
4007 | push eax edx |
4008 | call create_addressing_space |
4008 | call create_addressing_space |
4009 | call setup_elf_exe_labels_type |
4009 | call setup_elf_exe_labels_type |
4010 | mov ebp,ebx |
4010 | mov ebp,ebx |
4011 | mov ebx,[number_of_sections] |
4011 | mov ebx,[number_of_sections] |
4012 | imul ebx,38h |
4012 | imul ebx,38h |
4013 | add ebx,[code_start] |
4013 | add ebx,[code_start] |
4014 | add ebx,40h |
4014 | add ebx,40h |
4015 | cmp ebx,[symbols_stream] |
4015 | cmp ebx,[symbols_stream] |
4016 | jb new_elf64_segment |
4016 | jb new_elf64_segment |
4017 | or [next_pass_needed],-1 |
4017 | or [next_pass_needed],-1 |
4018 | new_elf64_segment: |
4018 | new_elf64_segment: |
4019 | mov byte [ebx],1 |
4019 | mov byte [ebx],1 |
4020 | and dword [ebx+4],0 |
4020 | and dword [ebx+4],0 |
4021 | mov word [ebx+30h],1000h |
4021 | mov word [ebx+30h],1000h |
4022 | elf64_segment_flags: |
4022 | elf64_segment_flags: |
4023 | cmp byte [esi],1Eh |
4023 | cmp byte [esi],1Eh |
4024 | je elf64_segment_type |
4024 | je elf64_segment_type |
4025 | cmp byte [esi],19h |
4025 | cmp byte [esi],19h |
4026 | jne elf64_segment_flags_ok |
4026 | jne elf64_segment_flags_ok |
4027 | lods word [esi] |
4027 | lods word [esi] |
4028 | sub ah,28 |
4028 | sub ah,28 |
4029 | jbe invalid_argument |
4029 | jbe invalid_argument |
4030 | cmp ah,1 |
4030 | cmp ah,1 |
4031 | je mark_elf64_segment_flag |
4031 | je mark_elf64_segment_flag |
4032 | cmp ah,3 |
4032 | cmp ah,3 |
4033 | ja invalid_argument |
4033 | ja invalid_argument |
4034 | xor ah,1 |
4034 | xor ah,1 |
4035 | cmp ah,2 |
4035 | cmp ah,2 |
4036 | je mark_elf64_segment_flag |
4036 | je mark_elf64_segment_flag |
4037 | inc ah |
4037 | inc ah |
4038 | mark_elf64_segment_flag: |
4038 | mark_elf64_segment_flag: |
4039 | test [ebx+4],ah |
4039 | test [ebx+4],ah |
4040 | jnz setting_already_specified |
4040 | jnz setting_already_specified |
4041 | or [ebx+4],ah |
4041 | or [ebx+4],ah |
4042 | jmp elf64_segment_flags |
4042 | jmp elf64_segment_flags |
4043 | elf64_segment_type: |
4043 | elf64_segment_type: |
4044 | cmp byte [ebx],1 |
4044 | cmp byte [ebx],1 |
4045 | jne setting_already_specified |
4045 | jne setting_already_specified |
4046 | lods word [esi] |
4046 | lods word [esi] |
4047 | mov ecx,[number_of_sections] |
4047 | mov ecx,[number_of_sections] |
4048 | jecxz elf64_segment_type_ok |
4048 | jecxz elf64_segment_type_ok |
4049 | mov edx,[code_start] |
4049 | mov edx,[code_start] |
4050 | add edx,40h |
4050 | add edx,40h |
4051 | scan_elf64_segment_types: |
4051 | scan_elf64_segment_types: |
4052 | cmp edx,[symbols_stream] |
4052 | cmp edx,[symbols_stream] |
4053 | jae elf64_segment_type_ok |
4053 | jae elf64_segment_type_ok |
4054 | cmp [edx],ah |
4054 | cmp [edx],ah |
4055 | je data_already_defined |
4055 | je data_already_defined |
4056 | add edx,38h |
4056 | add edx,38h |
4057 | loop scan_elf64_segment_types |
4057 | loop scan_elf64_segment_types |
4058 | elf64_segment_type_ok: |
4058 | elf64_segment_type_ok: |
4059 | mov [ebx],ah |
4059 | mov [ebx],ah |
4060 | mov word [ebx+30h],1 |
4060 | mov word [ebx+30h],1 |
4061 | cmp ah,50h |
4061 | cmp ah,50h |
4062 | jb elf64_segment_flags |
4062 | jb elf64_segment_flags |
4063 | or dword [ebx],6474E500h |
4063 | or dword [ebx],6474E500h |
4064 | jmp elf64_segment_flags |
4064 | jmp elf64_segment_flags |
4065 | elf64_segment_flags_ok: |
4065 | elf64_segment_flags_ok: |
4066 | pop edx eax |
4066 | pop edx eax |
4067 | cmp byte [ebx],1 |
4067 | cmp byte [ebx],1 |
4068 | jne no_elf64_segment_merging |
4068 | jne no_elf64_segment_merging |
4069 | cmp [merge_segment],0 |
4069 | cmp [merge_segment],0 |
4070 | jne merge_elf64_segment |
4070 | jne merge_elf64_segment |
4071 | no_elf64_segment_merging: |
4071 | no_elf64_segment_merging: |
4072 | mov ecx,edi |
4072 | mov ecx,edi |
4073 | sub ecx,[code_start] |
4073 | sub ecx,[code_start] |
4074 | mov [ebx+8],ecx |
4074 | mov [ebx+8],ecx |
4075 | and ecx,0FFFh |
4075 | and ecx,0FFFh |
4076 | add eax,ecx |
4076 | add eax,ecx |
4077 | adc edx,0 |
4077 | adc edx,0 |
4078 | mov [ebx+10h],eax |
4078 | mov [ebx+10h],eax |
4079 | mov [ebx+10h+4],edx |
4079 | mov [ebx+10h+4],edx |
4080 | mov [ebx+18h],eax |
4080 | mov [ebx+18h],eax |
4081 | mov [ebx+18h+4],edx |
4081 | mov [ebx+18h+4],edx |
4082 | jmp elf_segment_addressing_setup |
4082 | jmp elf_segment_addressing_setup |
4083 | merge_elf64_segment: |
4083 | merge_elf64_segment: |
4084 | xor ecx,ecx |
4084 | xor ecx,ecx |
4085 | xchg ecx,[merge_segment] |
4085 | xchg ecx,[merge_segment] |
4086 | cmp ecx,-1 |
4086 | cmp ecx,-1 |
4087 | je merge_elf64_header |
4087 | je merge_elf64_header |
4088 | mov eax,[ecx+10h] |
4088 | mov eax,[ecx+10h] |
4089 | mov edx,[ecx+10h+4] |
4089 | mov edx,[ecx+10h+4] |
4090 | mov ecx,[ecx+8] |
4090 | mov ecx,[ecx+8] |
4091 | elf64_segment_separated_base: |
4091 | elf64_segment_separated_base: |
4092 | mov [ebx+10h],eax |
4092 | mov [ebx+10h],eax |
4093 | mov [ebx+10h+4],edx |
4093 | mov [ebx+10h+4],edx |
4094 | mov [ebx+18h],eax |
4094 | mov [ebx+18h],eax |
4095 | mov [ebx+18h+4],edx |
4095 | mov [ebx+18h+4],edx |
4096 | mov [ebx+8],ecx |
4096 | mov [ebx+8],ecx |
4097 | neg ecx |
4097 | neg ecx |
4098 | add ecx,edi |
4098 | add ecx,edi |
4099 | sub ecx,[code_start] |
4099 | sub ecx,[code_start] |
4100 | add eax,ecx |
4100 | add eax,ecx |
4101 | adc edx,0 |
4101 | adc edx,0 |
4102 | jmp elf_segment_addressing_setup |
4102 | jmp elf_segment_addressing_setup |
4103 | merge_elf64_header: |
4103 | merge_elf64_header: |
4104 | mov eax,[image_base] |
4104 | mov eax,[image_base] |
4105 | mov edx,[image_base_high] |
4105 | mov edx,[image_base_high] |
4106 | xor ecx,ecx |
4106 | xor ecx,ecx |
4107 | jmp elf64_segment_separated_base |
4107 | jmp elf64_segment_separated_base |
4108 | close_elf64_segment: |
4108 | close_elf64_segment: |
4109 | cmp [number_of_sections],0 |
4109 | cmp [number_of_sections],0 |
4110 | jne finish_elf64_segment |
4110 | jne finish_elf64_segment |
4111 | cmp edi,[symbols_stream] |
4111 | cmp edi,[symbols_stream] |
4112 | jne first_elf64_segment_ok |
4112 | jne first_elf64_segment_ok |
4113 | or [merge_segment],-1 |
4113 | or [merge_segment],-1 |
4114 | mov eax,[image_base] |
4114 | mov eax,[image_base] |
4115 | mov edx,[image_base_high] |
4115 | mov edx,[image_base_high] |
4116 | ret |
4116 | ret |
4117 | first_elf64_segment_ok: |
4117 | first_elf64_segment_ok: |
4118 | and [merge_segment],0 |
4118 | and [merge_segment],0 |
4119 | inc [number_of_sections] |
4119 | inc [number_of_sections] |
4120 | finish_elf64_segment: |
4120 | finish_elf64_segment: |
4121 | mov ebx,[number_of_sections] |
4121 | mov ebx,[number_of_sections] |
4122 | dec ebx |
4122 | dec ebx |
4123 | imul ebx,38h |
4123 | imul ebx,38h |
4124 | add ebx,[code_start] |
4124 | add ebx,[code_start] |
4125 | add ebx,40h |
4125 | add ebx,40h |
4126 | mov eax,edi |
4126 | mov eax,edi |
4127 | sub eax,[code_start] |
4127 | sub eax,[code_start] |
4128 | sub eax,[ebx+8] |
4128 | sub eax,[ebx+8] |
4129 | mov edx,edi |
4129 | mov edx,edi |
4130 | cmp edi,[undefined_data_end] |
4130 | cmp edi,[undefined_data_end] |
4131 | jne elf64_segment_size_ok |
4131 | jne elf64_segment_size_ok |
4132 | cmp byte [ebx],1 |
4132 | cmp byte [ebx],1 |
4133 | jne elf64_segment_size_ok |
4133 | jne elf64_segment_size_ok |
4134 | mov edi,[undefined_data_start] |
4134 | mov edi,[undefined_data_start] |
4135 | elf64_segment_size_ok: |
4135 | elf64_segment_size_ok: |
4136 | mov [ebx+28h],eax |
4136 | mov [ebx+28h],eax |
4137 | add eax,edi |
4137 | add eax,edi |
4138 | sub eax,edx |
4138 | sub eax,edx |
4139 | mov [ebx+20h],eax |
4139 | mov [ebx+20h],eax |
4140 | and [undefined_data_end],0 |
4140 | and [undefined_data_end],0 |
4141 | mov eax,[ebx+10h] |
4141 | mov eax,[ebx+10h] |
4142 | mov edx,[ebx+10h+4] |
4142 | mov edx,[ebx+10h+4] |
4143 | cmp byte [ebx],1 |
4143 | cmp byte [ebx],1 |
4144 | je elf64_segment_position_move_and_align |
4144 | je elf64_segment_position_move_and_align |
4145 | cmp [merge_segment],0 |
4145 | cmp [merge_segment],0 |
4146 | jne elf64_segment_position_move |
4146 | jne elf64_segment_position_move |
4147 | cmp byte [ebx],4 |
4147 | cmp byte [ebx],4 |
4148 | je elf64_segment_position_ok |
4148 | je elf64_segment_position_ok |
4149 | cmp byte [ebx],51h |
4149 | cmp byte [ebx],51h |
4150 | je elf64_segment_position_ok |
4150 | je elf64_segment_position_ok |
4151 | mov [merge_segment],ebx |
4151 | mov [merge_segment],ebx |
4152 | elf64_segment_position_move: |
4152 | elf64_segment_position_move: |
4153 | add eax,[ebx+28h] |
4153 | add eax,[ebx+28h] |
4154 | adc edx,0 |
4154 | adc edx,0 |
4155 | jmp elf64_segment_position_ok |
4155 | jmp elf64_segment_position_ok |
4156 | elf64_segment_position_move_and_align: |
4156 | elf64_segment_position_move_and_align: |
4157 | add eax,[ebx+28h] |
4157 | add eax,[ebx+28h] |
4158 | adc edx,0 |
4158 | adc edx,0 |
4159 | add eax,0FFFh |
4159 | add eax,0FFFh |
4160 | adc edx,0 |
4160 | adc edx,0 |
4161 | elf64_segment_position_ok: |
4161 | elf64_segment_position_ok: |
4162 | and eax,not 0FFFh |
4162 | and eax,not 0FFFh |
4163 | ret |
4163 | ret |
4164 | close_elf_exe: |
4164 | close_elf_exe: |
4165 | test [format_flags],8 |
4165 | test [format_flags],8 |
4166 | jnz close_elf64_exe |
4166 | jnz close_elf64_exe |
4167 | call close_elf_segment |
4167 | call close_elf_segment |
4168 | mov edx,[code_start] |
4168 | mov edx,[code_start] |
4169 | mov eax,[number_of_sections] |
4169 | mov eax,[number_of_sections] |
4170 | mov byte [edx+1Ch],34h |
4170 | mov byte [edx+1Ch],34h |
4171 | mov [edx+2Ch],ax |
4171 | mov [edx+2Ch],ax |
4172 | shl eax,5 |
4172 | shl eax,5 |
4173 | add eax,edx |
4173 | add eax,edx |
4174 | add eax,34h |
4174 | add eax,34h |
4175 | cmp eax,[symbols_stream] |
4175 | cmp eax,[symbols_stream] |
4176 | je elf_exe_ok |
4176 | je elf_exe_ok |
4177 | or [next_pass_needed],-1 |
4177 | or [next_pass_needed],-1 |
4178 | elf_exe_ok: |
4178 | elf_exe_ok: |
4179 | ret |
4179 | ret |
4180 | close_elf64_exe: |
4180 | close_elf64_exe: |
4181 | call close_elf64_segment |
4181 | call close_elf64_segment |
4182 | mov edx,[code_start] |
4182 | mov edx,[code_start] |
4183 | mov eax,[number_of_sections] |
4183 | mov eax,[number_of_sections] |
4184 | mov byte [edx+20h],40h |
4184 | mov byte [edx+20h],40h |
4185 | mov [edx+38h],ax |
4185 | mov [edx+38h],ax |
4186 | imul eax,38h |
4186 | imul eax,38h |
4187 | add eax,edx |
4187 | add eax,edx |
4188 | add eax,40h |
4188 | add eax,40h |
4189 | cmp eax,[symbols_stream] |
4189 | cmp eax,[symbols_stream] |
4190 | je elf64_exe_ok |
4190 | je elf64_exe_ok |
4191 | or [next_pass_needed],-1 |
4191 | or [next_pass_needed],-1 |
4192 | elf64_exe_ok: |
4192 | elf64_exe_ok: |
4193 | ret |
4193 | ret |