-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexprcalc.inc
2272 lines (2265 loc) · 42 KB
/
exprcalc.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; flat assembler core
; Copyright (c) 1999-2022, Tomasz Grysztar.
; All rights reserved.
calculate_expression:
mov [current_offset],edi
mov [value_undefined],0
cmp byte [esi],0
je get_string_value
cmp byte [esi],'.'
je convert_fp
calculation_loop:
mov eax,[tagged_blocks]
sub eax,0Ch
cmp eax,edi
jbe out_of_memory
lods byte [esi]
cmp al,1
je get_byte_number
cmp al,2
je get_word_number
cmp al,4
je get_dword_number
cmp al,8
je get_qword_number
cmp al,0Fh
je value_out_of_range
cmp al,10h
je get_register
cmp al,11h
je get_label
cmp al,')'
je expression_calculated
cmp al,']'
je expression_calculated
cmp al,'!'
je invalid_expression
sub edi,14h
mov ebx,edi
sub ebx,14h
cmp al,0F0h
je calculate_rva
cmp al,0F1h
je calculate_plt
cmp al,0D0h
je calculate_not
cmp al,0E0h
je calculate_bsf
cmp al,0E1h
je calculate_bsr
cmp al,083h
je calculate_neg
mov dx,[ebx+8]
or dx,[edi+8]
cmp al,80h
je calculate_add
cmp al,81h
je calculate_sub
mov ah,[ebx+12]
or ah,[edi+12]
jz absolute_values_calculation
call recoverable_misuse
absolute_values_calculation:
cmp al,90h
je calculate_mul
cmp al,91h
je calculate_div
or dx,dx
jnz invalid_expression
cmp al,0A0h
je calculate_mod
cmp al,0B0h
je calculate_and
cmp al,0B1h
je calculate_or
cmp al,0B2h
je calculate_xor
cmp al,0C0h
je calculate_shl
cmp al,0C1h
je calculate_shr
jmp invalid_expression
expression_calculated:
sub edi,14h
cmp [value_undefined],0
je expression_value_ok
xor eax,eax
mov [edi],eax
mov [edi+4],eax
mov [edi+12],eax
expression_value_ok:
ret
get_byte_number:
xor eax,eax
lods byte [esi]
stos dword [edi]
xor al,al
stos dword [edi]
got_number:
and word [edi-8+8],0
and word [edi-8+12],0
and dword [edi-8+16],0
add edi,0Ch
jmp calculation_loop
get_word_number:
xor eax,eax
lods word [esi]
stos dword [edi]
xor ax,ax
stos dword [edi]
jmp got_number
get_dword_number:
movs dword [edi],[esi]
xor eax,eax
stos dword [edi]
jmp got_number
get_qword_number:
movs dword [edi],[esi]
movs dword [edi],[esi]
jmp got_number
get_register:
mov byte [edi+9],0
and word [edi+12],0
lods byte [esi]
mov [edi+8],al
mov byte [edi+10],1
xor eax,eax
mov [edi+16],eax
stos dword [edi]
stos dword [edi]
add edi,0Ch
jmp calculation_loop
get_label:
xor eax,eax
mov [edi+8],eax
mov [edi+12],eax
mov [edi+20],eax
lods dword [esi]
cmp eax,0Fh
jb predefined_label
je reserved_word_used_as_symbol
mov ebx,eax
mov ax,[current_pass]
mov [ebx+18],ax
mov cl,[ebx+9]
shr cl,1
and cl,1
neg cl
or byte [ebx+8],8
test byte [ebx+8],1
jz label_undefined
cmp ax,[ebx+16]
je unadjusted_label
test byte [ebx+8],4
jnz label_out_of_scope
test byte [ebx+9],1
jz unadjusted_label
mov eax,[ebx]
sub eax,dword [adjustment]
stos dword [edi]
mov eax,[ebx+4]
sbb eax,dword [adjustment+4]
stos dword [edi]
sbb cl,[adjustment_sign]
mov [edi-8+13],cl
mov eax,dword [adjustment]
or al,[adjustment_sign]
or eax,dword [adjustment+4]
jz got_label
or [next_pass_needed],-1
jmp got_label
unadjusted_label:
mov eax,[ebx]
stos dword [edi]
mov eax,[ebx+4]
stos dword [edi]
mov [edi-8+13],cl
got_label:
test byte [ebx+9],4
jnz invalid_use_of_symbol
call store_label_reference
mov al,[ebx+11]
mov [edi-8+12],al
mov eax,[ebx+12]
mov [edi-8+8],eax
cmp al,ah
jne labeled_registers_ok
shr eax,16
add al,ah
jo labeled_registers_ok
xor ah,ah
mov [edi-8+10],ax
mov [edi-8+9],ah
labeled_registers_ok:
mov eax,[ebx+20]
mov [edi-8+16],eax
add edi,0Ch
mov al,[ebx+10]
or al,al
jz calculation_loop
test [operand_flags],1
jnz calculation_loop
check_size:
xchg [operand_size],al
or al,al
jz calculation_loop
cmp al,[operand_size]
jne operand_sizes_do_not_match
jmp calculation_loop
actual_file_offset_label:
mov eax,[undefined_data_end]
mov ebp,[addressing_space]
test byte [ds:ebp+0Ah],1
jnz use_undefined_data_offset
cmp eax,[current_offset]
jne use_current_offset
use_undefined_data_offset:
mov eax,[undefined_data_start]
jmp make_file_offset_label
current_file_offset_label:
mov ebp,[addressing_space]
test byte [ds:ebp+0Ah],1
jz use_current_offset
mov eax,[undefined_data_end]
jmp make_file_offset_label
use_current_offset:
mov eax,[current_offset]
make_file_offset_label:
cmp [output_format],2
jae invalid_use_of_symbol
sub eax,[code_start]
jmp make_dword_label_value
current_offset_label:
mov eax,[current_offset]
make_current_offset_label:
xor edx,edx
xor ch,ch
mov ebp,[addressing_space]
sub eax,[ds:ebp]
sbb edx,[ds:ebp+4]
sbb ch,[ds:ebp+8]
jp current_offset_label_ok
call recoverable_overflow
current_offset_label_ok:
stos dword [edi]
mov eax,edx
stos dword [edi]
mov eax,[ds:ebp+10h]
stos dword [edi]
mov cl,[ds:ebp+9]
mov [edi-12+12],cx
mov eax,[ds:ebp+14h]
mov [edi-12+16],eax
add edi,8
jmp calculation_loop
org_origin_label:
mov eax,[addressing_space]
mov eax,[eax+18h]
jmp make_current_offset_label
counter_label:
mov eax,[counter]
make_dword_label_value:
stos dword [edi]
xor eax,eax
stos dword [edi]
add edi,0Ch
jmp calculation_loop
timestamp_label:
call make_timestamp
make_qword_label_value:
stos dword [edi]
mov eax,edx
stos dword [edi]
add edi,0Ch
jmp calculation_loop
predefined_label:
or eax,eax
jz current_offset_label
cmp eax,1
je counter_label
cmp eax,2
je timestamp_label
cmp eax,3
je org_origin_label
cmp eax,4
je current_file_offset_label
cmp eax,5
je actual_file_offset_label
mov edx,invalid_value
jmp error_undefined
label_out_of_scope:
mov edx,symbol_out_of_scope
jmp error_undefined
label_undefined:
mov edx,undefined_symbol
error_undefined:
cmp [current_pass],1
ja undefined_value
force_next_pass:
or [next_pass_needed],-1
undefined_value:
or [value_undefined],-1
and word [edi+12],0
xor eax,eax
stos dword [edi]
stos dword [edi]
add edi,0Ch
cmp [error_line],0
jne calculation_loop
mov eax,[current_line]
mov [error_line],eax
mov [error],edx
mov [error_info],ebx
jmp calculation_loop
calculate_add:
xor ah,ah
mov ah,[ebx+12]
mov al,[edi+12]
or al,al
jz add_values
or ah,ah
jz add_relocatable
add ah,al
jnz invalid_add
mov ecx,[edi+16]
cmp ecx,[ebx+16]
je add_values
invalid_add:
call recoverable_misuse
jmp add_values
add_relocatable:
mov ah,al
mov ecx,[edi+16]
mov [ebx+16],ecx
add_values:
mov [ebx+12],ah
mov eax,[edi]
add [ebx],eax
mov eax,[edi+4]
adc [ebx+4],eax
mov al,[edi+13]
adc [ebx+13],al
jp add_sign_ok
call recoverable_overflow
add_sign_ok:
or dx,dx
jz calculation_loop
push esi
mov esi,ebx
mov cl,[edi+10]
mov al,[edi+8]
call add_register
mov cl,[edi+11]
mov al,[edi+9]
call add_register
pop esi
jmp calculation_loop
add_register:
or al,al
jz add_register_done
add_register_start:
cmp [esi+8],al
jne add_in_second_slot
add [esi+10],cl
jo value_out_of_range
jnz add_register_done
mov byte [esi+8],0
ret
add_in_second_slot:
cmp [esi+9],al
jne create_in_first_slot
add [esi+11],cl
jo value_out_of_range
jnz add_register_done
mov byte [esi+9],0
ret
create_in_first_slot:
cmp byte [esi+8],0
jne create_in_second_slot
mov [esi+8],al
mov [esi+10],cl
ret
create_in_second_slot:
cmp byte [esi+9],0
jne invalid_expression
mov [esi+9],al
mov [esi+11],cl
add_register_done:
ret
out_of_range:
jmp calculation_loop
calculate_sub:
xor ah,ah
mov ah,[ebx+12]
mov al,[edi+12]
or al,al
jz sub_values
or ah,ah
jz negate_relocatable
cmp al,ah
jne invalid_sub
xor ah,ah
mov ecx,[edi+16]
cmp ecx,[ebx+16]
je sub_values
invalid_sub:
call recoverable_misuse
jmp sub_values
negate_relocatable:
neg al
mov ah,al
mov ecx,[edi+16]
mov [ebx+16],ecx
sub_values:
mov [ebx+12],ah
mov eax,[edi]
sub [ebx],eax
mov eax,[edi+4]
sbb [ebx+4],eax
mov al,[edi+13]
sbb [ebx+13],al
jp sub_sign_ok
cmp [error_line],0
jne sub_sign_ok
call recoverable_overflow
sub_sign_ok:
or dx,dx
jz calculation_loop
push esi
mov esi,ebx
mov cl,[edi+10]
mov al,[edi+8]
call sub_register
mov cl,[edi+11]
mov al,[edi+9]
call sub_register
pop esi
jmp calculation_loop
sub_register:
or al,al
jz add_register_done
neg cl
jo value_out_of_range
jmp add_register_start
calculate_mul:
or dx,dx
jz mul_start
cmp word [ebx+8],0
jne mul_start
xor ecx,ecx
swap_values:
mov eax,[ebx+ecx]
xchg eax,[edi+ecx]
mov [ebx+ecx],eax
add ecx,4
cmp ecx,16
jb swap_values
mul_start:
push esi edx
mov esi,ebx
xor bl,bl
cmp byte [esi+13],0
je mul_first_sign_ok
xor bl,-1
mov eax,[esi]
mov edx,[esi+4]
not eax
not edx
add eax,1
adc edx,0
mov [esi],eax
mov [esi+4],edx
or eax,edx
jz mul_overflow
mul_first_sign_ok:
cmp byte [edi+13],0
je mul_second_sign_ok
xor bl,-1
cmp byte [esi+8],0
je mul_first_register_sign_ok
neg byte [esi+10]
jo invalid_expression
mul_first_register_sign_ok:
cmp byte [esi+9],0
je mul_second_register_sign_ok
neg byte [esi+11]
jo invalid_expression
mul_second_register_sign_ok:
mov eax,[edi]
mov edx,[edi+4]
not eax
not edx
add eax,1
adc edx,0
mov [edi],eax
mov [edi+4],edx
or eax,edx
jz mul_overflow
mul_second_sign_ok:
cmp dword [esi+4],0
jz mul_numbers
cmp dword [edi+4],0
jz mul_numbers
jnz mul_overflow
mul_numbers:
mov eax,[esi+4]
mul dword [edi]
or edx,edx
jnz mul_overflow
mov ecx,eax
mov eax,[esi]
mul dword [edi+4]
or edx,edx
jnz mul_overflow
add ecx,eax
jc mul_overflow
mov eax,[esi]
mul dword [edi]
add edx,ecx
jc mul_overflow
mov [esi],eax
mov [esi+4],edx
or bl,bl
jz mul_ok
not eax
not edx
add eax,1
adc edx,0
mov [esi],eax
mov [esi+4],edx
or eax,edx
jnz mul_ok
not bl
mul_ok:
mov [esi+13],bl
pop edx
or dx,dx
jz mul_calculated
cmp word [edi+8],0
jne invalid_value
cmp byte [esi+8],0
je mul_first_register_ok
call get_byte_scale
imul byte [esi+10]
mov dl,ah
cbw
cmp ah,dl
jne value_out_of_range
mov [esi+10],al
or al,al
jnz mul_first_register_ok
mov [esi+8],al
mul_first_register_ok:
cmp byte [esi+9],0
je mul_calculated
call get_byte_scale
imul byte [esi+11]
mov dl,ah
cbw
cmp ah,dl
jne value_out_of_range
mov [esi+11],al
or al,al
jnz mul_calculated
mov [esi+9],al
mul_calculated:
pop esi
jmp calculation_loop
mul_overflow:
pop edx esi
call recoverable_overflow
jmp calculation_loop
get_byte_scale:
mov al,[edi]
cbw
cwde
cdq
cmp edx,[edi+4]
jne value_out_of_range
cmp eax,[edi]
jne value_out_of_range
ret
calculate_div:
push esi edx
mov esi,ebx
call div_64
pop edx
or dx,dx
jz div_calculated
cmp byte [esi+8],0
je div_first_register_ok
call get_byte_scale
or al,al
jz value_out_of_range
mov al,[esi+10]
cbw
idiv byte [edi]
or ah,ah
jnz invalid_use_of_symbol
mov [esi+10],al
div_first_register_ok:
cmp byte [esi+9],0
je div_calculated
call get_byte_scale
or al,al
jz value_out_of_range
mov al,[esi+11]
cbw
idiv byte [edi]
or ah,ah
jnz invalid_use_of_symbol
mov [esi+11],al
div_calculated:
pop esi
jmp calculation_loop
calculate_mod:
push esi
mov esi,ebx
call div_64
mov [esi],eax
mov [esi+4],edx
mov [esi+13],bh
pop esi
jmp calculation_loop
calculate_and:
mov eax,[edi]
mov edx,[edi+4]
mov cl,[edi+13]
and [ebx],eax
and [ebx+4],edx
and [ebx+13],cl
jmp calculation_loop
calculate_or:
mov eax,[edi]
mov edx,[edi+4]
mov cl,[edi+13]
or [ebx],eax
or [ebx+4],edx
or [ebx+13],cl
jmp calculation_loop
calculate_xor:
mov eax,[edi]
mov edx,[edi+4]
mov cl,[edi+13]
xor [ebx],eax
xor [ebx+4],edx
xor [ebx+13],cl
jmp calculation_loop
shr_negative:
mov byte [edi+13],0
not dword [edi]
not dword [edi+4]
add dword [edi],1
adc dword [edi+4],0
jc shl_over
calculate_shl:
cmp byte [edi+13],0
jne shl_negative
mov edx,[ebx+4]
mov eax,[ebx]
cmp dword [edi+4],0
jne shl_over
movsx ecx,byte [ebx+13]
xchg ecx,[edi]
cmp ecx,64
je shl_max
ja shl_over
cmp ecx,32
jae shl_high
shld [edi],edx,cl
shld edx,eax,cl
shl eax,cl
mov [ebx],eax
mov [ebx+4],edx
jmp shl_done
shl_over:
cmp byte [ebx+13],0
jne shl_overflow
shl_max:
movsx ecx,byte [ebx+13]
cmp eax,ecx
jne shl_overflow
cmp edx,ecx
jne shl_overflow
xor eax,eax
mov [ebx],eax
mov [ebx+4],eax
jmp calculation_loop
shl_high:
sub cl,32
shld [edi],edx,cl
shld edx,eax,cl
shl eax,cl
mov [ebx+4],eax
and dword [ebx],0
cmp edx,[edi]
jne shl_overflow
shl_done:
movsx eax,byte [ebx+13]
cmp eax,[edi]
je calculation_loop
shl_overflow:
call recoverable_overflow
jmp calculation_loop
shl_negative:
mov byte [edi+13],0
not dword [edi]
not dword [edi+4]
add dword [edi],1
adc dword [edi+4],0
jnc calculate_shr
dec dword [edi+4]
calculate_shr:
cmp byte [edi+13],0
jne shr_negative
mov edx,[ebx+4]
mov eax,[ebx]
cmp dword [edi+4],0
jne shr_over
mov ecx,[edi]
cmp ecx,64
jae shr_over
push esi
movsx esi,byte [ebx+13]
cmp ecx,32
jae shr_high
shrd eax,edx,cl
shrd edx,esi,cl
mov [ebx],eax
mov [ebx+4],edx
pop esi
jmp calculation_loop
shr_high:
sub cl,32
shrd edx,esi,cl
mov [ebx],edx
mov [ebx+4],esi
pop esi
jmp calculation_loop
shr_over:
movsx eax,byte [ebx+13]
mov dword [ebx],eax
mov dword [ebx+4],eax
jmp calculation_loop
calculate_not:
cmp word [edi+8],0
jne invalid_expression
cmp byte [edi+12],0
je not_ok
call recoverable_misuse
not_ok:
not dword [edi]
not dword [edi+4]
not byte [edi+13]
add edi,14h
jmp calculation_loop
calculate_bsf:
cmp word [edi+8],0
jne invalid_expression
cmp byte [edi+12],0
je bsf_ok
call recoverable_misuse
bsf_ok:
xor ecx,ecx
bsf eax,[edi]
jnz finish_bs
mov ecx,32
bsf eax,[edi+4]
jnz finish_bs
cmp byte [edi+13],0
jne finish_bs
bs_overflow:
call recoverable_overflow
add edi,14h
jmp calculation_loop
calculate_bsr:
cmp word [edi+8],0
jne invalid_expression
cmp byte [edi+12],0
je bsr_ok
call recoverable_misuse
bsr_ok:
cmp byte [edi+13],0
jne bs_overflow
mov ecx,32
bsr eax,[edi+4]
jnz finish_bs
xor ecx,ecx
bsr eax,[edi]
jz bs_overflow
finish_bs:
add eax,ecx
xor edx,edx
mov [edi],eax
mov [edi+4],edx
mov [edi+13],dl
add edi,14h
jmp calculation_loop
calculate_neg:
cmp byte [edi+8],0
je neg_first_register_ok
neg byte [edi+10]
jo invalid_expression
neg_first_register_ok:
cmp byte [edi+9],0
je neg_second_register_ok
neg byte [edi+11]
jo invalid_expression
neg_second_register_ok:
neg byte [edi+12]
xor eax,eax
xor edx,edx
xor cl,cl
xchg eax,[edi]
xchg edx,[edi+4]
xchg cl,[edi+13]
sub [edi],eax
sbb [edi+4],edx
sbb [edi+13],cl
jp neg_sign_ok
call recoverable_overflow
neg_sign_ok:
add edi,14h
jmp calculation_loop
calculate_rva:
cmp word [edi+8],0
jne invalid_expression
mov al,[output_format]
cmp al,5
je calculate_gotoff
cmp al,4
je calculate_coff_rva
cmp al,3
jne invalid_expression
test [format_flags],8
jnz pe64_rva
mov al,2
bt [resolver_flags],0
jc rva_type_ok
xor al,al
rva_type_ok:
cmp byte [edi+12],al
je rva_ok
call recoverable_misuse
rva_ok:
mov byte [edi+12],0
mov eax,[code_start]
mov eax,[eax+34h]
xor edx,edx
finish_rva:
sub [edi],eax
sbb [edi+4],edx
sbb byte [edi+13],0
jp rva_finished
call recoverable_overflow
rva_finished:
add edi,14h
jmp calculation_loop
pe64_rva:
mov al,4
bt [resolver_flags],0
jc pe64_rva_type_ok
xor al,al
pe64_rva_type_ok:
cmp byte [edi+12],al
je pe64_rva_ok
call recoverable_misuse
pe64_rva_ok:
mov byte [edi+12],0
mov eax,[code_start]
mov edx,[eax+34h]
mov eax,[eax+30h]
jmp finish_rva
calculate_gotoff:
test [format_flags],1
jnz calculate_elf_dyn_rva
test [format_flags],8
jnz invalid_expression
calculate_coff_rva:
mov dl,5
cmp byte [edi+12],2
je change_value_type
incorrect_change_of_value_type:
call recoverable_misuse
change_value_type:
mov byte [edi+12],dl
add edi,14h
jmp calculation_loop
calculate_elf_dyn_rva:
xor dl,dl
test byte [edi+12],1
jnz incorrect_change_of_value_type
jmp change_value_type
calculate_plt:
cmp word [edi+8],0
jne invalid_expression
cmp [output_format],5
jne invalid_expression
test [format_flags],1
jnz invalid_expression
mov dl,6
mov dh,2
test [format_flags],8
jz check_value_for_plt
mov dh,4
check_value_for_plt:
mov eax,[edi]
or eax,[edi+4]
jnz incorrect_change_of_value_type
cmp byte [edi+12],dh
jne incorrect_change_of_value_type
mov eax,[edi+16]
cmp byte [eax],80h
jne incorrect_change_of_value_type
jmp change_value_type
div_64:
xor ebx,ebx
cmp dword [edi],0
jne divider_ok
cmp dword [edi+4],0
jne divider_ok
cmp [next_pass_needed],0
je value_out_of_range
jmp div_done
divider_ok:
cmp byte [esi+13],0
je div_first_sign_ok
mov eax,[esi]
mov edx,[esi+4]
not eax
not edx
add eax,1
adc edx,0
mov [esi],eax
mov [esi+4],edx
or eax,edx
jz value_out_of_range
xor bx,-1
div_first_sign_ok:
cmp byte [edi+13],0
je div_second_sign_ok
mov eax,[edi]
mov edx,[edi+4]
not eax
not edx
add eax,1
adc edx,0
mov [edi],eax
mov [edi+4],edx
or eax,edx
jz value_out_of_range
xor bl,-1
div_second_sign_ok:
cmp dword [edi+4],0
jne div_high
mov ecx,[edi]
mov eax,[esi+4]
xor edx,edx
div ecx
mov [esi+4],eax
mov eax,[esi]
div ecx
mov [esi],eax
mov eax,edx
xor edx,edx
jmp div_done
div_high:
push ebx
mov eax,[esi+4]
xor edx,edx
div dword [edi+4]
mov ebx,[esi]
mov [esi],eax
and dword [esi+4],0
mov ecx,edx
mul dword [edi]
div_high_loop:
cmp ecx,edx
ja div_high_done
jb div_high_large_correction
cmp ebx,eax
jae div_high_done
div_high_correction:
dec dword [esi]
sub eax,[edi]
sbb edx,[edi+4]
jnc div_high_loop
div_high_done:
sub ebx,eax
sbb ecx,edx
mov edx,ecx
mov eax,ebx
pop ebx
jmp div_done
div_high_large_correction:
push eax edx
mov eax,edx
sub eax,ecx
xor edx,edx