Subversion Repositories Kolibri OS

Rev

Rev 31 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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