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