forked from shiltemann/CTF-writeups-public
-
Notifications
You must be signed in to change notification settings - Fork 0
/
comp.nasm
1178 lines (1003 loc) · 20.6 KB
/
comp.nasm
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
global rrf0
global rrf1
global rrf2
global rrf3
global rrf4
global rrf5
global rrf6
global rrf7
global rrf8
global rrf9
global rrfcl
global rrfscl
global rrflt
global rrfeq
global rrfgt
global rrfqm
global rrfat
global rrfA
global rrfB
global rrfC
global rrfD
global rrfE
global rrfF
global rrfG
global rrfH
global rrfI
global rrfJ
global rrfK
global rrfL
global rrfM
global rrfN
global rrfO
global rrfP
global rrfQ
global rrfR
global rrfS
global rrfT
global rrfU
global rrfV
global rrfW
global rrfX
global rrfY
global rrfZ
global rrflb
global rrfbs
global rrfrb
global rrfct
global rrfus
global rrftl
global rrfa
global rrfb
global rrfc
global rrfd
global rrfe
global rrff
global rrfg
global rrfh
global rrfi
global rrfj
global rrfk
global rrfl
global rrfm
global rrfn
global rrfo
global rrfp
global rrfq
global rrfr
global rrfs
global rrft
global rrfu
global rrfv
global rrfw
global rrfx
global rrfy
global rrfz
global rrflcb
global rrfst
global rrfrcb
global rrf00
global add
global sub
global xor
global main
extern write
SECTION .text
rrf0:
mov eax, 48
ret
rrf1:
mov eax, 49
ret
rrf2:
mov eax, 50
ret
rrf3:
mov eax, 51
ret
rrf4:
mov eax, 52
ret
rrf5:
mov eax, 53
ret
rrf6:
mov eax, 54
ret
rrf7:
mov eax, 55
ret
rrf8:
mov eax, 56
ret
rrf9:
mov eax, 57
ret
rrfcl:
mov eax, 58
ret
rrfscl:
mov eax, 59
ret
rrflt:
mov eax, 60
ret
rrfeq:
mov eax, 61
ret
rrfgt:
mov eax, 62
ret
rrfqm:
mov eax, 63
ret
rrfat:
mov eax, 64
ret
rrfA:
mov eax, 65
ret
rrfB:
mov eax, 66
ret
rrfC:
mov eax, 67
ret
rrfD:
mov eax, 68
ret
rrfE:
mov eax, 69
ret
rrfF:
mov eax, 70
ret
rrfG:
mov eax, 71
ret
rrfH:
mov eax, 72
ret
rrfI:
mov eax, 73
ret
rrfJ:
mov eax, 74
ret
rrfK:
mov eax, 75
ret
rrfL:
mov eax, 76
ret
rrfM:
mov eax, 77
ret
rrfN:
mov eax, 78
ret
rrfO:
mov eax, 79
ret
rrfP:
mov eax, 80
ret
rrfQ:
mov eax, 81
ret
rrfR:
mov eax, 82
ret
rrfS:
mov eax, 83
ret
rrfT:
mov eax, 84
ret
rrfU:
mov eax, 85
ret
rrfV:
mov eax, 86
ret
rrfW:
mov eax, 87
ret
rrfX:
mov eax, 88
ret
rrfY:
mov eax, 89
ret
rrfZ:
mov eax, 90
ret
rrflb:
mov eax, 91
ret
rrfbs:
mov eax, 92
ret
rrfrb:
mov eax, 93
ret
rrfct:
mov eax, 94
ret
rrfus:
mov eax, 95
ret
rrftl:
mov eax, 96
ret
rrfa:
mov eax, 97
ret
rrfb:
mov eax, 98
ret
rrfc:
mov eax, 99
ret
rrfd:
mov eax, 100
ret
rrfe:
mov eax, 101
ret
rrff:
mov eax, 102
ret
rrfg:
mov eax, 103
ret
rrfh:
mov eax, 104
ret
rrfi:
mov eax, 105
ret
rrfj:
mov eax, 106
ret
rrfk:
mov eax, 107
ret
rrfl:
mov eax, 108
ret
rrfm:
mov eax, 109
ret
rrfn:
mov eax, 110
ret
rrfo:
mov eax, 111
ret
rrfp:
mov eax, 112
ret
rrfq:
mov eax, 113
ret
rrfr:
mov eax, 114
ret
rrfs:
mov eax, 115
ret
rrft:
mov eax, 116
ret
rrfu:
mov eax, 117
ret
rrfv:
mov eax, 118
ret
rrfw:
mov eax, 119
ret
rrfx:
mov eax, 120
ret
rrfy:
mov eax, 121
ret
rrfz:
mov eax, 122
ret
rrflcb:
mov eax, 123
ret
rrfst:
mov eax, 124
ret
rrfrcb:
mov eax, 125
ret
rrf00:
mov eax, 0
ret
add:
movsx ecx, byte [esp+4H]
sub ecx, 48
add ecx, dword [esp+8H]
mov edx, 3524075731
mov eax, ecx
imul edx
add edx, ecx
sar edx, 6
mov eax, ecx
sar eax, 31
sub edx, eax
imul edx, edx, 78
sub ecx, edx
lea eax, [ecx+30H]
ret
sub:
movsx ecx, byte [esp+4H]
sub ecx, 48
sub ecx, dword [esp+8H]
mov edx, 3524075731
mov eax, ecx
imul edx
add edx, ecx
sar edx, 6
mov eax, ecx
sar eax, 31
sub edx, eax
imul edx, edx, 78
sub ecx, edx
mov edx, ecx
lea ecx, [ecx+7EH]
lea eax, [edx+30H]
test edx, edx
cmovs eax, ecx
ret
xor:
movsx ecx, byte [esp+4H]
sub ecx, 48
mov eax, dword [esp+8H]
and eax, 07H
xor ecx, eax
mov edx, 3524075731
mov eax, ecx
imul edx
add edx, ecx
sar edx, 6
mov eax, ecx
sar eax, 31
sub edx, eax
imul edx, edx, 78
sub ecx, edx
lea eax, [ecx+30H]
ret
main:
lea ecx, [esp+4H]
and esp, 0FFFFFFF0H
push dword [ecx-4H]
push ebp
mov ebp, esp
push esi
push ebx
push ecx
sub esp, 60
push 39
push 49
call sub
add esp, 8
movsx ecx, al
sub ecx, 24
mov ebx, 3524075731
mov eax, ecx
imul ebx
lea eax, [edx+ecx]
sar eax, 6
mov edx, ecx
sar edx, 31
sub eax, edx
imul eax, eax, 78
sub ecx, eax
add ecx, 48
mov byte [ebp-44H], cl
push 56
push 83
call sub
add esp, 8
mov byte [ebp-42H], al
push 19
push 90
call sub
add esp, 8
push 43
movsx ecx, al
sub ecx, 48
xor ecx, 07H
mov eax, ecx
imul ebx
lea eax, [edx+ecx]
sar eax, 6
mov edx, ecx
sar edx, 31
sub eax, edx
imul eax, eax, 78
sub ecx, eax
lea eax, [ecx+30H]
movsx eax, al
push eax
call sub
add esp, 8
mov byte [ebp-40H], al
push 33
push 89
call sub
add esp, 8
push 23
movsx eax, al
push eax
call sub
add esp, 8
mov byte [ebp-3EH], al
mov byte [ebp-3CH], 67
push 25
push 109
call sub
add esp, 8
mov byte [ebp-3AH], al
push 19
push 104
call sub
add esp, 8
push 21
movsx eax, al
push eax
call sub
add esp, 8
movsx ecx, al
sub ecx, 48
xor ecx, 06H
mov eax, ecx
imul ebx
lea eax, [edx+ecx]
sar eax, 6
mov edx, ecx
sar edx, 31
sub eax, edx
imul eax, eax, 78
sub ecx, eax
add ecx, 48
mov byte [ebp-38H], cl
push 25
push 102
call sub
add esp, 8
push 55
movsx eax, al
lea ecx, [eax-19H]
mov eax, ecx
imul ebx
lea eax, [edx+ecx]
sar eax, 6
mov edx, ecx
sar edx, 31
sub eax, edx
imul eax, eax, 78
sub ecx, eax
mov eax, ecx
add eax, 48
movsx eax, al
push eax
call sub
add esp, 8
mov byte [ebp-36H], al
mov byte [ebp-34H], 49
push 38
push 80
call sub
add esp, 8
push 30
movsx ecx, al
sub ecx, 48
xor ecx, 05H
mov eax, ecx
imul ebx
lea eax, [edx+ecx]
sar eax, 6
mov edx, ecx
sar edx, 31
sub eax, edx
imul eax, eax, 78
sub ecx, eax
lea eax, [ecx+30H]
movsx eax, al
push eax
call sub
add esp, 8
mov byte [ebp-32H], al
push 53
push 78
call sub
add esp, 8
push 54
movsx eax, al
push eax
call sub
add esp, 8
movsx ecx, al
add ecx, 7
mov eax, ecx
imul ebx
lea eax, [edx+ecx]
sar eax, 6
mov edx, ecx
sar edx, 31
sub eax, edx
imul eax, eax, 78
sub ecx, eax
add ecx, 48
mov byte [ebp-30H], cl
push 24
push 109
call sub
add esp, 8
push 34
movsx ecx, al
sub ecx, 48
xor ecx, 07H
mov eax, ecx
imul ebx
lea eax, [edx+ecx]
sar eax, 6
mov edx, ecx
sar edx, 31
sub eax, edx
imul eax, eax, 78
sub ecx, eax
lea eax, [ecx+30H]
movsx eax, al
push eax
call sub
add esp, 8
mov byte [ebp-2EH], al
push 33
push 115
call sub
add esp, 8
push 48
movsx eax, al
push eax
call sub
add esp, 8
mov byte [ebp-2CH], al
push 29
push 105
call sub
add esp, 8
movsx ecx, al
add ecx, 5
mov eax, ecx
imul ebx
lea eax, [edx+ecx]
sar eax, 6
mov edx, ecx
sar edx, 31
sub eax, edx
imul eax, eax, 78
sub ecx, eax
add ecx, 48
mov byte [ebp-2AH], cl
push 46
push 112
call sub
add esp, 8
movsx ecx, al
sub ecx, 21
mov eax, ecx
imul ebx
lea eax, [edx+ecx]
sar eax, 6
mov edx, ecx
sar edx, 31
sub eax, edx
imul eax, eax, 78
sub ecx, eax
add ecx, 48
movsx ecx, cl
sub ecx, 48
xor ecx, 02H
mov eax, ecx
imul ebx
lea eax, [edx+ecx]
sar eax, 6
mov edx, ecx
sar edx, 31
sub eax, edx
imul eax, eax, 78
sub ecx, eax
add ecx, 48
mov byte [ebp-28H], cl
push 49
push 93
call sub
add esp, 8
movsx ecx, al
sub ecx, 48
xor ecx, 03H
mov eax, ecx
imul ebx
lea eax, [edx+ecx]
sar eax, 6
mov edx, ecx
sar edx, 31
sub eax, edx
imul eax, eax, 78
sub ecx, eax
add ecx, 48
mov byte [ebp-26H], cl
push 32
push 60
call sub
add esp, 8
movsx ecx, al
sub ecx, 25
mov eax, ecx
imul ebx
lea eax, [edx+ecx]
sar eax, 6
mov edx, ecx
sar edx, 31
sub eax, edx
imul eax, eax, 78
sub ecx, eax
add ecx, 48
movsx ecx, cl
sub ecx, 48
xor ecx, 03H
mov eax, ecx
imul ebx
lea eax, [edx+ecx]
sar eax, 6
mov edx, ecx
sar edx, 31
sub eax, edx
imul eax, eax, 78
sub ecx, eax
add ecx, 48
mov byte [ebp-24H], cl
push 54
push 95
call sub
add esp, 8
movsx ecx, al
add ecx, 5
mov eax, ecx
imul ebx
lea eax, [edx+ecx]
sar eax, 6
mov edx, ecx
sar edx, 31
sub eax, edx
imul eax, eax, 78
sub ecx, eax
add ecx, 48
movsx ecx, cl
sub ecx, 25
mov eax, ecx
imul ebx
lea eax, [edx+ecx]
sar eax, 6
mov edx, ecx
sar edx, 31
sub eax, edx
imul eax, eax, 78
sub ecx, eax
add ecx, 48
mov byte [ebp-22H], cl
push 46
push 115
call sub
add esp, 8
push 52
movsx eax, al
push eax
call sub
add esp, 8
mov byte [ebp-20H], al
mov byte [ebp-1EH], 99
push 18
push 113
call sub
add esp, 8
push 47
movsx eax, al
push eax
call sub
add esp, 8
mov byte [ebp-1CH], al
push 54
push 98
call sub
add esp, 8
movsx ecx, al
sub ecx, 23
mov eax, ecx
imul ebx
lea eax, [edx+ecx]
sar eax, 6
mov edx, ecx
sar edx, 31
sub eax, edx
imul eax, eax, 78
sub ecx, eax
add ecx, 48
movsx ecx, cl
sub ecx, 8
mov eax, ecx
imul ebx
lea eax, [edx+ecx]
sar eax, 6
mov edx, ecx
sar edx, 31
sub eax, edx
imul eax, eax, 78
sub ecx, eax
add ecx, 48
mov byte [ebp-1AH], cl
push 48
push 110
call sub
add esp, 8
push 53
movsx eax, al
push eax
call sub
add esp, 8
movsx ecx, al
sub ecx, 48
xor ecx, 07H
mov eax, ecx
imul ebx
lea eax, [edx+ecx]
sar eax, 6
mov edx, ecx
sar edx, 31
sub eax, edx
imul eax, eax, 78
sub ecx, eax
add ecx, 48
mov byte [ebp-43H], cl
push 32
push 108
call sub
add esp, 8
push 48
movsx eax, al
push eax
call sub
add esp, 8
movsx ecx, al
sub ecx, 27
mov eax, ecx
imul ebx
lea eax, [edx+ecx]
sar eax, 6
mov edx, ecx
sar edx, 31
sub eax, edx
imul eax, eax, 78
sub ecx, eax
add ecx, 48
mov byte [ebp-41H], cl
push 49
push 79
call sub
add esp, 8
mov byte [ebp-3FH], al
push 50
push 90
call sub
add esp, 8
push 31
movsx eax, al
push eax
call sub
add esp, 8
push 36
movsx eax, al
push eax
call sub
add esp, 8
mov byte [ebp-3DH], al
mov byte [ebp-3BH], 100
mov byte [ebp-39H], 95
mov byte [ebp-37H], 116
push 34
push 112
call sub
add esp, 8
movsx ecx, al
sub ecx, 48
xor ecx, 06H
mov eax, ecx
imul ebx
lea eax, [edx+ecx]