-
Notifications
You must be signed in to change notification settings - Fork 18
/
dex.py
762 lines (626 loc) · 30.1 KB
/
dex.py
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
# This is a generated file based on https://formats.kaitai.io/dex/ but with minor tweaks for string processing.
# Unfortunately the original cannot parse KSY cannot parse the UTF16 strings in the "fake" UTF8 format we need which makes string processing way easier
# See line 460
from typing import List
from pkg_resources import parse_version
import kaitaistruct
from kaitaistruct import KaitaiStruct, KaitaiStream
from enum import Enum
if parse_version(kaitaistruct.__version__) < parse_version('0.9'):
raise Exception(
"Incompatible Kaitai Struct Python API: 0.9 or later is required, but you have %s" % (kaitaistruct.__version__))
import vlq_base128_le
class Dex(KaitaiStruct):
"""Android OS applications executables are typically stored in its own
format, optimized for more efficient execution in Dalvik virtual
machine.
This format is loosely similar to Java .class file format and
generally holds the similar set of data: i.e. classes, methods,
fields, annotations, etc.
.. seealso::
Source - https://source.android.com/devices/tech/dalvik/dex-format
"""
class ClassAccessFlags(Enum):
public = 1
private = 2
protected = 4
static = 8
final = 16
interface = 512
abstract = 1024
synthetic = 4096
annotation = 8192
enum = 16384
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.header = Dex.HeaderItem(self._io, self, self._root)
class HeaderItem(KaitaiStruct):
class EndianConstant(Enum):
endian_constant = 305419896
reverse_endian_constant = 2018915346
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.magic = self._io.read_bytes(4)
if not self.magic == b"\x64\x65\x78\x0A":
raise kaitaistruct.ValidationNotEqualError(b"\x64\x65\x78\x0A", self.magic, self._io,
u"/types/header_item/seq/0")
self.version_str = (KaitaiStream.bytes_terminate(self._io.read_bytes(4), 0, False)).decode(u"utf-8",
"ignore")
self.checksum = self._io.read_u4le()
self.signature = self._io.read_bytes(20)
self.file_size = self._io.read_u4le()
self.header_size = self._io.read_u4le()
self.endian_tag = KaitaiStream.resolve_enum(Dex.HeaderItem.EndianConstant, self._io.read_u4le())
self.link_size = self._io.read_u4le()
self.link_off = self._io.read_u4le()
self.map_off = self._io.read_u4le()
self.string_ids_size = self._io.read_u4le()
self.string_ids_off = self._io.read_u4le()
self.type_ids_size = self._io.read_u4le()
self.type_ids_off = self._io.read_u4le()
self.proto_ids_size = self._io.read_u4le()
self.proto_ids_off = self._io.read_u4le()
self.field_ids_size = self._io.read_u4le()
self.field_ids_off = self._io.read_u4le()
self.method_ids_size = self._io.read_u4le()
self.method_ids_off = self._io.read_u4le()
self.class_defs_size = self._io.read_u4le()
self.class_defs_off = self._io.read_u4le()
self.data_size = self._io.read_u4le()
self.data_off = self._io.read_u4le()
class MapList(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.size = self._io.read_u4le()
self.list = [None] * (self.size)
for i in range(self.size):
self.list[i] = Dex.MapItem(self._io, self, self._root)
class EncodedValue(KaitaiStruct):
class ValueTypeEnum(Enum):
byte = 0
short = 2
char = 3
int = 4
long = 6
float = 16
double = 17
method_type = 21
method_handle = 22
string = 23
type = 24
field = 25
method = 26
enum = 27
array = 28
annotation = 29
null = 30
boolean = 31
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.value_arg = self._io.read_bits_int_be(3)
self.value_type = KaitaiStream.resolve_enum(Dex.EncodedValue.ValueTypeEnum, self._io.read_bits_int_be(5))
self._io.align_to_byte()
_on = self.value_type
if _on == Dex.EncodedValue.ValueTypeEnum.int:
self.value = self._io.read_s4le()
elif _on == Dex.EncodedValue.ValueTypeEnum.annotation:
self.value = Dex.EncodedAnnotation(self._io, self, self._root)
elif _on == Dex.EncodedValue.ValueTypeEnum.long:
self.value = self._io.read_s8le()
elif _on == Dex.EncodedValue.ValueTypeEnum.method_handle:
self.value = self._io.read_u4le()
elif _on == Dex.EncodedValue.ValueTypeEnum.byte:
self.value = self._io.read_s1()
elif _on == Dex.EncodedValue.ValueTypeEnum.array:
self.value = Dex.EncodedArray(self._io, self, self._root)
elif _on == Dex.EncodedValue.ValueTypeEnum.method_type:
self.value = self._io.read_u4le()
elif _on == Dex.EncodedValue.ValueTypeEnum.short:
self.value = self._io.read_s2le()
elif _on == Dex.EncodedValue.ValueTypeEnum.method:
self.value = self._io.read_u4le()
elif _on == Dex.EncodedValue.ValueTypeEnum.double:
self.value = self._io.read_f8le()
elif _on == Dex.EncodedValue.ValueTypeEnum.float:
self.value = self._io.read_f4le()
elif _on == Dex.EncodedValue.ValueTypeEnum.type:
self.value = self._io.read_u4le()
elif _on == Dex.EncodedValue.ValueTypeEnum.enum:
self.value = self._io.read_u4le()
elif _on == Dex.EncodedValue.ValueTypeEnum.field:
self.value = self._io.read_u4le()
elif _on == Dex.EncodedValue.ValueTypeEnum.string:
self.value = self._io.read_u4le()
elif _on == Dex.EncodedValue.ValueTypeEnum.char:
self.value = self._io.read_u2le()
class CallSiteIdItem(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.call_site_off = self._io.read_u4le()
class MethodIdItem(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.class_idx = self._io.read_u2le()
self.proto_idx = self._io.read_u2le()
self.name_idx = self._io.read_u4le()
@property
def class_name(self):
"""the definer of this method."""
if hasattr(self, '_m_class_name'):
return self._m_class_name if hasattr(self, '_m_class_name') else None
self._m_class_name = self._root.type_ids[self.class_idx].type_name
return self._m_class_name if hasattr(self, '_m_class_name') else None
@property
def proto_desc(self):
"""the short-form descriptor of the prototype of this method."""
if hasattr(self, '_m_proto_desc'):
return self._m_proto_desc if hasattr(self, '_m_proto_desc') else None
self._m_proto_desc = self._root.proto_ids[self.proto_idx].shorty_desc
return self._m_proto_desc if hasattr(self, '_m_proto_desc') else None
@property
def proto_id(self):
return self._root.proto_ids[self.proto_idx]
@property
def method_name(self):
"""the name of this method."""
if hasattr(self, '_m_method_name'):
return self._m_method_name if hasattr(self, '_m_method_name') else None
self._m_method_name = self._root.string_ids[self.name_idx].value.data
return self._m_method_name if hasattr(self, '_m_method_name') else None
class TypeItem(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.type_idx = self._io.read_u2le()
@property
def value(self):
if hasattr(self, '_m_value'):
return self._m_value if hasattr(self, '_m_value') else None
self._m_value = self._root.type_ids[self.type_idx].type_name
return self._m_value if hasattr(self, '_m_value') else None
class TypeIdItem(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.descriptor_idx = self._io.read_u4le()
@property
def type_name(self):
if hasattr(self, '_m_type_name'):
return self._m_type_name if hasattr(self, '_m_type_name') else None
self._m_type_name = self._root.string_ids[self.descriptor_idx].value.data
return self._m_type_name if hasattr(self, '_m_type_name') else None
class AnnotationElement(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.name_idx = vlq_base128_le.VlqBase128Le(self._io)
self.value = Dex.EncodedValue(self._io, self, self._root)
class EncodedField(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.field_idx_diff = vlq_base128_le.VlqBase128Le(self._io)
self.access_flags = vlq_base128_le.VlqBase128Le(self._io)
class EncodedArrayItem(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.value = Dex.EncodedArray(self._io, self, self._root)
class ClassDataItem(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.static_fields_size = vlq_base128_le.VlqBase128Le(self._io)
self.instance_fields_size = vlq_base128_le.VlqBase128Le(self._io)
self.direct_methods_size = vlq_base128_le.VlqBase128Le(self._io)
self.virtual_methods_size = vlq_base128_le.VlqBase128Le(self._io)
self.static_fields = [None] * (self.static_fields_size.value)
for i in range(self.static_fields_size.value):
self.static_fields[i] = Dex.EncodedField(self._io, self, self._root)
self.instance_fields = [None] * (self.instance_fields_size.value)
for i in range(self.instance_fields_size.value):
self.instance_fields[i] = Dex.EncodedField(self._io, self, self._root)
self.direct_methods = [None] * (self.direct_methods_size.value)
for i in range(self.direct_methods_size.value):
self.direct_methods[i] = Dex.EncodedMethod(self._io, self, self._root)
self.virtual_methods = [None] * (self.virtual_methods_size.value)
for i in range(self.virtual_methods_size.value):
self.virtual_methods[i] = Dex.EncodedMethod(self._io, self, self._root)
class FieldIdItem(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.class_idx = self._io.read_u2le()
self.type_idx = self._io.read_u2le()
self.name_idx = self._io.read_u4le()
@property
def class_name(self):
"""the definer of this field."""
if hasattr(self, '_m_class_name'):
return self._m_class_name if hasattr(self, '_m_class_name') else None
self._m_class_name = self._root.type_ids[self.class_idx].type_name
return self._m_class_name if hasattr(self, '_m_class_name') else None
@property
def type_name(self):
"""the type of this field."""
if hasattr(self, '_m_type_name'):
return self._m_type_name if hasattr(self, '_m_type_name') else None
self._m_type_name = self._root.type_ids[self.type_idx].type_name
return self._m_type_name if hasattr(self, '_m_type_name') else None
@property
def field_name(self):
"""the name of this field."""
if hasattr(self, '_m_field_name'):
return self._m_field_name if hasattr(self, '_m_field_name') else None
self._m_field_name = self._root.string_ids[self.name_idx].value.data
return self._m_field_name if hasattr(self, '_m_field_name') else None
class EncodedAnnotation(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.type_idx = vlq_base128_le.VlqBase128Le(self._io)
self.size = vlq_base128_le.VlqBase128Le(self._io)
self.elements = [None] * (self.size.value)
for i in range(self.size.value):
self.elements[i] = Dex.AnnotationElement(self._io, self, self._root)
class ClassDefItem(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.class_idx = self._io.read_u4le()
self.access_flags = KaitaiStream.resolve_enum(Dex.ClassAccessFlags, self._io.read_u4le())
self.superclass_idx = self._io.read_u4le()
self.interfaces_off = self._io.read_u4le()
self.source_file_idx = self._io.read_u4le()
self.annotations_off = self._io.read_u4le()
self.class_data_off = self._io.read_u4le()
self.static_values_off = self._io.read_u4le()
@property
def type_name(self):
if hasattr(self, '_m_type_name'):
return self._m_type_name if hasattr(self, '_m_type_name') else None
self._m_type_name = self._root.type_ids[self.class_idx].type_name
return self._m_type_name if hasattr(self, '_m_type_name') else None
@property
def class_data(self):
if hasattr(self, '_m_class_data'):
return self._m_class_data if hasattr(self, '_m_class_data') else None
if self.class_data_off != 0:
_pos = self._io.pos()
self._io.seek(self.class_data_off)
self._m_class_data = Dex.ClassDataItem(self._io, self, self._root)
self._io.seek(_pos)
return self._m_class_data if hasattr(self, '_m_class_data') else None
@property
def static_values(self):
if hasattr(self, '_m_static_values'):
return self._m_static_values if hasattr(self, '_m_static_values') else None
if self.static_values_off != 0:
_pos = self._io.pos()
self._io.seek(self.static_values_off)
self._m_static_values = Dex.EncodedArrayItem(self._io, self, self._root)
self._io.seek(_pos)
return self._m_static_values if hasattr(self, '_m_static_values') else None
class TypeList(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.size = self._io.read_u4le()
self.list = [None] * (self.size)
for i in range(self.size):
self.list[i] = Dex.TypeItem(self._io, self, self._root)
class StringIdItem(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.string_data_off = self._io.read_u4le()
class StringDataItem(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.utf16_size = vlq_base128_le.VlqBase128Le(self._io)
byte = self._io.read_bytes(1)
self.raw_data = b''
#read until we hit a null byte, since the utf16 size does not corespond to the actual string size
while byte != b'\x00':
self.raw_data += byte
byte = self._io.read_bytes(1)
self.data = self.raw_data.decode(u"utf-8", "replace")
@property
def value(self):
if hasattr(self, '_m_value'):
return self._m_value if hasattr(self, '_m_value') else None
_pos = self._io.pos()
self._io.seek(self.string_data_off)
self._m_value = Dex.StringIdItem.StringDataItem(self._io, self, self._root)
self._io.seek(_pos)
return self._m_value if hasattr(self, '_m_value') else None
class ProtoIdItem(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.shorty_idx = self._io.read_u4le()
self.return_type_idx = self._io.read_u4le()
self.parameters_off = self._io.read_u4le()
@property
def shorty_desc(self):
"""short-form descriptor string of this prototype, as pointed to by shorty_idx."""
if hasattr(self, '_m_shorty_desc'):
return self._m_shorty_desc if hasattr(self, '_m_shorty_desc') else None
self._m_shorty_desc = self._root.string_ids[self.shorty_idx].value.data
return self._m_shorty_desc if hasattr(self, '_m_shorty_desc') else None
@property
def params_types(self):
"""list of parameter types for this prototype."""
if hasattr(self, '_m_params_types'):
return self._m_params_types if hasattr(self, '_m_params_types') else None
if self.parameters_off != 0:
io = self._root._io
_pos = io.pos()
io.seek(self.parameters_off)
self._m_params_types = Dex.TypeList(io, self, self._root)
io.seek(_pos)
return self._m_params_types if hasattr(self, '_m_params_types') else None
@property
def return_type(self):
"""return type of this prototype."""
if hasattr(self, '_m_return_type'):
return self._m_return_type if hasattr(self, '_m_return_type') else None
self._m_return_type = self._root.type_ids[self.return_type_idx].type_name
return self._m_return_type if hasattr(self, '_m_return_type') else None
class EncodedMethod(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.method_idx_diff = vlq_base128_le.VlqBase128Le(self._io)
self.access_flags = vlq_base128_le.VlqBase128Le(self._io)
self.code_off = vlq_base128_le.VlqBase128Le(self._io)
class MapItem(KaitaiStruct):
class MapItemType(Enum):
header_item = 0
string_id_item = 1
type_id_item = 2
proto_id_item = 3
field_id_item = 4
method_id_item = 5
class_def_item = 6
call_site_id_item = 7
method_handle_item = 8
map_list = 4096
type_list = 4097
annotation_set_ref_list = 4098
annotation_set_item = 4099
class_data_item = 8192
code_item = 8193
string_data_item = 8194
debug_info_item = 8195
annotation_item = 8196
encoded_array_item = 8197
annotations_directory_item = 8198
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.type = KaitaiStream.resolve_enum(Dex.MapItem.MapItemType, self._io.read_u2le())
self.unused = self._io.read_u2le()
self.size = self._io.read_u4le()
self.offset = self._io.read_u4le()
class EncodedArray(KaitaiStruct):
def __init__(self, _io, _parent=None, _root=None):
self._io = _io
self._parent = _parent
self._root = _root if _root else self
self._read()
def _read(self):
self.size = vlq_base128_le.VlqBase128Le(self._io)
self.values = [None] * (self.size.value)
for i in range(self.size.value):
self.values[i] = Dex.EncodedValue(self._io, self, self._root)
@property
def string_ids(self):
"""string identifiers list.
These are identifiers for all the strings used by this file, either for
internal naming (e.g., type descriptors) or as constant objects referred to by code.
This list must be sorted by string contents, using UTF-16 code point values
(not in a locale-sensitive manner), and it must not contain any duplicate entries.
"""
if hasattr(self, '_m_string_ids'):
return self._m_string_ids if hasattr(self, '_m_string_ids') else None
_pos = self._io.pos()
self._io.seek(self.header.string_ids_off)
self._m_string_ids = [None] * (self.header.string_ids_size)
for i in range(self.header.string_ids_size):
self._m_string_ids[i] = Dex.StringIdItem(self._io, self, self._root)
self._io.seek(_pos)
return self._m_string_ids if hasattr(self, '_m_string_ids') else None
@property
def method_ids(self) -> List[MethodIdItem]:
"""method identifiers list.
These are identifiers for all methods referred to by this file,
whether defined in the file or not.
This list must be sorted, where the defining type (by type_id index
is the major order, method name (by string_id index) is the intermediate
order, and method prototype (by proto_id index) is the minor order.
The list must not contain any duplicate entries.
"""
if hasattr(self, '_m_method_ids'):
return self._m_method_ids if hasattr(self, '_m_method_ids') else None
_pos = self._io.pos()
self._io.seek(self.header.method_ids_off)
self._m_method_ids = [None] * (self.header.method_ids_size)
for i in range(self.header.method_ids_size):
self._m_method_ids[i] = Dex.MethodIdItem(self._io, self, self._root)
self._io.seek(_pos)
return self._m_method_ids if hasattr(self, '_m_method_ids') else None
@property
def link_data(self) -> bytes:
"""data used in statically linked files.
The format of the data in this section is left unspecified by this document.
This section is empty in unlinked files, and runtime implementations may
use it as they see fit.
"""
if hasattr(self, '_m_link_data'):
return self._m_link_data if hasattr(self, '_m_link_data') else None
_pos = self._io.pos()
self._io.seek(self.header.link_off)
self._m_link_data = self._io.read_bytes(self.header.link_size)
self._io.seek(_pos)
return self._m_link_data if hasattr(self, '_m_link_data') else None
@property
def map(self):
if hasattr(self, '_m_map'):
return self._m_map if hasattr(self, '_m_map') else None
_pos = self._io.pos()
self._io.seek(self.header.map_off)
self._m_map = Dex.MapList(self._io, self, self._root)
self._io.seek(_pos)
return self._m_map if hasattr(self, '_m_map') else None
@property
def class_defs(self) -> List[ClassDefItem]:
"""class definitions list.
The classes must be ordered such that a given class's superclass and
implemented interfaces appear in the list earlier than the referring class.
Furthermore, it is invalid for a definition for the same-named class to
appear more than once in the list.
"""
if hasattr(self, '_m_class_defs'):
return self._m_class_defs if hasattr(self, '_m_class_defs') else None
_pos = self._io.pos()
self._io.seek(self.header.class_defs_off)
self._m_class_defs = [None] * (self.header.class_defs_size)
for i in range(self.header.class_defs_size):
self._m_class_defs[i] = Dex.ClassDefItem(self._io, self, self._root)
self._io.seek(_pos)
return self._m_class_defs if hasattr(self, '_m_class_defs') else None
@property
def data(self) -> bytes:
"""data area, containing all the support data for the tables listed above.
Different items have different alignment requirements, and padding bytes
are inserted before each item if necessary to achieve proper alignment.
"""
if hasattr(self, '_m_data'):
return self._m_data if hasattr(self, '_m_data') else None
_pos = self._io.pos()
self._io.seek(self.header.data_off)
self._m_data = self._io.read_bytes(self.header.data_size)
self._io.seek(_pos)
return self._m_data if hasattr(self, '_m_data') else None
@property
def type_ids(self) -> List[TypeIdItem]:
"""type identifiers list.
These are identifiers for all types (classes, arrays, or primitive types)
referred to by this file, whether defined in the file or not.
This list must be sorted by string_id index, and it must not contain any duplicate entries.
"""
if hasattr(self, '_m_type_ids'):
return self._m_type_ids if hasattr(self, '_m_type_ids') else None
_pos = self._io.pos()
self._io.seek(self.header.type_ids_off)
self._m_type_ids = [None] * (self.header.type_ids_size)
for i in range(self.header.type_ids_size):
self._m_type_ids[i] = Dex.TypeIdItem(self._io, self, self._root)
self._io.seek(_pos)
return self._m_type_ids if hasattr(self, '_m_type_ids') else None
@property
def proto_ids(self) -> List[ProtoIdItem]:
"""method prototype identifiers list.
These are identifiers for all prototypes referred to by this file.
This list must be sorted in return-type (by type_id index) major order,
and then by argument list (lexicographic ordering, individual arguments
ordered by type_id index). The list must not contain any duplicate entries.
"""
if hasattr(self, '_m_proto_ids'):
return self._m_proto_ids if hasattr(self, '_m_proto_ids') else None
_pos = self._io.pos()
self._io.seek(self.header.proto_ids_off)
self._m_proto_ids = [None] * (self.header.proto_ids_size)
for i in range(self.header.proto_ids_size):
self._m_proto_ids[i] = Dex.ProtoIdItem(self._io, self, self._root)
self._io.seek(_pos)
return self._m_proto_ids if hasattr(self, '_m_proto_ids') else None
@property
def field_ids(self) -> List[FieldIdItem]:
"""field identifiers list.
These are identifiers for all fields referred to by this file, whether defined in the file or not.
This list must be sorted, where the defining type (by type_id index)
is the major order, field name (by string_id index) is the intermediate
order, and type (by type_id index) is the minor order.
The list must not contain any duplicate entries.
"""
if hasattr(self, '_m_field_ids'):
return self._m_field_ids if hasattr(self, '_m_field_ids') else None
_pos = self._io.pos()
self._io.seek(self.header.field_ids_off)
self._m_field_ids = [None] * (self.header.field_ids_size)
for i in range(self.header.field_ids_size):
self._m_field_ids[i] = Dex.FieldIdItem(self._io, self, self._root)
self._io.seek(_pos)
return self._m_field_ids if hasattr(self, '_m_field_ids') else None