annotate paraspace/dexfile.py @ 1:05346b632adb

Parse records mentioned in file header
author Thinker K.F. Li <thinker@codemud.net>
date Sun, 22 May 2011 02:16:20 +0800
parents 31050a971b52
children add64d56b0e2
rev   line source
0
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1 class _DEX_header(object):
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
2 magic = None # 0x00, 8 bytes
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
3 checksum = None # 0x08, 4 bytes
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
4 signature = None # 0x0c, 20 bytes
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
5 fileSize = None # 0x20, 4 bytes
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
6 headerSize = None # 0x24
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
7 endianTag = None # 0x28
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
8 linkSize = None # 0x2c
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
9 linkOff = None # 0x30
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
10 mapOff = None # 0x34
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
11 stringIdsSize = None # 0x38
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
12 stringIdsOff = None # 0x3c
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
13 typeIdsSize = None # 0x40
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
14 typeIdsOff = None # 0x44
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
15 protoIdsSize = None # 0x48
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
16 protoIdsOff = None # 0x4c
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
17 fieldIdsSize = None # 0x50
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
18 fieldIdsOff = None # 0x54
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
19 methodIdsSize = None # 0x58
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
20 methodIdsOff = None # 0x5c
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
21 classDefsSize = None # 0x60
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
22 classDefsOff = None # 0x64
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
23 dataSize = None # 0x68
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
24 dataOff = None # 0x6c
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
25
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
26 def parse(self, data):
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
27 self.magic = data[:8]
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
28 self.checksum = data[8: 0x0c]
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
29 self.signature = data[0x0c: 0x20]
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
30
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
31 idx = 0x20
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
32 fields = 'fileSize headerSize endianTag linkSize linkOff mapOff ' \
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
33 'stringIdsSize stringIdsOff typeIdsSize typeIdsOff ' \
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
34 'protoIdsSize protoIdsOff fieldIdsSize fieldIdsOff ' \
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
35 'methodIdsSize methodIdsOff classDefsSize classDefsOff ' \
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
36 'dataSize dataOff'.split()
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
37 for field in fields:
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
38 d = data[idx: idx + 4]
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
39 value = _to_uint(d)
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
40 setattr(self, field, value)
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
41 idx = idx + 4
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
42 pass
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
43 pass
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
44 pass
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
45
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
46
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
47 def _to_uint(data):
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
48 v = 0
1
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
49 sh = 0
0
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
50 for c in data:
1
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
51 v = v + (ord(c) << sh)
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
52 sh = sh + 8
0
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
53 pass
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
54 return v
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
55
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
56
1
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
57 def _uleb128(data):
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
58 sh = 0
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
59 v = 0
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
60 for c in data:
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
61 cv = ord(c)
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
62 v = v + ((cv & 0x7f) << sh)
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
63 sh = sh + 7
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
64
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
65 if cv <= 0x7f:
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
66 break
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
67 pass
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
68
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
69 nbytes = sh / 7
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
70 return v, nbytes
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
71
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
72
0
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
73 class _DEX_MapItem(object):
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
74 type = None # 2 bytes
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
75 unused = None # 2 bytes
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
76 size = None # 4 bytes
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
77 offset = None # 4 bytes
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
78
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
79 data_size = 12
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
80
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
81 def parse(self, data):
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
82 self.type = _to_uint(data[:2])
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
83 self.size = _to_uint(data[4:8])
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
84 self.offset = _to_uint(data[8:12])
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
85 pass
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
86 pass
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
87
1
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
88
0
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
89 class _DEX_TypeId(object):
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
90 descriptorIdx = None # 4 bytes
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
91
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
92 data_size = 4
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
93
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
94 def parse(self, data):
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
95 self.descriptorIdx = _to_uint(data[:4])
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
96 pass
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
97 pass
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
98
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
99
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
100 class _DEX_ProtoId(object):
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
101 shortyIdx = None # 4 bytes
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
102 returnTypeIdx = None # 4 bytes
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
103 parametersOff = None # 4 bytes
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
104
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
105 data_size = 12
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
106
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
107 def parse(self, data):
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
108 self.shortyIdx = _to_uint(data[:4])
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
109 self.returnTypeIdx = _to_uint(data[4:8])
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
110 self.parametersOff = _to_uint(data[8:12])
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
111 pass
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
112 pass
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
113
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
114
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
115 class _DEX_FieldId(object):
1
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
116 classIdx = None # 2 bytes
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
117 typeIdx = None # 2 bytes
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
118 nameIdx = None # 4 bytes
0
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
119
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
120 data_size = 8
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
121
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
122 def parse(self, data):
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
123 self.classIdx = _to_uint(data[:2])
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
124 self.typeIdx = _to_uint(data[2:4])
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
125 self.nameIdx = _to_uint(data[4:8])
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
126 pass
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
127 pass
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
128
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
129
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
130 class _DEX_MethodId(object):
1
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
131 classIdx = None # 2 bytes
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
132 protoIdx = None # 2 bytes
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
133 nameIdx = None # 4 bytes
0
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
134
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
135 data_size = 8
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
136
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
137 def parse(self, data):
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
138 self.classIdx = _to_uint(data[:2])
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
139 self.protoIdx = _to_uint(data[2:4])
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
140 self.nameIdx = _to_uint(data[4:8])
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
141 pass
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
142 pass
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
143
1
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
144
0
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
145 class _DEX_ClassDef(object):
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
146 classIdx = None # 0x00
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
147 accessFlags = None # 0x04
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
148 superclassIdx = None # 0x08
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
149 interfacesOff = None # 0x0c
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
150 sourceFileIdx = None # 0x10
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
151 annotationsOff = None # 0x14
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
152 classDataOff = None # 0x18
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
153 staticValuesOff = None # 0x1c
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
154
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
155 data_size = 0x20
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
156
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
157 def parse(self, data):
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
158 self.classIdx = _to_uint(data[:4])
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
159 self.accessFlags = _to_uint(data[4:8])
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
160 self.superclassIdx = _to_uint(data[8:0xc])
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
161 self.interfacesOff = _to_uint(data[0xc:0x10])
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
162 self.sourceFileIdx = _to_uint(data[0x10:0x14])
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
163 self.annotationsOff = _to_uint(data[0x14:0x18])
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
164 self.classDataOff = _to_uint(data[0x18:0x1c])
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
165 self.staticValuesOff = _to_uint(data[0x1c:0x20])
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
166 pass
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
167 pass
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
168
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
169
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
170 class DEXFile(object):
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
171 _data = None
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
172 _header = None
1
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
173 _maps = None
0
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
174 _strings = None
1
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
175 _typeIds = None
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
176 _protoIds = None
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
177 _fieldIds = None
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
178 _methodIds = None
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
179 _classDefs = None
0
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
180
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
181 def __init__(self):
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
182 pass
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
183
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
184 def open(self, filename):
1
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
185 fo = file(filename, 'r')
0
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
186 data = fo.read()
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
187
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
188 self.parse(data)
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
189 pass
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
190
1
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
191 def _parse_maps(self):
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
192 data = self._data
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
193 header = self._header
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
194 off = header.mapOff
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
195
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
196 num = _to_uint(data[off:off + 4])
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
197 off = off + 4
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
198
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
199 maps = []
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
200 for i in range(num):
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
201 item_data = data[off:off + _DEX_MapItem.data_size]
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
202 item = _DEX_MapItem()
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
203 item.parse(item_data)
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
204 maps.append(item)
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
205 off = off + _DEX_MapItem.data_size
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
206 pass
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
207
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
208 self._maps = map
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
209 pass
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
210
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
211 def _parse_strings(self):
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
212 data = self._data
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
213 header = self._header
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
214 strings = []
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
215
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
216 num = header.stringIdsSize
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
217 off = header.stringIdsOff
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
218 for i in range(num):
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
219 str_start_off = _to_uint(data[off:off + 4])
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
220 str_stop_off = data.index('\x00', str_start_off)
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
221 string = data[str_start_off:str_stop_off]
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
222
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
223 sz, sh = _uleb128(string)
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
224 string = string[sh:]
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
225 strings.append(string)
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
226 off = off + 4
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
227 pass
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
228
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
229 self._strings = strings
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
230 pass
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
231
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
232 def _parse_typeIds(self):
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
233 data = self._data
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
234 header = self._header
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
235
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
236 num = header.typeIdsSize
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
237 off = header.typeIdsOff
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
238
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
239 def parse(item_data):
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
240 type_id = _DEX_TypeId()
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
241 type_id.parse(item_data)
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
242 return type_id
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
243
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
244 item_size = _DEX_TypeId.data_size
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
245 item_offs = range(off, off + item_size * num, item_size)
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
246 item_datas = [data[item_off:item_off + item_size]
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
247 for item_off in item_offs]
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
248 typeIds = [parse(item_data) for item_data in item_datas]
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
249
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
250 self._typeIds = typeIds
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
251 pass
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
252
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
253 def _parse_protoIds(self):
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
254 data = self._data
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
255 header = self._header
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
256
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
257 num = header.protoIdsSize
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
258 off = header.protoIdsOff
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
259
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
260 def parse(item_data):
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
261 proto_id = _DEX_ProtoId()
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
262 proto_id.parse(item_data)
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
263 return proto_id
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
264
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
265 item_size = _DEX_ProtoId.data_size
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
266 item_offs = range(off, off + item_size * num, item_size)
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
267 item_datas = [data[item_off:item_off + item_size]
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
268 for item_off in item_offs]
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
269 protoIds = [parse(item_data) for item_data in item_datas]
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
270
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
271 self._protoIds = protoIds
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
272 pass
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
273
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
274 def _parse_fieldIds(self):
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
275 data = self._data
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
276 header = self._header
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
277
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
278 num = header.fieldIdsSize
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
279 off = header.fieldIdsOff
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
280
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
281 def parse(item_data):
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
282 field_id = _DEX_FieldId()
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
283 field_id.parse(item_data)
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
284 return field_id
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
285
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
286 item_size = _DEX_FieldId.data_size
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
287 item_offs = range(off, off + item_size * num, item_size)
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
288 item_datas = [data[item_off:item_off + item_size]
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
289 for item_off in item_offs]
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
290 fieldIds = [parse(item_data) for item_data in item_datas]
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
291
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
292 self._fieldIds = fieldIds
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
293 pass
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
294
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
295 def _parse_methodIds(self):
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
296 data = self._data
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
297 header = self._header
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
298
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
299 num = header.methodIdsSize
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
300 off = header.methodIdsOff
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
301
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
302 def parse(item_data):
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
303 method_id = _DEX_MethodId()
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
304 method_id.parse(item_data)
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
305 return method_id
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
306
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
307 item_size = _DEX_MethodId.data_size
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
308 item_offs = range(off, off + item_size * num, item_size)
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
309 item_datas = [data[item_off:item_off + item_size]
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
310 for item_off in item_offs]
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
311 methodIds = [parse(item_data) for item_data in item_datas]
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
312
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
313 self._methodIds = methodIds
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
314 pass
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
315
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
316 def _parse_classDefs(self):
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
317 data = self._data
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
318 header = self._header
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
319
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
320 num = header.classDefsSize
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
321 off = header.classDefsOff
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
322
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
323 def parse(item_data):
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
324 class_def = _DEX_ClassDef()
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
325 class_def.parse(item_data)
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
326 return class_def
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
327
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
328 item_size = _DEX_ClassDef.data_size
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
329 item_offs = range(off, off + item_size * num, item_size)
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
330 item_datas = [data[item_off:item_off + item_size]
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
331 for item_off in item_offs]
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
332 classDefs = [parse(item_data) for item_data in item_datas]
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
333
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
334 self._classDefs = classDefs
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
335 pass
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
336
0
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
337 def parse(self, data):
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
338 self._data = data
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
339 header = _DEX_header()
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
340 header.parse(data)
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
341 self._header = header
1
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
342
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
343 self._parse_maps()
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
344 self._parse_strings()
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
345 self._parse_typeIds()
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
346 self._parse_protoIds()
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
347 self._parse_fieldIds()
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
348 self._parse_methodIds()
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
349 self._parse_classDefs()
0
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
350 pass
31050a971b52 Project ParaSpace
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
351 pass
1
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
352
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
353 if __name__ == '__main__':
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
354 dex = DEXFile()
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
355 dex.open('test.dex')
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
356
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
357 h = dex._header
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
358 for attr in h.__dict__.keys():
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
359 print '%s: %s' % (attr, repr(h.__dict__[attr]))
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
360 pass
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
361
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
362 print
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
363 print 'Define Classes'
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
364 strings = dex._strings
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
365 classDefs = dex._classDefs
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
366 typeIds = dex._typeIds
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
367 for classDef in classDefs:
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
368 typeId = typeIds[classDef.classIdx]
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
369 descriptor = strings[typeId.descriptorIdx]
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
370 print descriptor
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
371 pass
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
372
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
373 print
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
374 print 'Reference Classes'
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
375 for typeId in typeIds:
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
376 descriptor = strings[typeId.descriptorIdx]
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
377 print descriptor
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
378 pass
05346b632adb Parse records mentioned in file header
Thinker K.F. Li <thinker@codemud.net>
parents: 0
diff changeset
379 pass