blob: 58b8e792ee9719e9e65fa68ecbba1d7176e6ad33 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Carl Shapiro1fb86202011-06-27 17:43:13 -070016
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_DEX_FILE_H_
18#define ART_RUNTIME_DEX_FILE_H_
Carl Shapiro1fb86202011-06-27 17:43:13 -070019
Ian Rogers700a4022014-05-19 16:49:03 -070020#include <memory>
Elliott Hughes0c424cb2011-08-26 10:16:25 -070021#include <string>
Brian Carlstrom74eb46a2011-08-02 20:10:14 -070022#include <vector>
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070023
Elliott Hughes07ed66b2012-12-12 18:34:25 -080024#include "base/logging.h"
Ian Rogers03b6eaf2014-10-28 09:34:57 -070025#include "base/value_object.h"
Andreas Gampea5b09a62016-11-17 15:21:22 -080026#include "dex_file_types.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070027#include "globals.h"
Ian Rogers08f753d2012-08-24 14:35:25 -070028#include "invoke_type.h"
Jesse Wilson6bf19152011-09-29 13:12:33 -040029#include "jni.h"
Ian Rogers08f753d2012-08-24 14:35:25 -070030#include "modifiers.h"
Ian Rogers68b56852014-08-29 20:19:11 -070031#include "utf.h"
Carl Shapiro1fb86202011-06-27 17:43:13 -070032
33namespace art {
34
Ian Rogers576ca0c2014-06-06 15:58:22 -070035class MemMap;
Richard Uhler07b3c232015-03-31 15:57:54 -070036class OatDexFile;
Ian Rogersd91d6d62013-09-25 20:26:14 -070037class Signature;
Ian Rogersfc0e94b2013-09-23 23:51:32 -070038class StringPiece;
Brian Carlstroma6cc8932012-01-04 14:44:07 -080039class ZipArchive;
40
Brian Carlstromf615a612011-07-23 12:50:34 -070041class DexFile {
Carl Shapiro1fb86202011-06-27 17:43:13 -070042 public:
Roland Levillain621b5ea2016-05-18 11:41:33 +010043 // First Dex format version supporting default methods.
Alex Lightb55f1ac2016-04-12 15:50:55 -070044 static const uint32_t kDefaultMethodsVersion = 37;
Roland Levillain621b5ea2016-05-18 11:41:33 +010045 // First Dex format version enforcing class definition ordering rules.
46 static const uint32_t kClassDefinitionOrderEnforcedVersion = 37;
47
Ian Rogers13735952014-10-08 12:43:28 -070048 static const uint8_t kDexMagic[];
Narayan Kamath52e66502016-08-01 14:20:31 +010049 static constexpr size_t kNumDexVersions = 3;
Alex Lightc4961812016-03-23 10:20:41 -070050 static constexpr size_t kDexVersionLen = 4;
51 static const uint8_t kDexMagicVersions[kNumDexVersions][kDexVersionLen];
52
Ian Rogers13735952014-10-08 12:43:28 -070053 static constexpr size_t kSha1DigestSize = 20;
54 static constexpr uint32_t kDexEndianConstant = 0x12345678;
Carl Shapiro80d4dde2011-06-28 16:24:07 -070055
Brian Carlstromb7bbba42011-10-13 14:58:47 -070056 // name of the DexFile entry within a zip archive
57 static const char* kClassesDex;
58
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070059 // The value of an invalid index.
60 static const uint32_t kDexNoIndex = 0xFFFFFFFF;
61
Ian Rogers0571d352011-11-03 19:51:38 -070062 // The value of an invalid index.
63 static const uint16_t kDexNoIndex16 = 0xFFFF;
Carl Shapiro1fb86202011-06-27 17:43:13 -070064
Alex Lightc4961812016-03-23 10:20:41 -070065 // The separator character in MultiDex locations.
Andreas Gampe833a4852014-05-21 18:46:59 -070066 static constexpr char kMultiDexSeparator = ':';
67
68 // A string version of the previous. This is a define so that we can merge string literals in the
69 // preprocessor.
70 #define kMultiDexSeparatorString ":"
71
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070072 // Raw header_item.
73 struct Header {
74 uint8_t magic_[8];
Brian Carlstrom7934ac22013-07-26 10:54:15 -070075 uint32_t checksum_; // See also location_checksum_
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070076 uint8_t signature_[kSha1DigestSize];
jeffhaof6174e82012-01-31 16:14:17 -080077 uint32_t file_size_; // size of entire file
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070078 uint32_t header_size_; // offset to start of next section
79 uint32_t endian_tag_;
Ian Rogers0571d352011-11-03 19:51:38 -070080 uint32_t link_size_; // unused
81 uint32_t link_off_; // unused
82 uint32_t map_off_; // unused
83 uint32_t string_ids_size_; // number of StringIds
84 uint32_t string_ids_off_; // file offset of StringIds array
85 uint32_t type_ids_size_; // number of TypeIds, we don't support more than 65535
86 uint32_t type_ids_off_; // file offset of TypeIds array
87 uint32_t proto_ids_size_; // number of ProtoIds, we don't support more than 65535
88 uint32_t proto_ids_off_; // file offset of ProtoIds array
89 uint32_t field_ids_size_; // number of FieldIds
90 uint32_t field_ids_off_; // file offset of FieldIds array
91 uint32_t method_ids_size_; // number of MethodIds
92 uint32_t method_ids_off_; // file offset of MethodIds array
93 uint32_t class_defs_size_; // number of ClassDefs
94 uint32_t class_defs_off_; // file offset of ClassDef array
95 uint32_t data_size_; // unused
96 uint32_t data_off_; // unused
Elliott Hughesa21039c2012-06-21 12:09:25 -070097
Andreas Gampe76ed99d2016-03-28 18:31:29 -070098 // Decode the dex magic version
99 uint32_t GetVersion() const;
100
Brian Carlstromd2fbb2b2011-08-23 11:57:08 -0700101 private:
102 DISALLOW_COPY_AND_ASSIGN(Header);
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700103 };
Carl Shapiro1fb86202011-06-27 17:43:13 -0700104
jeffhao10037c82012-01-23 15:06:23 -0800105 // Map item type codes.
Orion Hodson12f4ff42017-01-13 16:43:12 +0000106 enum MapItemType : uint16_t { // private
jeffhao10037c82012-01-23 15:06:23 -0800107 kDexTypeHeaderItem = 0x0000,
108 kDexTypeStringIdItem = 0x0001,
109 kDexTypeTypeIdItem = 0x0002,
110 kDexTypeProtoIdItem = 0x0003,
111 kDexTypeFieldIdItem = 0x0004,
112 kDexTypeMethodIdItem = 0x0005,
113 kDexTypeClassDefItem = 0x0006,
Orion Hodson12f4ff42017-01-13 16:43:12 +0000114 kDexTypeCallSiteIdItem = 0x0007,
115 kDexTypeMethodHandleItem = 0x0008,
jeffhao10037c82012-01-23 15:06:23 -0800116 kDexTypeMapList = 0x1000,
117 kDexTypeTypeList = 0x1001,
118 kDexTypeAnnotationSetRefList = 0x1002,
119 kDexTypeAnnotationSetItem = 0x1003,
120 kDexTypeClassDataItem = 0x2000,
121 kDexTypeCodeItem = 0x2001,
122 kDexTypeStringDataItem = 0x2002,
123 kDexTypeDebugInfoItem = 0x2003,
124 kDexTypeAnnotationItem = 0x2004,
125 kDexTypeEncodedArrayItem = 0x2005,
126 kDexTypeAnnotationsDirectoryItem = 0x2006,
127 };
128
129 struct MapItem {
130 uint16_t type_;
131 uint16_t unused_;
132 uint32_t size_;
133 uint32_t offset_;
Elliott Hughesa21039c2012-06-21 12:09:25 -0700134
jeffhao10037c82012-01-23 15:06:23 -0800135 private:
136 DISALLOW_COPY_AND_ASSIGN(MapItem);
137 };
138
139 struct MapList {
140 uint32_t size_;
141 MapItem list_[1];
Elliott Hughesa21039c2012-06-21 12:09:25 -0700142
jeffhao10037c82012-01-23 15:06:23 -0800143 private:
144 DISALLOW_COPY_AND_ASSIGN(MapList);
145 };
146
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700147 // Raw string_id_item.
148 struct StringId {
149 uint32_t string_data_off_; // offset in bytes from the base address
Elliott Hughesa21039c2012-06-21 12:09:25 -0700150
Brian Carlstromd2fbb2b2011-08-23 11:57:08 -0700151 private:
152 DISALLOW_COPY_AND_ASSIGN(StringId);
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700153 };
154
155 // Raw type_id_item.
156 struct TypeId {
Andreas Gampe8a0128a2016-11-28 07:38:35 -0800157 dex::StringIndex descriptor_idx_; // index into string_ids
Elliott Hughesa21039c2012-06-21 12:09:25 -0700158
Brian Carlstromd2fbb2b2011-08-23 11:57:08 -0700159 private:
160 DISALLOW_COPY_AND_ASSIGN(TypeId);
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700161 };
162
163 // Raw field_id_item.
164 struct FieldId {
Andreas Gampe8a0128a2016-11-28 07:38:35 -0800165 dex::TypeIndex class_idx_; // index into type_ids_ array for defining class
166 dex::TypeIndex type_idx_; // index into type_ids_ array for field type
167 dex::StringIndex name_idx_; // index into string_ids_ array for field name
Elliott Hughesa21039c2012-06-21 12:09:25 -0700168
Brian Carlstromd2fbb2b2011-08-23 11:57:08 -0700169 private:
170 DISALLOW_COPY_AND_ASSIGN(FieldId);
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700171 };
172
Andreas Gampea5b09a62016-11-17 15:21:22 -0800173 // Raw proto_id_item.
174 struct ProtoId {
Andreas Gampe8a0128a2016-11-28 07:38:35 -0800175 dex::StringIndex shorty_idx_; // index into string_ids array for shorty descriptor
Andreas Gampea5b09a62016-11-17 15:21:22 -0800176 dex::TypeIndex return_type_idx_; // index into type_ids array for return type
Andreas Gampe8a0128a2016-11-28 07:38:35 -0800177 uint16_t pad_; // padding = 0
178 uint32_t parameters_off_; // file offset to type_list for parameter types
Andreas Gampea5b09a62016-11-17 15:21:22 -0800179
180 private:
181 DISALLOW_COPY_AND_ASSIGN(ProtoId);
182 };
183
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700184 // Raw method_id_item.
185 struct MethodId {
Andreas Gampea5b09a62016-11-17 15:21:22 -0800186 dex::TypeIndex class_idx_; // index into type_ids_ array for defining class
Andreas Gampe8a0128a2016-11-28 07:38:35 -0800187 uint16_t proto_idx_; // index into proto_ids_ array for method prototype
188 dex::StringIndex name_idx_; // index into string_ids_ array for method name
Elliott Hughesa21039c2012-06-21 12:09:25 -0700189
Brian Carlstromd2fbb2b2011-08-23 11:57:08 -0700190 private:
191 DISALLOW_COPY_AND_ASSIGN(MethodId);
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700192 };
193
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700194 // Raw class_def_item.
195 struct ClassDef {
Andreas Gampea5b09a62016-11-17 15:21:22 -0800196 dex::TypeIndex class_idx_; // index into type_ids_ array for this class
Ian Rogers0571d352011-11-03 19:51:38 -0700197 uint16_t pad1_; // padding = 0
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700198 uint32_t access_flags_;
Andreas Gampea5b09a62016-11-17 15:21:22 -0800199 dex::TypeIndex superclass_idx_; // index into type_ids_ array for superclass
Ian Rogers0571d352011-11-03 19:51:38 -0700200 uint16_t pad2_; // padding = 0
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700201 uint32_t interfaces_off_; // file offset to TypeList
Andreas Gampe8a0128a2016-11-28 07:38:35 -0800202 dex::StringIndex source_file_idx_; // index into string_ids_ for source file name
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700203 uint32_t annotations_off_; // file offset to annotations_directory_item
204 uint32_t class_data_off_; // file offset to class_data_item
205 uint32_t static_values_off_; // file offset to EncodedArray
Elliott Hughesa21039c2012-06-21 12:09:25 -0700206
Andreas Gampe51829322014-08-25 15:05:04 -0700207 // Returns the valid access flags, that is, Java modifier bits relevant to the ClassDef type
208 // (class or interface). These are all in the lower 16b and do not contain runtime flags.
209 uint32_t GetJavaAccessFlags() const {
210 // Make sure that none of our runtime-only flags are set.
Andreas Gampe575e78c2014-11-03 23:41:03 -0800211 static_assert((kAccValidClassFlags & kAccJavaFlagsMask) == kAccValidClassFlags,
212 "Valid class flags not a subset of Java flags");
213 static_assert((kAccValidInterfaceFlags & kAccJavaFlagsMask) == kAccValidInterfaceFlags,
214 "Valid interface flags not a subset of Java flags");
Andreas Gampe51829322014-08-25 15:05:04 -0700215
216 if ((access_flags_ & kAccInterface) != 0) {
217 // Interface.
218 return access_flags_ & kAccValidInterfaceFlags;
219 } else {
220 // Class.
221 return access_flags_ & kAccValidClassFlags;
222 }
223 }
224
Brian Carlstromd2fbb2b2011-08-23 11:57:08 -0700225 private:
226 DISALLOW_COPY_AND_ASSIGN(ClassDef);
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700227 };
228
229 // Raw type_item.
230 struct TypeItem {
Andreas Gampea5b09a62016-11-17 15:21:22 -0800231 dex::TypeIndex type_idx_; // index into type_ids section
Elliott Hughesa21039c2012-06-21 12:09:25 -0700232
Brian Carlstromd2fbb2b2011-08-23 11:57:08 -0700233 private:
234 DISALLOW_COPY_AND_ASSIGN(TypeItem);
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700235 };
236
237 // Raw type_list.
238 class TypeList {
239 public:
240 uint32_t Size() const {
241 return size_;
242 }
243
244 const TypeItem& GetTypeItem(uint32_t idx) const {
Sebastien Hertzb24bd992013-08-02 15:19:09 +0200245 DCHECK_LT(idx, this->size_);
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700246 return this->list_[idx];
247 }
248
Andreas Gampe31a7a0c2014-08-29 16:07:49 -0700249 // Size in bytes of the part of the list that is common.
250 static constexpr size_t GetHeaderSize() {
251 return 4U;
252 }
253
254 // Size in bytes of the whole type list including all the stored elements.
255 static constexpr size_t GetListSize(size_t count) {
256 return GetHeaderSize() + sizeof(TypeItem) * count;
257 }
258
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700259 private:
260 uint32_t size_; // size of the list, in entries
261 TypeItem list_[1]; // elements of the list
Brian Carlstromd2fbb2b2011-08-23 11:57:08 -0700262 DISALLOW_COPY_AND_ASSIGN(TypeList);
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700263 };
264
Orion Hodson12f4ff42017-01-13 16:43:12 +0000265 // MethodHandle Types
266 enum class MethodHandleType : uint16_t { // private
Orion Hodsonc069a302017-01-18 09:23:12 +0000267 kStaticPut = 0x0000, // a setter for a given static field.
268 kStaticGet = 0x0001, // a getter for a given static field.
269 kInstancePut = 0x0002, // a setter for a given instance field.
270 kInstanceGet = 0x0003, // a getter for a given instance field.
271 kInvokeStatic = 0x0004, // an invoker for a given static method.
Orion Hodson12f4ff42017-01-13 16:43:12 +0000272 kInvokeInstance = 0x0005, // invoke_instance : an invoker for a given instance method. This
273 // can be any non-static method on any class (or interface) except
274 // for “<init>”.
275 kInvokeConstructor = 0x0006, // an invoker for a given constructor.
276 kLast = kInvokeConstructor
277 };
278
279 // raw method_handle_item
280 struct MethodHandleItem {
281 uint16_t method_handle_type_;
Orion Hodsonc069a302017-01-18 09:23:12 +0000282 uint16_t reserved1_; // Reserved for future use.
283 uint16_t field_or_method_idx_; // Field index for accessors, method index otherwise.
284 uint16_t reserved2_; // Reserved for future use.
Orion Hodson12f4ff42017-01-13 16:43:12 +0000285 private:
286 DISALLOW_COPY_AND_ASSIGN(MethodHandleItem);
287 };
288
289 // raw call_site_id_item
290 struct CallSiteIdItem {
291 uint32_t data_off_; // Offset into data section pointing to encoded array items.
292 private:
293 DISALLOW_COPY_AND_ASSIGN(CallSiteIdItem);
294 };
295
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700296 // Raw code_item.
297 struct CodeItem {
Igor Murashkinc449e8b2015-06-10 15:56:42 -0700298 uint16_t registers_size_; // the number of registers used by this code
299 // (locals + parameters)
300 uint16_t ins_size_; // the number of words of incoming arguments to the method
301 // that this code is for
302 uint16_t outs_size_; // the number of words of outgoing argument space required
303 // by this code for method invocation
304 uint16_t tries_size_; // the number of try_items for this instance. If non-zero,
305 // then these appear as the tries array just after the
306 // insns in this instance.
307 uint32_t debug_info_off_; // file offset to debug info stream
Ian Rogersd81871c2011-10-03 13:57:23 -0700308 uint32_t insns_size_in_code_units_; // size of the insns array, in 2 byte code units
Igor Murashkinc449e8b2015-06-10 15:56:42 -0700309 uint16_t insns_[1]; // actual array of bytecode.
Elliott Hughesa21039c2012-06-21 12:09:25 -0700310
Brian Carlstromd2fbb2b2011-08-23 11:57:08 -0700311 private:
312 DISALLOW_COPY_AND_ASSIGN(CodeItem);
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700313 };
314
Carl Shapiro2eaa9682011-08-04 19:26:11 -0700315 // Raw try_item.
316 struct TryItem {
317 uint32_t start_addr_;
318 uint16_t insn_count_;
319 uint16_t handler_off_;
Elliott Hughesa21039c2012-06-21 12:09:25 -0700320
Brian Carlstromd2fbb2b2011-08-23 11:57:08 -0700321 private:
322 DISALLOW_COPY_AND_ASSIGN(TryItem);
Carl Shapiro2eaa9682011-08-04 19:26:11 -0700323 };
324
jeffhao10037c82012-01-23 15:06:23 -0800325 // Annotation constants.
326 enum {
327 kDexVisibilityBuild = 0x00, /* annotation visibility */
328 kDexVisibilityRuntime = 0x01,
329 kDexVisibilitySystem = 0x02,
330
331 kDexAnnotationByte = 0x00,
332 kDexAnnotationShort = 0x02,
333 kDexAnnotationChar = 0x03,
334 kDexAnnotationInt = 0x04,
335 kDexAnnotationLong = 0x06,
336 kDexAnnotationFloat = 0x10,
337 kDexAnnotationDouble = 0x11,
Orion Hodson12f4ff42017-01-13 16:43:12 +0000338 kDexAnnotationMethodType = 0x15,
339 kDexAnnotationMethodHandle = 0x16,
jeffhao10037c82012-01-23 15:06:23 -0800340 kDexAnnotationString = 0x17,
341 kDexAnnotationType = 0x18,
342 kDexAnnotationField = 0x19,
343 kDexAnnotationMethod = 0x1a,
344 kDexAnnotationEnum = 0x1b,
345 kDexAnnotationArray = 0x1c,
346 kDexAnnotationAnnotation = 0x1d,
347 kDexAnnotationNull = 0x1e,
348 kDexAnnotationBoolean = 0x1f,
349
350 kDexAnnotationValueTypeMask = 0x1f, /* low 5 bits */
351 kDexAnnotationValueArgShift = 5,
352 };
353
354 struct AnnotationsDirectoryItem {
355 uint32_t class_annotations_off_;
356 uint32_t fields_size_;
357 uint32_t methods_size_;
358 uint32_t parameters_size_;
Elliott Hughesa21039c2012-06-21 12:09:25 -0700359
jeffhao10037c82012-01-23 15:06:23 -0800360 private:
361 DISALLOW_COPY_AND_ASSIGN(AnnotationsDirectoryItem);
362 };
363
364 struct FieldAnnotationsItem {
365 uint32_t field_idx_;
366 uint32_t annotations_off_;
Elliott Hughesa21039c2012-06-21 12:09:25 -0700367
jeffhao10037c82012-01-23 15:06:23 -0800368 private:
369 DISALLOW_COPY_AND_ASSIGN(FieldAnnotationsItem);
370 };
371
372 struct MethodAnnotationsItem {
373 uint32_t method_idx_;
374 uint32_t annotations_off_;
Elliott Hughesa21039c2012-06-21 12:09:25 -0700375
jeffhao10037c82012-01-23 15:06:23 -0800376 private:
377 DISALLOW_COPY_AND_ASSIGN(MethodAnnotationsItem);
378 };
379
380 struct ParameterAnnotationsItem {
381 uint32_t method_idx_;
382 uint32_t annotations_off_;
Elliott Hughesa21039c2012-06-21 12:09:25 -0700383
jeffhao10037c82012-01-23 15:06:23 -0800384 private:
385 DISALLOW_COPY_AND_ASSIGN(ParameterAnnotationsItem);
386 };
387
388 struct AnnotationSetRefItem {
389 uint32_t annotations_off_;
Elliott Hughesa21039c2012-06-21 12:09:25 -0700390
jeffhao10037c82012-01-23 15:06:23 -0800391 private:
392 DISALLOW_COPY_AND_ASSIGN(AnnotationSetRefItem);
393 };
394
395 struct AnnotationSetRefList {
396 uint32_t size_;
397 AnnotationSetRefItem list_[1];
Elliott Hughesa21039c2012-06-21 12:09:25 -0700398
jeffhao10037c82012-01-23 15:06:23 -0800399 private:
400 DISALLOW_COPY_AND_ASSIGN(AnnotationSetRefList);
401 };
402
403 struct AnnotationSetItem {
404 uint32_t size_;
405 uint32_t entries_[1];
Elliott Hughesa21039c2012-06-21 12:09:25 -0700406
jeffhao10037c82012-01-23 15:06:23 -0800407 private:
408 DISALLOW_COPY_AND_ASSIGN(AnnotationSetItem);
409 };
410
411 struct AnnotationItem {
412 uint8_t visibility_;
413 uint8_t annotation_[1];
Elliott Hughesa21039c2012-06-21 12:09:25 -0700414
jeffhao10037c82012-01-23 15:06:23 -0800415 private:
416 DISALLOW_COPY_AND_ASSIGN(AnnotationItem);
417 };
418
Jeff Hao13e748b2015-08-25 20:44:19 +0000419 enum AnnotationResultStyle { // private
420 kAllObjects,
421 kPrimitivesOrObjects,
422 kAllRaw
423 };
424
David Sehr9323e6e2016-09-13 08:58:35 -0700425 struct AnnotationValue;
426
Richard Uhler69bcf2c2017-01-24 10:25:21 +0000427 // Returns the checksums of a file for comparison with GetLocationChecksum().
428 // For .dex files, this is the single header checksum.
429 // For zip files, this is the zip entry CRC32 checksum for classes.dex and
430 // each additional multidex entry classes2.dex, classes3.dex, etc.
431 // Return true if the checksums could be found, false otherwise.
432 static bool GetMultiDexChecksums(const char* filename,
433 std::vector<uint32_t>* checksums,
434 std::string* error_msg);
435
Richard Uhler84f50ae2017-02-06 15:12:45 +0000436 // Check whether a location denotes a multidex dex file. This is a very simple check: returns
437 // whether the string contains the separator character.
438 static bool IsMultiDexLocation(const char* location);
439
Brian Carlstrom89521892011-12-07 22:05:07 -0800440 // Opens .dex file, backed by existing memory
David Sehr733ddb22016-09-19 15:02:18 -0700441 static std::unique_ptr<const DexFile> Open(const uint8_t* base,
442 size_t size,
Richard Uhlerfbef44d2014-12-23 09:48:51 -0800443 const std::string& location,
444 uint32_t location_checksum,
Richard Uhler07b3c232015-03-31 15:57:54 -0700445 const OatDexFile* oat_dex_file,
Andreas Gampe3a2bd292016-01-26 17:23:47 -0800446 bool verify,
Aart Bik37d6a3b2016-06-21 18:30:10 -0700447 bool verify_checksum,
Andreas Gampe3a2bd292016-01-26 17:23:47 -0800448 std::string* error_msg);
Brian Carlstrom89521892011-12-07 22:05:07 -0800449
Orion Hodsona4c2a052016-08-17 10:51:42 +0100450 // Opens .dex file that has been memory-mapped by the caller.
451 static std::unique_ptr<const DexFile> Open(const std::string& location,
452 uint32_t location_checkum,
453 std::unique_ptr<MemMap> mem_map,
454 bool verify,
455 bool verify_checksum,
456 std::string* error_msg);
457
David Sehr733ddb22016-09-19 15:02:18 -0700458 // Opens all .dex files found in the file, guessing the container format based on file extension.
459 static bool Open(const char* filename,
460 const std::string& location,
461 bool verify_checksum,
462 std::string* error_msg,
463 std::vector<std::unique_ptr<const DexFile>>* dex_files);
Orion Hodsona4c2a052016-08-17 10:51:42 +0100464
David Sehr733ddb22016-09-19 15:02:18 -0700465 // Open a single dex file from an fd.
466 static std::unique_ptr<const DexFile> OpenDex(int fd,
467 const std::string& location,
468 bool verify_checksum,
469 std::string* error_msg);
470
471 // Opens dex files from within a .jar, .zip, or .apk file
472 static bool OpenZip(int fd,
473 const std::string& location,
474 bool verify_checksum,
475 std::string* error_msg,
476 std::vector<std::unique_ptr<const DexFile>>* dex_files);
Brian Carlstroma6cc8932012-01-04 14:44:07 -0800477
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700478 // Closes a .dex file.
Brian Carlstromf615a612011-07-23 12:50:34 -0700479 virtual ~DexFile();
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700480
Brian Carlstroma663ea52011-08-19 23:33:41 -0700481 const std::string& GetLocation() const {
482 return location_;
483 }
484
Andreas Gampecb8f9e82014-07-24 15:35:50 -0700485 // For normal dex files, location and base location coincide. If a dex file is part of a multidex
486 // archive, the base location is the name of the originating jar/apk, stripped of any internal
487 // classes*.dex path.
Vladimir Markoaa4497d2014-09-05 14:01:17 +0100488 static std::string GetBaseLocation(const char* location) {
489 const char* pos = strrchr(location, kMultiDexSeparator);
490 if (pos == nullptr) {
491 return location;
Andreas Gampecb8f9e82014-07-24 15:35:50 -0700492 } else {
Vladimir Markoaa4497d2014-09-05 14:01:17 +0100493 return std::string(location, pos - location);
494 }
495 }
496
Richard Uhlere5fed032015-03-18 08:21:11 -0700497 static std::string GetBaseLocation(const std::string& location) {
498 return GetBaseLocation(location.c_str());
499 }
500
501 // Returns the ':classes*.dex' part of the dex location. Returns an empty
502 // string if there is no multidex suffix for the given location.
503 // The kMultiDexSeparator is included in the returned suffix.
504 static std::string GetMultiDexSuffix(const std::string& location) {
505 size_t pos = location.rfind(kMultiDexSeparator);
Vladimir Markoaa4497d2014-09-05 14:01:17 +0100506 if (pos == std::string::npos) {
Richard Uhlere5fed032015-03-18 08:21:11 -0700507 return "";
Vladimir Markoaa4497d2014-09-05 14:01:17 +0100508 } else {
Richard Uhlere5fed032015-03-18 08:21:11 -0700509 return location.substr(pos);
Andreas Gampecb8f9e82014-07-24 15:35:50 -0700510 }
511 }
512
Richard Uhlere5fed032015-03-18 08:21:11 -0700513 std::string GetBaseLocation() const {
514 return GetBaseLocation(location_);
515 }
516
Brian Carlstrom5b332c82012-02-01 15:02:31 -0800517 // For DexFiles directly from .dex files, this is the checksum from the DexFile::Header.
518 // For DexFiles opened from a zip files, this will be the ZipEntry CRC32 of classes.dex.
519 uint32_t GetLocationChecksum() const {
520 return location_checksum_;
521 }
522
Brian Carlstroma663ea52011-08-19 23:33:41 -0700523 const Header& GetHeader() const {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700524 DCHECK(header_ != nullptr) << GetLocation();
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700525 return *header_;
Carl Shapiro1fb86202011-06-27 17:43:13 -0700526 }
527
Ian Rogers0571d352011-11-03 19:51:38 -0700528 // Decode the dex magic version
Andreas Gampe76ed99d2016-03-28 18:31:29 -0700529 uint32_t GetVersion() const {
530 return GetHeader().GetVersion();
531 }
Ian Rogersd81871c2011-10-03 13:57:23 -0700532
Brian Carlstrom6e3b1d92012-01-11 01:36:32 -0800533 // Returns true if the byte string points to the magic value.
Ian Rogers13735952014-10-08 12:43:28 -0700534 static bool IsMagicValid(const uint8_t* magic);
Brian Carlstrom6e3b1d92012-01-11 01:36:32 -0800535
536 // Returns true if the byte string after the magic is the correct value.
Ian Rogers13735952014-10-08 12:43:28 -0700537 static bool IsVersionValid(const uint8_t* magic);
Brian Carlstrom6e3b1d92012-01-11 01:36:32 -0800538
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700539 // Returns the number of string identifiers in the .dex file.
540 size_t NumStringIds() const {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700541 DCHECK(header_ != nullptr) << GetLocation();
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700542 return header_->string_ids_size_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700543 }
544
Ian Rogers0571d352011-11-03 19:51:38 -0700545 // Returns the StringId at the specified index.
Andreas Gampe8a0128a2016-11-28 07:38:35 -0800546 const StringId& GetStringId(dex::StringIndex idx) const {
547 DCHECK_LT(idx.index_, NumStringIds()) << GetLocation();
548 return string_ids_[idx.index_];
Ian Rogers0571d352011-11-03 19:51:38 -0700549 }
550
Andreas Gampe8a0128a2016-11-28 07:38:35 -0800551 dex::StringIndex GetIndexForStringId(const StringId& string_id) const {
Brian Carlstrom61e513c2011-12-09 15:30:06 -0800552 CHECK_GE(&string_id, string_ids_) << GetLocation();
553 CHECK_LT(&string_id, string_ids_ + header_->string_ids_size_) << GetLocation();
Andreas Gampe8a0128a2016-11-28 07:38:35 -0800554 return dex::StringIndex(&string_id - string_ids_);
Ian Rogers0571d352011-11-03 19:51:38 -0700555 }
556
557 int32_t GetStringLength(const StringId& string_id) const;
558
Ian Rogersdfb325e2013-10-30 01:00:44 -0700559 // Returns a pointer to the UTF-8 string data referred to by the given string_id as well as the
560 // length of the string when decoded as a UTF-16 string. Note the UTF-16 length is not the same
561 // as the string length of the string data.
562 const char* GetStringDataAndUtf16Length(const StringId& string_id, uint32_t* utf16_length) const;
Ian Rogers0571d352011-11-03 19:51:38 -0700563
Vladimir Marko5c6a5872016-06-27 13:50:16 +0100564 const char* GetStringData(const StringId& string_id) const;
Ian Rogers0571d352011-11-03 19:51:38 -0700565
Ian Rogersdfb325e2013-10-30 01:00:44 -0700566 // Index version of GetStringDataAndUtf16Length.
Andreas Gampe8a0128a2016-11-28 07:38:35 -0800567 const char* StringDataAndUtf16LengthByIdx(dex::StringIndex idx, uint32_t* utf16_length) const;
Ian Rogers0571d352011-11-03 19:51:38 -0700568
Andreas Gampe8a0128a2016-11-28 07:38:35 -0800569 const char* StringDataByIdx(dex::StringIndex idx) const;
Ian Rogers0571d352011-11-03 19:51:38 -0700570
Ian Rogers637c65b2013-05-31 11:46:00 -0700571 // Looks up a string id for a given modified utf8 string.
572 const StringId* FindStringId(const char* string) const;
573
Artem Udovichenkod9786b02015-10-14 16:36:55 +0300574 const TypeId* FindTypeId(const char* string) const;
575
Ian Rogers637c65b2013-05-31 11:46:00 -0700576 // Looks up a string id for a given utf16 string.
Vladimir Markoa48aef42014-12-03 17:53:53 +0000577 const StringId* FindStringId(const uint16_t* string, size_t length) const;
Ian Rogers0571d352011-11-03 19:51:38 -0700578
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700579 // Returns the number of type identifiers in the .dex file.
Ian Rogers68b56852014-08-29 20:19:11 -0700580 uint32_t NumTypeIds() const {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700581 DCHECK(header_ != nullptr) << GetLocation();
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700582 return header_->type_ids_size_;
Carl Shapiro5fafe2b2011-07-09 15:34:41 -0700583 }
584
Ian Rogers0571d352011-11-03 19:51:38 -0700585 // Returns the TypeId at the specified index.
Andreas Gampea5b09a62016-11-17 15:21:22 -0800586 const TypeId& GetTypeId(dex::TypeIndex idx) const {
587 DCHECK_LT(idx.index_, NumTypeIds()) << GetLocation();
588 return type_ids_[idx.index_];
Carl Shapiro5fafe2b2011-07-09 15:34:41 -0700589 }
590
Andreas Gampea5b09a62016-11-17 15:21:22 -0800591 dex::TypeIndex GetIndexForTypeId(const TypeId& type_id) const {
Brian Carlstrom61e513c2011-12-09 15:30:06 -0800592 CHECK_GE(&type_id, type_ids_) << GetLocation();
593 CHECK_LT(&type_id, type_ids_ + header_->type_ids_size_) << GetLocation();
Ian Rogers0571d352011-11-03 19:51:38 -0700594 size_t result = &type_id - type_ids_;
Brian Carlstrom61e513c2011-12-09 15:30:06 -0800595 DCHECK_LT(result, 65536U) << GetLocation();
Andreas Gampea5b09a62016-11-17 15:21:22 -0800596 return dex::TypeIndex(static_cast<uint16_t>(result));
Ian Rogers0571d352011-11-03 19:51:38 -0700597 }
598
599 // Get the descriptor string associated with a given type index.
Andreas Gampea5b09a62016-11-17 15:21:22 -0800600 const char* StringByTypeIdx(dex::TypeIndex idx, uint32_t* unicode_length) const;
Ian Rogers0571d352011-11-03 19:51:38 -0700601
Andreas Gampea5b09a62016-11-17 15:21:22 -0800602 const char* StringByTypeIdx(dex::TypeIndex idx) const;
Ian Rogers0571d352011-11-03 19:51:38 -0700603
604 // Returns the type descriptor string of a type id.
Vladimir Marko5c6a5872016-06-27 13:50:16 +0100605 const char* GetTypeDescriptor(const TypeId& type_id) const;
Ian Rogers0571d352011-11-03 19:51:38 -0700606
607 // Looks up a type for the given string index
Andreas Gampe8a0128a2016-11-28 07:38:35 -0800608 const TypeId* FindTypeId(dex::StringIndex string_idx) const;
Ian Rogers0571d352011-11-03 19:51:38 -0700609
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700610 // Returns the number of field identifiers in the .dex file.
611 size_t NumFieldIds() const {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700612 DCHECK(header_ != nullptr) << GetLocation();
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700613 return header_->field_ids_size_;
Carl Shapiro0e5d75d2011-07-06 18:28:37 -0700614 }
615
Ian Rogers0571d352011-11-03 19:51:38 -0700616 // Returns the FieldId at the specified index.
617 const FieldId& GetFieldId(uint32_t idx) const {
Sebastien Hertzb24bd992013-08-02 15:19:09 +0200618 DCHECK_LT(idx, NumFieldIds()) << GetLocation();
Ian Rogers0571d352011-11-03 19:51:38 -0700619 return field_ids_[idx];
Brian Carlstromd2fbb2b2011-08-23 11:57:08 -0700620 }
621
Ian Rogers9b1a4f42011-11-14 18:35:10 -0800622 uint32_t GetIndexForFieldId(const FieldId& field_id) const {
Brian Carlstrom61e513c2011-12-09 15:30:06 -0800623 CHECK_GE(&field_id, field_ids_) << GetLocation();
624 CHECK_LT(&field_id, field_ids_ + header_->field_ids_size_) << GetLocation();
Ian Rogers9b1a4f42011-11-14 18:35:10 -0800625 return &field_id - field_ids_;
626 }
627
628 // Looks up a field by its declaring class, name and type
629 const FieldId* FindFieldId(const DexFile::TypeId& declaring_klass,
630 const DexFile::StringId& name,
631 const DexFile::TypeId& type) const;
632
Alex Light9c20a142016-08-23 15:05:12 -0700633 uint32_t FindCodeItemOffset(const DexFile::ClassDef& class_def,
634 uint32_t dex_method_idx) const;
635
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700636 // Returns the declaring class descriptor string of a field id.
637 const char* GetFieldDeclaringClassDescriptor(const FieldId& field_id) const {
Brian Carlstromb9edb842011-08-28 16:31:06 -0700638 const DexFile::TypeId& type_id = GetTypeId(field_id.class_idx_);
639 return GetTypeDescriptor(type_id);
640 }
641
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700642 // Returns the class descriptor string of a field id.
Vladimir Marko5c6a5872016-06-27 13:50:16 +0100643 const char* GetFieldTypeDescriptor(const FieldId& field_id) const;
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700644
Brian Carlstromb9edb842011-08-28 16:31:06 -0700645 // Returns the name of a field id.
Vladimir Marko5c6a5872016-06-27 13:50:16 +0100646 const char* GetFieldName(const FieldId& field_id) const;
Brian Carlstromb9edb842011-08-28 16:31:06 -0700647
Ian Rogers0571d352011-11-03 19:51:38 -0700648 // Returns the number of method identifiers in the .dex file.
649 size_t NumMethodIds() const {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700650 DCHECK(header_ != nullptr) << GetLocation();
Ian Rogers0571d352011-11-03 19:51:38 -0700651 return header_->method_ids_size_;
652 }
653
654 // Returns the MethodId at the specified index.
655 const MethodId& GetMethodId(uint32_t idx) const {
Ian Rogers4f6ad8a2013-03-18 15:27:28 -0700656 DCHECK_LT(idx, NumMethodIds()) << GetLocation();
Ian Rogers0571d352011-11-03 19:51:38 -0700657 return method_ids_[idx];
658 }
659
660 uint32_t GetIndexForMethodId(const MethodId& method_id) const {
Brian Carlstrom61e513c2011-12-09 15:30:06 -0800661 CHECK_GE(&method_id, method_ids_) << GetLocation();
662 CHECK_LT(&method_id, method_ids_ + header_->method_ids_size_) << GetLocation();
Ian Rogers0571d352011-11-03 19:51:38 -0700663 return &method_id - method_ids_;
664 }
665
Ian Rogers9b1a4f42011-11-14 18:35:10 -0800666 // Looks up a method by its declaring class, name and proto_id
667 const MethodId* FindMethodId(const DexFile::TypeId& declaring_klass,
668 const DexFile::StringId& name,
Ian Rogers0571d352011-11-03 19:51:38 -0700669 const DexFile::ProtoId& signature) const;
670
Brian Carlstrom6b4ef022011-10-23 14:59:04 -0700671 // Returns the declaring class descriptor string of a method id.
Vladimir Marko5c6a5872016-06-27 13:50:16 +0100672 const char* GetMethodDeclaringClassDescriptor(const MethodId& method_id) const;
Brian Carlstrom7540ff42011-09-04 16:38:46 -0700673
jeffhao98eacac2011-09-14 16:11:53 -0700674 // Returns the prototype of a method id.
Brian Carlstromaded5f72011-10-07 17:15:04 -0700675 const ProtoId& GetMethodPrototype(const MethodId& method_id) const {
676 return GetProtoId(method_id.proto_idx_);
677 }
678
Ian Rogersd91d6d62013-09-25 20:26:14 -0700679 // Returns a representation of the signature of a method id.
680 const Signature GetMethodSignature(const MethodId& method_id) const;
jeffhao98eacac2011-09-14 16:11:53 -0700681
Orion Hodsonb34bb192016-10-18 17:02:58 +0100682 // Returns a representation of the signature of a proto id.
683 const Signature GetProtoSignature(const ProtoId& proto_id) const;
684
Brian Carlstrom7540ff42011-09-04 16:38:46 -0700685 // Returns the name of a method id.
Vladimir Marko5c6a5872016-06-27 13:50:16 +0100686 const char* GetMethodName(const MethodId& method_id) const;
Brian Carlstrom7540ff42011-09-04 16:38:46 -0700687
Calin Juravle68ad6492015-08-18 17:08:12 +0100688 // Returns the shorty of a method by its index.
Vladimir Marko5c6a5872016-06-27 13:50:16 +0100689 const char* GetMethodShorty(uint32_t idx) const;
Calin Juravle68ad6492015-08-18 17:08:12 +0100690
Ian Rogers0571d352011-11-03 19:51:38 -0700691 // Returns the shorty of a method id.
Vladimir Marko5c6a5872016-06-27 13:50:16 +0100692 const char* GetMethodShorty(const MethodId& method_id) const;
693 const char* GetMethodShorty(const MethodId& method_id, uint32_t* length) const;
694
Ian Rogers0571d352011-11-03 19:51:38 -0700695 // Returns the number of class definitions in the .dex file.
Ian Rogers68b56852014-08-29 20:19:11 -0700696 uint32_t NumClassDefs() const {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700697 DCHECK(header_ != nullptr) << GetLocation();
Ian Rogers0571d352011-11-03 19:51:38 -0700698 return header_->class_defs_size_;
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700699 }
700
701 // Returns the ClassDef at the specified index.
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700702 const ClassDef& GetClassDef(uint16_t idx) const {
Sebastien Hertzb24bd992013-08-02 15:19:09 +0200703 DCHECK_LT(idx, NumClassDefs()) << GetLocation();
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700704 return class_defs_[idx];
705 }
706
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700707 uint16_t GetIndexForClassDef(const ClassDef& class_def) const {
Brian Carlstrom61e513c2011-12-09 15:30:06 -0800708 CHECK_GE(&class_def, class_defs_) << GetLocation();
709 CHECK_LT(&class_def, class_defs_ + header_->class_defs_size_) << GetLocation();
Ian Rogers0571d352011-11-03 19:51:38 -0700710 return &class_def - class_defs_;
711 }
712
713 // Returns the class descriptor string of a class definition.
Vladimir Marko5c6a5872016-06-27 13:50:16 +0100714 const char* GetClassDescriptor(const ClassDef& class_def) const;
Ian Rogers0571d352011-11-03 19:51:38 -0700715
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700716 // Looks up a class definition by its type index.
Andreas Gampea5b09a62016-11-17 15:21:22 -0800717 const ClassDef* FindClassDef(dex::TypeIndex type_idx) const;
Ian Rogers0571d352011-11-03 19:51:38 -0700718
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700719 const TypeList* GetInterfacesList(const ClassDef& class_def) const {
720 if (class_def.interfaces_off_ == 0) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700721 return nullptr;
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700722 } else {
Ian Rogers13735952014-10-08 12:43:28 -0700723 const uint8_t* addr = begin_ + class_def.interfaces_off_;
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700724 return reinterpret_cast<const TypeList*>(addr);
725 }
726 }
727
Orion Hodson12f4ff42017-01-13 16:43:12 +0000728 uint32_t NumMethodHandles() const {
729 return num_method_handles_;
730 }
731
Orion Hodsonc069a302017-01-18 09:23:12 +0000732 const MethodHandleItem& GetMethodHandle(uint32_t idx) const {
733 CHECK_LT(idx, NumMethodHandles());
734 return method_handles_[idx];
735 }
736
737 uint32_t NumCallSiteIds() const {
738 return num_call_site_ids_;
739 }
740
741 const CallSiteIdItem& GetCallSiteId(uint32_t idx) const {
742 CHECK_LT(idx, NumCallSiteIds());
743 return call_site_ids_[idx];
744 }
745
Ian Rogers0571d352011-11-03 19:51:38 -0700746 // Returns a pointer to the raw memory mapped class_data_item
Ian Rogers13735952014-10-08 12:43:28 -0700747 const uint8_t* GetClassData(const ClassDef& class_def) const {
Ian Rogers0571d352011-11-03 19:51:38 -0700748 if (class_def.class_data_off_ == 0) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700749 return nullptr;
Ian Rogers0571d352011-11-03 19:51:38 -0700750 } else {
Ian Rogers30fab402012-01-23 15:43:46 -0800751 return begin_ + class_def.class_data_off_;
Ian Rogers0571d352011-11-03 19:51:38 -0700752 }
Shih-wei Liao2fb97532011-08-11 16:17:23 -0700753 }
754
Ian Rogers0571d352011-11-03 19:51:38 -0700755 //
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800756 const CodeItem* GetCodeItem(const uint32_t code_off) const {
Alex Light9139e002015-10-09 15:59:48 -0700757 DCHECK_LT(code_off, size_) << "Code item offset larger then maximum allowed offset";
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800758 if (code_off == 0) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700759 return nullptr; // native or abstract method
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700760 } else {
Ian Rogers13735952014-10-08 12:43:28 -0700761 const uint8_t* addr = begin_ + code_off;
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700762 return reinterpret_cast<const CodeItem*>(addr);
763 }
764 }
765
Vladimir Marko5c6a5872016-06-27 13:50:16 +0100766 const char* GetReturnTypeDescriptor(const ProtoId& proto_id) const;
Ian Rogers0571d352011-11-03 19:51:38 -0700767
768 // Returns the number of prototype identifiers in the .dex file.
769 size_t NumProtoIds() const {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700770 DCHECK(header_ != nullptr) << GetLocation();
Ian Rogers0571d352011-11-03 19:51:38 -0700771 return header_->proto_ids_size_;
772 }
773
774 // Returns the ProtoId at the specified index.
Andreas Gampea5b09a62016-11-17 15:21:22 -0800775 const ProtoId& GetProtoId(uint16_t idx) const {
Ian Rogers4f6ad8a2013-03-18 15:27:28 -0700776 DCHECK_LT(idx, NumProtoIds()) << GetLocation();
Ian Rogers0571d352011-11-03 19:51:38 -0700777 return proto_ids_[idx];
778 }
779
780 uint16_t GetIndexForProtoId(const ProtoId& proto_id) const {
Brian Carlstrom61e513c2011-12-09 15:30:06 -0800781 CHECK_GE(&proto_id, proto_ids_) << GetLocation();
782 CHECK_LT(&proto_id, proto_ids_ + header_->proto_ids_size_) << GetLocation();
Ian Rogers0571d352011-11-03 19:51:38 -0700783 return &proto_id - proto_ids_;
784 }
785
786 // Looks up a proto id for a given return type and signature type list
Andreas Gampea5b09a62016-11-17 15:21:22 -0800787 const ProtoId* FindProtoId(dex::TypeIndex return_type_idx,
788 const dex::TypeIndex* signature_type_idxs,
789 uint32_t signature_length) const;
790 const ProtoId* FindProtoId(dex::TypeIndex return_type_idx,
791 const std::vector<dex::TypeIndex>& signature_type_idxs) const {
Vladimir Marko5c96e6b2013-11-14 15:34:17 +0000792 return FindProtoId(return_type_idx, &signature_type_idxs[0], signature_type_idxs.size());
793 }
Ian Rogers0571d352011-11-03 19:51:38 -0700794
795 // Given a signature place the type ids into the given vector, returns true on success
Andreas Gampea5b09a62016-11-17 15:21:22 -0800796 bool CreateTypeList(const StringPiece& signature,
797 dex::TypeIndex* return_type_idx,
798 std::vector<dex::TypeIndex>* param_type_idxs) const;
Ian Rogers0571d352011-11-03 19:51:38 -0700799
Ian Rogersd91d6d62013-09-25 20:26:14 -0700800 // Create a Signature from the given string signature or return Signature::NoSignature if not
801 // possible.
802 const Signature CreateSignature(const StringPiece& signature) const;
Ian Rogers0571d352011-11-03 19:51:38 -0700803
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700804 // Returns the short form method descriptor for the given prototype.
Vladimir Marko5c6a5872016-06-27 13:50:16 +0100805 const char* GetShorty(uint32_t proto_idx) const;
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700806
807 const TypeList* GetProtoParameters(const ProtoId& proto_id) const {
808 if (proto_id.parameters_off_ == 0) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700809 return nullptr;
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700810 } else {
Ian Rogers13735952014-10-08 12:43:28 -0700811 const uint8_t* addr = begin_ + proto_id.parameters_off_;
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700812 return reinterpret_cast<const TypeList*>(addr);
813 }
814 }
815
Ian Rogers13735952014-10-08 12:43:28 -0700816 const uint8_t* GetEncodedStaticFieldValuesArray(const ClassDef& class_def) const {
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700817 if (class_def.static_values_off_ == 0) {
818 return 0;
819 } else {
Ian Rogers30fab402012-01-23 15:43:46 -0800820 return begin_ + class_def.static_values_off_;
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700821 }
822 }
823
Orion Hodson12f4ff42017-01-13 16:43:12 +0000824 const uint8_t* GetCallSiteEncodedValuesArray(const CallSiteIdItem& call_site_id) const {
825 return begin_ + call_site_id.data_off_;
826 }
827
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800828 static const TryItem* GetTryItems(const CodeItem& code_item, uint32_t offset);
Shih-wei Liao2fb97532011-08-11 16:17:23 -0700829
830 // Get the base of the encoded data for the given DexCode.
Ian Rogers13735952014-10-08 12:43:28 -0700831 static const uint8_t* GetCatchHandlerData(const CodeItem& code_item, uint32_t offset) {
832 const uint8_t* handler_data =
833 reinterpret_cast<const uint8_t*>(GetTryItems(code_item, code_item.tries_size_));
Shih-wei Liao2fb97532011-08-11 16:17:23 -0700834 return handler_data + offset;
835 }
836
Ian Rogersdbbc99d2013-04-18 16:51:54 -0700837 // Find which try region is associated with the given address (ie dex pc). Returns -1 if none.
838 static int32_t FindTryItem(const CodeItem &code_item, uint32_t address);
839
840 // Find the handler offset associated with the given address (ie dex pc). Returns -1 if none.
841 static int32_t FindCatchHandlerOffset(const CodeItem &code_item, uint32_t address);
Shih-wei Liao2fb97532011-08-11 16:17:23 -0700842
Shih-wei Liao195487c2011-08-20 13:29:04 -0700843 // Get the pointer to the start of the debugging data
Ian Rogers13735952014-10-08 12:43:28 -0700844 const uint8_t* GetDebugInfoStream(const CodeItem* code_item) const {
David Srbecky68529422015-07-07 19:13:29 +0100845 // Check that the offset is in bounds.
846 // Note that although the specification says that 0 should be used if there
847 // is no debug information, some applications incorrectly use 0xFFFFFFFF.
848 if (code_item->debug_info_off_ == 0 || code_item->debug_info_off_ >= size_) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700849 return nullptr;
Shih-wei Liao195487c2011-08-20 13:29:04 -0700850 } else {
Ian Rogers30fab402012-01-23 15:43:46 -0800851 return begin_ + code_item->debug_info_off_;
Shih-wei Liao195487c2011-08-20 13:29:04 -0700852 }
853 }
854
David Srbeckyb06e28e2015-12-10 13:15:00 +0000855 struct PositionInfo {
856 PositionInfo()
857 : address_(0),
858 line_(0),
859 source_file_(nullptr),
860 prologue_end_(false),
861 epilogue_begin_(false) {
862 }
863
864 uint32_t address_; // In 16-bit code units.
865 uint32_t line_; // Source code line number starting at 1.
866 const char* source_file_; // nullptr if the file from ClassDef still applies.
867 bool prologue_end_;
868 bool epilogue_begin_;
869 };
870
Shih-wei Liao195487c2011-08-20 13:29:04 -0700871 // Callback for "new position table entry".
872 // Returning true causes the decoder to stop early.
David Srbeckyb06e28e2015-12-10 13:15:00 +0000873 typedef bool (*DexDebugNewPositionCb)(void* context, const PositionInfo& entry);
Shih-wei Liao195487c2011-08-20 13:29:04 -0700874
David Srbeckyb06e28e2015-12-10 13:15:00 +0000875 struct LocalInfo {
876 LocalInfo()
877 : name_(nullptr),
878 descriptor_(nullptr),
879 signature_(nullptr),
880 start_address_(0),
881 end_address_(0),
882 reg_(0),
883 is_live_(false) {
884 }
Shih-wei Liao195487c2011-08-20 13:29:04 -0700885
David Srbeckyb06e28e2015-12-10 13:15:00 +0000886 const char* name_; // E.g., list. It can be nullptr if unknown.
887 const char* descriptor_; // E.g., Ljava/util/LinkedList;
888 const char* signature_; // E.g., java.util.LinkedList<java.lang.Integer>
889 uint32_t start_address_; // PC location where the local is first defined.
890 uint32_t end_address_; // PC location where the local is no longer defined.
891 uint16_t reg_; // Dex register which stores the values.
892 bool is_live_; // Is the local defined and live.
893 };
894
895 // Callback for "new locals table entry".
896 typedef void (*DexDebugNewLocalCb)(void* context, const LocalInfo& entry);
897
898 static bool LineNumForPcCb(void* context, const PositionInfo& entry);
Shih-wei Liao195487c2011-08-20 13:29:04 -0700899
Jeff Hao13e748b2015-08-25 20:44:19 +0000900 const AnnotationsDirectoryItem* GetAnnotationsDirectory(const ClassDef& class_def) const {
901 if (class_def.annotations_off_ == 0) {
902 return nullptr;
903 } else {
904 return reinterpret_cast<const AnnotationsDirectoryItem*>(begin_ + class_def.annotations_off_);
905 }
906 }
907
908 const AnnotationSetItem* GetClassAnnotationSet(const AnnotationsDirectoryItem* anno_dir) const {
909 if (anno_dir->class_annotations_off_ == 0) {
910 return nullptr;
911 } else {
912 return reinterpret_cast<const AnnotationSetItem*>(begin_ + anno_dir->class_annotations_off_);
913 }
914 }
915
916 const FieldAnnotationsItem* GetFieldAnnotations(const AnnotationsDirectoryItem* anno_dir) const {
917 if (anno_dir->fields_size_ == 0) {
918 return nullptr;
919 } else {
920 return reinterpret_cast<const FieldAnnotationsItem*>(&anno_dir[1]);
921 }
922 }
923
924 const MethodAnnotationsItem* GetMethodAnnotations(const AnnotationsDirectoryItem* anno_dir)
925 const {
926 if (anno_dir->methods_size_ == 0) {
927 return nullptr;
928 } else {
929 // Skip past the header and field annotations.
930 const uint8_t* addr = reinterpret_cast<const uint8_t*>(&anno_dir[1]);
931 addr += anno_dir->fields_size_ * sizeof(FieldAnnotationsItem);
932 return reinterpret_cast<const MethodAnnotationsItem*>(addr);
933 }
934 }
935
936 const ParameterAnnotationsItem* GetParameterAnnotations(const AnnotationsDirectoryItem* anno_dir)
937 const {
938 if (anno_dir->parameters_size_ == 0) {
939 return nullptr;
940 } else {
941 // Skip past the header, field annotations, and method annotations.
942 const uint8_t* addr = reinterpret_cast<const uint8_t*>(&anno_dir[1]);
943 addr += anno_dir->fields_size_ * sizeof(FieldAnnotationsItem);
944 addr += anno_dir->methods_size_ * sizeof(MethodAnnotationsItem);
945 return reinterpret_cast<const ParameterAnnotationsItem*>(addr);
946 }
947 }
948
949 const AnnotationSetItem* GetFieldAnnotationSetItem(const FieldAnnotationsItem& anno_item) const {
950 uint32_t offset = anno_item.annotations_off_;
951 if (offset == 0) {
952 return nullptr;
953 } else {
954 return reinterpret_cast<const AnnotationSetItem*>(begin_ + offset);
955 }
956 }
957
958 const AnnotationSetItem* GetMethodAnnotationSetItem(const MethodAnnotationsItem& anno_item)
959 const {
960 uint32_t offset = anno_item.annotations_off_;
961 if (offset == 0) {
962 return nullptr;
963 } else {
964 return reinterpret_cast<const AnnotationSetItem*>(begin_ + offset);
965 }
966 }
967
968 const AnnotationSetRefList* GetParameterAnnotationSetRefList(
969 const ParameterAnnotationsItem* anno_item) const {
970 uint32_t offset = anno_item->annotations_off_;
971 if (offset == 0) {
972 return nullptr;
973 }
974 return reinterpret_cast<const AnnotationSetRefList*>(begin_ + offset);
975 }
976
977 const AnnotationItem* GetAnnotationItem(const AnnotationSetItem* set_item, uint32_t index) const {
978 DCHECK_LE(index, set_item->size_);
979 uint32_t offset = set_item->entries_[index];
980 if (offset == 0) {
981 return nullptr;
982 } else {
983 return reinterpret_cast<const AnnotationItem*>(begin_ + offset);
984 }
985 }
986
987 const AnnotationSetItem* GetSetRefItemItem(const AnnotationSetRefItem* anno_item) const {
988 uint32_t offset = anno_item->annotations_off_;
989 if (offset == 0) {
990 return nullptr;
991 }
992 return reinterpret_cast<const AnnotationSetItem*>(begin_ + offset);
993 }
994
Shih-wei Liao195487c2011-08-20 13:29:04 -0700995 // Debug info opcodes and constants
996 enum {
997 DBG_END_SEQUENCE = 0x00,
998 DBG_ADVANCE_PC = 0x01,
999 DBG_ADVANCE_LINE = 0x02,
1000 DBG_START_LOCAL = 0x03,
1001 DBG_START_LOCAL_EXTENDED = 0x04,
1002 DBG_END_LOCAL = 0x05,
1003 DBG_RESTART_LOCAL = 0x06,
1004 DBG_SET_PROLOGUE_END = 0x07,
1005 DBG_SET_EPILOGUE_BEGIN = 0x08,
1006 DBG_SET_FILE = 0x09,
1007 DBG_FIRST_SPECIAL = 0x0a,
1008 DBG_LINE_BASE = -4,
1009 DBG_LINE_RANGE = 15,
1010 };
1011
Shih-wei Liao195487c2011-08-20 13:29:04 -07001012 struct LineNumFromPcContext {
Ian Rogersca190662012-06-26 15:45:57 -07001013 LineNumFromPcContext(uint32_t address, uint32_t line_num)
1014 : address_(address), line_num_(line_num) {}
Shih-wei Liao195487c2011-08-20 13:29:04 -07001015 uint32_t address_;
1016 uint32_t line_num_;
Brian Carlstromd2fbb2b2011-08-23 11:57:08 -07001017 private:
1018 DISALLOW_COPY_AND_ASSIGN(LineNumFromPcContext);
Shih-wei Liao195487c2011-08-20 13:29:04 -07001019 };
1020
Roland Levillain91d65e02016-01-19 15:59:16 +00001021 // Returns false if there is no debugging information or if it cannot be decoded.
David Srbeckyb06e28e2015-12-10 13:15:00 +00001022 bool DecodeDebugLocalInfo(const CodeItem* code_item, bool is_static, uint32_t method_idx,
1023 DexDebugNewLocalCb local_cb, void* context) const;
1024
Roland Levillain91d65e02016-01-19 15:59:16 +00001025 // Returns false if there is no debugging information or if it cannot be decoded.
David Srbeckyb06e28e2015-12-10 13:15:00 +00001026 bool DecodeDebugPositionInfo(const CodeItem* code_item, DexDebugNewPositionCb position_cb,
1027 void* context) const;
Shih-wei Liao195487c2011-08-20 13:29:04 -07001028
Ian Rogers0571d352011-11-03 19:51:38 -07001029 const char* GetSourceFile(const ClassDef& class_def) const {
Andreas Gampe8a0128a2016-11-28 07:38:35 -08001030 if (!class_def.source_file_idx_.IsValid()) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001031 return nullptr;
Brian Carlstrom7e49dca2011-07-22 18:07:34 -07001032 } else {
Ian Rogers0571d352011-11-03 19:51:38 -07001033 return StringDataByIdx(class_def.source_file_idx_);
Brian Carlstrom7e49dca2011-07-22 18:07:34 -07001034 }
Carl Shapiro0e5d75d2011-07-06 18:28:37 -07001035 }
1036
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001037 int GetPermissions() const;
Ian Rogers1c849e52012-06-28 14:00:33 -07001038
Sebastien Hertz2d6ba512013-05-17 11:31:37 +02001039 bool IsReadOnly() const;
1040
Brian Carlstrome0948e12013-08-29 09:36:15 -07001041 bool EnableWrite() const;
Sebastien Hertz2d6ba512013-05-17 11:31:37 +02001042
Brian Carlstrome0948e12013-08-29 09:36:15 -07001043 bool DisableWrite() const;
Sebastien Hertz2d6ba512013-05-17 11:31:37 +02001044
Ian Rogers13735952014-10-08 12:43:28 -07001045 const uint8_t* Begin() const {
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001046 return begin_;
1047 }
1048
1049 size_t Size() const {
1050 return size_;
1051 }
1052
Andreas Gampe90e34042015-04-27 20:01:52 -07001053 // Return the name of the index-th classes.dex in a multidex zip file. This is classes.dex for
1054 // index == 0, and classes{index + 1}.dex else.
1055 static std::string GetMultiDexClassesDexName(size_t index);
1056
1057 // Return the (possibly synthetic) dex location for a multidex entry. This is dex_location for
1058 // index == 0, and dex_location + multi-dex-separator + GetMultiDexClassesDexName(index) else.
1059 static std::string GetMultiDexLocation(size_t index, const char* dex_location);
Calin Juravle4e1d5792014-07-15 23:56:47 +01001060
1061 // Returns the canonical form of the given dex location.
1062 //
1063 // There are different flavors of "dex locations" as follows:
1064 // the file name of a dex file:
1065 // The actual file path that the dex file has on disk.
1066 // dex_location:
1067 // This acts as a key for the class linker to know which dex file to load.
1068 // It may correspond to either an old odex file or a particular dex file
1069 // inside an oat file. In the first case it will also match the file name
1070 // of the dex file. In the second case (oat) it will include the file name
1071 // and possibly some multidex annotation to uniquely identify it.
1072 // canonical_dex_location:
1073 // the dex_location where it's file name part has been made canonical.
1074 static std::string GetDexCanonicalLocation(const char* dex_location);
1075
Richard Uhler07b3c232015-03-31 15:57:54 -07001076 const OatDexFile* GetOatDexFile() const {
1077 return oat_dex_file_;
Andreas Gampefd9eb392014-11-06 16:52:58 -08001078 }
1079
Mathieu Chartier1b868492016-11-16 16:22:37 -08001080 // Used by oat writer.
1081 void SetOatDexFile(OatDexFile* oat_dex_file) const {
1082 oat_dex_file_ = oat_dex_file;
1083 }
1084
David Sehr9323e6e2016-09-13 08:58:35 -07001085 // Utility methods for reading integral values from a buffer.
1086 static int32_t ReadSignedInt(const uint8_t* ptr, int zwidth);
1087 static uint32_t ReadUnsignedInt(const uint8_t* ptr, int zwidth, bool fill_on_right);
1088 static int64_t ReadSignedLong(const uint8_t* ptr, int zwidth);
1089 static uint64_t ReadUnsignedLong(const uint8_t* ptr, int zwidth, bool fill_on_right);
1090
David Sehr709b0702016-10-13 09:12:37 -07001091 // Returns a human-readable form of the method at an index.
1092 std::string PrettyMethod(uint32_t method_idx, bool with_signature = true) const;
1093 // Returns a human-readable form of the field at an index.
1094 std::string PrettyField(uint32_t field_idx, bool with_type = true) const;
1095 // Returns a human-readable form of the type at an index.
Andreas Gampea5b09a62016-11-17 15:21:22 -08001096 std::string PrettyType(dex::TypeIndex type_idx) const;
David Sehr709b0702016-10-13 09:12:37 -07001097
Carl Shapiro1fb86202011-06-27 17:43:13 -07001098 private:
Aart Bik37d6a3b2016-06-21 18:30:10 -07001099 static std::unique_ptr<const DexFile> OpenFile(int fd,
David Sehr733ddb22016-09-19 15:02:18 -07001100 const std::string& location,
Aart Bik37d6a3b2016-06-21 18:30:10 -07001101 bool verify,
1102 bool verify_checksum,
1103 std::string* error_msg);
Brian Carlstrom58ae9412011-10-04 00:56:06 -07001104
Andreas Gampe833a4852014-05-21 18:46:59 -07001105 enum class ZipOpenErrorCode { // private
1106 kNoError,
1107 kEntryNotFound,
1108 kExtractToMemoryError,
1109 kDexFileError,
1110 kMakeReadOnlyError,
1111 kVerifyError
1112 };
1113
David Sehr733ddb22016-09-19 15:02:18 -07001114 // Open all classesXXX.dex files from a zip archive.
1115 static bool OpenAllDexFilesFromZip(const ZipArchive& zip_archive,
1116 const std::string& location,
1117 bool verify_checksum,
1118 std::string* error_msg,
1119 std::vector<std::unique_ptr<const DexFile>>* dex_files);
1120
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001121 // Opens .dex file from the entry_name in a zip archive. error_code is undefined when non-null
Andreas Gampe833a4852014-05-21 18:46:59 -07001122 // return.
David Sehr733ddb22016-09-19 15:02:18 -07001123 static std::unique_ptr<const DexFile> OpenOneDexFileFromZip(const ZipArchive& zip_archive,
1124 const char* entry_name,
1125 const std::string& location,
1126 bool verify_checksum,
1127 std::string* error_msg,
1128 ZipOpenErrorCode* error_code);
1129
1130 enum class VerifyResult { // private
David Sehr9fddd362016-09-22 14:05:37 -07001131 kVerifyNotAttempted,
David Sehr733ddb22016-09-19 15:02:18 -07001132 kVerifySucceeded,
1133 kVerifyFailed
1134 };
1135
1136 static std::unique_ptr<DexFile> OpenCommon(const uint8_t* base,
1137 size_t size,
Aart Bik37d6a3b2016-06-21 18:30:10 -07001138 const std::string& location,
David Sehr733ddb22016-09-19 15:02:18 -07001139 uint32_t location_checksum,
1140 const OatDexFile* oat_dex_file,
1141 bool verify,
Aart Bik37d6a3b2016-06-21 18:30:10 -07001142 bool verify_checksum,
1143 std::string* error_msg,
David Sehr733ddb22016-09-19 15:02:18 -07001144 VerifyResult* verify_result = nullptr);
Brian Carlstrom58ae9412011-10-04 00:56:06 -07001145
Alex Light9c20a142016-08-23 15:05:12 -07001146
1147 // Opens a .dex file at the given address, optionally backed by a MemMap
1148 static std::unique_ptr<const DexFile> OpenMemory(const uint8_t* dex_file,
1149 size_t size,
1150 const std::string& location,
1151 uint32_t location_checksum,
1152 std::unique_ptr<MemMap> mem_map,
1153 const OatDexFile* oat_dex_file,
1154 std::string* error_msg);
1155
David Sehr733ddb22016-09-19 15:02:18 -07001156 DexFile(const uint8_t* base,
1157 size_t size,
Brian Carlstrom28db0122012-10-18 16:20:41 -07001158 const std::string& location,
1159 uint32_t location_checksum,
Richard Uhler07b3c232015-03-31 15:57:54 -07001160 const OatDexFile* oat_dex_file);
jeffhaof6174e82012-01-31 16:14:17 -08001161
Brian Carlstrom7e49dca2011-07-22 18:07:34 -07001162 // Top-level initializer that calls other Init methods.
Ian Rogers8d31bbd2013-10-13 10:44:14 -07001163 bool Init(std::string* error_msg);
Brian Carlstrom7e49dca2011-07-22 18:07:34 -07001164
Brian Carlstrom6e3b1d92012-01-11 01:36:32 -08001165 // Returns true if the header magic and version numbers are of the expected values.
Ian Rogers8d31bbd2013-10-13 10:44:14 -07001166 bool CheckMagicAndVersion(std::string* error_msg) const;
Brian Carlstrom7e49dca2011-07-22 18:07:34 -07001167
Orion Hodson12f4ff42017-01-13 16:43:12 +00001168 // Initialize section info for sections only found in map. Returns true on success.
1169 void InitializeSectionsFromMapList();
1170
Brian Carlstrom7e49dca2011-07-22 18:07:34 -07001171 // The base address of the memory mapping.
Ian Rogers13735952014-10-08 12:43:28 -07001172 const uint8_t* const begin_;
Brian Carlstrom7e49dca2011-07-22 18:07:34 -07001173
1174 // The size of the underlying memory allocation in bytes.
Ian Rogers62d6c772013-02-27 08:32:07 -08001175 const size_t size_;
Brian Carlstrom7e49dca2011-07-22 18:07:34 -07001176
Elliott Hughes64bf5a32011-09-20 14:43:12 -07001177 // Typically the dex file name when available, alternatively some identifying string.
Brian Carlstroma663ea52011-08-19 23:33:41 -07001178 //
1179 // The ClassLinker will use this to match DexFiles the boot class
1180 // path to DexCache::GetLocation when loading from an image.
1181 const std::string location_;
1182
Brian Carlstrom5b332c82012-02-01 15:02:31 -08001183 const uint32_t location_checksum_;
1184
Brian Carlstrom33f741e2011-10-03 11:24:05 -07001185 // Manages the underlying memory allocation.
Ian Rogers700a4022014-05-19 16:49:03 -07001186 std::unique_ptr<MemMap> mem_map_;
Brian Carlstrom7e49dca2011-07-22 18:07:34 -07001187
1188 // Points to the header section.
Brian Carlstrom0d6adac2014-02-05 17:39:16 -08001189 const Header* const header_;
Brian Carlstrom7e49dca2011-07-22 18:07:34 -07001190
1191 // Points to the base of the string identifier list.
Brian Carlstrom0d6adac2014-02-05 17:39:16 -08001192 const StringId* const string_ids_;
Brian Carlstrom7e49dca2011-07-22 18:07:34 -07001193
1194 // Points to the base of the type identifier list.
Brian Carlstrom0d6adac2014-02-05 17:39:16 -08001195 const TypeId* const type_ids_;
Brian Carlstrom7e49dca2011-07-22 18:07:34 -07001196
1197 // Points to the base of the field identifier list.
Brian Carlstrom0d6adac2014-02-05 17:39:16 -08001198 const FieldId* const field_ids_;
Brian Carlstrom7e49dca2011-07-22 18:07:34 -07001199
1200 // Points to the base of the method identifier list.
Brian Carlstrom0d6adac2014-02-05 17:39:16 -08001201 const MethodId* const method_ids_;
Brian Carlstrom7e49dca2011-07-22 18:07:34 -07001202
1203 // Points to the base of the prototype identifier list.
Brian Carlstrom0d6adac2014-02-05 17:39:16 -08001204 const ProtoId* const proto_ids_;
Brian Carlstrom7e49dca2011-07-22 18:07:34 -07001205
1206 // Points to the base of the class definition list.
Brian Carlstrom0d6adac2014-02-05 17:39:16 -08001207 const ClassDef* const class_defs_;
Ian Rogers68b56852014-08-29 20:19:11 -07001208
Orion Hodson12f4ff42017-01-13 16:43:12 +00001209 // Points to the base of the method handles list.
1210 const MethodHandleItem* method_handles_;
1211
1212 // Number of elements in the method handles list.
1213 size_t num_method_handles_;
1214
1215 // Points to the base of the call sites id list.
1216 const CallSiteIdItem* call_site_ids_;
1217
1218 // Number of elements in the call sites list.
1219 size_t num_call_site_ids_;
1220
Richard Uhler07b3c232015-03-31 15:57:54 -07001221 // If this dex file was loaded from an oat file, oat_dex_file_ contains a
1222 // pointer to the OatDexFile it was loaded from. Otherwise oat_dex_file_ is
1223 // null.
Mathieu Chartier1b868492016-11-16 16:22:37 -08001224 mutable const OatDexFile* oat_dex_file_;
Andreas Gampee6215c02015-08-31 18:54:38 -07001225
1226 friend class DexFileVerifierTest;
Mathieu Chartier1b868492016-11-16 16:22:37 -08001227 friend class OatWriter;
Mathieu Chartier76172162016-01-26 14:54:06 -08001228 ART_FRIEND_TEST(ClassLinkerTest, RegisterDexFileName); // for constructor
Carl Shapiro1fb86202011-06-27 17:43:13 -07001229};
Mathieu Chartiere5f13e52015-02-24 09:37:21 -08001230
1231struct DexFileReference {
1232 DexFileReference(const DexFile* file, uint32_t idx) : dex_file(file), index(idx) { }
1233 const DexFile* dex_file;
1234 uint32_t index;
1235};
1236
Brian Carlstrom0d6adac2014-02-05 17:39:16 -08001237std::ostream& operator<<(std::ostream& os, const DexFile& dex_file);
Carl Shapiro1fb86202011-06-27 17:43:13 -07001238
Ian Rogers0571d352011-11-03 19:51:38 -07001239// Iterate over a dex file's ProtoId's paramters
1240class DexFileParameterIterator {
1241 public:
1242 DexFileParameterIterator(const DexFile& dex_file, const DexFile::ProtoId& proto_id)
1243 : dex_file_(dex_file), size_(0), pos_(0) {
1244 type_list_ = dex_file_.GetProtoParameters(proto_id);
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001245 if (type_list_ != nullptr) {
Ian Rogers0571d352011-11-03 19:51:38 -07001246 size_ = type_list_->Size();
1247 }
1248 }
1249 bool HasNext() const { return pos_ < size_; }
David Srbeckyb06e28e2015-12-10 13:15:00 +00001250 size_t Size() const { return size_; }
Ian Rogers0571d352011-11-03 19:51:38 -07001251 void Next() { ++pos_; }
Andreas Gampea5b09a62016-11-17 15:21:22 -08001252 dex::TypeIndex GetTypeIdx() {
Ian Rogers0571d352011-11-03 19:51:38 -07001253 return type_list_->GetTypeItem(pos_).type_idx_;
1254 }
1255 const char* GetDescriptor() {
Andreas Gampea5b09a62016-11-17 15:21:22 -08001256 return dex_file_.StringByTypeIdx(dex::TypeIndex(GetTypeIdx()));
Ian Rogers0571d352011-11-03 19:51:38 -07001257 }
1258 private:
1259 const DexFile& dex_file_;
1260 const DexFile::TypeList* type_list_;
1261 uint32_t size_;
1262 uint32_t pos_;
1263 DISALLOW_IMPLICIT_CONSTRUCTORS(DexFileParameterIterator);
1264};
1265
Ian Rogersd91d6d62013-09-25 20:26:14 -07001266// Abstract the signature of a method.
Ian Rogers03b6eaf2014-10-28 09:34:57 -07001267class Signature : public ValueObject {
Ian Rogersd91d6d62013-09-25 20:26:14 -07001268 public:
1269 std::string ToString() const;
1270
1271 static Signature NoSignature() {
1272 return Signature();
1273 }
1274
Orion Hodson6c4921b2016-09-21 15:41:06 +01001275 bool IsVoid() const;
1276 uint32_t GetNumberOfParameters() const;
1277
Ian Rogersdfb325e2013-10-30 01:00:44 -07001278 bool operator==(const Signature& rhs) const;
Ian Rogersd91d6d62013-09-25 20:26:14 -07001279 bool operator!=(const Signature& rhs) const {
1280 return !(*this == rhs);
1281 }
1282
Vladimir Markod9cffea2013-11-25 15:08:02 +00001283 bool operator==(const StringPiece& rhs) const;
Ian Rogersd91d6d62013-09-25 20:26:14 -07001284
1285 private:
1286 Signature(const DexFile* dex, const DexFile::ProtoId& proto) : dex_file_(dex), proto_id_(&proto) {
1287 }
1288
1289 Signature() : dex_file_(nullptr), proto_id_(nullptr) {
1290 }
1291
1292 friend class DexFile;
1293
1294 const DexFile* const dex_file_;
1295 const DexFile::ProtoId* const proto_id_;
1296};
1297std::ostream& operator<<(std::ostream& os, const Signature& sig);
1298
Ian Rogers0571d352011-11-03 19:51:38 -07001299// Iterate and decode class_data_item
1300class ClassDataItemIterator {
1301 public:
Ian Rogers13735952014-10-08 12:43:28 -07001302 ClassDataItemIterator(const DexFile& dex_file, const uint8_t* raw_class_data_item)
Ian Rogers0571d352011-11-03 19:51:38 -07001303 : dex_file_(dex_file), pos_(0), ptr_pos_(raw_class_data_item), last_idx_(0) {
1304 ReadClassDataHeader();
1305 if (EndOfInstanceFieldsPos() > 0) {
1306 ReadClassDataField();
1307 } else if (EndOfVirtualMethodsPos() > 0) {
1308 ReadClassDataMethod();
1309 }
1310 }
1311 uint32_t NumStaticFields() const {
1312 return header_.static_fields_size_;
1313 }
1314 uint32_t NumInstanceFields() const {
1315 return header_.instance_fields_size_;
1316 }
1317 uint32_t NumDirectMethods() const {
1318 return header_.direct_methods_size_;
1319 }
1320 uint32_t NumVirtualMethods() const {
1321 return header_.virtual_methods_size_;
1322 }
1323 bool HasNextStaticField() const {
1324 return pos_ < EndOfStaticFieldsPos();
1325 }
1326 bool HasNextInstanceField() const {
1327 return pos_ >= EndOfStaticFieldsPos() && pos_ < EndOfInstanceFieldsPos();
1328 }
1329 bool HasNextDirectMethod() const {
1330 return pos_ >= EndOfInstanceFieldsPos() && pos_ < EndOfDirectMethodsPos();
1331 }
1332 bool HasNextVirtualMethod() const {
1333 return pos_ >= EndOfDirectMethodsPos() && pos_ < EndOfVirtualMethodsPos();
1334 }
1335 bool HasNext() const {
1336 return pos_ < EndOfVirtualMethodsPos();
1337 }
Ian Rogers637c65b2013-05-31 11:46:00 -07001338 inline void Next() {
Ian Rogers0571d352011-11-03 19:51:38 -07001339 pos_++;
1340 if (pos_ < EndOfStaticFieldsPos()) {
1341 last_idx_ = GetMemberIndex();
1342 ReadClassDataField();
1343 } else if (pos_ == EndOfStaticFieldsPos() && NumInstanceFields() > 0) {
1344 last_idx_ = 0; // transition to next array, reset last index
1345 ReadClassDataField();
1346 } else if (pos_ < EndOfInstanceFieldsPos()) {
1347 last_idx_ = GetMemberIndex();
1348 ReadClassDataField();
1349 } else if (pos_ == EndOfInstanceFieldsPos() && NumDirectMethods() > 0) {
1350 last_idx_ = 0; // transition to next array, reset last index
1351 ReadClassDataMethod();
1352 } else if (pos_ < EndOfDirectMethodsPos()) {
1353 last_idx_ = GetMemberIndex();
1354 ReadClassDataMethod();
1355 } else if (pos_ == EndOfDirectMethodsPos() && NumVirtualMethods() > 0) {
1356 last_idx_ = 0; // transition to next array, reset last index
1357 ReadClassDataMethod();
1358 } else if (pos_ < EndOfVirtualMethodsPos()) {
1359 last_idx_ = GetMemberIndex();
1360 ReadClassDataMethod();
1361 } else {
1362 DCHECK(!HasNext());
1363 }
1364 }
1365 uint32_t GetMemberIndex() const {
1366 if (pos_ < EndOfInstanceFieldsPos()) {
1367 return last_idx_ + field_.field_idx_delta_;
1368 } else {
Sebastien Hertzb24bd992013-08-02 15:19:09 +02001369 DCHECK_LT(pos_, EndOfVirtualMethodsPos());
Ian Rogers0571d352011-11-03 19:51:38 -07001370 return last_idx_ + method_.method_idx_delta_;
1371 }
1372 }
Andreas Gampe51829322014-08-25 15:05:04 -07001373 uint32_t GetRawMemberAccessFlags() const {
Ian Rogers0571d352011-11-03 19:51:38 -07001374 if (pos_ < EndOfInstanceFieldsPos()) {
1375 return field_.access_flags_;
1376 } else {
Sebastien Hertzb24bd992013-08-02 15:19:09 +02001377 DCHECK_LT(pos_, EndOfVirtualMethodsPos());
Ian Rogers0571d352011-11-03 19:51:38 -07001378 return method_.access_flags_;
1379 }
1380 }
Andreas Gampe51829322014-08-25 15:05:04 -07001381 uint32_t GetFieldAccessFlags() const {
1382 return GetRawMemberAccessFlags() & kAccValidFieldFlags;
1383 }
1384 uint32_t GetMethodAccessFlags() const {
1385 return GetRawMemberAccessFlags() & kAccValidMethodFlags;
1386 }
1387 bool MemberIsNative() const {
1388 return GetRawMemberAccessFlags() & kAccNative;
1389 }
1390 bool MemberIsFinal() const {
1391 return GetRawMemberAccessFlags() & kAccFinal;
1392 }
Ian Rogers08f753d2012-08-24 14:35:25 -07001393 InvokeType GetMethodInvokeType(const DexFile::ClassDef& class_def) const {
1394 if (HasNextDirectMethod()) {
Andreas Gampe51829322014-08-25 15:05:04 -07001395 if ((GetRawMemberAccessFlags() & kAccStatic) != 0) {
Ian Rogers08f753d2012-08-24 14:35:25 -07001396 return kStatic;
1397 } else {
1398 return kDirect;
1399 }
1400 } else {
Andreas Gampe51829322014-08-25 15:05:04 -07001401 DCHECK_EQ(GetRawMemberAccessFlags() & kAccStatic, 0U);
Ian Rogers08f753d2012-08-24 14:35:25 -07001402 if ((class_def.access_flags_ & kAccInterface) != 0) {
1403 return kInterface;
Andreas Gampe51829322014-08-25 15:05:04 -07001404 } else if ((GetRawMemberAccessFlags() & kAccConstructor) != 0) {
Ian Rogers08f753d2012-08-24 14:35:25 -07001405 return kSuper;
1406 } else {
1407 return kVirtual;
1408 }
1409 }
1410 }
Ian Rogers0571d352011-11-03 19:51:38 -07001411 const DexFile::CodeItem* GetMethodCodeItem() const {
1412 return dex_file_.GetCodeItem(method_.code_off_);
1413 }
1414 uint32_t GetMethodCodeItemOffset() const {
1415 return method_.code_off_;
1416 }
Andreas Gampee6215c02015-08-31 18:54:38 -07001417 const uint8_t* DataPointer() const {
1418 return ptr_pos_;
1419 }
Ian Rogers13735952014-10-08 12:43:28 -07001420 const uint8_t* EndDataPointer() const {
jeffhao10037c82012-01-23 15:06:23 -08001421 CHECK(!HasNext());
1422 return ptr_pos_;
1423 }
Elliott Hughesa21039c2012-06-21 12:09:25 -07001424
Ian Rogers0571d352011-11-03 19:51:38 -07001425 private:
1426 // A dex file's class_data_item is leb128 encoded, this structure holds a decoded form of the
1427 // header for a class_data_item
1428 struct ClassDataHeader {
1429 uint32_t static_fields_size_; // the number of static fields
1430 uint32_t instance_fields_size_; // the number of instance fields
1431 uint32_t direct_methods_size_; // the number of direct methods
1432 uint32_t virtual_methods_size_; // the number of virtual methods
1433 } header_;
1434
1435 // Read and decode header from a class_data_item stream into header
1436 void ReadClassDataHeader();
1437
1438 uint32_t EndOfStaticFieldsPos() const {
1439 return header_.static_fields_size_;
1440 }
1441 uint32_t EndOfInstanceFieldsPos() const {
1442 return EndOfStaticFieldsPos() + header_.instance_fields_size_;
1443 }
1444 uint32_t EndOfDirectMethodsPos() const {
1445 return EndOfInstanceFieldsPos() + header_.direct_methods_size_;
1446 }
1447 uint32_t EndOfVirtualMethodsPos() const {
1448 return EndOfDirectMethodsPos() + header_.virtual_methods_size_;
1449 }
1450
1451 // A decoded version of the field of a class_data_item
1452 struct ClassDataField {
1453 uint32_t field_idx_delta_; // delta of index into the field_ids array for FieldId
1454 uint32_t access_flags_; // access flags for the field
1455 ClassDataField() : field_idx_delta_(0), access_flags_(0) {}
Elliott Hughesa21039c2012-06-21 12:09:25 -07001456
Ian Rogers0571d352011-11-03 19:51:38 -07001457 private:
1458 DISALLOW_COPY_AND_ASSIGN(ClassDataField);
Elliott Hughesee0fa762012-03-26 17:12:41 -07001459 };
1460 ClassDataField field_;
Ian Rogers0571d352011-11-03 19:51:38 -07001461
1462 // Read and decode a field from a class_data_item stream into field
1463 void ReadClassDataField();
1464
1465 // A decoded version of the method of a class_data_item
1466 struct ClassDataMethod {
1467 uint32_t method_idx_delta_; // delta of index into the method_ids array for MethodId
1468 uint32_t access_flags_;
1469 uint32_t code_off_;
1470 ClassDataMethod() : method_idx_delta_(0), access_flags_(0), code_off_(0) {}
Elliott Hughesa21039c2012-06-21 12:09:25 -07001471
Ian Rogers0571d352011-11-03 19:51:38 -07001472 private:
1473 DISALLOW_COPY_AND_ASSIGN(ClassDataMethod);
Elliott Hughesee0fa762012-03-26 17:12:41 -07001474 };
1475 ClassDataMethod method_;
Ian Rogers0571d352011-11-03 19:51:38 -07001476
1477 // Read and decode a method from a class_data_item stream into method
1478 void ReadClassDataMethod();
1479
1480 const DexFile& dex_file_;
1481 size_t pos_; // integral number of items passed
Ian Rogers13735952014-10-08 12:43:28 -07001482 const uint8_t* ptr_pos_; // pointer into stream of class_data_item
Ian Rogers0571d352011-11-03 19:51:38 -07001483 uint32_t last_idx_; // last read field or method index to apply delta to
1484 DISALLOW_IMPLICIT_CONSTRUCTORS(ClassDataItemIterator);
1485};
1486
Orion Hodson12f4ff42017-01-13 16:43:12 +00001487class EncodedArrayValueIterator {
Ian Rogers0571d352011-11-03 19:51:38 -07001488 public:
Orion Hodson12f4ff42017-01-13 16:43:12 +00001489 EncodedArrayValueIterator(const DexFile& dex_file, const uint8_t* array_data);
Shinichiro Hamaji82863f02015-11-05 16:51:33 +09001490
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001491 bool HasNext() const { return pos_ < array_size_; }
Ian Rogers0571d352011-11-03 19:51:38 -07001492
1493 void Next();
Elliott Hughesa21039c2012-06-21 12:09:25 -07001494
Ian Rogers0571d352011-11-03 19:51:38 -07001495 enum ValueType {
Orion Hodson12f4ff42017-01-13 16:43:12 +00001496 kByte = 0x00,
1497 kShort = 0x02,
1498 kChar = 0x03,
1499 kInt = 0x04,
1500 kLong = 0x06,
1501 kFloat = 0x10,
1502 kDouble = 0x11,
1503 kMethodType = 0x15,
1504 kMethodHandle = 0x16,
1505 kString = 0x17,
1506 kType = 0x18,
1507 kField = 0x19,
1508 kMethod = 0x1a,
1509 kEnum = 0x1b,
1510 kArray = 0x1c,
1511 kAnnotation = 0x1d,
1512 kNull = 0x1e,
1513 kBoolean = 0x1f,
Ian Rogers0571d352011-11-03 19:51:38 -07001514 };
1515
Shinichiro Hamaji82863f02015-11-05 16:51:33 +09001516 ValueType GetValueType() const { return type_; }
1517 const jvalue& GetJavaValue() const { return jval_; }
1518
David Sehr9323e6e2016-09-13 08:58:35 -07001519 protected:
Ian Rogers13735952014-10-08 12:43:28 -07001520 static constexpr uint8_t kEncodedValueTypeMask = 0x1f; // 0b11111
1521 static constexpr uint8_t kEncodedValueArgShift = 5;
Ian Rogers0571d352011-11-03 19:51:38 -07001522
1523 const DexFile& dex_file_;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001524 size_t array_size_; // Size of array.
1525 size_t pos_; // Current position.
Ian Rogers13735952014-10-08 12:43:28 -07001526 const uint8_t* ptr_; // Pointer into encoded data array.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001527 ValueType type_; // Type of current encoded value.
1528 jvalue jval_; // Value of current encoded value.
David Sehr9323e6e2016-09-13 08:58:35 -07001529
1530 private:
Orion Hodson12f4ff42017-01-13 16:43:12 +00001531 DISALLOW_IMPLICIT_CONSTRUCTORS(EncodedArrayValueIterator);
1532};
1533std::ostream& operator<<(std::ostream& os, const EncodedArrayValueIterator::ValueType& code);
1534
1535class EncodedStaticFieldValueIterator : public EncodedArrayValueIterator {
1536 public:
1537 EncodedStaticFieldValueIterator(const DexFile& dex_file,
1538 const DexFile::ClassDef& class_def)
1539 : EncodedArrayValueIterator(dex_file,
1540 dex_file.GetEncodedStaticFieldValuesArray(class_def))
1541 {}
1542
1543 private:
Ian Rogers0571d352011-11-03 19:51:38 -07001544 DISALLOW_IMPLICIT_CONSTRUCTORS(EncodedStaticFieldValueIterator);
1545};
Brian Carlstrom88f36542012-10-16 23:24:21 -07001546std::ostream& operator<<(std::ostream& os, const EncodedStaticFieldValueIterator::ValueType& code);
Ian Rogers0571d352011-11-03 19:51:38 -07001547
Orion Hodson12f4ff42017-01-13 16:43:12 +00001548class CallSiteArrayValueIterator : public EncodedArrayValueIterator {
1549 public:
1550 CallSiteArrayValueIterator(const DexFile& dex_file,
1551 const DexFile::CallSiteIdItem& call_site_id)
1552 : EncodedArrayValueIterator(dex_file,
1553 dex_file.GetCallSiteEncodedValuesArray(call_site_id))
1554 {}
1555
1556 uint32_t Size() const { return array_size_; }
1557
1558 private:
1559 DISALLOW_IMPLICIT_CONSTRUCTORS(CallSiteArrayValueIterator);
1560};
1561std::ostream& operator<<(std::ostream& os, const CallSiteArrayValueIterator::ValueType& code);
1562
Ian Rogers0571d352011-11-03 19:51:38 -07001563class CatchHandlerIterator {
1564 public:
1565 CatchHandlerIterator(const DexFile::CodeItem& code_item, uint32_t address);
Logan Chien736df022012-04-27 16:25:57 +08001566
1567 CatchHandlerIterator(const DexFile::CodeItem& code_item,
1568 const DexFile::TryItem& try_item);
1569
Ian Rogers13735952014-10-08 12:43:28 -07001570 explicit CatchHandlerIterator(const uint8_t* handler_data) {
Ian Rogers0571d352011-11-03 19:51:38 -07001571 Init(handler_data);
1572 }
1573
Andreas Gampea5b09a62016-11-17 15:21:22 -08001574 dex::TypeIndex GetHandlerTypeIndex() const {
Ian Rogers0571d352011-11-03 19:51:38 -07001575 return handler_.type_idx_;
1576 }
1577 uint32_t GetHandlerAddress() const {
1578 return handler_.address_;
1579 }
1580 void Next();
1581 bool HasNext() const {
1582 return remaining_count_ != -1 || catch_all_;
1583 }
1584 // End of this set of catch blocks, convenience method to locate next set of catch blocks
Ian Rogers13735952014-10-08 12:43:28 -07001585 const uint8_t* EndDataPointer() const {
Ian Rogers0571d352011-11-03 19:51:38 -07001586 CHECK(!HasNext());
1587 return current_data_;
1588 }
Elliott Hughesa21039c2012-06-21 12:09:25 -07001589
Ian Rogers0571d352011-11-03 19:51:38 -07001590 private:
Logan Chien736df022012-04-27 16:25:57 +08001591 void Init(const DexFile::CodeItem& code_item, int32_t offset);
Ian Rogers13735952014-10-08 12:43:28 -07001592 void Init(const uint8_t* handler_data);
Ian Rogers0571d352011-11-03 19:51:38 -07001593
1594 struct CatchHandlerItem {
Andreas Gampea5b09a62016-11-17 15:21:22 -08001595 dex::TypeIndex type_idx_; // type index of the caught exception type
Ian Rogers0571d352011-11-03 19:51:38 -07001596 uint32_t address_; // handler address
1597 } handler_;
Ian Rogers13735952014-10-08 12:43:28 -07001598 const uint8_t* current_data_; // the current handler in dex file.
Ian Rogers0571d352011-11-03 19:51:38 -07001599 int32_t remaining_count_; // number of handlers not read.
1600 bool catch_all_; // is there a handler that will catch all exceptions in case
1601 // that all typed handler does not match.
1602};
1603
Carl Shapiro1fb86202011-06-27 17:43:13 -07001604} // namespace art
1605
Brian Carlstromfc0e3212013-07-17 14:40:12 -07001606#endif // ART_RUNTIME_DEX_FILE_H_