-
Notifications
You must be signed in to change notification settings - Fork 0
/
dexparser.h
241 lines (213 loc) · 5.18 KB
/
dexparser.h
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
#include <stdio.h>
#include <stdint.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#define TRUE 1
#define FALSE 0
#define HEADER_FRONT 11
#define NO_INDEX 0xffffffff
#define ENDIAN_CONSTANT 0x12345678
#define REVERSE_ENDIAN_CONSTANT 0x78563412
enum access_flags{
ACC_PUBLIC = 0x1,
ACC_PRIVATE = 0x2,
ACC_PROTECTED = 0x4,
ACC_STATIC = 0x8,
ACC_FINAL = 0x10,
ACC_SYNCHRONIZED = 0x20,
ACC_VOLATILE = 0x40,
ACC_BRIDGE = 0x40,
ACC_TRANSIENT = 0x80,
ACC_VARARGS = 0x80,
ACC_NATIVE = 0x100,
ACC_INTERFACE = 0x200,
ACC_ABSTRACT = 0x400,
ACC_STRICT = 0x800,
ACC_SYNTHETIC = 0x1000,
ACC_ANNOTATION = 0x2000,
ACC_ENUM = 0x4000,
unused = 0x8000,
ACC_CONSTRUCTOR = 0x10000,
ACC_DECLARED_SYNCHRONIZED = 0x20000,
};
enum type_codes{
TYPE_HEADER_ITEM = 0x0000,
TYPE_STRING_ID_ITEM = 0x0001,
TYPE_TYPE_ID_ITEM = 0x0002,
TYPE_PROTO_ID_ITEM = 0x0003,
TYPE_FIELD_ID_ITEM = 0x0004,
TYPE_METHOD_ID_ITEM = 0x0005,
TYPE_CLASS_DEF_ITEM = 0x0006,
TYPE_CALL_SITE_ID_ITEM = 0x0007,
TYPE_METHOD_HANDLE_ITEM = 0x0008,
TYPE_MAP_LIST = 0x1000,
TYPE_TYPE_LIST = 0x1001,
TYPE_ANNOTATION_SET_REF_LIST = 0x1002,
TYPE_ANNOTATION_SET_ITEM = 0x1003,
TYPE_CLASS_DATA_ITEM = 0x2000,
TYPE_CODE_ITEM = 0x2001,
TYPE_STRING_DATA_ITEM = 0x2002,
TYPE_DEBUG_INFO_ITEM = 0x2003,
TYPE_ANNOTATION_ITEM = 0x2004,
TYPE_ENCODED_ARRAY_ITEM = 0x2005,
TYPE_ANNOTATIONS_DIRECTORY_ITEM = 0x2006,
};
typedef uint8_t uleb128;
typedef struct header_item{
uint8_t magic[8];
uint32_t checksum;
uint8_t signature[20];
uint32_t file_size;
uint32_t header_size;
uint32_t endian_tag;
uint32_t link_size;
uint32_t link_off;
uint32_t map_off;
uint32_t string_ids_size;
uint32_t string_ids_off;
uint32_t type_ids_size;
uint32_t type_ids_off;
uint32_t proto_ids_size;
uint32_t proto_ids_off;
uint32_t field_ids_size;
uint32_t field_ids_off;
uint32_t method_ids_size;
uint32_t method_ids_off;
uint32_t class_defs_size;
uint32_t class_defs_off;
uint32_t data_size;
uint32_t data_off;
} header_item;
typedef struct map_item{
uint16_t type;
uint16_t unused;
uint32_t size;
uint32_t offset;
} map_item;
typedef struct map_list{
uint32_t size;
map_item *pList;
} map_list;
typedef uint32_t string_id_item;
typedef uint32_t type_id_item;
typedef struct proto_id_item{
uint32_t shorty_idx;
uint32_t return_type_idx;
uint32_t parameters_off;
} proto_id_item;
typedef struct field_id_item{
uint16_t class_idx;
uint16_t type_idx;
uint32_t name_idx;
} field_id_item;
typedef struct method_id_item{
uint16_t class_idx;
uint16_t proto_idx;
uint32_t name_idx;
} method_id_item;
typedef struct class_def_item{
uint32_t class_idx;
uint32_t access_flags;
uint32_t superclass_idx;
uint32_t interfaces_off;
uint32_t source_file_idx;
uint32_t annotations_off;
uint32_t class_data_off;
uint32_t static_values_off;
} class_def_item;
typedef struct method_handle_item{
uint16_t method_handle_type;
uint16_t unused;
uint16_t field_or_method_id;
uint16_t unused_2;
} method_handle_item;
typedef struct string_data_item{
// uint32_t string_data_off;
uleb128 utf16_size;
uint8_t *data;
} string_data_item;
typedef uint16_t type_item;
typedef struct type_list{
uint32_t size;
type_item *list;
} type_list;
typedef struct parameter_annotation{
uint32_t method_idx;
uint32_t annotations_off;
} param_anot;
typedef struct method_annotation{
uint32_t method_idx;
uint32_t annotations_off;
} method_anot;
typedef struct field_annotation{
uint32_t field_idx;
uint32_t annotations_off;
} field_anot;
typedef struct annotations_directory_item{
uint32_t class_annotations_off;
uint32_t fields_size;
uint32_t annotated_methods_size;
uint32_t annotated_parameters_size;
field_anot *field_annotations;
method_anot *method_annotations;
param_anot *parameter_annotations;
} anot_dir_item;
// need to learn about uleb128
typedef struct encoded_field{
uleb128 field_idx_diff;
uleb128 access_flags;
} encoded_field;
typedef struct encoded_method{
uleb128 method_idx_diff;
uleb128 access_flags;
uleb128 code_off;
} encoded_method;
typedef struct class_data_item{
uleb128 static_fields_size;
uleb128 instance_fields_size;
uleb128 direct_methods_size;
uleb128 virtual_methods_size;
encoded_field *static_fields;
encoded_field *instance_fields;
encoded_method *direct_methods;
encoded_method *virtual_methods;
} class_data_item;
typedef struct encoded_value{
uint8_t value_type;
uint8_t *value;
} encoded_value;
typedef struct annotation_element{
uleb128 name_idx;
encoded_value value;
} annotation_element;
typedef struct pChunk_item{
uint32_t *pLink;
string_id_item *pString_data_off;
uint32_t *pMap;
uint32_t *pType_ids;
proto_id_item *pProto_ids;
field_id_item *pField_ids;
method_id_item *pMethod_ids;
class_def_item *pClass_defs;
uint32_t *pData;
} pChunk_item;
typedef struct file_layout{
header_item *pHeader;
map_list mapList;
uint32_t *pLink;
string_id_item *pString_ids;
type_id_item *pType_ids;
type_list typeList;
proto_id_item *pProto_ids;
field_id_item *pField_ids;
method_id_item *pMethod_ids;
class_def_item *pClass_defs;
method_handle_item *pMethod_handles;
uint8_t *pDdata;
uint8_t *pLink_data;
anot_dir_item *pAnotDir;
} file_layout;
//file_layout *pFileLayout;
header_item *pHeader;
map_list map;