-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathabc9.bt
1056 lines (954 loc) · 43.8 KB
/
abc9.bt
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
//------------------------------------------------
//--- 010 Editor v12.0.1 Binary Template
//
// File: abc.bt
// Authors: hx1997
// Version: 1.1
// Purpose: 010Editor template for .abc (Open/HarmonyOS Ark Bytecode) files
// Category: Operating Systems
// History:
// 1.1 2024-09-28 hx1997: Fix size of modulerecord_literalarrs; better handling of constant_pool (thanks to @alviszh)
// 1.0 2024-06-21 hx1997: Initial release on Script Repository
//------------------------------------------------
uint Align( uint value, uint alignment )
{
return (value + (alignment - 1)) & ~(alignment - 1);
}
void FAlign( uint alignment )
{
FSeek( Align( FTell(), alignment ) );
}
typedef struct {
ubyte val <comment="uleb128 element">;
if(val > 0x7f) {
ubyte val <comment="uleb128 element">;
if (val > 0x7f) {
ubyte val <comment="uleb128 element">;
if(val > 0x7f) {
ubyte val <comment="uleb128 element">;
if(val > 0x7f) {
ubyte val <comment="uleb128 element">;
}
}
}
}
} uleb128 <read=ULeb128Read, comment="Unsigned little-endian base 128 value">;
// get the actual uint value of the uleb128
uint uleb128_value(uleb128 &u) {
local uint result;
local ubyte cur;
result = u.val[0];
if(result > 0x7f) {
cur = u.val[1];
result = (result & 0x7f) | (uint)((cur & 0x7f) << 7);
if(cur > 0x7f) {
cur = u.val[2];
result |= (uint)(cur & 0x7f) << 14;
if(cur > 0x7f) {
cur = u.val[3];
result |= (uint)(cur & 0x7f) << 21;
if(cur > 0x7f) {
cur = u.val[4];
result |= (uint)cur << 28;
}
}
}
}
return result;
}
// get the number of bytes taken by a uleb128
uint uleb128_size(uleb128 &u) {
local uint result;
local ubyte cur;
local uint size = 1;
result = u.val[0];
if(result > 0x7f) {
size = 2;
cur = u.val[1];
result = (result & 0x7f) | (uint)((cur & 0x7f) << 7);
if(cur > 0x7f) {
size = 3;
cur = u.val[2];
result |= (uint)(cur & 0x7f) << 14;
if(cur > 0x7f) {
size = 4;
cur = u.val[3];
result |= (uint)(cur & 0x7f) << 21;
if(cur > 0x7f) {
size = 5;
cur = u.val[4];
result |= (uint)cur << 28;
}
}
}
}
return size;
}
typedef struct uleb128 uleb128p1;
int uleb128p1_value(uleb128 &u) {
return (int)uleb128_value(u) - 1;
}
string ULeb128Read(uleb128 &u) {
local string s;
s = SPrintf(s, "0x%X", uleb128_value(u));
return s;
}
// sleb128
typedef struct {
ubyte val <comment="sleb128 element">;
if(val > 0x7f) {
ubyte val <comment="sleb128 element">;
if (val > 0x7f) {
ubyte val <comment="sleb128 element">;
if(val > 0x7f) {
ubyte val <comment="sleb128 element">;
if(val > 0x7f) {
ubyte val <comment="sleb128 element">;
}
}
}
}
} sleb128 <read=SLeb128Read, comment="Signed little-endian base 128 value">;
// get the actual uint value of the uleb128
int sleb128_value(sleb128 &u) {
local int result;
local ubyte cur;
result = u.val[0];
if(result <= 0x7f) {
result = (result << 25) >> 25;
} else {
cur = u.val[1];
result = (result & 0x7f) | ((uint)(cur & 0x7f) << 7);
if(cur <= 0x7f) {
result = (result << 18) >> 18;
} else {
cur = u.val[2];
result |= (uint)(cur & 0x7f) << 14;
if(cur <= 0x7f) {
result = (result << 11) >> 11;
} else {
cur = u.val[3];
result |= (uint)(cur & 0x7f) << 21;
if(cur <= 0x7f) {
result = (result << 4) >> 4;
} else {
cur = u.val[4];
result |= (uint)cur << 28;
}
}
}
}
return result;
}
string SLeb128Read(sleb128 &u) {
local string s;
s = SPrintf(s, "%i", sleb128_value(u));
return s;
}
typedef struct {
uleb128 utf16_length <comment="len << 1 | is_ascii where len is the length of the string in UTF-16 code units.">;
string data <comment="0-terminated character sequence in MUTF-8 encoding.">;
} String <read=data>;
typedef struct {
char panda[5];
char padding[3];
if(Strcmp(panda, "PANDA") || padding[0] != 0 || padding[1] != 0 || padding[2] != 0) {
PrintWarning("Invalid ABC file");
return -1;
}
} abc_magic <read=AbcMagicRead, size=8>;
string AbcMagicRead(abc_magic &m) {
string s;
SPrintf(s, "%s\\0\\0\\0", m.panda);
return s;
}
typedef struct {
abc_magic magic <comment="Magic string. Must be 'P' 'A' 'N' 'D' 'A' '\\0' '\\0' '\\0'">;
uint checksum <comment="adler32 checksum of the file except magic and checksum fields.">;
uchar version[4] <comment="Version of the format.">;
uint filesize <comment="Size of the file in bytes.">;
uint foreign_off <comment="Offset to the foreign region. The region must contain elements only of types ForeignField, ForeignMethod, or ForeignClass. It is not necessary foreign_off points to the first entity. Runtime should use foreign_off and foreign_size to determine type of an offset.">;
uint foreign_size <comment="Size of the foreign region in bytes.">;
uint num_classes <comment="Number of classes defined in the file. Also this is the number of elements in the ClassIndex structure.">;
uint class_idx_off <comment="Offset to the class index structure. The offset must point to a structure in ClassIndex format.">;
uint num_lnps <comment="Number of line number programs in the file. Also this is the number of elements in the LineNumberProgramIndex structure.">;
uint lnp_idx_off <comment="Offset to the line number program index structure. The offset must point to a structure in LineNumberProgramIndex format.">;
uint num_literalarrays <comment="Number of literalArrays defined in the file. Also this is the number of elements in the LiteralArrayIndex structure.">;
uint literalarray_idx_off <comment="Offset to the literalarray index structure. The offset must point to a structure in LiteralArrayIndex format.">;
uint num_index_regions <comment="Number of the index regions in the file. Also this is the number of elements in the RegionIndex structure.">;
uint index_section_off <comment="Offset to the index section. The offset must point to a structure in RegionIndex format.">;
FAlign(4);
} Header <size=readHeaderItemSize>;
int readHeaderItemSize(Header &item) {
return 60;
}
typedef struct {
uleb128 type_idx <comment="Index + 1 of the exception's type the block handles in a ClassRegionIndex structure or 0 in case of catch all block. Corresponding index entry must be an offset to a ForeignClass or to Class. The case when the index is 0 means it is a catch all block which catches all exceptions.">;
uleb128 handler_pc <comment="pc of the first instruction of the exception handler.">;
uleb128 code_size <comment="Handler's code size in bytes">;
} CatchBlock;
typedef struct {
uleb128 start_pc <comment="Start pc of the try block. This pc points to the first instruction covered by this try block.">;
uleb128 length <comment="Number of instructions covered by the try block.">;
uleb128 num_catches <comment="Number of catch blocks associated with the try block.">;
CatchBlock catch_blocks[uleb128_value(num_catches)] <optimize=false, comment="Array of catch blocks associated with the try block. The array has num_catches elements in CatchBlock format. Catch blocks follows in the order runtime must check the exception's type. The catch all block, if present, must be the last.">;
} TryBlock;
typedef struct {
uleb128 num_vregs <comment="Number of registers (without argument registers).">;
uleb128 num_args <comment="Number of arguments.">;
uleb128 code_size <comment="Size of instructions in bytes.">;
uleb128 tries_size <comment="Number of try blocks.">;
uchar instructions[uleb128_value(code_size)] <comment="Instructions.">;
TryBlock try_blocks[uleb128_value(tries_size)] <optimize=false, comment="Array of try blocks. The array has tries_size elements in TryBlock format.">;
} Code;
typedef struct {
uint name_off <comment="Offset to the element's name. The offset must point to a String.">;
readStringAt(name_off);
// size of value is fixed (32-bit), see `arkcompiler\runtime_core\libpandafile\annotation_data_accessor.cpp`
uint value <comment="Value of the element. If the annotation element has type boolean, byte, short, char, int or float the field value contains the value itself in the corresponding Value format. Else the field contains offset to a Value. Format of the value could be determined based on element's type.">;
} AnnotationElement;
typedef struct {
ushort class_idx <comment="Index of the declaring class in a ClassRegionIndex structure. Corresponding index entry must be an offset to a Class or a ForeignClass.">;
ushort count <comment="Number of name-value pairs in the annotation (number of elements in elements array).">;
AnnotationElement elements[count] <comment="Array of annotation elements. Each element is in AnnotationElement format. Order of elements must be the same as they follow in the annotation class.">;
uchar element_types[count] <comment="Array of annotation element's types. Each element in the array describes the type of AnnotationElement. The order of elements in the array matches the order of elements field.">;
} Annotation;
typedef struct {
uint count <comment="Number of elements in the array.">;
uint offsets[count] <comment="Array of offsets to the parameter annotations. Each offset must refers to an Annotation. The array has count elements.">;
} AnnotationArray;
typedef struct {
uint count <comment="Number of parameters the method has. This number includes synthetic and mandated parameters.">;
AnnotationArray annotations[count] <comment="Array of annotation lists for each parameter. The array has count elements and each element is in AnnotationArray format.">;
} ParamAnnotations;
typedef struct {
uleb128 line_start <comment="The initial value of line register of the state machine.">;
uleb128 num_parameters <comment="Number of method parameters.">;
uleb128 parameters[uleb128_value(num_parameters)] <optimize=false, comment="Parameters names of the method. The array has num_parameters elements. Each element is an offset to String or 0 if there is no name.">;
uleb128 constant_pool_size <comment="Size of constant pool in bytes.">;
local uint64 offset = 0;
while (offset < uleb128_value(constant_pool_size)) {
uleb128 constant_pool <comment="Constant pool data of length constant_pool_size bytes.">;
offset += uleb128_size(constant_pool);
}
uleb128 line_number_program_idx <comment="Line number program index in a LineNumberProgramIndex structure. The program has variable length and ends with DBG_END_SEQUENCE opcode.">;
} DebugInfo;
void readCodeAt(uint offset) {
local int64 pos;
local int color;
if (offset != 0) {
color = GetBackColor();
pos = FTell();
FSeek(offset);
SetBackColor(0x00a5ff);
Code code_data <comment="Code data.">;
FSeek(pos);
SetBackColor(color);
}
}
void readAnnotationAt(uint offset) {
local int64 pos;
local int color;
if (offset != 0) {
color = GetBackColor();
pos = FTell();
FSeek(offset);
SetBackColor(0xf09020);
Annotation annotation_data;
FSeek(pos);
SetBackColor(color);
}
}
void readParamAnnotationsAt(uint offset) {
local int64 pos;
local int color;
if (offset != 0) {
color = GetBackColor();
pos = FTell();
FSeek(offset);
SetBackColor(0xf09020);
ParamAnnotations annotation_data;
FSeek(pos);
SetBackColor(color);
}
}
void readDebugInfoAt(uint offset) {
local int64 pos;
local int color;
if (offset != 0) {
color = GetBackColor();
pos = FTell();
FSeek(offset);
SetBackColor(0xc0c0c0);
DebugInfo debug_info_data <comment="Debug information contains mapping between program counter of a method and line numbers in source code and information about local variables. The format is derived from DWARF Debugging Information Format, Version 3 (see item 6.2). The mapping and local variable information are encoded in line number program which is interpreted by the state machine. To deduplicate the same line number programs of different methods all constants the program refers to are moved into the constant pool.">;
FSeek(pos);
SetBackColor(color);
}
}
typedef struct {
uchar tag_value <comment="The first 8 bits contain tag which determines the meaning of the data. Depending on the tag there may be optional data. Runtime must be able to determine size of the data.">;
switch (tag_value) {
case 0: // NOTHING
break;
case 1: // INTERFACES
uleb128 num_interfaces <comment="Number of interfaces.">;
ushort interfaces_idx[uleb128_value(num_interfaces)] <comment="Indexes of the interfaces in a ClassRegionIndex structure. Each index is 2 bytes long and must be resolved to offset point to a ForeignClass or to a Class.">;
break;
case 2: // SOURCE_LANG
uchar source_lang <comment="Data represents the source language.">;
break;
case 3: // RUNTIME_ANNOTATION
uint runtime_annotation <comment="Offset to runtime visible annotation of the class. The tag may be repeated in case the class has several annotations. The offset must point to the value in Annotation format.">;
readAnnotationAt(runtime_annotation);
break;
case 4: // ANNOTATION
uint annotation <comment="Offset to runtime invisible annotation of the class. The tag may be repeated in case the class has several annotations. The offset must point to the value in Annotation format.">;
readAnnotationAt(annotation);
break;
case 5: // RUNTIME_TYPE_ANNOTATION
uchar runtime_type_annotation <comment="Offset to runtime visible type annotation of the class. The tag may be repeated in case the class has several annotations. The offset must point to the value in Annotation format.">;
readAnnotationAt(runtime_type_annotation);
break;
case 6: // TYPE_ANNOTATION
uchar type_annotation <comment="Offset to runtime invisible type annotation of the class. The tag may be repeated in case the class has several annotations. The offset must point to the value in Annotation format.">;
readAnnotationAt(type_annotation);
break;
case 7: // SOURCE_FILE
uchar source_file <comment="Offset to a file name string containing source code of this class.">;
break;
}
} ClassTag;
uint getFieldTypeByIdx(ushort type_idx) {
local int i;
local uint64 pos = FTell();
for (i = 0; i < abc_header.num_index_regions; i++) {
if (pos < abc_region_idxs.region_headers[i].start_off || pos > abc_region_idxs.region_headers[i].end_off)
continue;
return abc_region_idxs.region_headers[i].class_idx.types[type_idx].field_type;
}
}
void readFieldValue(uint field_type) {
// arkcompiler\runtime_core\libpandafile\field_data_accessor.cpp
if (field_type < 16) {
switch (field_type) {
case 0x0: // u1
case 0x2: // u8
case 0x1: // i8
case 0x3: // i16
case 0x4: // u16
case 0x5: // i32
case 0x6: // u32
case 0x7: // f32
case 0xb: // any, not sure if this is right
uint value <comment="Contains value in the Value format.">;
break;
case 0x8: // f64
case 0x9: // i64
case 0xa: // u64
uint offset;
uint64 pos = FTell();
FSeek(offset);
uint64 value <comment="Contains value in the Value format.">;
FSeek(pos);
break;
}
} else {
uint value <comment="Contains value in the Value format.">;
}
}
typedef struct (ushort type_idx) {
uchar tag_value <comment="The first 8 bits contain tag which determines the meaning of the data. Depending on the tag there may be optional data. Runtime must be able to determine size of the data.">;
switch (tag_value) {
case 0: // NOTHING
break;
case 1: // INT_VALUE
sleb128 int_value <comment="Integral value of the field. This tag is used when the field has type boolean, byte, char, short or int.">;
break;
case 2: // VALUE
local uint field_type = getFieldTypeByIdx(type_idx);
readFieldValue(field_type);
break;
case 3: // RUNTIME_ANNOTATIONS
uint runtime_annotations <comment="Offset to runtime visible annotation of the field. The tag may be repeated in case the field has several annotations. The offset must point to the value in Annotation format.">;
readAnnotationAt(runtime_annotations);
break;
case 4: // ANNOTATIONS
uint annotations <comment="Offset to runtime invisible annotation of the field. The tag may be repeated in case the field has several annotations. The offset must point to the value in Annotation format.">;
readAnnotationAt(annotations);
break;
case 5: // RUNTIME_TYPE_ANNOTATION
uint runtime_type_annotation <comment="Offset to runtime visible type annotation of the field. The tag may be repeated in case the class has several annotations. The offset must point to the value in Annotation format.">;
readAnnotationAt(runtime_type_annotation);
break;
case 6: // TYPE_ANNOTATION
uint type_annotation <comment="Offset to runtime invisible type annotation of the field. The tag may be repeated in case the class has several annotations. The offset must point to the value in Annotation format.">;
readAnnotationAt(type_annotation);
break;
}
} FieldTag;
typedef struct {
uchar tag_value <comment="The first 8 bits contain tag which determines the meaning of the data. Depending on the tag there may be optional data. Runtime must be able to determine size of the data.">;
switch (tag_value) {
case 0: // NOTHING
break;
case 1: // CODE
uint code <comment="Data represents the offset to method's code. The offset must point to Code.">;
readCodeAt(code);
break;
case 2: // SOURCE_LANG
uchar source_lang <comment="Data represents the source language.">;
break;
case 3: // RUNTIME_ANNOTATION
uint runtime_annotation <comment="Data represents the offset to runtime visible annotation of the method. The tag may be repeated in case the method has several annotations. The offset must point to the value in Annotation format.">;
readAnnotationAt(runtime_annotation);
break;
case 4: // RUNTIME_PARAM_ANNOTATION
uint runtime_param_annotation <comment="Data represents the offset to the runtime visible annotations of the method's parameters. The offset must point to the value in ParamAnnotations format.">;
readParamAnnotationAt(runtime_param_annotation);
break;
case 5: // DEBUG_INFO
uint debug_info <comment="Data represents the offset to debug information related to the method. The offset must point to DebugInfo.">;
readDebugInfoAt(debug_info);
break;
case 6: // ANNOTATIONS
uint annotations <comment="Data represents the offset to runtime invisible annotation of the method. The tag may be repeated in case the method has several annotations. The offset must point to the value in Annotation format.">;
readAnnotationAt(annotations);
break;
case 7: // PARAM_ANNOTATION
uint param_annotation <comment="Data represents the offset to the runtime invisible annotations of the method's parameters. The offset must point to the value in ParamAnnotations format.">;
readParamAnnotationAt(runtime_param_annotation);
break;
case 8: // TYPE_ANNOTATION
uint type_annotation <comment="Data represents the offset to runtime invisible type annotation of the method. The tag may be repeated in case the method has several annotations. The offset must point to the value in Annotation format.">;
readAnnotationAt(type_annotation);
break;
case 9: // RUNTIME_TYPE_ANNOTATION
uint runtime_type_annotation <comment="Data represents the offset to runtime visible type annotation of the method. The tag may be repeated in case the method has several annotations. The offset must point to the value in Annotation format.">;
readAnnotationAt(runtime_type_annotation);
break;
}
} MethodTag;
string getShortyTypeName(uchar shorty_nibble) {
switch (shorty_nibble) {
case 0x0:
return "end";
case 0x1:
return "void";
case 0x2:
return "u1";
case 0x3:
return "i8";
case 0x4:
return "u8";
case 0x5:
return "i16";
case 0x6:
return "u16";
case 0x7:
return "i32";
case 0x8:
return "u32";
case 0x9:
return "f32";
case 0xa:
return "f64";
case 0xb:
return "i64";
case 0xc:
return "u64";
case 0xd:
return "ref";
case 0xe:
return "any";
}
}
uint parseShorty() {
BitfieldDisablePadding();
// Note that the bitfields within each byte are interpreted right-to-left. For example, if you have "0xec 0xce", this is read as 0xc (u64), 0xe (any), 0xe (any), 0xc (u64)
local uint num_bits = 4;
local uint num_refs = 0;
ushort shorty_returntype : 4 <read=getShortyTypeName, comment="Shorty is a short description of method's signature without detailed information about reference types. A shorty begins with a return type followed by method arguments and ends with 0x0.">;
if (shorty_returntype == 0xd) {
num_refs++;
}
ushort shorty_paramlist : 4 <read=getShortyTypeName>;
while (shorty_paramlist != 0) {
num_bits = (num_bits + 4) % 16;
if (shorty_paramlist == 0xd) {
num_refs++;
}
ushort shorty_paramlist : 4 <read=getShortyTypeName>;
}
num_bits = (num_bits + 4) % 16;
if (num_bits != 0) {
// `Shorty` elements appear in groups of 16 bits. Padding is required if the `Shorty` ends when a group hasn't reached 16 bits.
local uint padding_size = 16 - num_bits;
ushort : padding_size;
}
return num_refs;
}
typedef struct {
local uint num_refs = parseShorty();
ushort reference_types[num_refs] <optimize=false, comment="Array of indexes of the method's signature non-primitive types. For each non-primitive type in the shorty there is the corresponding element in the array. Size of the array is equals to number of reference types in the shorty.">;
} Proto;
void readStringAt(uint offset) {
local int64 pos;
if (offset != 0) {
pos = FTell();
FSeek(offset);
String str <comment="String">;
FSeek(pos);
}
}
typedef struct {
ushort class_idx <comment="Index of the declaring class in a ClassRegionIndex structure. Corresponding index entry must be an offset to a Class.">;
ushort type_idx <comment="Index of the field's type in a ClassRegionIndex structure. Corresponding index entry must be in FieldType format.">;
uint name_off <comment="Offset to the name of the field. The offset must point to a String">;
readStringAt(name_off);
uleb128 access_flags <comment="Access flags of the field. The value must be a combination of the Field access flags.">;
FieldTag field_data(type_idx);
while (field_data.tag_value != 0) {
FieldTag field_data(type_idx);
}
if (str.data == "moduleRecordIdx") {
modulerecord_literalarrs[class_idx] = field_data[0].value;
}
} Field;
typedef struct {
ushort class_idx <comment="Index of the declaring class in a ClassRegionIndex structure. Corresponding index entry must be an offset to a Class.">;
ushort proto_idx <comment="Index of the method's prototype in a ProtoRegionIndex structure. Corresponding index entry must be an offset to a Proto.">;
uint name_off <comment="Offset to the name of the method. The offset must point to a String.">;
readStringAt(name_off);
uleb128 access_flags <comment="Access flags of the method. The value must be a combination of Method access flags.">;
MethodTag method_data;
while (method_data.tag_value != 0) {
MethodTag method_data;
}
} Method;
typedef struct {
String name <comment="Name of the class. The name must conform to TypeDescriptor syntax.">;
uint super_class_off <comment="Offset to the name of the super class or 0 for root object class (panda.Object in Panda Assembly, plugin-specific in plugins). Non-zero offset must point to a ForeignClass or to a Class.">;
uleb128 access_flags <comment="Access flags of the class. The value must be a combination of Class access flags.">;
uleb128 num_fields <comment="Number of fields the class has.">;
uleb128 num_methods <comment="Number of methods the class has.">;
ClassTag class_data;
while (class_data.tag_value != 0) {
ClassTag class_data;
}
Field fields[uleb128_value(num_fields)] <optimize=false, comment="Class fields. Number of elements is num_fields. Each element must have Field format.">;
Method methods[uleb128_value(num_methods)] <optimize=false, comment="Class methods. Number of elements is num_methods. Each element must have Method format.">;
} class_item;
typedef struct {
uchar insns;
while (insns != 0) { // END_SEQUENCE opcode
uchar insns;
}
} LineNumberProgram;
typedef struct {
uchar tag;
switch (tag) {
case 0x0: // shouldn't be here according to source code but... seems to work?
uchar value;
break;
case 0x2: // LiteralTag::INTEGER
case 0x17: // LiteralTag::LITERALBUFFERINDEX
uint value;
break;
case 0x4: // LiteralTag::DOUBLE
double value;
break;
case 0x1: // LiteralTag::BOOL
uchar value;
break;
case 0x3: // LiteralTag::FLOAT
float value;
break;
case 0x5: // LiteralTag::STRING
uint value;
readStringAt(value);
break;
case 0x6: // LiteralTag::METHOD
case 0x7: // LiteralTag::GENERATORMETHOD
case 0x18: // LiteralTag::LITERALARRAY
case 0x16: // LiteralTag::ASYNCGENERATORMETHOD
uint value;
break;
case 0x9: // LiteralTag::METHODAFFILIATE
ushort value;
break;
case 0x19: // LiteralTag::BUILTINTYPEINDEX
case 0x8: // LiteralTag::ACCESSOR
case 0xff: // LiteralTag::NULLVALUE
uchar value;
break;
case 0xa: // LiteralTag::ARRAY_U1
case 0xb: // LiteralTag::ARRAY_U8
uchar value;
break;
case 0xc: // LiteralTag::ARRAY_I8
char value;
break;
case 0xd: // LiteralTag::ARRAY_U16
ushort value;
break;
case 0xe: // LiteralTag::ARRAY_I16
short value;
break;
case 0xf: // LiteralTag::ARRAY_U32
uint value;
break;
case 0x10: // LiteralTag::ARRAY_I32
int value;
break;
case 0x11: // LiteralTag::ARRAY_U64
uint64 value;
break;
case 0x12: // LiteralTag::ARRAY_I64
int64 value;
break;
case 0x13: // LiteralTag::ARRAY_F32
float value;
break;
case 0x14: // LiteralTag::ARRAY_F64
double value;
break;
case 0x15: // LiteralTag::ARRAY_STRING
uint value;
break;
}
} Literal;
uint GetActualNumLiterals(uint num_literals) {
local uint64 pos = FTell();
local int i;
local uint actual_num_literals = 0;
local uchar tag;
for (i = 0; i < num_literals / 2; i++) {
tag = ReadUByte(pos);
pos++;
switch (tag) {
case 0x0: // shouldn't be here according to source code but... seems to work?
pos += 1;
actual_num_literals++;
break;
case 0x2: // LiteralTag::INTEGER
case 0x17: // LiteralTag::LITERALBUFFERINDEX
pos += 4;
actual_num_literals++;
break;
case 0x4: // LiteralTag::DOUBLE
pos += 8;
actual_num_literals++;
break;
case 0x1: // LiteralTag::BOOL
pos += 1;
actual_num_literals++;
break;
case 0x3: // LiteralTag::FLOAT
pos += 4;
actual_num_literals++;
break;
case 0x5: // LiteralTag::STRING
case 0x6: // LiteralTag::METHOD
case 0x7: // LiteralTag::GENERATORMETHOD
case 0x18: // LiteralTag::LITERALARRAY
case 0x16: // LiteralTag::ASYNCGENERATORMETHOD
pos += 4;
actual_num_literals++;
break;
case 0x9: // LiteralTag::METHODAFFILIATE
pos += 2;
actual_num_literals++;
break;
case 0x19: // LiteralTag::BUILTINTYPEINDEX
case 0x8: // LiteralTag::ACCESSOR
case 0xff: // LiteralTag::NULLVALUE
pos += 1;
actual_num_literals++;
break;
case 0xa: // LiteralTag::ARRAY_U1
case 0xb: // LiteralTag::ARRAY_U8
case 0xc: // LiteralTag::ARRAY_I8
pos += 1;
actual_num_literals++;
i = num_literals / 2;
break;
case 0xd: // LiteralTag::ARRAY_U16
case 0xe: // LiteralTag::ARRAY_I16
pos += 2;
actual_num_literals++;
i = num_literals / 2;
break;
case 0xf: // LiteralTag::ARRAY_U32
case 0x10: // LiteralTag::ARRAY_I32
pos += 4;
actual_num_literals++;
i = num_literals / 2;
break;
case 0x11: // LiteralTag::ARRAY_U64
case 0x12: // LiteralTag::ARRAY_I64
pos += 8;
actual_num_literals++;
i = num_literals / 2;
break;
case 0x13: // LiteralTag::ARRAY_F32
pos += 4;
actual_num_literals++;
i = num_literals / 2;
break;
case 0x14: // LiteralTag::ARRAY_F64
pos += 8;
actual_num_literals++;
i = num_literals / 2;
break;
case 0x15: // LiteralTag::ARRAY_STRING
actual_num_literals++;
i = num_literals / 2;
break;
default: // invalid tag
i = num_literals / 2;
break;
}
}
return actual_num_literals;
}
int indexof(uint64 arr[], int arrlen, uint64 key) {
local int i;
for (i = 0; i < arrlen; i++) {
if (arr[i] == key) {
return i;
}
}
return -1;
}
typedef struct {
uint local_name_offset;
readStringAt(local_name_offset);
uint import_name_offset;
readStringAt(import_name_offset);
ushort module_request_idx;
} RegularImport;
typedef struct {
uint local_name_offset;
readStringAt(local_name_offset);
ushort module_request_idx;
} NamespaceImport;
typedef struct {
uint local_name_offset;
readStringAt(local_name_offset);
uint export_name_offset;
readStringAt(export_name_offset);
} LocalExport;
typedef struct {
uint export_name_offset;
readStringAt(export_name_offset);
uint import_name_offset;
readStringAt(import_name_offset);
ushort module_request_idx;
} IndirectExport;
typedef struct {
ushort module_request_idx;
} StarExport;
typedef struct {
uint num_literals <comment="num of literals that a literalarray has.">;
local int idx = indexof(modulerecord_literalarrs, abc_region_idxs.region_headers.class_idx_size, startof(this));
if (idx == -1) {
// Actual number of literals is `num_literals / 2` if no `LiteralTag::ARRAY_*` types are present.
// If any of these types is present, the actual number stops at the first occurrence (i.e., no more literals once a `LiteralTag::ARRAY_*` type is encountered), no matter what `num_literals / 2` is.
// I don't know why this is so designed, see source code at `arkcompiler\runtime_core\libpandafile\literal_data_accessor-inl.h`
local uint actual_num_literals = GetActualNumLiterals(num_literals);
Literal literals[actual_num_literals] <optimize=false, comment="Array of literal in one LiteralArray. The array has num_literals elements in Literal format.">;
} else {
uint num_module_requests;
local int i;
for (i = 0; i < num_module_requests; i++) {
uint module_requests;
readStringAt(module_requests);
}
uint regular_import_num;
for (i = 0; i < regular_import_num; i++) {
RegularImport regular_imports;
}
uint namespace_import_num;
for (i = 0; i < namespace_import_num; i++) {
NamespaceImport namespace_imports;
}
uint local_export_num;
for (i = 0; i < local_export_num; i++) {
LocalExport local_exports;
}
uint indirect_export_num;
for (i = 0; i < indirect_export_num; i++) {
IndirectExport indirect_exports;
}
uint starExportNum;
for (i = 0; i < starExportNum; i++) {
StarExport star_exports;
}
}
} LiteralArray;
typedef struct {
uint field_type <comment="Since the first bytes of the file contain the header and size of the header > 16 bytes, any offset in the range [0; sizeof(Header)) is invalid. FieldType encoding uses this fact to encode primitive types of the field in the low 4 bits. For non-primitive type the value is an offset to Class or to ForeignClass. In both cases FieldType is uint32_t.">;
} FieldType;
typedef struct {
String name;
} ForeignClass;
typedef struct {
ushort class_idx <comment="Index of the declaring class in a ClassRegionIndex structure. Corresponding index entry must be an offset to a Class or a ForeignClass.">;
ushort type_idx <comment="Index of the field's type in a ClassRegionIndex structure. Corresponding index entry must be in FieldType format.">;
uint name_off <comment="Offset to the name of the field. The offset must point to a String">;
readStringAt(name_off);
} ForeignField;
typedef struct {
ushort class_idx <comment="Index of the declaring class in a ClassRegionIndex structure. Corresponding index entry must be an offset to a Class or a ForeignClass.">;
ushort proto_idx <comment="Index of the method's prototype in a ProtoRegionIndex structure. Corresponding index entry must be an offset to a Proto.">;
uint name_off <comment="Offset to the name of the field. The offset must point to a String">;
readStringAt(name_off);
uleb128 access_flags <comment="Access flags of the method. The value must be a combination of Method access flags. For foreign methods, only ACC_STATIC flag is used, other flags should be ignored.">;
} ForeignMethod;
typedef struct (uint offset, int size) {
local uint64 pos = FTell();
FSeek(offset);
SetBackColor(0xd060d0);
FieldType types[size] <optimize=false, comment="Array of FieldType structures.">;
FAlign(4);
FSeek(pos);
} ClassRegionIndex;
typedef struct (uint offset, int size) {
local uint64 pos = FTell();
FSeek(offset);
SetBackColor(0xd060d0);
uint offsets[size] <optimize=false, comment="Array of offsets to Method or ForeignMethod structures.">;
FAlign(4);
//local int i;
//local uint foreign_start = abc_header.foreign_off;
//local uint foreign_end = foreign_start + abc_header.foreign_size;
//local uint method_addr;
//for (i = 0; i < size; i++) {
// method_addr = offsets[i];
// FSeek(method_addr);
// if (foreign_start <= method_addr && method_addr < foreign_end)
// ForeignMethod abc_method_items <optimize=false>;
// else
// Method abc_method_items <optimize=false>;
//}
FSeek(pos);
} MethodRegionIndex;
typedef struct (uint offset, int size) {
local uint64 pos = FTell();
FSeek(offset);
SetBackColor(0xd060d0);
uint offsets[size] <optimize=false, comment="Array of offsets to Field or ForeignField structures.">;
FAlign(4);
local int i;
local uint foreign_start = abc_header.foreign_off;
local uint foreign_end = foreign_start + abc_header.foreign_size;
local uint field_addr;
for (i = 0; i < size; i++) {
field_addr = offsets[i];
FSeek(field_addr);
if (foreign_start <= field_addr && field_addr < foreign_end)
ForeignField abc_field_items <optimize=false>;
else
Field abc_field_items <optimize=false>;
}
FSeek(pos);
} FieldRegionIndex;
typedef struct (uint offset, int size) {
local uint64 pos = FTell();
FSeek(offset);
SetBackColor(0xd060d0);
uint offsets[size] <optimize=false, comment="Array of offsets to Proto structures.">;
FAlign(4);
local int i;
local uint proto_addr;
for (i = 0; i < size; i++) {
proto_addr = offsets[i];
FSeek(proto_addr);
Proto abc_proto_items <optimize=false>;
}
FSeek(pos);
} ProtoRegionIndex;
typedef struct {
uint start_off <comment="Start offset of the region.">;
uint end_off <comment="End offset of the region.">;
uint class_idx_size <comment="Number of elements in the ClassRegionIndex structure. Max value is 65536.">;
uint class_idx_off <comment="Offset to the class index structure. The offset must point to a structure in ClassRegionIndex format.">;
ClassRegionIndex class_idx(class_idx_off, class_idx_size) <comment="The structure is organized as an array of FieldType. Number of elements in the index is class_idx_size from RegionHeader.">;
uint method_idx_size <comment="Number of elements in the MethodRegionIndex structure. Max value is 65536.">;
uint method_idx_off <comment="Offset to the method index structure. The offset must point to a structure in MethodRegionIndex format.">;
MethodRegionIndex method_idx(method_idx_off, method_idx_size) <comment="The structure is organized as an array of offsets from the beginning of the file to the Method or the ForeignMethod structure. Number of elements in the index is method_idx_size from RegionHeader.">;
uint field_idx_size <comment="Number of elements in the FieldRegionIndex structure. Max value is 65536.">;
uint field_idx_off <comment="Offset to the field index structure. The offset must point to a structure in FieldRegionIndex format.">;
FieldRegionIndex field_idx(field_idx_off, field_idx_size) <comment="The structure is organized as an array of offsets from the beginning of the file to the Field or the ForeignField structure. Number of elements in the index is field_idx_size from RegionHeader.">;
uint proto_idx_size <comment="Number of elements in the ProtoRegionIndex structure. Max value is 65536.">;
uint proto_idx_off <comment="Offset to the proto index structure. The offset must point to a structure in ProtoRegionIndex format.">;
ProtoRegionIndex proto_idx(proto_idx_off, proto_idx_size) <comment="The structure is organized as an array of offsets from the beginning of the file to the Proto structure. Number of elements in the index is proto_idx_size from RegionHeader.">;
FAlign(4);
} RegionHeader;
typedef struct (int size) {
uint class_def[size] <comment="Class structure offset", optimize=false>;
FAlign(4);
local uint64 pos = FTell();
SetBackColor(cLtBlue);
local int i;
local uint foreign_start = abc_header.foreign_off;
local uint foreign_end = foreign_start + abc_header.foreign_size;
local uint class_addr;
for (i = 0; i < size; i++) {
class_addr = class_def[i];
FSeek(class_addr);
if (foreign_start <= class_addr && class_addr < foreign_end)
ForeignClass abc_class_items <optimize=false>;
else
class_item abc_class_items <optimize=false>;
}
FSeek(pos);
} ClassIndex;
typedef struct (int size) {
uint offsets[size] <comment="Array of offsets to Line Number Program structures.", optimize=false>;