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