Repository navigation
Expand file tree
/
Copy pathSymexMain.lean
More file actions
1240 lines (1214 loc) · 46.9 KB
/
Copy pathSymexMain.lean
File metadata and controls
1240 lines (1214 loc) · 46.9 KB
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
import TouhouFormal.Search.Symbolic
import TouhouFormal.Search.Symbolic.Extension
namespace SymexMain
private def usage : String :=
"usage: lake exe symex <list-paths|list-body-paths|list-int-resolver-paths|" ++
"list-callret-paths|list-condcall-paths|list-int-binary-paths|list-boss-int-paths|" ++
"list-boss-float-paths|list-extension-paths|" ++
"query|query-values|query-body|query-body-values|query-int-resolver|query-int-resolver-values|" ++
"query-callret|query-callret-values|query-condcall|query-condcall-values|" ++
"query-int-binary|query-int-binary-values|query-boss-int|query-boss-int-values|" ++
"query-boss-float|query-boss-float-values|query-extension|query-extension-values|" ++
"materialize|materialize-file|materialize-body|materialize-int-resolver|" ++
"materialize-callret|materialize-condcall|materialize-int-binary|" ++
"materialize-boss-int|materialize-boss-float|materialize-extension ...>"
private def parseNat? (value : String) : Option Nat :=
value.toNat?
private def parseInt? (value : String) : Option Int :=
value.toInt?
private def parseBool? : String -> Option Bool
| "true" => some true
| "false" => some false
| "1" => some true
| "0" => some false
| _ => none
private def runQuery
(valuesOnly : Bool)
(titleText pathText : String)
(activeMask overrideMask : Nat) :
IO UInt32 := do
if 255 < activeMask || 255 < overrideMask then
IO.eprintln "activeMask and overrideMask must fit in an unsigned byte"
IO.eprintln usage
return 2
else
match TouhouFormal.Search.Symbolic.Title.parse? titleText,
TouhouFormal.Search.Symbolic.RawStepPath.parse? pathText with
| some title, some path =>
if valuesOnly then
IO.print
(TouhouFormal.Search.Symbolic.rawStepValuesQuery title path activeMask overrideMask)
else
IO.print
(TouhouFormal.Search.Symbolic.rawStepQuery title path activeMask overrideMask)
return 0
| none, _ =>
IO.eprintln s!"unknown title: {titleText}"
IO.eprintln usage
return 2
| _, none =>
IO.eprintln s!"unknown path: {pathText}"
IO.eprintln usage
return 2
private def runBodyQuery
(valuesOnly : Bool)
(titleText pathText : String)
(activeMask overrideMask : Nat) :
IO UInt32 := do
if 255 < activeMask || 255 < overrideMask then
IO.eprintln "activeMask and overrideMask must fit in an unsigned byte"
IO.eprintln usage
return 2
else
match TouhouFormal.Search.Symbolic.Title.parse? titleText,
TouhouFormal.Search.Symbolic.RawBodyPath.parse? pathText with
| some title, some path =>
if valuesOnly then
IO.print
(TouhouFormal.Search.Symbolic.rawBodyValuesQuery title path activeMask overrideMask)
else
IO.print
(TouhouFormal.Search.Symbolic.rawBodyQuery title path activeMask overrideMask)
return 0
| none, _ =>
IO.eprintln s!"unknown title: {titleText}"
IO.eprintln usage
return 2
| _, none =>
IO.eprintln s!"unknown body path: {pathText}"
IO.eprintln usage
return 2
private def runIntResolverQuery
(valuesOnly : Bool)
(titleText pathText : String)
(slot : Nat) :
IO UInt32 := do
match TouhouFormal.Search.Symbolic.Title.parse? titleText,
TouhouFormal.Search.Symbolic.RawIntResolverPath.parse? pathText with
| some title, some path =>
if valuesOnly then
IO.print
(TouhouFormal.Search.Symbolic.rawIntResolverValuesQuery title path slot)
else
IO.print
(TouhouFormal.Search.Symbolic.rawIntResolverQuery title path slot)
return 0
| none, _ =>
IO.eprintln s!"unknown title: {titleText}"
IO.eprintln usage
return 2
| _, none =>
IO.eprintln s!"unknown integer resolver path: {pathText}"
IO.eprintln usage
return 2
private def runCallRetQuery
(valuesOnly : Bool)
(titleText pathText : String)
(activeMask overrideMask : Nat) :
IO UInt32 := do
if 255 < activeMask || 255 < overrideMask then
IO.eprintln "activeMask and overrideMask must fit in an unsigned byte"
IO.eprintln usage
return 2
else
match TouhouFormal.Search.Symbolic.Title.parse? titleText,
TouhouFormal.Search.Symbolic.RawCallRetPath.parse? pathText with
| some title, some path =>
if valuesOnly then
IO.print
(TouhouFormal.Search.Symbolic.rawCallRetValuesQuery title path activeMask overrideMask)
else
IO.print
(TouhouFormal.Search.Symbolic.rawCallRetQuery title path activeMask overrideMask)
return 0
| none, _ =>
IO.eprintln s!"unknown title: {titleText}"
IO.eprintln usage
return 2
| _, none =>
IO.eprintln s!"unknown CALL/RET path: {pathText}"
IO.eprintln usage
return 2
private def runConditionalCallQuery
(valuesOnly : Bool)
(titleText pathText : String)
(activeMask overrideMask : Nat) :
IO UInt32 := do
if 255 < activeMask || 255 < overrideMask then
IO.eprintln "activeMask and overrideMask must fit in an unsigned byte"
IO.eprintln usage
return 2
else
match TouhouFormal.Search.Symbolic.Title.parse? titleText,
TouhouFormal.Search.Symbolic.RawConditionalCallPath.parse? pathText with
| some title, some path =>
if valuesOnly then
IO.print
(TouhouFormal.Search.Symbolic.rawConditionalCallValuesQuery title path activeMask overrideMask)
else
IO.print
(TouhouFormal.Search.Symbolic.rawConditionalCallQuery title path activeMask overrideMask)
return 0
| none, _ =>
IO.eprintln s!"unknown title: {titleText}"
IO.eprintln usage
return 2
| _, none =>
IO.eprintln s!"unknown conditional CALL path: {pathText}"
IO.eprintln usage
return 2
private def runIntBinaryQuery
(valuesOnly : Bool)
(titleText pathText : String)
(activeMask overrideMask : Nat) :
IO UInt32 := do
if 255 < activeMask || 255 < overrideMask then
IO.eprintln "activeMask and overrideMask must fit in an unsigned byte"
IO.eprintln usage
return 2
else
match TouhouFormal.Search.Symbolic.Title.parse? titleText,
TouhouFormal.Search.Symbolic.RawIntBinaryPath.parse? pathText with
| some title, some path =>
if valuesOnly then
IO.print
(TouhouFormal.Search.Symbolic.rawIntBinaryValuesQuery title path activeMask overrideMask)
else
IO.print
(TouhouFormal.Search.Symbolic.rawIntBinaryQuery title path activeMask overrideMask)
return 0
| none, _ =>
IO.eprintln s!"unknown title: {titleText}"
IO.eprintln usage
return 2
| _, none =>
IO.eprintln s!"unknown integer binary path: {pathText}"
IO.eprintln usage
return 2
private def runBossIntReadQuery
(valuesOnly : Bool)
(titleText pathText : String)
(activeMask overrideMask : Nat) :
IO UInt32 := do
if 255 < activeMask || 255 < overrideMask then
IO.eprintln "activeMask and overrideMask must fit in an unsigned byte"
IO.eprintln usage
return 2
else
match TouhouFormal.Search.Symbolic.Title.parse? titleText,
TouhouFormal.Search.Symbolic.RawBossIntReadPath.parse? pathText with
| some title, some path =>
if valuesOnly then
IO.print
(TouhouFormal.Search.Symbolic.rawBossIntReadValuesQuery title path activeMask overrideMask)
else
IO.print
(TouhouFormal.Search.Symbolic.rawBossIntReadQuery title path activeMask overrideMask)
return 0
| none, _ =>
IO.eprintln s!"unknown title: {titleText}"
IO.eprintln usage
return 2
| _, none =>
IO.eprintln s!"unknown boss integer-read path: {pathText}"
IO.eprintln usage
return 2
private def runBossFloatReadQuery
(valuesOnly : Bool)
(titleText pathText : String)
(activeMask overrideMask : Nat) :
IO UInt32 := do
if 255 < activeMask || 255 < overrideMask then
IO.eprintln "activeMask and overrideMask must fit in an unsigned byte"
IO.eprintln usage
return 2
else
match TouhouFormal.Search.Symbolic.Title.parse? titleText,
TouhouFormal.Search.Symbolic.RawBossFloatReadPath.parse? pathText with
| some title, some path =>
if valuesOnly then
IO.print
(TouhouFormal.Search.Symbolic.rawBossFloatReadValuesQuery title path activeMask overrideMask)
else
IO.print
(TouhouFormal.Search.Symbolic.rawBossFloatReadQuery title path activeMask overrideMask)
return 0
| none, _ =>
IO.eprintln s!"unknown title: {titleText}"
IO.eprintln usage
return 2
| _, none =>
IO.eprintln s!"unknown boss float-read path: {pathText}"
IO.eprintln usage
return 2
private def runExtensionQuery
(valuesOnly : Bool)
(titleText pathText : String)
(activeMask overrideMask : Nat) :
IO UInt32 := do
if 255 < activeMask || 255 < overrideMask then
IO.eprintln "activeMask and overrideMask must fit in an unsigned byte"
IO.eprintln usage
return 2
else
match TouhouFormal.Search.Symbolic.Title.parse? titleText,
TouhouFormal.Search.Symbolic.RawExtensionPath.parse? pathText with
| some title, some path =>
if valuesOnly then
IO.print
(TouhouFormal.Search.Symbolic.rawExtensionValuesQuery title path activeMask overrideMask)
else
IO.print
(TouhouFormal.Search.Symbolic.rawExtensionQuery title path activeMask overrideMask)
return 0
| none, _ =>
IO.eprintln s!"unknown title: {titleText}"
IO.eprintln usage
return 2
| _, none =>
IO.eprintln s!"unknown extension-dispatch path: {pathText}"
IO.eprintln usage
return 2
private def runMaterialize
(asFile : Bool)
(titleText pathText currentTimeText instrTimeText opcodeText nextOffsetText
instructionMaskText operandMaskText activeMaskText overrideMaskText jumpTargetTimeText
jumpDisplacementText bufferSizeText : String) : IO UInt32 := do
match TouhouFormal.Search.Symbolic.Title.parse? titleText,
TouhouFormal.Search.Symbolic.RawStepPath.parse? pathText,
parseInt? currentTimeText,
parseInt? instrTimeText,
parseInt? opcodeText,
parseInt? nextOffsetText,
parseNat? instructionMaskText,
parseInt? operandMaskText,
parseNat? activeMaskText,
parseNat? overrideMaskText,
parseInt? jumpTargetTimeText,
parseInt? jumpDisplacementText,
parseNat? bufferSizeText with
| some title, some path, some currentTime, some instrTime, some opcode, some nextOffset,
some instructionMask, some operandMask, some activeMask, some overrideMask,
some jumpTargetTime, some jumpDisplacement, some bufferSize =>
let witness : TouhouFormal.Search.Symbolic.RawStepWitness :=
{ currentTime := currentTime
instrTime := instrTime
opcode := opcode
nextOffset := nextOffset
instructionMask := instructionMask
operandMask := operandMask
activeMask := activeMask
overrideMask := overrideMask
jumpTargetTime := jumpTargetTime
jumpDisplacement := jumpDisplacement
bufferSize := bufferSize }
if asFile then
match TouhouFormal.Search.Symbolic.rawStepEclFileMaterialize title path witness with
| .ok materialization =>
IO.print materialization.report
return 0
| .error message =>
IO.eprintln message
return 1
else
match TouhouFormal.Search.Symbolic.rawStepMaterialize title path witness with
| .ok materialization =>
IO.print materialization.report
return 0
| .error message =>
IO.eprintln message
return 1
| none, _, _, _, _, _, _, _, _, _, _, _, _ =>
IO.eprintln s!"unknown title: {titleText}"
IO.eprintln usage
return 2
| _, none, _, _, _, _, _, _, _, _, _, _, _ =>
IO.eprintln s!"unknown path: {pathText}"
IO.eprintln usage
return 2
| _, _, _, _, _, _, _, _, _, _, _, _, _ =>
IO.eprintln "invalid materialize witness field"
IO.eprintln usage
return 2
private def runBodyMaterialize
(titleText pathText currentTimeText instrTimeText opcodeText nextOffsetText
instructionMaskText operandMaskText activeMaskText overrideMaskText jumpTargetTimeText
jumpDisplacementText counterBeforeText divisorValueText lhsRawText rhsRawText lhsHostText
rhsHostText compareRegisterText bufferSizeText : String) :
IO UInt32 := do
match TouhouFormal.Search.Symbolic.Title.parse? titleText,
TouhouFormal.Search.Symbolic.RawBodyPath.parse? pathText,
parseInt? currentTimeText,
parseInt? instrTimeText,
parseInt? opcodeText,
parseInt? nextOffsetText,
parseNat? instructionMaskText,
parseInt? operandMaskText,
parseNat? activeMaskText,
parseNat? overrideMaskText,
parseInt? jumpTargetTimeText,
parseInt? jumpDisplacementText,
parseInt? counterBeforeText,
parseInt? divisorValueText,
parseInt? lhsRawText,
parseInt? rhsRawText,
parseInt? lhsHostText,
parseInt? rhsHostText,
parseInt? compareRegisterText,
parseNat? bufferSizeText with
| some title, some path, some currentTime, some instrTime, some opcode, some nextOffset,
some instructionMask, some operandMask, some activeMask, some overrideMask,
some jumpTargetTime, some jumpDisplacement, some counterBefore, some divisorValue,
some lhsRaw, some rhsRaw, some lhsHost, some rhsHost, some compareRegister, some bufferSize =>
let witness : TouhouFormal.Search.Symbolic.RawBodyWitness :=
{ currentTime := currentTime
instrTime := instrTime
opcode := opcode
nextOffset := nextOffset
instructionMask := instructionMask
operandMask := operandMask
activeMask := activeMask
overrideMask := overrideMask
jumpTargetTime := jumpTargetTime
jumpDisplacement := jumpDisplacement
bufferSize := bufferSize
counterBefore := counterBefore
divisorValue := divisorValue
lhsRaw := lhsRaw
rhsRaw := rhsRaw
lhsHost := lhsHost
rhsHost := rhsHost
compareRegister := compareRegister }
match TouhouFormal.Search.Symbolic.rawBodyMaterialize title path witness with
| .ok materialization =>
IO.print materialization.report
return 0
| .error message =>
IO.eprintln message
return 1
| none, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ =>
IO.eprintln s!"unknown title: {titleText}"
IO.eprintln usage
return 2
| _, none, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ =>
IO.eprintln s!"unknown body path: {pathText}"
IO.eprintln usage
return 2
| _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ =>
IO.eprintln "invalid materialize-body witness field"
IO.eprintln usage
return 2
private def runIntResolverMaterialize
(titleText pathText slotText rawValueText hostValueText operandMaskText : String) :
IO UInt32 := do
match TouhouFormal.Search.Symbolic.Title.parse? titleText,
TouhouFormal.Search.Symbolic.RawIntResolverPath.parse? pathText,
parseNat? slotText,
parseInt? rawValueText,
parseInt? hostValueText,
parseInt? operandMaskText with
| some title, some path, some slot, some rawValue, some hostValue, some operandMask =>
let witness : TouhouFormal.Search.Symbolic.RawIntResolverWitness :=
{ slot := slot
rawValue := rawValue
hostValue := hostValue
operandMask := operandMask }
match TouhouFormal.Search.Symbolic.rawIntResolverMaterialize title path witness with
| .ok materialization =>
IO.print materialization.report
return 0
| .error message =>
IO.eprintln message
return 1
| none, _, _, _, _, _ =>
IO.eprintln s!"unknown title: {titleText}"
IO.eprintln usage
return 2
| _, none, _, _, _, _ =>
IO.eprintln s!"unknown integer resolver path: {pathText}"
IO.eprintln usage
return 2
| _, _, _, _, _, _ =>
IO.eprintln "invalid materialize-int-resolver witness field"
IO.eprintln usage
return 2
private def runCallRetMaterialize
(titleText pathText currentTimeText instrTimeText opcodeText nextOffsetText
instructionMaskText operandMaskText activeMaskText overrideMaskText subIdText
stackDepthText stackDisabledText subCountText childContextSlotText bufferSizeText : String) :
IO UInt32 := do
match TouhouFormal.Search.Symbolic.Title.parse? titleText,
TouhouFormal.Search.Symbolic.RawCallRetPath.parse? pathText,
parseInt? currentTimeText,
parseInt? instrTimeText,
parseInt? opcodeText,
parseInt? nextOffsetText,
parseNat? instructionMaskText,
parseInt? operandMaskText,
parseNat? activeMaskText,
parseNat? overrideMaskText,
parseInt? subIdText,
parseInt? stackDepthText,
parseBool? stackDisabledText,
parseNat? subCountText,
parseInt? childContextSlotText,
parseNat? bufferSizeText with
| some title, some path, some currentTime, some instrTime, some opcode, some nextOffset,
some instructionMask, some operandMask, some activeMask, some overrideMask,
some subId, some stackDepth, some stackDisabled, some subCount, some childContextSlot,
some bufferSize =>
let witness : TouhouFormal.Search.Symbolic.RawCallRetWitness :=
{ currentTime := currentTime
instrTime := instrTime
opcode := opcode
nextOffset := nextOffset
instructionMask := instructionMask
operandMask := operandMask
activeMask := activeMask
overrideMask := overrideMask
jumpTargetTime := 0
jumpDisplacement := 0
bufferSize := bufferSize
subId := subId
stackDepth := stackDepth
stackDisabled := stackDisabled
subCount := subCount
childContextSlot := childContextSlot }
match TouhouFormal.Search.Symbolic.rawCallRetMaterialize title path witness with
| .ok materialization =>
IO.print materialization.report
return 0
| .error message =>
IO.eprintln message
return 1
| none, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ =>
IO.eprintln s!"unknown title: {titleText}"
IO.eprintln usage
return 2
| _, none, _, _, _, _, _, _, _, _, _, _, _, _, _, _ =>
IO.eprintln s!"unknown CALL/RET path: {pathText}"
IO.eprintln usage
return 2
| _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ =>
IO.eprintln "invalid materialize-callret witness field"
IO.eprintln usage
return 2
private def runConditionalCallMaterialize
(titleText pathText currentTimeText instrTimeText opcodeText nextOffsetText
instructionMaskText operandMaskText activeMaskText overrideMaskText subIdText
stackDepthText stackDisabledText subCountText lhsRawText lhsHostText rhsRawText
bufferSizeText : String) :
IO UInt32 := do
match TouhouFormal.Search.Symbolic.Title.parse? titleText,
TouhouFormal.Search.Symbolic.RawConditionalCallPath.parse? pathText,
parseInt? currentTimeText,
parseInt? instrTimeText,
parseInt? opcodeText,
parseInt? nextOffsetText,
parseNat? instructionMaskText,
parseInt? operandMaskText,
parseNat? activeMaskText,
parseNat? overrideMaskText,
parseInt? subIdText,
parseInt? stackDepthText,
parseBool? stackDisabledText,
parseNat? subCountText,
parseInt? lhsRawText,
parseInt? lhsHostText,
parseInt? rhsRawText,
parseNat? bufferSizeText with
| some title, some path, some currentTime, some instrTime, some opcode, some nextOffset,
some instructionMask, some operandMask, some activeMask, some overrideMask,
some subId, some stackDepth, some stackDisabled, some subCount, some lhsRaw,
some lhsHost, some rhsRaw, some bufferSize =>
let witness : TouhouFormal.Search.Symbolic.RawConditionalCallWitness :=
{ currentTime := currentTime
instrTime := instrTime
opcode := opcode
nextOffset := nextOffset
instructionMask := instructionMask
operandMask := operandMask
activeMask := activeMask
overrideMask := overrideMask
jumpTargetTime := 0
jumpDisplacement := 0
bufferSize := bufferSize
subId := subId
stackDepth := stackDepth
stackDisabled := stackDisabled
subCount := subCount
lhsRaw := lhsRaw
lhsHost := lhsHost
rhsRaw := rhsRaw }
match TouhouFormal.Search.Symbolic.rawConditionalCallMaterialize title path witness with
| .ok materialization =>
IO.print materialization.report
return 0
| .error message =>
IO.eprintln message
return 1
| none, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ =>
IO.eprintln s!"unknown title: {titleText}"
IO.eprintln usage
return 2
| _, none, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ =>
IO.eprintln s!"unknown conditional CALL path: {pathText}"
IO.eprintln usage
return 2
| _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ =>
IO.eprintln "invalid materialize-condcall witness field"
IO.eprintln usage
return 2
private def runIntBinaryMaterialize
(titleText pathText currentTimeText instrTimeText opcodeText nextOffsetText
instructionMaskText operandMaskText activeMaskText overrideMaskText outputRawText
outputHostBeforeText lhsRawText rhsRawText lhsHostText rhsHostText bufferSizeText : String) :
IO UInt32 := do
match TouhouFormal.Search.Symbolic.Title.parse? titleText,
TouhouFormal.Search.Symbolic.RawIntBinaryPath.parse? pathText,
parseInt? currentTimeText,
parseInt? instrTimeText,
parseInt? opcodeText,
parseInt? nextOffsetText,
parseNat? instructionMaskText,
parseInt? operandMaskText,
parseNat? activeMaskText,
parseNat? overrideMaskText,
parseInt? outputRawText,
parseInt? outputHostBeforeText,
parseInt? lhsRawText,
parseInt? rhsRawText,
parseInt? lhsHostText,
parseInt? rhsHostText,
parseNat? bufferSizeText with
| some title, some path, some currentTime, some instrTime, some opcode, some nextOffset,
some instructionMask, some operandMask, some activeMask, some overrideMask,
some outputRaw, some outputHostBefore, some lhsRaw, some rhsRaw, some lhsHost,
some rhsHost, some bufferSize =>
let witness : TouhouFormal.Search.Symbolic.RawIntBinaryWitness :=
{ currentTime := currentTime
instrTime := instrTime
opcode := opcode
nextOffset := nextOffset
instructionMask := instructionMask
operandMask := operandMask
activeMask := activeMask
overrideMask := overrideMask
jumpTargetTime := 0
jumpDisplacement := 0
bufferSize := bufferSize
outputRaw := outputRaw
outputHostBefore := outputHostBefore
lhsRaw := lhsRaw
rhsRaw := rhsRaw
lhsHost := lhsHost
rhsHost := rhsHost }
match TouhouFormal.Search.Symbolic.rawIntBinaryMaterialize title path witness with
| .ok materialization =>
IO.print materialization.report
return 0
| .error message =>
IO.eprintln message
return 1
| none, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ =>
IO.eprintln s!"unknown title: {titleText}"
IO.eprintln usage
return 2
| _, none, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ =>
IO.eprintln s!"unknown integer binary path: {pathText}"
IO.eprintln usage
return 2
| _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ =>
IO.eprintln "invalid materialize-int-binary witness field"
IO.eprintln usage
return 2
private def runBossIntReadMaterialize
(titleText pathText currentTimeText instrTimeText opcodeText nextOffsetText
instructionMaskText operandMaskText activeMaskText overrideMaskText outputRawText
outputHostBeforeText valueRawText valueHostText bossIndexRawText bossIndexHostText
bossPresentText bufferSizeText : String) :
IO UInt32 := do
match TouhouFormal.Search.Symbolic.Title.parse? titleText,
TouhouFormal.Search.Symbolic.RawBossIntReadPath.parse? pathText,
parseInt? currentTimeText,
parseInt? instrTimeText,
parseInt? opcodeText,
parseInt? nextOffsetText,
parseNat? instructionMaskText,
parseInt? operandMaskText,
parseNat? activeMaskText,
parseNat? overrideMaskText,
parseInt? outputRawText,
parseInt? outputHostBeforeText,
parseInt? valueRawText,
parseInt? valueHostText,
parseInt? bossIndexRawText,
parseInt? bossIndexHostText,
parseBool? bossPresentText,
parseNat? bufferSizeText with
| some title, some path, some currentTime, some instrTime, some opcode, some nextOffset,
some instructionMask, some operandMask, some activeMask, some overrideMask,
some outputRaw, some outputHostBefore, some valueRaw, some valueHost,
some bossIndexRaw, some bossIndexHost, some bossPresent, some bufferSize =>
let witness : TouhouFormal.Search.Symbolic.RawBossIntReadWitness :=
{ currentTime := currentTime
instrTime := instrTime
opcode := opcode
nextOffset := nextOffset
instructionMask := instructionMask
operandMask := operandMask
activeMask := activeMask
overrideMask := overrideMask
jumpTargetTime := 0
jumpDisplacement := 0
bufferSize := bufferSize
outputRaw := outputRaw
outputHostBefore := outputHostBefore
valueRaw := valueRaw
valueHost := valueHost
bossIndexRaw := bossIndexRaw
bossIndexHost := bossIndexHost
bossPresent := bossPresent }
match TouhouFormal.Search.Symbolic.rawBossIntReadMaterialize title path witness with
| .ok materialization =>
IO.print materialization.report
return 0
| .error message =>
IO.eprintln message
return 1
| none, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ =>
IO.eprintln s!"unknown title: {titleText}"
IO.eprintln usage
return 2
| _, none, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ =>
IO.eprintln s!"unknown boss integer-read path: {pathText}"
IO.eprintln usage
return 2
| _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ =>
IO.eprintln "invalid materialize-boss-int witness field"
IO.eprintln usage
return 2
private def runBossFloatReadMaterialize
(titleText pathText currentTimeText instrTimeText opcodeText nextOffsetText
instructionMaskText operandMaskText activeMaskText overrideMaskText outputRawText
outputHostBeforeText valueRawText valueHostText bossIndexRawText bossIndexHostText
bossPresentText bufferSizeText : String) :
IO UInt32 := do
match TouhouFormal.Search.Symbolic.Title.parse? titleText,
TouhouFormal.Search.Symbolic.RawBossFloatReadPath.parse? pathText,
parseInt? currentTimeText,
parseInt? instrTimeText,
parseInt? opcodeText,
parseInt? nextOffsetText,
parseNat? instructionMaskText,
parseInt? operandMaskText,
parseNat? activeMaskText,
parseNat? overrideMaskText,
parseInt? outputRawText,
parseInt? outputHostBeforeText,
parseInt? valueRawText,
parseInt? valueHostText,
parseInt? bossIndexRawText,
parseInt? bossIndexHostText,
parseBool? bossPresentText,
parseNat? bufferSizeText with
| some title, some path, some currentTime, some instrTime, some opcode, some nextOffset,
some instructionMask, some operandMask, some activeMask, some overrideMask,
some outputRaw, some outputHostBefore, some valueRaw, some valueHost,
some bossIndexRaw, some bossIndexHost, some bossPresent, some bufferSize =>
let witness : TouhouFormal.Search.Symbolic.RawBossFloatReadWitness :=
{ currentTime := currentTime
instrTime := instrTime
opcode := opcode
nextOffset := nextOffset
instructionMask := instructionMask
operandMask := operandMask
activeMask := activeMask
overrideMask := overrideMask
jumpTargetTime := 0
jumpDisplacement := 0
bufferSize := bufferSize
outputRaw := outputRaw
outputHostBefore := outputHostBefore
valueRaw := valueRaw
valueHost := valueHost
bossIndexRaw := bossIndexRaw
bossIndexHost := bossIndexHost
bossPresent := bossPresent }
match TouhouFormal.Search.Symbolic.rawBossFloatReadMaterialize title path witness with
| .ok materialization =>
IO.print materialization.report
return 0
| .error message =>
IO.eprintln message
return 1
| none, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ =>
IO.eprintln s!"unknown title: {titleText}"
IO.eprintln usage
return 2
| _, none, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ =>
IO.eprintln s!"unknown boss float-read path: {pathText}"
IO.eprintln usage
return 2
| _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ =>
IO.eprintln "invalid materialize-boss-float witness field"
IO.eprintln usage
return 2
private def runExtensionMaterialize
(titleText pathText currentTimeText instrTimeText opcodeText nextOffsetText
instructionMaskText operandMaskText activeMaskText overrideMaskText indexRaw0Text
indexHost0Text indexRaw1Text indexHost1Text bufferSizeText : String) :
IO UInt32 := do
match TouhouFormal.Search.Symbolic.Title.parse? titleText,
TouhouFormal.Search.Symbolic.RawExtensionPath.parse? pathText,
parseInt? currentTimeText,
parseInt? instrTimeText,
parseInt? opcodeText,
parseInt? nextOffsetText,
parseNat? instructionMaskText,
parseInt? operandMaskText,
parseNat? activeMaskText,
parseNat? overrideMaskText,
parseInt? indexRaw0Text,
parseInt? indexHost0Text,
parseInt? indexRaw1Text,
parseInt? indexHost1Text,
parseNat? bufferSizeText with
| some title, some path, some currentTime, some instrTime, some opcode, some nextOffset,
some instructionMask, some operandMask, some activeMask, some overrideMask,
some indexRaw0, some indexHost0, some indexRaw1, some indexHost1, some bufferSize =>
let witness : TouhouFormal.Search.Symbolic.RawExtensionWitness :=
{ currentTime := currentTime
instrTime := instrTime
opcode := opcode
nextOffset := nextOffset
instructionMask := instructionMask
operandMask := operandMask
activeMask := activeMask
overrideMask := overrideMask
indexRaw0 := indexRaw0
indexHost0 := indexHost0
indexRaw1 := indexRaw1
indexHost1 := indexHost1
bufferSize := bufferSize }
match TouhouFormal.Search.Symbolic.rawExtensionMaterialize title path witness with
| .ok materialization =>
IO.print materialization.report
return 0
| .error message =>
IO.eprintln message
return 1
| none, _, _, _, _, _, _, _, _, _, _, _, _, _, _ =>
IO.eprintln s!"unknown title: {titleText}"
IO.eprintln usage
return 2
| _, none, _, _, _, _, _, _, _, _, _, _, _, _, _ =>
IO.eprintln s!"unknown extension-dispatch path: {pathText}"
IO.eprintln usage
return 2
| _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ =>
IO.eprintln "invalid materialize-extension witness field"
IO.eprintln usage
return 2
def main (args : List String) : IO UInt32 := do
match args with
| ["list-paths"] =>
IO.print TouhouFormal.Search.Symbolic.listRawStepPathsText
return 0
| ["list-body-paths"] =>
IO.print TouhouFormal.Search.Symbolic.listRawBodyPathsText
return 0
| ["list-int-resolver-paths"] =>
IO.print TouhouFormal.Search.Symbolic.listRawIntResolverPathsText
return 0
| ["list-callret-paths"] =>
IO.print TouhouFormal.Search.Symbolic.listRawCallRetPathsText
return 0
| ["list-condcall-paths"] =>
IO.print TouhouFormal.Search.Symbolic.listRawConditionalCallPathsText
return 0
| ["list-int-binary-paths"] =>
IO.print TouhouFormal.Search.Symbolic.listRawIntBinaryPathsText
return 0
| ["list-boss-int-paths"] =>
IO.print TouhouFormal.Search.Symbolic.listRawBossIntReadPathsText
return 0
| ["list-boss-float-paths"] =>
IO.print TouhouFormal.Search.Symbolic.listRawBossFloatReadPathsText
return 0
| ["list-extension-paths"] =>
IO.print TouhouFormal.Search.Symbolic.listRawExtensionPathsText
return 0
| ["query", title, path] =>
runQuery false title path 1 0
| ["query-values", title, path] =>
runQuery true title path 1 0
| ["query-body", title, path] =>
runBodyQuery false title path 1 0
| ["query-body-values", title, path] =>
runBodyQuery true title path 1 0
| ["query-int-resolver", title, path] =>
runIntResolverQuery false title path 0
| ["query-int-resolver-values", title, path] =>
runIntResolverQuery true title path 0
| ["query-callret", title, path] =>
runCallRetQuery false title path 1 0
| ["query-callret-values", title, path] =>
runCallRetQuery true title path 1 0
| ["query-condcall", title, path] =>
runConditionalCallQuery false title path 1 0
| ["query-condcall-values", title, path] =>
runConditionalCallQuery true title path 1 0
| ["query-int-binary", title, path] =>
runIntBinaryQuery false title path 1 0
| ["query-int-binary-values", title, path] =>
runIntBinaryQuery true title path 1 0
| ["query-boss-int", title, path] =>
runBossIntReadQuery false title path 1 0
| ["query-boss-int-values", title, path] =>
runBossIntReadQuery true title path 1 0
| ["query-boss-float", title, path] =>
runBossFloatReadQuery false title path 1 0
| ["query-boss-float-values", title, path] =>
runBossFloatReadQuery true title path 1 0
| ["query-extension", title, path] =>
runExtensionQuery false title path 1 0
| ["query-extension-values", title, path] =>
runExtensionQuery true title path 1 0
| ["query", title, path, activeMaskText, overrideMaskText] =>
match parseNat? activeMaskText, parseNat? overrideMaskText with
| some activeMask, some overrideMask =>
runQuery false title path activeMask overrideMask
| _, _ =>
IO.eprintln "activeMask and overrideMask must be natural numbers"
IO.eprintln usage
return 2
| ["query-body", title, path, activeMaskText, overrideMaskText] =>
match parseNat? activeMaskText, parseNat? overrideMaskText with
| some activeMask, some overrideMask =>
runBodyQuery false title path activeMask overrideMask
| _, _ =>
IO.eprintln "activeMask and overrideMask must be natural numbers"
IO.eprintln usage
return 2
| ["query-body-values", title, path, activeMaskText, overrideMaskText] =>
match parseNat? activeMaskText, parseNat? overrideMaskText with
| some activeMask, some overrideMask =>
runBodyQuery true title path activeMask overrideMask
| _, _ =>
IO.eprintln "activeMask and overrideMask must be natural numbers"
IO.eprintln usage
return 2
| ["query-values", title, path, activeMaskText, overrideMaskText] =>
match parseNat? activeMaskText, parseNat? overrideMaskText with
| some activeMask, some overrideMask =>
runQuery true title path activeMask overrideMask
| _, _ =>
IO.eprintln "activeMask and overrideMask must be natural numbers"
IO.eprintln usage
return 2
| ["query-callret", title, path, activeMaskText, overrideMaskText] =>
match parseNat? activeMaskText, parseNat? overrideMaskText with
| some activeMask, some overrideMask =>
runCallRetQuery false title path activeMask overrideMask
| _, _ =>
IO.eprintln "activeMask and overrideMask must be natural numbers"
IO.eprintln usage
return 2
| ["query-callret-values", title, path, activeMaskText, overrideMaskText] =>
match parseNat? activeMaskText, parseNat? overrideMaskText with
| some activeMask, some overrideMask =>
runCallRetQuery true title path activeMask overrideMask
| _, _ =>
IO.eprintln "activeMask and overrideMask must be natural numbers"
IO.eprintln usage
return 2
| ["query-condcall", title, path, activeMaskText, overrideMaskText] =>
match parseNat? activeMaskText, parseNat? overrideMaskText with
| some activeMask, some overrideMask =>
runConditionalCallQuery false title path activeMask overrideMask
| _, _ =>
IO.eprintln "activeMask and overrideMask must be natural numbers"
IO.eprintln usage
return 2
| ["query-condcall-values", title, path, activeMaskText, overrideMaskText] =>
match parseNat? activeMaskText, parseNat? overrideMaskText with
| some activeMask, some overrideMask =>
runConditionalCallQuery true title path activeMask overrideMask
| _, _ =>
IO.eprintln "activeMask and overrideMask must be natural numbers"
IO.eprintln usage
return 2
| ["query-int-binary", title, path, activeMaskText, overrideMaskText] =>
match parseNat? activeMaskText, parseNat? overrideMaskText with
| some activeMask, some overrideMask =>
runIntBinaryQuery false title path activeMask overrideMask
| _, _ =>
IO.eprintln "activeMask and overrideMask must be natural numbers"
IO.eprintln usage
return 2
| ["query-int-binary-values", title, path, activeMaskText, overrideMaskText] =>
match parseNat? activeMaskText, parseNat? overrideMaskText with
| some activeMask, some overrideMask =>
runIntBinaryQuery true title path activeMask overrideMask
| _, _ =>
IO.eprintln "activeMask and overrideMask must be natural numbers"
IO.eprintln usage
return 2
| ["query-boss-int", title, path, activeMaskText, overrideMaskText] =>
match parseNat? activeMaskText, parseNat? overrideMaskText with
| some activeMask, some overrideMask =>
runBossIntReadQuery false title path activeMask overrideMask
| _, _ =>
IO.eprintln "activeMask and overrideMask must be natural numbers"
IO.eprintln usage
return 2
| ["query-boss-int-values", title, path, activeMaskText, overrideMaskText] =>
match parseNat? activeMaskText, parseNat? overrideMaskText with
| some activeMask, some overrideMask =>
runBossIntReadQuery true title path activeMask overrideMask
| _, _ =>
IO.eprintln "activeMask and overrideMask must be natural numbers"
IO.eprintln usage
return 2
| ["query-boss-float", title, path, activeMaskText, overrideMaskText] =>
match parseNat? activeMaskText, parseNat? overrideMaskText with
| some activeMask, some overrideMask =>