-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstructions.go
1416 lines (1312 loc) · 25.3 KB
/
instructions.go
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
package main
import "fmt"
type Instruction interface {
Execute(env *JEnv, this *JMetaObject, rcp RuntimeConstantPool, lv []RuntimeLocalVariable, stack *Stack, frame *Frame)
}
type Instructionaaload struct { // 0x32
Instruction
}
type Instructionaastore struct { // 0x53
Instruction
}
type InstructionaconstNull struct { // 0x01
Instruction
}
type Instructionaload struct { // 0x19
Instruction
Index byte
}
type Instructionaload0 struct { // 0x2a
Instruction
}
type Instructionaload1 struct { // 0x2b
Instruction
}
type Instructionaload2 struct { // 0x2c
Instruction
}
type Instructionaload3 struct { // 0x2d
Instruction
}
type Instructionanewarray struct { // 0xbd
Instruction
Index uint16
}
type Instructionareturn struct { // 0xb0
Instruction
}
type Instructionarraylength struct { // 0xbe
Instruction
}
type Instructionastore struct { // 0x3a
Instruction
Index byte
}
type Instructionastore0 struct { // 0x4b
Instruction
}
type Instructionastore1 struct { // 0x4c
Instruction
}
type Instructionastore2 struct { // 0x4d
Instruction
}
type Instructionastore3 struct { // 0x4e
Instruction
}
type Instructionathrow struct { // 0xbf
Instruction
}
type Instructionbaload struct { // 0x33
Instruction
}
type Instructionbastore struct { // 0x54
Instruction
}
type Instructionbipush struct { // 0x10
Instruction
Value byte
}
type Instructionbreakpoint struct { // 0xca
Instruction
}
type Instructioncaload struct { // 0x34
Instruction
}
type Instructioncastore struct { // 0x55
Instruction
}
type Instructioncheckcast struct { // 0xc0
Instruction
Index uint16
}
type Instructiond2f struct { // 0x90
Instruction
}
type Instructiond2i struct { // 0x8e
Instruction
}
type Instructiond2l struct { // 0x8f
Instruction
}
type Instructiondadd struct { // 0x63
Instruction
}
type Instructiondaload struct { // 0x31
Instruction
}
type Instructiondastore struct { // 0x52
Instruction
}
type Instructiondcmpg struct { // 0x98
Instruction
}
type Instructiondcmpl struct { // 0x97
Instruction
}
type Instructiondconst0 struct { // 0x0e
Instruction
}
type Instructiondconst1 struct { // 0x0f
Instruction
}
type Instructionddiv struct { // 0x6f
Instruction
}
type Instructiondload struct { // 0x18
Instruction
Index byte
}
type Instructiondload0 struct { // 0x26
Instruction
}
type Instructiondload1 struct { // 0x27
Instruction
}
type Instructiondload2 struct { // 0x28
Instruction
}
type Instructiondload3 struct { // 0x29
Instruction
}
type Instructiondmul struct { // 0x6b
Instruction
}
type Instructiondneg struct { // 0x77
Instruction
}
type Instructiondrem struct { // 0x73
Instruction
}
type Instructiondreturn struct { // 0xaf
Instruction
}
type Instructiondstore struct { // 0x39
Instruction
Index byte
}
type Instructiondstore0 struct { // 0x47
Instruction
}
type Instructiondstore1 struct { // 0x48
Instruction
}
type Instructiondstore2 struct { // 0x49
Instruction
}
type Instructiondstore3 struct { // 0x4a
Instruction
}
type Instructiondsub struct { // 0x67
Instruction
}
type Instructiondup struct { // 0x59
Instruction
}
type InstructiondupX1 struct { // 0x5a
Instruction
}
type InstructiondupX2 struct { // 0x5b
Instruction
}
type Instructiondup2 struct { // 0x5c
Instruction
}
type Instructiondup2X1 struct { // 0x5d
Instruction
}
type Instructiondup2X2 struct { // 0x5e
Instruction
}
type Instructionf2d struct { // 0x8d
Instruction
}
type Instructionf2i struct { // 0x8b
Instruction
}
type Instructionf2l struct { // 0x8c
Instruction
}
type Instructionfadd struct { // 0x62
Instruction
}
type Instructionfaload struct { // 0x30
Instruction
}
type Instructionfastore struct { // 0x51
Instruction
}
type Instructionfcmpg struct { // 0x96
Instruction
}
type Instructionfcmpl struct { // 0x95
Instruction
}
type Instructionfconst0 struct { // 0x0b
Instruction
}
type Instructionfconst1 struct { // 0x0c
Instruction
}
type Instructionfconst2 struct { // 0x0d
Instruction
}
type Instructionfdiv struct { // 0x6e
Instruction
}
type Instructionfload struct { // 0x17
Instruction
Index byte
}
type Instructionfload0 struct { // 0x22
Instruction
}
type Instructionfload1 struct { // 0x23
Instruction
}
type Instructionfload2 struct { // 0x24
Instruction
}
type Instructionfload3 struct { // 0x25
Instruction
}
type Instructionfmul struct { // 0x6a
Instruction
}
type Instructionfneg struct { // 0x76
Instruction
}
type Instructionfrem struct { // 0x72
Instruction
}
type Instructionfreturn struct { // 0xae
Instruction
}
type Instructionfstore struct { // 0x38
Instruction
Index byte
}
type Instructionfstore0 struct { // 0x43
Instruction
}
type Instructionfstore1 struct { // 0x44
Instruction
}
type Instructionfstore2 struct { // 0x45
Instruction
}
type Instructionfstore3 struct { // 0x46
Instruction
}
type Instructionfsub struct { // 0x66
Instruction
}
type Instructiongetfield struct { // 0xb4
Instruction
Index uint16
}
type Instructiongetstatic struct { // 0xb2
Instruction
Index uint16
}
type Instructiongoto struct { // 0xa7
Instruction
OffsetShort int16
}
type InstructiongotoW struct { // 0xc8
Instruction
OffsetInt int32
}
type Instructioni2b struct { // 0x91
Instruction
}
type Instructioni2c struct { // 0x92
Instruction
}
type Instructioni2d struct { // 0x87
Instruction
}
type Instructioni2f struct { // 0x86
Instruction
}
type Instructioni2l struct { // 0x85
Instruction
}
type Instructioni2s struct { // 0x93
Instruction
}
type Instructioniadd struct { // 0x60
Instruction
}
type Instructioniaload struct { // 0x2e
Instruction
}
type Instructioniand struct { // 0x7e
Instruction
}
type Instructioniastore struct { // 0x4f
Instruction
}
type InstructioniconstM1 struct { // 0x02
Instruction
}
type Instructioniconst0 struct { // 0x03
Instruction
}
type Instructioniconst1 struct { // 0x04
Instruction
}
type Instructioniconst2 struct { // 0x05
Instruction
}
type Instructioniconst3 struct { // 0x06
Instruction
}
type Instructioniconst4 struct { // 0x07
Instruction
}
type Instructioniconst5 struct { // 0x08
Instruction
}
type Instructionidiv struct { // 0x6c
Instruction
}
type InstructionifAcmpeq struct { // 0xa5
Instruction
OffsetShort int16
}
type InstructionifAcmpne struct { // 0xa6
Instruction
OffsetShort int16
}
type InstructionifIcmpeq struct { // 0x9f
Instruction
OffsetShort int16
}
type InstructionifIcmpge struct { // 0xa2
Instruction
OffsetShort int16
}
type InstructionifIcmpgt struct { // 0xa3
Instruction
OffsetShort int16
}
type InstructionifIcmple struct { // 0xa4
Instruction
OffsetShort int16
}
type InstructionifIcmplt struct { // 0xa1
Instruction
OffsetShort int16
}
type InstructionifIcmpne struct { // 0xa0
Instruction
OffsetShort int16
}
type Instructionifeq struct { // 0x99
Instruction
OffsetShort int16
}
type Instructionifge struct { // 0x9c
Instruction
OffsetShort int16
}
type Instructionifgt struct { // 0x9d
Instruction
OffsetShort int16
}
type Instructionifle struct { // 0x9e
Instruction
OffsetShort int16
}
type Instructioniflt struct { // 0x9b
Instruction
OffsetShort int16
}
type Instructionifne struct { // 0x9a
Instruction
OffsetShort int16
}
type Instructionifnonnull struct { // 0xc7
Instruction
OffsetShort int16
}
type Instructionifnull struct { // 0xc6
Instruction
OffsetShort int16
}
type Instructioniinc struct { // 0x84
Instruction
Index byte
Const byte
}
type Instructioniload struct { // 0x15
Instruction
Index byte
}
type Instructioniload0 struct { // 0x1a
Instruction
}
type Instructioniload1 struct { // 0x1b
Instruction
}
type Instructioniload2 struct { // 0x1c
Instruction
}
type Instructioniload3 struct { // 0x1d
Instruction
}
type Instructionimpdep1 struct { // 0xfe
Instruction
}
type Instructionimpdep2 struct { // 0xff
Instruction
}
type Instructionimul struct { // 0x68
Instruction
}
type Instructionineg struct { // 0x74
Instruction
}
type Instructioninstanceof struct { // 0xc1
Instruction
Index uint16
}
type Instructioninvokedynamic struct { // 0xba
Instruction
Index uint16
}
type Instructioninvokeinterface struct { // 0xb9
Instruction
Index uint16
Count byte
}
type Instructioninvokespecial struct { // 0xb7
Instruction
Index uint16
}
type Instructioninvokestatic struct { // 0xb8
Instruction
Index uint16
}
type Instructioninvokevirtual struct { // 0xb6
Instruction
Index uint16
}
type Instructionior struct { // 0x80
Instruction
}
type Instructionirem struct { // 0x70
Instruction
}
type Instructionireturn struct { // 0xac
Instruction
}
type Instructionishl struct { // 0x78
Instruction
}
type Instructionishr struct { // 0x7a
Instruction
}
type Instructionistore struct { // 0x36
Instruction
Index byte
}
type Instructionistore0 struct { // 0x3b
Instruction
}
type Instructionistore1 struct { // 0x3c
Instruction
}
type Instructionistore2 struct { // 0x3d
Instruction
}
type Instructionistore3 struct { // 0x3e
Instruction
}
type Instructionisub struct { // 0x64
Instruction
}
type Instructioniushr struct { // 0x7c
Instruction
}
type Instructionixor struct { // 0x82
Instruction
}
type Instructionjsr struct { // 0xa8
Instruction
OffsetShort int16
}
type InstructionjsrW struct { // 0xc9
Instruction
OffsetInt int32
}
type Instructionl2d struct { // 0x8a
Instruction
}
type Instructionl2f struct { // 0x89
Instruction
}
type Instructionl2i struct { // 0x88
Instruction
}
type Instructionladd struct { // 0x61
Instruction
}
type Instructionlaload struct { // 0x2f
Instruction
}
type Instructionland struct { // 0x7f
Instruction
}
type Instructionlastore struct { // 0x50
Instruction
}
type Instructionlcmp struct { // 0x94
Instruction
}
type Instructionlconst0 struct { // 0x09
Instruction
}
type Instructionlconst1 struct { // 0x0a
Instruction
}
type Instructionldc struct { // 0x12
Instruction
Index byte
}
type InstructionldcW struct { // 0x13
Instruction
Index uint16
}
type Instructionldc2W struct { // 0x14
Instruction
Index uint16
}
type Instructionldiv struct { // 0x6d
Instruction
}
type Instructionlload struct { // 0x16
Instruction
Index byte
}
type Instructionlload0 struct { // 0x1e
Instruction
}
type Instructionlload1 struct { // 0x1f
Instruction
}
type Instructionlload2 struct { // 0x20
Instruction
}
type Instructionlload3 struct { // 0x21
Instruction
}
type Instructionlmul struct { // 0x69
Instruction
}
type Instructionlneg struct { // 0x75
Instruction
}
type Instructionlookupswitch struct { // 0xab
Instruction
Default int32
Pairs []MatchOffsetPair
}
type MatchOffsetPair struct {
Match int32
Offset int32
}
type Instructionlor struct { // 0x81
Instruction
}
type Instructionlrem struct { // 0x71
Instruction
}
type Instructionlreturn struct { // 0xad
Instruction
}
type Instructionlshl struct { // 0x79
Instruction
}
type Instructionlshr struct { // 0x7b
Instruction
}
type Instructionlstore struct { // 0x37
Instruction
Index byte
}
type Instructionlstore0 struct { // 0x3f
Instruction
}
type Instructionlstore1 struct { // 0x40
Instruction
}
type Instructionlstore2 struct { // 0x41
Instruction
}
type Instructionlstore3 struct { // 0x42
Instruction
}
type Instructionlsub struct { // 0x65
Instruction
}
type Instructionlushr struct { // 0x7d
Instruction
}
type Instructionlxor struct { // 0x83
Instruction
}
type Instructionmonitorenter struct { // 0xc2
Instruction
}
type Instructionmonitorexit struct { // 0xc3
Instruction
}
type Instructionmultianewarray struct { // 0xc5
Instruction
Index uint16
Dimensions byte
}
type Instructionnew struct { // 0xbb
Instruction
Index uint16
}
type Instructionnewarray struct { // 0xbc
Instruction
Atype byte
}
type Instructionnop struct { // 0x00
Instruction
}
type Instructionpop struct { // 0x57
Instruction
}
type Instructionpop2 struct { // 0x58
Instruction
}
type Instructionputfield struct { // 0xb5
Instruction
Index uint16
}
type Instructionputstatic struct { // 0xb3
Instruction
Index uint16
}
type Instructionret struct { // 0xa9
Instruction
Index byte
}
type Instructionreturn struct { // 0xb1
Instruction
}
type Instructionsaload struct { // 0x35
Instruction
}
type Instructionsastore struct { // 0x53
Instruction
}
type Instructionsipush struct { // 0x15
Instruction
Value int16
}
type Instructionswap struct { // 0x5f
Instruction
}
type Instructiontableswitch struct { // 0xaa
Instruction
Default int32
Low int32
High int32
JumpOffsets []int32
}
type Instructionwide struct { // 0xc4
Instruction
Opcode byte
}
func ParseInstructions(bytes []byte) (instructions map[uint16]Instruction) {
container := ByteContainer{bytes, 0}
instructions = make(map[uint16]Instruction)
for container.HasNext() {
pre := container.bytesRead
//instructions = append(instructions, ParseInstruction(&container))
instructions[uint16(pre)] = ParseInstruction(&container)
}
return
}
func ParseInstruction(bytes *ByteContainer) Instruction {
opcode := bytes.NextByte()
switch opcode {
case 0x00:
return Instructionnop{}
case 0x01:
return InstructionaconstNull{}
case 0x02:
return InstructioniconstM1{}
case 0x03:
return Instructioniconst0{}
case 0x04:
return Instructioniconst1{}
case 0x05:
return Instructioniconst2{}
case 0x06:
return Instructioniconst3{}
case 0x07:
return Instructioniconst4{}
case 0x08:
return Instructioniconst5{}
case 0x09:
return Instructionlconst0{}
case 0x0a:
return Instructionlconst1{}
case 0x0b:
return Instructionfconst0{}
case 0x0c:
return Instructionfconst1{}
case 0x0d:
return Instructionfconst2{}
case 0x0e:
return Instructiondconst0{}
case 0x0f:
return Instructiondconst1{}
case 0x10:
return Instructionbipush{
Value: bytes.NextByte(),
}
case 0x11:
return Instructionsipush{
Value: bytes.Nexti16(),
}
case 0x12:
return Instructionldc{
Index: bytes.NextByte(),
}
case 0x13:
return InstructionldcW{
Index: bytes.Nextu16(),
}
case 0x14:
return Instructionldc2W{
Index: bytes.Nextu16(),
}
case 0x15:
return Instructioniload{
Index: bytes.NextByte(),
}
case 0x16:
return Instructionlload{
Index: bytes.NextByte(),
}
case 0x17:
return Instructionfload{
Index: bytes.NextByte(),
}
case 0x18:
return Instructiondload{
Index: bytes.NextByte(),
}
case 0x19:
return Instructionaload{
Index: bytes.NextByte(),
}
case 0x1a:
return Instructioniload0{}
case 0x1b:
return Instructioniload1{}
case 0x1c:
return Instructioniload2{}
case 0x1d:
return Instructioniload3{}
case 0x1e:
return Instructionlload0{}
case 0x1f:
return Instructionlload1{}
case 0x20:
return Instructionlload2{}
case 0x21:
return Instructionlload3{}
case 0x22:
return Instructionfload0{}
case 0x23:
return Instructionfload1{}
case 0x24:
return Instructionfload2{}
case 0x25:
return Instructionfload3{}
case 0x26:
return Instructiondload0{}
case 0x27:
return Instructiondload1{}
case 0x28:
return Instructiondload2{}
case 0x29:
return Instructiondload3{}
case 0x2a:
return Instructionaload0{}
case 0x2b:
return Instructionaload1{}
case 0x2c:
return Instructionaload2{}
case 0x2d:
return Instructionaload3{}
case 0x2e:
return Instructioniaload{}
case 0x2f:
return Instructionlaload{}
case 0x30:
return Instructionfaload{}
case 0x31:
return Instructiondaload{}
case 0x32:
return Instructionaaload{}
case 0x33:
return Instructionbaload{}
case 0x34:
return Instructioncaload{}
case 0x35:
return Instructionsaload{}
case 0x36:
return Instructionistore{
Index: bytes.NextByte(),
}
case 0x37:
return Instructionlstore{
Index: bytes.NextByte(),
}
case 0x38:
return Instructionfstore{
Index: bytes.NextByte(),
}
case 0x39:
return Instructiondstore{
Index: bytes.NextByte(),
}
case 0x3a:
return Instructionastore{
Index: bytes.NextByte(),
}
case 0x3b:
return Instructionistore0{}
case 0x3c:
return Instructionistore1{}
case 0x3d:
return Instructionistore2{}
case 0x3e:
return Instructionistore3{}
case 0x3f:
return Instructionlstore0{}
case 0x40:
return Instructionlstore1{}
case 0x41:
return Instructionlstore2{}
case 0x42:
return Instructionlstore3{}
case 0x43:
return Instructionfstore0{}
case 0x44:
return Instructionfstore1{}
case 0x45:
return Instructionfstore2{}
case 0x46:
return Instructionfstore3{}
case 0x47:
return Instructiondstore0{}
case 0x48:
return Instructiondstore1{}
case 0x49:
return Instructiondstore2{}
case 0x4a:
return Instructiondstore3{}
case 0x4b:
return Instructionastore0{}
case 0x4c:
return Instructionastore1{}
case 0x4d:
return Instructionastore2{}
case 0x4e:
return Instructionastore3{}
case 0x4f:
return Instructioniastore{}
case 0x50:
return Instructionlastore{}
case 0x51:
return Instructionfastore{}
case 0x52:
return Instructiondastore{}
case 0x53:
return Instructionaastore{}
case 0x54:
return Instructionbastore{}
case 0x55:
return Instructioncastore{}
case 0x56:
return Instructionsastore{}
case 0x57:
return Instructionpop{}
case 0x58:
return Instructionpop2{}
case 0x59:
return Instructiondup{}
case 0x5a:
return InstructiondupX1{}
case 0x5b:
return InstructiondupX2{}
case 0x5c:
return Instructiondup2{}
case 0x5d:
return Instructiondup2X1{}
case 0x5e:
return Instructiondup2X2{}
case 0x5f:
return Instructionswap{}
case 0x60:
return Instructioniadd{}
case 0x61:
return Instructionladd{}
case 0x62:
return Instructionfadd{}
case 0x63:
return Instructiondadd{}
case 0x64:
return Instructionisub{}
case 0x65:
return Instructionlsub{}
case 0x66:
return Instructionfsub{}