和明天说你好!OvO
浅尝 010 Editor 的模板编写

目录

  1. 1. 起因与结果
  2. 2. 010 Editor 之:模板结果
  3. 3. 010 Editor 之:模板语法
    1. 3.1. 010 Editor 之:模板变量
    2. 3.2. 010 Editor 之:当前地址
    3. 3.3. 010 Editor 之:其它
  4. 4. 更新后的 CLASSAdv 模板源码

起因与结果

今天在学习 JVM 的 .class 字节码时,浅浅地用了用 010 Editor 工具,拿着它分析和查看字节码文件的结构,还用到了模板仓库中的
CLASSAdv 模板。由于模板比较老旧,遇到版本大于 53 的字节码时,就不能正确地识别对应的 Java 版本,故最终决定对 CLASSAdv
模板做一下修复和更新,浅尝一下 010 Editor 的模板编写。

更新已经提交到了 010 Editor 的官方模板仓库,搜索 CLASSAdv 模板并安装 1.3 版本即可。

010 Editor 之:模板结果

010 Editor 的模板可以很方便的从某类二进制文件中提取它的结构,模板文件以 .pt 为后缀,内容使用了类似 C 语言风格的 Binary
Template Language 来编写,下图就是对 .class 字节码文件使用更新后的 CLASSAdv 模板的结果:

Use CLASSAdv template on JVM class

模板结果类似于文件系统中的目录结构,是一种树形结构,结构体可类比成文件夹,基本数据类型可以类比成文件。结果中的每一个元素
(每一行)均由名称、值、起始地址、大小、类型、颜色、注释组成。

010 Editor 之:模板语法

Binary Template Language 的基础语法和代码风格基本等同于 C 语言,主要的差异有如下几点:

010 Editor 之:模板变量

  1. 在模板中可以定义变量,语法为变量类型 变量名,例如:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    // 该模板中定义了变量 a, b, c, d, e, f, g
    // 枚举的变量类型为 “enum ENUM1 { COMP_1 = 1, COMP_2 = 2, COMP_3 = 3 }” 整体,结构体同理
    int a;
    float b;
    double c;
    string d;
    int e[4];
    enum ENUM1 { COMP_1 = 1, COMP_2 = 2, COMP_3 = 3 } f;
    struct STRUCT1 { int x; int y; int z; } g;

    所有支持的变量类型详见:官方数据类型文档

  2. 在模板中定义的变量将会自动关联到文件中的一段二进制序列,例如:

    1
    2
    3
    4
    5
    // 执行此模板后,将会创建一个 char 数组并关联到起始的 4 个字节,以及一个 int 变量并关联到接下来的 4 个字节
    // 所谓的关联就是指把这些字节作为变量的值
    // 关联多少字节取决于这个变量的类型(类型决定了大小)
    char header[4];
    int numRecords;
  3. 在模板中定义的变量会显示到模板结果中,成为结果中的一行、多行(数组)或嵌套的行(结构体),而在结构体或函数中定义的变量,
    只有当结构体在模板中被定义或函数在模板中被调用时,才会显示到模板结果中,例如:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    // 该变量是第一个变量,名称为 fileID,类型为 int
    // int 类型的大小为 32 位二进制,表示为 4h
    // 当前地址为初始值 0h
    // 因此将前 32 bit 的数据,即地址为 0h ~ 4h(前包括,后不包括)的数据作为变量 fileID 的值
    // 假设这段数据为 67 FF 53 01,则最终在模板结果中显示为:
    // Name Value Start Size Type Color Comment
    // fileID 22282087 0h 4h int
    int fileID;

    // 这一行定义了一个结构体类型 OPTION,此时不会在结果中显示
    struct OPTION { int tag; uint64 data; };
    // 这一行定义了结构体变量 option,会依据子变量的定义创建子行
    // 该变量是第二个变量,名称为 option,类型为 struct OPTION
    // 结构体类型的大小取决于它里面的变量,本例中总计为 96 位二进制,表示为 Ch
    // 第一个变量起始地址和大小为 0h、4h,则当前地址变为 0h + 4h = 4h
    // 将接下来 32 位的数据,即地址为 4h ~ 8h 的数据作为子变量 tag 的值
    // 将接下来 64 位的数据,即地址为 8h ~ 10h 的数据作为子变量 data 的值
    // 假设这段数据分别为 66 66 46 40 和 00 02 00 00 18 02 00 00,则最终在模板结果中显示为(双击展开后):
    // Name Value Start Size Type Color Comment
    // option 4h Ch struct OPTION
    // tag 1078355558 4h 4h int
    // data 2302102471168 8h 8h uint64
    struct OPTION option;
  4. 重复定义同名的变量将被视作定义一个数组变量,也可以通过循环语句和定义变量语句组合实现。如:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    // 方法 1,显示为:
    // Name Value Start Size Type Color Comment
    // a[0] ... 0h 4h int
    // a[1] ... 4h 4h int
    // a[2] ... 8h 4h int
    int a[3]

    // 方法 2,效果相同
    int a;
    int a;
    int a;

    // 方法 3,效果相同
    local int i;
    for (i = 0; i < 4; i++)
    {
    int a;
    }
  5. 使用 local 修饰的变量称为本地变量,不会自动关联二进制序列,也不会显示在模板结果中。本地变量主要用来做过程计算和作为循环索引

  6. 变量具有属性,可以在变量定义时设置,整体的语法为变量类型 变量名 <属性名=属性值>,例如:

    1
    2
    // 设置变量 abc 关联的值在模板结果中展示时使用的格式,这里是十六进制 hex
    int abc <format=hex>;

    常用的变量属性包括显示格式 format、背景颜色 bgcolor、前景颜色 fgcolor、样式 style、读取函数 read、注释函数 comment。
    所有支持的变量属性详见:官方模板变量文档的“Special Attributes”小节

  7. 有些属性如 read、comment 接受的值是特定函数的函数名称,其大题用法如下:

    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
    // 下列代码基于 byte 类型定义了一个名为 MySize 的类型
    // 使用该类型定义的变量,它的注释函数都会被设置为 SizeCommentFunc
    typedef byte MySize <comment=SizeCommentFunc>;
    string SizeCommentFunc( MySize &s )
    {
    if( s < 0 )
    return "Negative sizes not allowed.";
    else
    return "";
    }

    // 当一个 MySize 类型的变量被定义时,会自动关联下一个字节作为变量值,并在模板结果中显示
    // 处理注释显示时,会将这个变量传递给注释函数,即 SizeCommentFunc 函数,并将返回值作为注释的内容
    MySize mySize;

    // 在 12.0 以上版本,010 Editor 支持了内联函数,此后 read、comment 等属性也支持了内联函数
    // 形式 1:填写一个函数调用,并指定参数
    typedef float Vec3f[3] <read=Str("<%g %g %g>",this[0],this[1],this[2])>;
    Vec3f v1;
    // 形式 2:填写一个内联函数,内联函数用一对小括号 () 包裹,其内可以是一个任意的表达式
    int64 c1 <bgcolor=(this < 0 ? cRed : cNone )>;
    // 其中的 this 表示被设置属性的变量自己

    // 使用如上两种形式优化 MySize 类型的定义
    typedef byte MySize <comment=(this < 0 ? "Negative sizes not allowed." : "")>;
  8. 学过操作系统和计算机组成原理的我们知道,一个值在计算机中的存储方式分为小端方式和大端方式,我们读取这个值时也需要按照
    对应的方式。模板中通常在第一行会调用 LittleEndian()BigEndian() 函数来显示指定小端方式或大端方式

010 Editor 之:当前地址

  1. 当前地址是下一个被定义变量的起始地址,初始为 0h,每定义一个变量,当前地址将会后移该变量的大小(通常用十六进制表示)

  2. FTell() 函数用于获取当前地址,FSeek() 函数用于修改当前地址,FSkip() 函数用于移动当前地址,使用这些函数的组合
    可以实现不按序读取数据。

  3. 使用 ReadInt()ReadByte() 等读取函数配合 FTell() 等函数可以从当前地址开始读取一段符合类型的值,常在条件语句中
    用作判断,例如:

    1
    2
    3
    4
    5
    6
    7
    8
    // 从当前地址开始读取一段 int 值,且这个值为 1 时,将会定义结构体变量 opt1,类型为 OPTION1
    // 否则将会定义结构体变量 opt2,类型为 OPTION2
    struct OPTION1 { int tag; uchar data[8]; };
    struct OPTION2 { int tag; uint64 data; };
    if( ReadInt( FTell() ) == 1 )
    struct OPTION1 opt1;
    else
    struct OPTION2 opt2;

010 Editor 之:其它

  1. 字符串需要与非字符串拼接时可以使用 SPrintf() 函数,例如:

    1
    2
    3
    // str 的最终结果为 "Hello 123"
    local string str;
    SPrintf(str, "Hello %d", 123);

更新后的 CLASSAdv 模板源码

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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
//------------------------------------------------
//--- 010 Editor v5.0 Binary Template
//
// File: CLASSAdv.bt
// Authors: Pishchik Ilya L. (RUS)
// Version: 1.3
// Purpose: A template for parsing Java Class (JVM) Files.
// Includes visualizing bytecode.
// Category: Programming
// File Mask: *.class
// ID Bytes: CA FE BA BE
// History:
// 1.3 2024-07-27 Charlott2: Future JDK version detection support;
// optimise the format of access flag detection results.
// 1.2 2017-02-22 Jupiter: JDK 1.8 and 1.9 detection;
// link to JVM Specification from Java SE 8 Edition.
// 1.1 2016-02-12 SweetScape Software: Updated header for repository submission.
// 1.0 Pishchik Ilya: Initial release.
//
// More info in The Java Virtual Machine Specification:
// http://docs.oracle.com/javase/specs/jvms/se8/html/
//
// Current (JDK 1.9) version info defined in src/java.base/share/native/libjava/System.c:
// #define JAVA_MAX_SUPPORTED_VERSION 53
// #define JAVA_MAX_SUPPORTED_MINOR_VERSION 0
//------------------------------------------------

BigEndian();

typedef ubyte u1;
typedef uint16 u2;
typedef uint32 u4;
typedef uint64 u8;
typedef byte i1;
typedef int16 i2;
typedef int32 i4;

enum Constant_pool
{
CONSTANT_Class=7,
CONSTANT_Fieldref=9,
CONSTANT_Methodref=10,
CONSTANT_InterfaceMethodref=11,
CONSTANT_String=8,
CONSTANT_Integer=3,
CONSTANT_Float=4,
CONSTANT_Long=5,
CONSTANT_Double=6,
CONSTANT_NameAndType=12,
CONSTANT_Utf8=1,
CONSTANT_MethodHandle=15,
CONSTANT_MethodType=16,
CONSTANT_InvokeDynamic=18
};

enum<u2> access_property_flags
{
ACC_PUBLIC=0x0001,
ACC_PRIVATE=0x0002,
ACC_PROTECTED=0x0004,
ACC_STATIC=0x0008,
ACC_FINAL=0x0010,
ACC_SUPER_ACC_SYNCHRONIZED=0x0020,
ACC_BRIDGE_ACC_VOLATILE=0x0040,
ACC_VARARGS_ACC_TRANSIENT=0x0080,
ACC_NATIVE=0x0100,
ACC_INTERFACE=0x0200,
ACC_ABSTRACT=0x0400,
ACC_STRICT=0x0800,
ACC_SYNTHETIC=0x1000,
ACC_ANNOTATION=0x2000,
ACC_ENUM=0x4000
};

enum enum_type
{
Class,
Method,
Field,
Nested_Class
};


enum <u1> enum_opcodes
{
nop=0x00,
aconst_null=0x01,
iconst_m1=0x02,
iconst_0=0x03,
iconst_1=0x04,
iconst_2=0x05,
iconst_3=0x06,
iconst_4=0x07,
iconst_5=0x08,
lconst_0=0x09,
lconst_1=0x0a,
fconst_0=0x0b,
fconst_1=0x0c,
fconst_2=0x0d,
dconst_0=0x0e,
dconst_1=0x0f,
bipush=0x10,
sipush=0x11,
ldc=0x12,
ldc_w=0x13,
ldc2_w=0x14,
iload=0x15,
lload=0x16,
fload=0x17,
dload=0x18,
aload=0x19,
iload_0=0x1a,
iload_1=0x1b,
iload_2=0x1c,
iload_3=0x1d,
lload_0=0x1e,
lload_1=0x1f,
lload_2=0x20,
lload_3=0x21,
fload_0=0x22,
fload_1=0x23,
fload_2=0x24,
fload_3=0x25,
dload_0=0x26,
dload_1=0x27,
dload_2=0x28,
dload_3=0x29,
aload_0=0x2a,
aload_1=0x2b,
aload_2=0x2c,
aload_3=0x2d,
iaload=0x2e,
laload=0x2f,
faload=0x30,
daload=0x31,
aaload=0x32,
baload=0x33,
caload=0x34,
saload=0x35,
istore=0x36,
lstore=0x37,
fstore=0x38,
dstore=0x39,
astore=0x3a,
istore_0=0x3b,
istore_1=0x3c,
istore_2=0x3d,
istore_3=0x3e,
lstore_0=0x3f,
lstore_1=0x40,
lstore_2=0x41,
lstore_3=0x42,
fstore_0=0x43,
fstore_1=0x44,
fstore_2=0x45,
fstore_3=0x46,
dstore_0=0x47,
dstore_1=0x48,
dstore_2=0x49,
dstore_3=0x4a,
astore_0=0x4b,
astore_1=0x4c,
astore_2=0x4d,
astore_3=0x4e,
iastore=0x4f,
lastore=0x50,
fastore=0x51,
dastore=0x52,
aastore=0x53,
bastore=0x54,
castore=0x55,
sastore=0x56,
pop=0x57,
pop2=0x58,
dup=0x59,
dup_x1=0x5a,
dup_x2=0x5b,
dup2=0x5c,
dup2_x1=0x5d,
dup2_x2=0x5e,
swap=0x5f,
iadd=0x60,
ladd=0x61,
fadd=0x62,
dadd=0x63,
isub=0x64,
lsub=0x65,
fsub=0x66,
dsub=0x67,
imul=0x68,
lmul=0x69,
fmul=0x6a,
dmul=0x6b,
idiv=0x6c,
ldiv=0x6d,
fdiv=0x6e,
ddiv=0x6f,
irem=0x70,
lrem=0x71,
frem=0x72,
drem=0x73,
ineg=0x74,
lneg=0x75,
fneg=0x76,
dneg=0x77,
ishl=0x78,
lshl=0x79,
ishr=0x7a,
lshr=0x7b,
iushr=0x7c,
lushr=0x7d,
iand=0x7e,
land=0x7f,
ior=0x80,
lor=0x81,
ixor=0x82,
lxor=0x83,
iinc=0x84,
i2l=0x85,
i2f=0x86,
i2d=0x87,
l2i=0x88,
l2f=0x89,
l2d=0x8a,
f2i=0x8b,
f2l=0x8c,
f2d=0x8d,
d2i=0x8e,
d2l=0x8f,
d2f=0x90,
i2b=0x91,
i2c=0x92,
i2s=0x93,
lcmp=0x94,
fcmpl=0x95,
fcmpg=0x96,
dcmpl=0x97,
dcmpg=0x98,
ifeq=0x99,
ifne=0x9a,
iflt=0x9b,
ifge=0x9c,
ifgt=0x9d,
ifle=0x9e,
if_icmpeq=0x9f,
if_icmpne=0xa0,
if_icmplt=0xa1,
if_icmpge=0xa2,
if_icmpgt=0xa3,
if_icmple=0xa4,
if_acmpeq=0xa5,
if_acmpne=0xa6,
goto=0xa7,
jsr=0xa8,
ret=0xa9,
tableswitch=0xaa,
lookupswitch=0xab,
ireturn=0xac,
lreturn=0xad,
freturn=0xae,
dreturn=0xaf,
areturn=0xb0,
Return=0xb1,
getstatic=0xb2,
putstatic=0xb3,
getfield=0xb4,
putfield=0xb5,
invokevirtual=0xb6,
invokespecial=0xb7,
invokestatic=0xb8,
invokeinterface=0xb9,
invokedynamic=0xba,
new=0xbb,
newarray=0xbc,
anewarray=0xbd,
arraylength=0xbe,
athrow=0xbf,
checkcast=0xc0,
instanceof=0xc1,
monitorenter=0xc2,
monitorexit=0xc3,
wide=0xc4,
multianewarray=0xc5,
ifnull=0xc6,
ifnonnull=0xc7,
goto_w=0xc8,
jsr_w=0xc9,
breakpoint=0xca,
impdep1=0xfe,
impdep2=0xff
};

enum <u1> enum_array_type
{
no_body=0,
index_body=1,
index_const_body=2,
sipush_body=3,
bipush_body=4,
newarray_body=5,
indexbyte_1_2_body=6,
branchbyte1_2_body=7,
branchbyte1_4_body=8,
invokeinterface_body=9,
invokedynamic_body=10,
multianewarray_body=11,
wide_body=12,
tableswitch_body=13,
lookupswitch_body=14,
index_v2_body=15
};


enum <u1> enum_opcodes_body_type
{
T_BOOLEAN=4,
T_CHAR=5,
T_FLOAT=6,
T_DOUBLE=7,
T_BYTE=8,
T_SHORT=9,
T_INT=10,
T_LONG=11
};


const u4 address_constant_pool=0xA;
const u4 address_constant_pool_count=0x8;
const u2 constant_pool_count=ReadUShort(address_constant_pool_count)-1;

local u8 map_address_constant_pool[constant_pool_count]<format=hex>;
local u1 array_opcodes_body_type[256];


array_opcodes_body_type[tableswitch]=tableswitch_body;//170
array_opcodes_body_type[lookupswitch]=lookupswitch_body;//171


array_opcodes_body_type[bipush]=bipush_body; //16 +byte

array_opcodes_body_type[iload]=index_body; //21 +index
array_opcodes_body_type[lload]=index_body; //22 +index
array_opcodes_body_type[fload]=index_body; //23 +index
array_opcodes_body_type[dload]=index_body; //24 +index
array_opcodes_body_type[aload]=index_body; //25 +index

array_opcodes_body_type[istore]=index_body; //54 +index
array_opcodes_body_type[lstore]=index_body; //55 +index
array_opcodes_body_type[fstore]=index_body; //56 +index
array_opcodes_body_type[dstore]=index_body; //57 +index
array_opcodes_body_type[astore]=index_body; //58 +index

array_opcodes_body_type[sipush]=sipush_body; //17 +byte1,byte2
array_opcodes_body_type[ldc]=index_v2_body; //18 +index
array_opcodes_body_type[ldc_w]=indexbyte_1_2_body; //19 +indexbyte1,indexbyte2
array_opcodes_body_type[ldc2_w]=indexbyte_1_2_body;//20 +indexbyte1,indexbyte2

array_opcodes_body_type[iinc]=index_const_body; //132 +index,const

array_opcodes_body_type[ifeq]=branchbyte1_2_body; //153 +branchbyte1,branchbyte2
array_opcodes_body_type[ifne]=branchbyte1_2_body; //154 +branchbyte1,branchbyte2
array_opcodes_body_type[iflt]=branchbyte1_2_body; //155 +branchbyte1,branchbyte2
array_opcodes_body_type[ifge]=branchbyte1_2_body; //156 +branchbyte1,branchbyte2
array_opcodes_body_type[ifgt]=branchbyte1_2_body; //157 +branchbyte1,branchbyte2
array_opcodes_body_type[ifle]=branchbyte1_2_body; //158 +branchbyte1,branchbyte2

array_opcodes_body_type[if_icmpeq]=branchbyte1_2_body; //159 +branchbyte1,branchbyte2
array_opcodes_body_type[if_icmpne]=branchbyte1_2_body; //160 +branchbyte1,branchbyte2
array_opcodes_body_type[if_icmplt]=branchbyte1_2_body; //161 +branchbyte1,branchbyte2
array_opcodes_body_type[if_icmpge]=branchbyte1_2_body; //162 +branchbyte1,branchbyte2
array_opcodes_body_type[if_icmpgt]=branchbyte1_2_body; //163 +branchbyte1,branchbyte2
array_opcodes_body_type[if_icmple]=branchbyte1_2_body; //164 +branchbyte1,branchbyte2

array_opcodes_body_type[if_acmpeq]=branchbyte1_2_body; //165 +branchbyte1,branchbyte2
array_opcodes_body_type[if_acmpne]=branchbyte1_2_body; //166 +branchbyte1,branchbyte2

array_opcodes_body_type[goto]=branchbyte1_2_body; //167 +branchbyte1,branchbyte2
array_opcodes_body_type[jsr]=branchbyte1_2_body; //168 +branchbyte1,branchbyte2

array_opcodes_body_type[ret]=index_body;//169 +index

array_opcodes_body_type[getstatic]=indexbyte_1_2_body; //178 +indexbyte1,indexbyte2
array_opcodes_body_type[putstatic]=indexbyte_1_2_body; //179 +indexbyte1,indexbyte2

array_opcodes_body_type[getfield]=indexbyte_1_2_body; //180 +indexbyte1,indexbyte2
array_opcodes_body_type[putfield]=indexbyte_1_2_body; //181 +indexbyte1,indexbyte2

array_opcodes_body_type[new]=indexbyte_1_2_body; //187 +indexbyte1,indexbyte2
array_opcodes_body_type[newarray]=newarray_body; //188 +atype

array_opcodes_body_type[invokevirtual]=indexbyte_1_2_body; //182 +indexbyte1,indexbyte2
array_opcodes_body_type[invokespecial]=indexbyte_1_2_body; //183 +indexbyte1,indexbyte2
array_opcodes_body_type[invokestatic]=indexbyte_1_2_body; //184 +indexbyte1,indexbyte2

array_opcodes_body_type[anewarray]=indexbyte_1_2_body; //189 +indexbyte1,indexbyte2
array_opcodes_body_type[checkcast]=indexbyte_1_2_body; //192 +indexbyte1,indexbyte2
array_opcodes_body_type[instanceof]=indexbyte_1_2_body; //193 +indexbyte1,indexbyte2

array_opcodes_body_type[wide]=wide_body; //196 (iload,fload,aload,lload,dload,istore,fstore,astore,lstore,dstore,ret),indexbyte1,indexbyte2 or iinc,indexbyte1,indexbyte2,constbyte1,constbyte2
array_opcodes_body_type[multianewarray]=multianewarray_body; //197 indexbyte1,indexbyte2,dimensions

array_opcodes_body_type[ifnull]=branchbyte1_2_body; //198 +branchbyte1,branchbyte2
array_opcodes_body_type[ifnonnull]=branchbyte1_2_body; //199 +branchbyte1,branchbyte2

array_opcodes_body_type[invokeinterface]=invokeinterface_body; //185 +indexbyte1,indexbyte2,count,0
array_opcodes_body_type[invokedynamic]=invokedynamic_body; //186 +indexbyte1,indexbyte2,0,0
array_opcodes_body_type[goto_w]=branchbyte1_4_body;//200 +branchbyte1,branchbyte2,branchbyte3,branchbyte4
array_opcodes_body_type[jsr_w]=branchbyte1_4_body; //201 +branchbyte1,branchbyte2,branchbyte3,branchbyte4

/*
+ConstantValue OK
+Code OK
+StackMapTable OK!
+Exceptions OK
+InnerClasses OK
+EnclosingMethod OK
+Synthetic OK
+Signature OK
+SourceFile OK
+SourceDebugExtension
+LineNumberTable OK
+LocalVariableTable OK
+LocalVariableTypeTable ?
+Deprecated OK
+RuntimeVisibleAnnotations OK
+RuntimeInvisibleAnnotations OK
+RuntimeVisibleParameterAnnotations OK
+RuntimeInvisibleParameterAnnotations OK
+AnnotationDefault OK
+BootstrapMethods*/

struct element_value;

typedef struct{
u2 type_index;
u2 num_element_value_pairs;
if(0<num_element_value_pairs)
{


struct{
u2 element_name_index<comment=Name_OnComment>;
element_value value;
}element_value_pairs[num_element_value_pairs]<optimize=false>;



}
}annotation<comment=annotation_OnComment>;

typedef struct{
u1 tag;
if(tag=='e')
{
struct{
u2 type_name_index<comment=Name_OnComment>;
u2 const_name_index<comment=Name_OnComment>;
}enum_const_value<comment="enum">;
}
else if(tag=='c')
{
u2 class_info_index;
}
else if(tag=='@')
{
annotation annotation_value;
}
else if(tag=='[')
{
struct{
u2 num_values;
element_value values[num_values]<optimize=false>;
}array_value<comment="array">;
}
else
{
//B,C,D,F,I,J,S Z,or s.
u2 const_value_index<comment=Name_OnComment>;
}
}element_value<comment=element_value_OnComment>;

typedef struct{
u1 tag;
/*Top_variable_info 0
Integer_variable_info 1
Float_variable_info 2
Double_variable_info 3
Long_variable_info 4
Null_variable_info 5
UninitializedThis_variable_info 6*/
if(tag==7)
{
//Object_variable_info 7
u2 cpool_index<comment=Name_OnComment>;
}
else if(tag==8)
{
//Uninitialized_variable_info//Object_variable_info 7 8
u2 offset;
}
}verification_type_info;

typedef struct{
u1 frame_type;//same_frame
if(frame_type>=64&&frame_type<=127)
{
//same_locals_1_stack_item_frame
verification_type_info stack[1]<optimize=false>;
}
else if(frame_type==247)
{
//same_locals_1_stack_item_frame_extended
u2 offset_delta;
verification_type_info stack[1];
}
else if(frame_type>=248&&frame_type<=251)
{
//chop_frame or same_frame_extended
u2 offset_delta;
}
else if(frame_type>=252&&frame_type<=254)
{
//append_frame
u2 offset_delta;
verification_type_info locals[frame_type - 251]<optimize=false>;
}
else if(frame_type==255)
{
//full_frame
u2 offset_delta;
u2 number_of_locals;
if(0<number_of_locals)verification_type_info locals[number_of_locals]<optimize=false>;
u2 number_of_stack_items;
if(0<number_of_stack_items)verification_type_info stack[number_of_stack_items]<optimize=false>;
}
}stack_map_frame<comment=stack_map_frame_OnComment>;

typedef struct(int hidden,u8 offsets){

if(exists(hidden))
{
u1 operation<format=hex>;
switch(array_opcodes_body_type[operation])
{
case index_body:
case index_v2_body:
u1 index;
break;
case index_const_body:
u1 index;
i1 _const<name="const">;
break;
case sipush_body:
u2 _byte<name="byte">; //byte1,byte2;
break;
case bipush_body:
u1 _byte<name="byte">;
break;
case newarray_body:
u1 atype;
break;
case multianewarray_body:
u2 indexbyte; //indexbyte1,indexbyte2;
u1 dimensions;
break;
case wide_body:
u1 operation2;
u2 indexbyte; //indexbyte1,indexbyte2;
if(operation2==iinc)
{
u2 constbyte; //constbyte1,constbyte2;
}
break;
case tableswitch_body:
local u4 len=4-(offsets+1)%4;
if(len<4) u1 byte_pad[len];
i4 defaultbyte; //defaultbyte1,defaultbyte2,defaultbyte3,defaultbyte4
i4 lowbyte; //lowbyte1,lowbyte2,lowbyte3,lowbyte4
i4 highbyte; //highbyte1,highbyte2,highbyte3,highbyte4
u4 jump[highbyte-lowbyte+1]<optimize=false>;
break;
case lookupswitch_body:
local u4 len=4-(offsets+1)%4;
if(len<4)u1 byte_pad[len];
i4 defaultbyte; //defaultbyte1,defaultbyte2,defaultbyte3,defaultbyte4
i4 npairs; //npairs1,npairs2,npairs3,npairs4
struct
{
i4 match;
i4 offset;
}match_offset[npairs];
break;
case indexbyte_1_2_body:
u2 indexbyte; //indexbyte1,indexbyte2;
break;
case branchbyte1_2_body:
i2 branchbyte; //indexbyte1,indexbyte2;
break;
case branchbyte1_4_body:
i4 branchbyte; //branchbyte1,branchbyte2,branchbyte3,branchbyte4
break;
case invokeinterface_body:
u2 indexbyte; //indexbyte1,indexbyte2;
u1 _count<name="const">;
u1 zero;
break;
case invokedynamic_body:
u2 indexbyte; //indexbyte1,indexbyte2;
u1 zero;
u1 zero;
break;
default:
break;
}
}
}opcodes_operation<comment=opcodes_operation_OnComment>;


struct attribute_info;

typedef struct{
u2 attribute_name_index;
u4 attribute_length;

local string attribute_name=get_constant_pool_Utf8(attribute_name_index);

if(attribute_name=="ConstantValue")
{
u2 constantvalue_index <comment=Name_OnComment>;
}
else if(attribute_name=="Code")
{
u2 max_stack;
u2 max_locals;
u4 code_length<format=hex>;
//u1 code[code_length]<format=hex>;
struct
{
local u8 begin_address=FTell();
local u8 current_address=FTell();
local u8 end_address=begin_address+code_length;
local u4 i;
local u8 Len;
while( FTell() < end_address)
{
opcodes_operation operation(0,current_address-begin_address);
Len=FTell()-current_address-1;
FSkip(-Len);
for(i=0;i<Len;i++)
{
opcodes_operation operation(1,0)<size=1,hidden=true>;
}
current_address=FTell();
}
}code;

u2 exception_table_length;
if(exception_table_length>0)
{
struct
{
u2 start_pc;
u2 end_pc;
u2 handler_pc;
u2 catch_type<comment=Name_Exception_OnComment>;
}exception_table[exception_table_length];
}
u2 attributes_count;
if(attributes_count>0)attribute_info attributes[attributes_count]<optimize=false>;
}
else if(attribute_name=="Exceptions")
{
u2 number_of_exceptions;
u2 exception_index_table[number_of_exceptions]<comment=Name_Exception_OnComment,optimize=false>;
}
else if(attribute_name=="LineNumberTable")
{
u2 line_number_table_length;
struct{
u2 start_pc;
u2 line_number;
}line_number_table[line_number_table_length] <optimize=false>;
}
else if(attribute_name=="LocalVariableTable")
{
u2 local_variable_table_length;
struct LocalVariableTable_struct{
u2 start_pc;
u2 length;
u2 name_index<comment=Name_OnComment>;
u2 descriptor_index<comment=Name_OnComment>;
u2 index;
}local_variable_table[local_variable_table_length] <comment=attribute_info_LocalVariableTable_OnComment,optimize=false>;
}
else if(attribute_name=="LocalVariableTypeTable")
{
u2 local_variable_type_table_length;
struct{
u2 start_pc;
u2 length;
u2 name_index;
u2 signature_index;
u2 index;
}local_variable_type_table[local_variable_type_table_length]<optimize=false>;
}
else if(attribute_name=="SourceFile")
{
u2 sourcefile_index<comment=Name_OnComment>;
}
else if(attribute_name=="InnerClasses")
{
u2 number_of_classes;
struct InnerClasses_struct{
u2 inner_class_info_index<comment=Name_OnComment>;
u2 outer_class_info_index<comment=Name_OnComment>;
u2 inner_name_index<comment=Name_OnComment>;
u2 inner_class_access_flags<comment=Nested_Class_access_flags_OnComment>;
}classes[number_of_classes] <comment=attribute_info_InnerClasses_OnComment,optimize=false>;
}
else if(attribute_name=="EnclosingMethod")
{
u2 class_index<comment=Name_OnComment>;
u2 method_index<comment=Name_OnComment>;
}
else if(attribute_name=="Signature")
{
u2 signature_index<comment=Name_OnComment>;
}
else if(attribute_name=="SourceDebugExtension")
{
u1 debug_extension[attribute_length] <optimize=false>;
}
else if(attribute_name=="RuntimeVisibleAnnotations"||attribute_name=="RuntimeInvisibleAnnotations")
{
u2 num_annotations;
annotation annotations[num_annotations]<optimize=false>;
}
else if(attribute_name=="RuntimeVisibleParameterAnnotations"||attribute_name=="RuntimeInvisibleParameterAnnotations")
{
u1 num_parameters;
struct{
u2 num_annotations;
annotation annotations[num_annotations]<optimize=false>;
}parameter_annotations[num_parameters]<optimize=false>;
}
else if(attribute_name=="AnnotationDefault")
{
element_value default_value;
}
else if(attribute_name=="BootstrapMethods")
{
u2 num_bootstrap_methods;
struct{
u2 bootstrap_method_ref;
u2 num_bootstrap_arguments;
u2 bootstrap_arguments[num_bootstrap_arguments]<optimize=false>;
}bootstrap_methods[num_bootstrap_methods]<optimize=false>;
}
else if(attribute_name=="StackMapTable")
{
u2 number_of_entries;
stack_map_frame entries[number_of_entries]<optimize=false>;
}
else
{
if(attribute_length>0) u1 info[attribute_length] <optimize=false>;
}
}attribute_info <comment=attribute_info_OnComment>;

typedef struct
{
u2 access_flags<comment=Field_access_flags_OnComment>;
u2 name_index;
u2 descriptor_index;
u2 attributes_count;
if(0<attributes_count)
{
attribute_info attributes[attributes_count] <optimize=false>;
}
}field_info <comment=field_info_OnComment>;

typedef struct{
u2 access_flags<comment=Method_access_flags_OnComment>;
u2 name_index;
u2 descriptor_index;
u2 attributes_count;
if(0<attributes_count)
{
attribute_info attributes[attributes_count] <optimize=false>;
}
}method_info <comment=method_info_OnComment>;




typedef struct{
if(sizeof(this)>1)
{
u1 tag;
switch(tag)
{
case CONSTANT_Class:
u2 name_index;
break;
case CONSTANT_Fieldref:
case CONSTANT_Methodref:
case CONSTANT_InterfaceMethodref:
u2 class_index;
u2 name_and_type_index;
break;
case CONSTANT_String:
u2 string_index;
break;
case CONSTANT_Integer:
case CONSTANT_Float:
u4 bytes;
break;
case CONSTANT_Long:
case CONSTANT_Double:
u4 high_bytes<format=hex>;
u4 low_bytes<format=hex>;
break;
case CONSTANT_NameAndType:
u2 name_index;
u2 descriptor_index;
break;
case CONSTANT_Utf8:
u2 length;
if(length>0)
{
u1 bytes[length]<optimize=false>;
}
break;
case CONSTANT_MethodHandle:
u1 reference_kind;
u2 reference_index;
break;
case CONSTANT_MethodType:
u2 descriptor_index;
break;
case CONSTANT_InvokeDynamic:
u2 bootstrap_method_attr_index;
u2 name_and_type_index;
break;
default:
Warning("fix cp_info");
break;
}
}
}cp_info<comment=cp_infoOnComment,size=cp_infoOnSize>;


typedef struct
{
u4 magic <format=hex>;
u2 minor_version;
u2 major_version;
u2 constant_pool_count;
cp_info constant_pool[constant_pool_count-1]<optimize=false>;
u2 access_flags <comment=Class_access_flags_OnComment>;
u2 this_class <comment=Name_OnComment>;
u2 super_class <comment=Name_OnComment>;

u2 interfaces_count;
if(0<interfaces_count)
{
u2 interfaces[interfaces_count]<comment=ClassFile_interfaces_OnComment,optimize=false>;
}

u2 fields_count;
if(0<fields_count)
{
field_info fields[fields_count]<optimize=false>;
}

u2 methods_count;
if(0<methods_count)
{
method_info methods[methods_count]<optimize=false>;
}

u2 attributes_count;
if(0<attributes_count)
{
attribute_info attributes[attributes_count]<optimize=false>;
}

}ClassFile<comment=ClassFileOnComment>;

//main


void generator_map_address_constant_pool()
{
local u8 address=address_constant_pool;
local u1 tag;


local int i;
for(i = 0; i <constant_pool_count; i++)
{
map_address_constant_pool[i]=address;

tag=ReadUByte(address);

switch(tag)
{
case CONSTANT_Class: //sizeof(tag)+sizeof(name_index)
case CONSTANT_String: //sizeof(tag)+sizeof(string_index)
case CONSTANT_MethodType: //sizeof(tag)+sizeof(descriptor_index)
address=address+3;
break;
case CONSTANT_Fieldref: //sizeof(tag)+sizeof(class_index)+sizeof(name_and_type_index)
case CONSTANT_Methodref: //sizeof(tag)+sizeof(class_index)+sizeof(name_and_type_index)
case CONSTANT_InterfaceMethodref: //sizeof(tag)+sizeof(class_index)+sizeof(name_and_type_index)
case CONSTANT_NameAndType: //sizeof(tag)+sizeof(name_index)+sizeof(descriptor_index)
case CONSTANT_InvokeDynamic: //sizeof(tag)+sizeof(bootstrap_method_attr_index)+sizeof(name_and_type_index)
case CONSTANT_Integer: //sizeof(tag)+sizeof(bytes)
case CONSTANT_Float: //sizeof(tag)+sizeof(bytes)
address=address+5;
break;
case CONSTANT_Long: //sizeof(tag)+sizeof(high_bytes)+sizeof(low_bytes)
case CONSTANT_Double: //sizeof(tag)+sizeof(high_bytes)+sizeof(low_bytes)
i++;
map_address_constant_pool[i]=0;
address=address+9;
break;
case CONSTANT_Utf8: //sizeof(tag)+sizeof(length)+length
address=address+3+ReadUShort(address+1);
break;
case CONSTANT_MethodHandle://sizeof(tag)+sizeof(reference_kind)+sizeof(reference_index)
address=address+4;
break;
default:
Warning("fix generator_map_address_constant_pool");
break;
}
}
}

u8 find_constant_pool2(u2 n)
{
return map_address_constant_pool[n-1];
}

string get_constant_pool_Utf8(u2 n)
{
if(n<=0) return "NO NAME";

local u8 address=find_constant_pool2(n);
local u8 address2=0;
local u8 address3=0;
local string str="";
switch(ReadUByte(address))
{
case CONSTANT_Class:
case CONSTANT_String:
case CONSTANT_InvokeDynamic:
address=find_constant_pool2(ReadUShort(address+1)); //address+sizeof(tag)
break;
case CONSTANT_NameAndType:
address2=address;
address=find_constant_pool2(ReadUShort(address+1)); //address+sizeof(tag)
address2=find_constant_pool2(ReadUShort(address2+3)); //address+sizeof(tag)+sizeof(name_index)
break;
case CONSTANT_Fieldref:
case CONSTANT_Methodref:
case CONSTANT_InterfaceMethodref:
address2=address;
address=find_constant_pool2(ReadUShort(address+1)); //address+sizeof(tag)=class_index
address=find_constant_pool2(ReadUShort(address+1));
address2=find_constant_pool2(ReadUShort(address2+3)); //address+sizeof(tag)+sizeof(class_index)=name_and_type_index
address3=address2;
address2=find_constant_pool2(ReadUShort(address3+1)); //address+sizeof(tag)=name_index;
address3=find_constant_pool2(ReadUShort(address3+3)); //address+sizeof(tag)+sizeof(name_index)=descriptor_index
break;
case CONSTANT_Integer:
SPrintf(str, "%d",ReadUInt(address+1));
break;
case CONSTANT_Long:
SPrintf(str, "%Ld",ReadInt64(address+1));
break;
case CONSTANT_Float:
SPrintf(str, "%f",ReadFloat(address+1));
break;
case CONSTANT_Double:
SPrintf(str, "%Lf",ReadDouble(address+1));
break;
case CONSTANT_Utf8:
break;
default:
Warning("fix get_constant_pool_Utf8");
return "NULL";
break;
}

if(0<Strlen(str))return str;
if(address2==0) return ReadUShort(address+1)==0?" ":ReadString(address+3,ReadUShort(address+1));
if(address3==0)return ReadString(address+3,ReadUShort(address+1))+ReadString(address2+3,ReadUShort(address2+1));

return ReadString(address+3,ReadUShort(address+1))+"."+ReadString(address2+3,ReadUShort(address2+1))+ReadString(address3+3,ReadUShort(address3+1));

}

string Access_flags(u2 access_flags,enum_type type)
{
string access_flags_text;

if((access_flags&ACC_PUBLIC)==ACC_PUBLIC)
{
access_flags_text=access_flags_text+"public ";
}

if(type==Field||type==Method||type==Nested_Class)
{

if((access_flags&ACC_PRIVATE)==ACC_PRIVATE)
{
access_flags_text=access_flags_text+"private ";
}

if((access_flags&ACC_PROTECTED)==ACC_PROTECTED)
{
access_flags_text=access_flags_text+"protected ";
}

if((access_flags&ACC_STATIC)==ACC_STATIC)
{
access_flags_text=access_flags_text+"static ";
}

}

if((access_flags&ACC_FINAL)==ACC_FINAL)
{
access_flags_text=access_flags_text+"final ";
}

if(type==Class)
{
if((access_flags&ACC_SUPER_ACC_SYNCHRONIZED)==ACC_SUPER_ACC_SYNCHRONIZED)
{
access_flags_text=access_flags_text+"superclass ";
}
}

if(type==Method)
{

if((access_flags&ACC_SUPER_ACC_SYNCHRONIZED)==ACC_SUPER_ACC_SYNCHRONIZED)
{
access_flags_text=access_flags_text+"synchronized ";
}

if((access_flags&ACC_BRIDGE_ACC_VOLATILE)==ACC_BRIDGE_ACC_VOLATILE)
{
access_flags_text=access_flags_text+"bridge ";
}

if((access_flags&ACC_VARARGS_ACC_TRANSIENT)==ACC_VARARGS_ACC_TRANSIENT)
{
access_flags_text=access_flags_text+"varargs ";
}

if((access_flags&ACC_NATIVE)==ACC_NATIVE)
{
access_flags_text=access_flags_text+"native ";
}

if((access_flags&ACC_STRICT)==ACC_STRICT)
{
access_flags_text=access_flags_text+"strictfp ";
}

}

if(type==Field)
{
if((access_flags&ACC_BRIDGE_ACC_VOLATILE)==ACC_BRIDGE_ACC_VOLATILE)
{
access_flags_text=access_flags_text+"volatile ";
}

if((access_flags&ACC_VARARGS_ACC_TRANSIENT)==ACC_VARARGS_ACC_TRANSIENT)
{
access_flags_text=access_flags_text+"transient ";
}

}

if(type==Class||type==Nested_Class)
{

if((access_flags&ACC_INTERFACE)==ACC_INTERFACE)
{
access_flags_text=access_flags_text+"interface ";
}

if((access_flags&ACC_ANNOTATION)==ACC_ANNOTATION)
{
access_flags_text=access_flags_text+"annotation ";
}

}

if(type==Class||type==Method||type==Nested_Class)
{
if((access_flags&ACC_ABSTRACT)==ACC_ABSTRACT)
{
access_flags_text=access_flags_text+"abstract ";
}
}


if((access_flags&ACC_SYNTHETIC)==ACC_SYNTHETIC)
{
access_flags_text=access_flags_text+"synthetic ";
}

if(type==Class||type==Field||type==Nested_Class)
{
if((access_flags&ACC_ENUM)==ACC_ENUM)
{
access_flags_text=access_flags_text+"enum ";
}
}
return access_flags_text;
}

//Event

string ClassFileOnComment(ClassFile &obj)
{
string str;
SPrintf(str, "JVM Byte Code v%d (Java ", obj.major_version);
if (obj.major_version <= 43)
{
str += "1.0)";
}
else if (obj.major_version <= 52)
{
SPrintf(str, str + "1.%d)", obj.major_version - 44);
}
else
{
SPrintf(str, str + "%d)", obj.major_version - 44);
}
return str;
}

local u1 flag_CONSTANT_Long_CONSTANT_Double=0;

u4 cp_infoOnSize(cp_info &obj)
{
switch(ReadUByte(FTell()))
{
case CONSTANT_Class: //sizeof(tag)+sizeof(name_index)
case CONSTANT_String: //sizeof(tag)+sizeof(string_index)
case CONSTANT_MethodType: //sizeof(tag)+sizeof(descriptor_index)
return 3;
break;
case CONSTANT_Fieldref: //sizeof(tag)+sizeof(class_index)+sizeof(name_and_type_index)
case CONSTANT_Methodref: //sizeof(tag)+sizeof(class_index)+sizeof(name_and_type_index)
case CONSTANT_InterfaceMethodref: //sizeof(tag)+sizeof(class_index)+sizeof(name_and_type_index)
case CONSTANT_NameAndType: //sizeof(tag)+sizeof(name_index)+sizeof(descriptor_index)
case CONSTANT_InvokeDynamic: //sizeof(tag)+sizeof(bootstrap_method_attr_index)+sizeof(name_and_type_index)
case CONSTANT_Integer: //sizeof(tag)+sizeof(bytes)
case CONSTANT_Float: //sizeof(tag)+sizeof(bytes)
return 5;
break;
case CONSTANT_Long: //sizeof(tag)+sizeof(high_bytes)+sizeof(low_bytes)
case CONSTANT_Double: //sizeof(tag)+sizeof(high_bytes)+sizeof(low_bytes)
{
if(flag_CONSTANT_Long_CONSTANT_Double==0)
{
FSkip(-9);
flag_CONSTANT_Long_CONSTANT_Double=1;
return 9;

}
else
{
flag_CONSTANT_Long_CONSTANT_Double=0;
FSkip(8);
return 1;
}
break;
}
case CONSTANT_Utf8: //sizeof(tag)+sizeof(length)+length
return 3+ReadUShort(FTell()+1);
break;
case CONSTANT_MethodHandle: //sizeof(tag)+sizeof(reference_kind)+sizeof(reference_index)
return 4;
break;
default:
Warning("fix cp_infoOnSize");
return 0;
break;
}
}

string cp_infoOnComment(cp_info &obj)
{
//obj.tag
switch(ReadUByte(startof(obj)))
{
case CONSTANT_Class:
return "CONSTANT_Class_info";
break;
case CONSTANT_Fieldref:
return "CONSTANT_Fieldref";
break;
case CONSTANT_Methodref:
return "CONSTANT_Methodref";
break;
case CONSTANT_InterfaceMethodref:
return "CONSTANT_InterfaceMethodref";
break;
case CONSTANT_String:
return "CONSTANT_String";
break;
case CONSTANT_Integer:
return "CONSTANT_Integer";
break;
case CONSTANT_Float:
return "CONSTANT_Float";
break;
case CONSTANT_Long:
if(sizeof(obj)==1)return "CONSTANT_Long continued";
return "CONSTANT_Long";
break;
case CONSTANT_Double:
if(sizeof(obj)==1)return "CONSTANT_Double continued";
return "CONSTANT_Double";
break;
case CONSTANT_NameAndType:
return "CONSTANT_NameAndType";
break;
case CONSTANT_Utf8:
return "CONSTANT_Utf8";
break;
case CONSTANT_MethodHandle:
return "CONSTANT_MethodHandle";
break;
case CONSTANT_MethodType:
return "CONSTANT_MethodType";
break;
case CONSTANT_InvokeDynamic:
return "CONSTANT_InvokeDynamic";
break;
default:
Warning("fix cp_infoOnCommen");
return "fix cp_infoOnCommen";
break;
}
}

string ClassFile_interfaces_OnComment(u2 interfaces)
{
return get_constant_pool_Utf8(interfaces);
}

string Class_access_flags_OnComment(u2 access_flags)
{
return Access_flags(access_flags,Class);
}

string Field_access_flags_OnComment(u2 access_flags)
{
return Access_flags(access_flags,Field);
}

string Method_access_flags_OnComment(u2 access_flags)
{
return Access_flags(access_flags,Method);
}

string Nested_Class_access_flags_OnComment(u2 access_flags)
{
return Access_flags(access_flags,Nested_Class);
}

string method_info_OnComment(method_info &obj)
{
return get_constant_pool_Utf8(obj.name_index)+get_constant_pool_Utf8(obj.descriptor_index);
}

string field_info_OnComment(field_info &obj)
{
return get_constant_pool_Utf8(obj.descriptor_index)+" "+get_constant_pool_Utf8(obj.name_index);
}

string attribute_info_OnComment(attribute_info &obj)
{
return get_constant_pool_Utf8(obj.attribute_name_index);
}

string attribute_info_InnerClasses_OnComment(InnerClasses_struct &obj)
{
return get_constant_pool_Utf8(obj.inner_name_index);
}

string attribute_info_LocalVariableTable_OnComment(LocalVariableTable_struct &obj)
{
return get_constant_pool_Utf8(obj.name_index);
}



string stack_map_frame_OnComment(stack_map_frame &obj)
{
if(obj.frame_type>=0&&obj.frame_type<=63)
{
return "same_frame";
}
else if(obj.frame_type>=64&&obj.frame_type<=127)
{
return "same_locals_1_stack_item_frame";
}
else if(obj.frame_type==247)
{
return "same_locals_1_stack_item_frame_extended";
}
else if(obj.frame_type>=248&&obj.frame_type<=251)
{
return "chop_frame or same_frame_extended";
}
else if(obj.frame_type>=252&&obj.frame_type<=254)
{
return "append_frame";
}
else if(obj.frame_type==255)
{
return "full_frame";
}
}


string annotation_OnComment(annotation &obj)
{
return get_constant_pool_Utf8(obj.type_index);
}

string Name_OnComment(u2 n)
{
return get_constant_pool_Utf8(n);
}

string Name_Exception_OnComment(u2 n)
{
if(n==0)return "any";
return get_constant_pool_Utf8(n);
}

string element_value_OnComment(element_value &obj)
{
switch(obj.tag)
{
case 's':
return "String";
break;
case 'e':
return "enum";
break;
case 'c':
return "class";
break;
case '@':
return "annotation type";
break;
case '[':
return "array";
break;
default:
return "";
break;
}
}


string opcodes_operation_OnComment(opcodes_operation &obj)
{
if(!exists(obj.operation))return "";

string str;
string str2;
enum_opcodes obj_operation=obj.operation;

switch(array_opcodes_body_type[obj.operation])
{
case index_body:
SPrintf(str," %d",obj.index);
break;
case index_v2_body:
str=" "+get_constant_pool_Utf8(obj.index);
break;
case index_const_body:
SPrintf(str," %d",obj.index);
SPrintf(str2," %d",obj._const);
str=str+" by"+str2;
break;
case sipush_body:
SPrintf(str," %d",obj._byte);
break;
case bipush_body:
SPrintf(str," %d",obj._byte);
break;
case newarray_body:
switch(obj.atype)
{
case T_BOOLEAN:
str=" boolean";
break;
case T_CHAR:
str=" char";
break;
case T_FLOAT:
str=" float";
break;
case T_DOUBLE:
str=" double";
break;
case T_BYTE:
str=" byte";
break;
case T_SHORT:
str=" short";
break;
case T_INT:
str=" int";
break;
case T_LONG:
str=" long";
break;
default:
Warning("fix opcodes_operation_OnComment");
break;
}
break;
case multianewarray_body:
SPrintf(str,"%d",obj.dimensions);
str=" "+get_constant_pool_Utf8(obj.indexbyte)+" dimensions "+str;
break;
case wide_body:
enum_opcodes obj_operation2=obj.operation2;
str=" "+EnumToString(obj_operation2)+get_constant_pool_Utf8(obj.indexbyte);
if(obj_operation2==iinc)
{
SPrintf(str2,"%d",obj.constbyte);
str=str+" by "+str2;
}
break;
case tableswitch_body:
SPrintf(str,"%d",obj.lowbyte);
SPrintf(str2,"%d",obj.highbyte);
str=" "+str+" to "+str2;
break;
case lookupswitch_body:
SPrintf(str,"%d",obj.npairs);
str=" "+str;
break;
case invokedynamic_body:
case indexbyte_1_2_body:
str=" "+get_constant_pool_Utf8(obj.indexbyte);
break;
case branchbyte1_2_body:
case branchbyte1_4_body:
SPrintf(str," %d",obj.branchbyte);
break;
case invokeinterface_body:
SPrintf(str," %d",obj._count);
str=" "+get_constant_pool_Utf8(obj.indexbyte)+" count "+str;
break;
default:
break;
}

return EnumToString(obj_operation)+str;
}

generator_map_address_constant_pool();

ClassFile classFile;
010Editor
影像处理学习指南
前端学习路线
© 2024 Lyana-nullptr
Powered by hexo | Theme is blank