blob: fe7457231a405a7d2b0aa1f03f2ae6ddc4bf1774 [file] [log] [blame]
David Sehr7629f602016-08-07 16:01:51 -07001/*
2 * Copyright (C) 2016 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 *
16 * Header file of an in-memory representation of DEX files.
17 */
18
19#ifndef ART_DEXLAYOUT_DEX_IR_H_
20#define ART_DEXLAYOUT_DEX_IR_H_
21
Jeff Haoea7c6292016-11-14 18:10:16 -080022#include <map>
David Sehr7629f602016-08-07 16:01:51 -070023#include <vector>
24#include <stdint.h>
25
Andreas Gampe5678db52017-06-08 14:11:18 -070026#include "base/stl_util.h"
David Sehr853a8e12016-09-01 13:03:50 -070027#include "dex_file-inl.h"
Jeff Hao3ab96b42016-09-09 18:35:01 -070028#include "leb128.h"
Jeff Haoa8621002016-10-04 18:13:44 +000029#include "utf.h"
David Sehr7629f602016-08-07 16:01:51 -070030
31namespace art {
32namespace dex_ir {
33
34// Forward declarations for classes used in containers or pointed to.
Jeff Hao3ab96b42016-09-09 18:35:01 -070035class AnnotationItem;
David Sehr7629f602016-08-07 16:01:51 -070036class AnnotationsDirectoryItem;
37class AnnotationSetItem;
Jeff Hao3ab96b42016-09-09 18:35:01 -070038class AnnotationSetRefList;
Jeff Hao5daee902017-04-27 18:00:38 -070039class CallSiteId;
David Sehr7629f602016-08-07 16:01:51 -070040class ClassData;
41class ClassDef;
42class CodeItem;
43class DebugInfoItem;
Jeff Hao3ab96b42016-09-09 18:35:01 -070044class EncodedAnnotation;
45class EncodedArrayItem;
46class EncodedValue;
David Sehr7629f602016-08-07 16:01:51 -070047class FieldId;
48class FieldItem;
49class Header;
50class MapList;
51class MapItem;
Jeff Hao5daee902017-04-27 18:00:38 -070052class MethodHandleItem;
David Sehr7629f602016-08-07 16:01:51 -070053class MethodId;
54class MethodItem;
Jeff Hao3ab96b42016-09-09 18:35:01 -070055class ParameterAnnotation;
David Sehr7629f602016-08-07 16:01:51 -070056class ProtoId;
Jeff Hao3ab96b42016-09-09 18:35:01 -070057class StringData;
David Sehr7629f602016-08-07 16:01:51 -070058class StringId;
59class TryItem;
60class TypeId;
Jeff Hao3ab96b42016-09-09 18:35:01 -070061class TypeList;
62
63// Item size constants.
64static constexpr size_t kHeaderItemSize = 112;
65static constexpr size_t kStringIdItemSize = 4;
66static constexpr size_t kTypeIdItemSize = 4;
67static constexpr size_t kProtoIdItemSize = 12;
68static constexpr size_t kFieldIdItemSize = 8;
69static constexpr size_t kMethodIdItemSize = 8;
70static constexpr size_t kClassDefItemSize = 32;
Jeff Hao5daee902017-04-27 18:00:38 -070071static constexpr size_t kCallSiteIdItemSize = 4;
72static constexpr size_t kMethodHandleItemSize = 8;
David Sehr7629f602016-08-07 16:01:51 -070073
74// Visitor support
75class AbstractDispatcher {
76 public:
77 AbstractDispatcher() = default;
78 virtual ~AbstractDispatcher() { }
79
80 virtual void Dispatch(Header* header) = 0;
Jeff Hao3ab96b42016-09-09 18:35:01 -070081 virtual void Dispatch(const StringData* string_data) = 0;
David Sehr7629f602016-08-07 16:01:51 -070082 virtual void Dispatch(const StringId* string_id) = 0;
83 virtual void Dispatch(const TypeId* type_id) = 0;
84 virtual void Dispatch(const ProtoId* proto_id) = 0;
85 virtual void Dispatch(const FieldId* field_id) = 0;
86 virtual void Dispatch(const MethodId* method_id) = 0;
Jeff Hao5daee902017-04-27 18:00:38 -070087 virtual void Dispatch(const CallSiteId* call_site_id) = 0;
88 virtual void Dispatch(const MethodHandleItem* method_handle_item) = 0;
David Sehr7629f602016-08-07 16:01:51 -070089 virtual void Dispatch(ClassData* class_data) = 0;
90 virtual void Dispatch(ClassDef* class_def) = 0;
91 virtual void Dispatch(FieldItem* field_item) = 0;
92 virtual void Dispatch(MethodItem* method_item) = 0;
Jeff Hao3ab96b42016-09-09 18:35:01 -070093 virtual void Dispatch(EncodedArrayItem* array_item) = 0;
David Sehr7629f602016-08-07 16:01:51 -070094 virtual void Dispatch(CodeItem* code_item) = 0;
95 virtual void Dispatch(TryItem* try_item) = 0;
96 virtual void Dispatch(DebugInfoItem* debug_info_item) = 0;
Jeff Hao3ab96b42016-09-09 18:35:01 -070097 virtual void Dispatch(AnnotationItem* annotation_item) = 0;
David Sehr7629f602016-08-07 16:01:51 -070098 virtual void Dispatch(AnnotationSetItem* annotation_set_item) = 0;
Jeff Hao3ab96b42016-09-09 18:35:01 -070099 virtual void Dispatch(AnnotationSetRefList* annotation_set_ref_list) = 0;
David Sehr7629f602016-08-07 16:01:51 -0700100 virtual void Dispatch(AnnotationsDirectoryItem* annotations_directory_item) = 0;
101 virtual void Dispatch(MapList* map_list) = 0;
102 virtual void Dispatch(MapItem* map_item) = 0;
103
104 private:
105 DISALLOW_COPY_AND_ASSIGN(AbstractDispatcher);
106};
107
108// Collections become owners of the objects added by moving them into unique pointers.
Jeff Haoea7c6292016-11-14 18:10:16 -0800109template<class T> class CollectionBase {
David Sehr7629f602016-08-07 16:01:51 -0700110 public:
Jeff Haoea7c6292016-11-14 18:10:16 -0800111 CollectionBase() = default;
112
113 uint32_t GetOffset() const { return offset_; }
114 void SetOffset(uint32_t new_offset) { offset_ = new_offset; }
115
116 private:
117 uint32_t offset_ = 0;
118
119 DISALLOW_COPY_AND_ASSIGN(CollectionBase);
120};
121
122template<class T> class CollectionVector : public CollectionBase<T> {
123 public:
124 CollectionVector() = default;
125
Jeff Hao3ab96b42016-09-09 18:35:01 -0700126 void AddIndexedItem(T* object, uint32_t offset, uint32_t index) {
127 object->SetOffset(offset);
128 object->SetIndex(index);
129 collection_.push_back(std::unique_ptr<T>(object));
David Sehr7629f602016-08-07 16:01:51 -0700130 }
David Sehr7629f602016-08-07 16:01:51 -0700131 uint32_t Size() const { return collection_.size(); }
Jeff Haoea7c6292016-11-14 18:10:16 -0800132 std::vector<std::unique_ptr<T>>& Collection() { return collection_; }
David Sehr7629f602016-08-07 16:01:51 -0700133
134 private:
135 std::vector<std::unique_ptr<T>> collection_;
Jeff Hao3ab96b42016-09-09 18:35:01 -0700136
Jeff Haoea7c6292016-11-14 18:10:16 -0800137 DISALLOW_COPY_AND_ASSIGN(CollectionVector);
138};
139
140template<class T> class CollectionMap : public CollectionBase<T> {
141 public:
142 CollectionMap() = default;
143
Mathieu Chartiera2973d72017-02-14 17:12:20 -0800144 // Returns the existing item if it is already inserted, null otherwise.
145 T* GetExistingObject(uint32_t offset) {
146 auto it = collection_.find(offset);
147 return it != collection_.end() ? it->second.get() : nullptr;
148 }
149
Jeff Haoea7c6292016-11-14 18:10:16 -0800150 void AddItem(T* object, uint32_t offset) {
151 object->SetOffset(offset);
Mathieu Chartiera2973d72017-02-14 17:12:20 -0800152 auto it = collection_.emplace(offset, std::unique_ptr<T>(object));
153 CHECK(it.second) << "CollectionMap already has an object with offset " << offset << " "
154 << " and address " << it.first->second.get();
Jeff Haoea7c6292016-11-14 18:10:16 -0800155 }
156 uint32_t Size() const { return collection_.size(); }
157 std::map<uint32_t, std::unique_ptr<T>>& Collection() { return collection_; }
158
159 private:
160 std::map<uint32_t, std::unique_ptr<T>> collection_;
161
162 DISALLOW_COPY_AND_ASSIGN(CollectionMap);
David Sehr7629f602016-08-07 16:01:51 -0700163};
164
Jeff Hao3ab96b42016-09-09 18:35:01 -0700165class Collections {
166 public:
167 Collections() = default;
168
169 std::vector<std::unique_ptr<StringId>>& StringIds() { return string_ids_.Collection(); }
170 std::vector<std::unique_ptr<TypeId>>& TypeIds() { return type_ids_.Collection(); }
171 std::vector<std::unique_ptr<ProtoId>>& ProtoIds() { return proto_ids_.Collection(); }
172 std::vector<std::unique_ptr<FieldId>>& FieldIds() { return field_ids_.Collection(); }
173 std::vector<std::unique_ptr<MethodId>>& MethodIds() { return method_ids_.Collection(); }
174 std::vector<std::unique_ptr<ClassDef>>& ClassDefs() { return class_defs_.Collection(); }
Jeff Hao5daee902017-04-27 18:00:38 -0700175 std::vector<std::unique_ptr<CallSiteId>>& CallSiteIds() { return call_site_ids_.Collection(); }
176 std::vector<std::unique_ptr<MethodHandleItem>>& MethodHandleItems()
177 { return method_handle_items_.Collection(); }
Jeff Haoea7c6292016-11-14 18:10:16 -0800178 std::map<uint32_t, std::unique_ptr<StringData>>& StringDatas()
179 { return string_datas_.Collection(); }
180 std::map<uint32_t, std::unique_ptr<TypeList>>& TypeLists() { return type_lists_.Collection(); }
181 std::map<uint32_t, std::unique_ptr<EncodedArrayItem>>& EncodedArrayItems()
Jeff Hao3ab96b42016-09-09 18:35:01 -0700182 { return encoded_array_items_.Collection(); }
Jeff Haoea7c6292016-11-14 18:10:16 -0800183 std::map<uint32_t, std::unique_ptr<AnnotationItem>>& AnnotationItems()
Jeff Haoa8621002016-10-04 18:13:44 +0000184 { return annotation_items_.Collection(); }
Jeff Haoea7c6292016-11-14 18:10:16 -0800185 std::map<uint32_t, std::unique_ptr<AnnotationSetItem>>& AnnotationSetItems()
Jeff Haoa8621002016-10-04 18:13:44 +0000186 { return annotation_set_items_.Collection(); }
Jeff Haoea7c6292016-11-14 18:10:16 -0800187 std::map<uint32_t, std::unique_ptr<AnnotationSetRefList>>& AnnotationSetRefLists()
Jeff Haoa8621002016-10-04 18:13:44 +0000188 { return annotation_set_ref_lists_.Collection(); }
Jeff Haoea7c6292016-11-14 18:10:16 -0800189 std::map<uint32_t, std::unique_ptr<AnnotationsDirectoryItem>>& AnnotationsDirectoryItems()
Jeff Haoa8621002016-10-04 18:13:44 +0000190 { return annotations_directory_items_.Collection(); }
Jeff Haoea7c6292016-11-14 18:10:16 -0800191 std::map<uint32_t, std::unique_ptr<DebugInfoItem>>& DebugInfoItems()
Jeff Haoa8621002016-10-04 18:13:44 +0000192 { return debug_info_items_.Collection(); }
Jeff Haoea7c6292016-11-14 18:10:16 -0800193 std::map<uint32_t, std::unique_ptr<CodeItem>>& CodeItems() { return code_items_.Collection(); }
194 std::map<uint32_t, std::unique_ptr<ClassData>>& ClassDatas() { return class_datas_.Collection(); }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700195
196 void CreateStringId(const DexFile& dex_file, uint32_t i);
197 void CreateTypeId(const DexFile& dex_file, uint32_t i);
198 void CreateProtoId(const DexFile& dex_file, uint32_t i);
199 void CreateFieldId(const DexFile& dex_file, uint32_t i);
200 void CreateMethodId(const DexFile& dex_file, uint32_t i);
201 void CreateClassDef(const DexFile& dex_file, uint32_t i);
Jeff Hao5daee902017-04-27 18:00:38 -0700202 void CreateCallSiteId(const DexFile& dex_file, uint32_t i);
203 void CreateMethodHandleItem(const DexFile& dex_file, uint32_t i);
204
205 void CreateCallSitesAndMethodHandles(const DexFile& dex_file);
Jeff Hao3ab96b42016-09-09 18:35:01 -0700206
Jeff Haoa8621002016-10-04 18:13:44 +0000207 TypeList* CreateTypeList(const DexFile::TypeList* type_list, uint32_t offset);
Jeff Hao3ab96b42016-09-09 18:35:01 -0700208 EncodedArrayItem* CreateEncodedArrayItem(const uint8_t* static_data, uint32_t offset);
209 AnnotationItem* CreateAnnotationItem(const DexFile::AnnotationItem* annotation, uint32_t offset);
210 AnnotationSetItem* CreateAnnotationSetItem(const DexFile& dex_file,
Jeff Haobe9b44b2017-02-16 13:34:38 -0800211 const DexFile::AnnotationSetItem* disk_annotations_item, uint32_t offset);
Jeff Hao3ab96b42016-09-09 18:35:01 -0700212 AnnotationsDirectoryItem* CreateAnnotationsDirectoryItem(const DexFile& dex_file,
213 const DexFile::AnnotationsDirectoryItem* disk_annotations_item, uint32_t offset);
214 CodeItem* CreateCodeItem(
215 const DexFile& dex_file, const DexFile::CodeItem& disk_code_item, uint32_t offset);
216 ClassData* CreateClassData(const DexFile& dex_file, const uint8_t* encoded_data, uint32_t offset);
217
Jeff Hao9804e9e2017-06-15 14:04:51 -0700218 StringId* GetStringId(uint32_t index) {
219 CHECK_LT(index, StringIdsSize());
220 return StringIds()[index].get();
221 }
222 TypeId* GetTypeId(uint32_t index) {
223 CHECK_LT(index, TypeIdsSize());
224 return TypeIds()[index].get();
225 }
226 ProtoId* GetProtoId(uint32_t index) {
227 CHECK_LT(index, ProtoIdsSize());
228 return ProtoIds()[index].get();
229 }
230 FieldId* GetFieldId(uint32_t index) {
231 CHECK_LT(index, FieldIdsSize());
232 return FieldIds()[index].get();
233 }
234 MethodId* GetMethodId(uint32_t index) {
235 CHECK_LT(index, MethodIdsSize());
236 return MethodIds()[index].get();
237 }
238 ClassDef* GetClassDef(uint32_t index) {
239 CHECK_LT(index, ClassDefsSize());
240 return ClassDefs()[index].get();
241 }
242 CallSiteId* GetCallSiteId(uint32_t index) {
243 CHECK_LT(index, CallSiteIdsSize());
244 return CallSiteIds()[index].get();
245 }
246 MethodHandleItem* GetMethodHandle(uint32_t index) {
247 CHECK_LT(index, MethodHandleItemsSize());
248 return MethodHandleItems()[index].get();
249 }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700250
251 StringId* GetStringIdOrNullPtr(uint32_t index) {
252 return index == DexFile::kDexNoIndex ? nullptr : GetStringId(index);
253 }
254 TypeId* GetTypeIdOrNullPtr(uint16_t index) {
255 return index == DexFile::kDexNoIndex16 ? nullptr : GetTypeId(index);
256 }
257
258 uint32_t StringIdsOffset() const { return string_ids_.GetOffset(); }
259 uint32_t TypeIdsOffset() const { return type_ids_.GetOffset(); }
260 uint32_t ProtoIdsOffset() const { return proto_ids_.GetOffset(); }
261 uint32_t FieldIdsOffset() const { return field_ids_.GetOffset(); }
262 uint32_t MethodIdsOffset() const { return method_ids_.GetOffset(); }
263 uint32_t ClassDefsOffset() const { return class_defs_.GetOffset(); }
Jeff Hao5daee902017-04-27 18:00:38 -0700264 uint32_t CallSiteIdsOffset() const { return call_site_ids_.GetOffset(); }
265 uint32_t MethodHandleItemsOffset() const { return method_handle_items_.GetOffset(); }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700266 uint32_t StringDatasOffset() const { return string_datas_.GetOffset(); }
267 uint32_t TypeListsOffset() const { return type_lists_.GetOffset(); }
Jeff Haoa8621002016-10-04 18:13:44 +0000268 uint32_t EncodedArrayItemsOffset() const { return encoded_array_items_.GetOffset(); }
269 uint32_t AnnotationItemsOffset() const { return annotation_items_.GetOffset(); }
270 uint32_t AnnotationSetItemsOffset() const { return annotation_set_items_.GetOffset(); }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700271 uint32_t AnnotationSetRefListsOffset() const { return annotation_set_ref_lists_.GetOffset(); }
Jeff Haoa8621002016-10-04 18:13:44 +0000272 uint32_t AnnotationsDirectoryItemsOffset() const
273 { return annotations_directory_items_.GetOffset(); }
274 uint32_t DebugInfoItemsOffset() const { return debug_info_items_.GetOffset(); }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700275 uint32_t CodeItemsOffset() const { return code_items_.GetOffset(); }
276 uint32_t ClassDatasOffset() const { return class_datas_.GetOffset(); }
Jeff Haoea7c6292016-11-14 18:10:16 -0800277 uint32_t MapListOffset() const { return map_list_offset_; }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700278
279 void SetStringIdsOffset(uint32_t new_offset) { string_ids_.SetOffset(new_offset); }
280 void SetTypeIdsOffset(uint32_t new_offset) { type_ids_.SetOffset(new_offset); }
281 void SetProtoIdsOffset(uint32_t new_offset) { proto_ids_.SetOffset(new_offset); }
282 void SetFieldIdsOffset(uint32_t new_offset) { field_ids_.SetOffset(new_offset); }
283 void SetMethodIdsOffset(uint32_t new_offset) { method_ids_.SetOffset(new_offset); }
284 void SetClassDefsOffset(uint32_t new_offset) { class_defs_.SetOffset(new_offset); }
Jeff Hao5daee902017-04-27 18:00:38 -0700285 void SetCallSiteIdsOffset(uint32_t new_offset) { call_site_ids_.SetOffset(new_offset); }
286 void SetMethodHandleItemsOffset(uint32_t new_offset)
287 { method_handle_items_.SetOffset(new_offset); }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700288 void SetStringDatasOffset(uint32_t new_offset) { string_datas_.SetOffset(new_offset); }
289 void SetTypeListsOffset(uint32_t new_offset) { type_lists_.SetOffset(new_offset); }
Jeff Haoa8621002016-10-04 18:13:44 +0000290 void SetEncodedArrayItemsOffset(uint32_t new_offset)
291 { encoded_array_items_.SetOffset(new_offset); }
292 void SetAnnotationItemsOffset(uint32_t new_offset) { annotation_items_.SetOffset(new_offset); }
293 void SetAnnotationSetItemsOffset(uint32_t new_offset)
294 { annotation_set_items_.SetOffset(new_offset); }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700295 void SetAnnotationSetRefListsOffset(uint32_t new_offset)
296 { annotation_set_ref_lists_.SetOffset(new_offset); }
Jeff Haoa8621002016-10-04 18:13:44 +0000297 void SetAnnotationsDirectoryItemsOffset(uint32_t new_offset)
Jeff Hao3ab96b42016-09-09 18:35:01 -0700298 { annotations_directory_items_.SetOffset(new_offset); }
Jeff Haoa8621002016-10-04 18:13:44 +0000299 void SetDebugInfoItemsOffset(uint32_t new_offset) { debug_info_items_.SetOffset(new_offset); }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700300 void SetCodeItemsOffset(uint32_t new_offset) { code_items_.SetOffset(new_offset); }
301 void SetClassDatasOffset(uint32_t new_offset) { class_datas_.SetOffset(new_offset); }
Jeff Haoea7c6292016-11-14 18:10:16 -0800302 void SetMapListOffset(uint32_t new_offset) { map_list_offset_ = new_offset; }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700303
304 uint32_t StringIdsSize() const { return string_ids_.Size(); }
305 uint32_t TypeIdsSize() const { return type_ids_.Size(); }
306 uint32_t ProtoIdsSize() const { return proto_ids_.Size(); }
307 uint32_t FieldIdsSize() const { return field_ids_.Size(); }
308 uint32_t MethodIdsSize() const { return method_ids_.Size(); }
309 uint32_t ClassDefsSize() const { return class_defs_.Size(); }
Jeff Hao5daee902017-04-27 18:00:38 -0700310 uint32_t CallSiteIdsSize() const { return call_site_ids_.Size(); }
311 uint32_t MethodHandleItemsSize() const { return method_handle_items_.Size(); }
David Sehrcdcfde72016-09-26 07:44:04 -0700312 uint32_t StringDatasSize() const { return string_datas_.Size(); }
313 uint32_t TypeListsSize() const { return type_lists_.Size(); }
Jeff Haoa8621002016-10-04 18:13:44 +0000314 uint32_t EncodedArrayItemsSize() const { return encoded_array_items_.Size(); }
315 uint32_t AnnotationItemsSize() const { return annotation_items_.Size(); }
316 uint32_t AnnotationSetItemsSize() const { return annotation_set_items_.Size(); }
David Sehrcdcfde72016-09-26 07:44:04 -0700317 uint32_t AnnotationSetRefListsSize() const { return annotation_set_ref_lists_.Size(); }
Jeff Haoa8621002016-10-04 18:13:44 +0000318 uint32_t AnnotationsDirectoryItemsSize() const { return annotations_directory_items_.Size(); }
319 uint32_t DebugInfoItemsSize() const { return debug_info_items_.Size(); }
David Sehrcdcfde72016-09-26 07:44:04 -0700320 uint32_t CodeItemsSize() const { return code_items_.Size(); }
321 uint32_t ClassDatasSize() const { return class_datas_.Size(); }
322
Jeff Hao3ab96b42016-09-09 18:35:01 -0700323 private:
324 EncodedValue* ReadEncodedValue(const uint8_t** data);
325 EncodedValue* ReadEncodedValue(const uint8_t** data, uint8_t type, uint8_t length);
326 void ReadEncodedValue(const uint8_t** data, uint8_t type, uint8_t length, EncodedValue* item);
327
328 ParameterAnnotation* GenerateParameterAnnotation(const DexFile& dex_file, MethodId* method_id,
329 const DexFile::AnnotationSetRefList* annotation_set_ref_list, uint32_t offset);
330 MethodItem* GenerateMethodItem(const DexFile& dex_file, ClassDataItemIterator& cdii);
331
Jeff Haoea7c6292016-11-14 18:10:16 -0800332 CollectionVector<StringId> string_ids_;
333 CollectionVector<TypeId> type_ids_;
334 CollectionVector<ProtoId> proto_ids_;
335 CollectionVector<FieldId> field_ids_;
336 CollectionVector<MethodId> method_ids_;
337 CollectionVector<ClassDef> class_defs_;
Jeff Hao5daee902017-04-27 18:00:38 -0700338 CollectionVector<CallSiteId> call_site_ids_;
339 CollectionVector<MethodHandleItem> method_handle_items_;
Jeff Hao3ab96b42016-09-09 18:35:01 -0700340
Jeff Haoea7c6292016-11-14 18:10:16 -0800341 CollectionMap<StringData> string_datas_;
342 CollectionMap<TypeList> type_lists_;
343 CollectionMap<EncodedArrayItem> encoded_array_items_;
344 CollectionMap<AnnotationItem> annotation_items_;
345 CollectionMap<AnnotationSetItem> annotation_set_items_;
346 CollectionMap<AnnotationSetRefList> annotation_set_ref_lists_;
347 CollectionMap<AnnotationsDirectoryItem> annotations_directory_items_;
348 CollectionMap<DebugInfoItem> debug_info_items_;
349 CollectionMap<CodeItem> code_items_;
350 CollectionMap<ClassData> class_datas_;
Jeff Hao3ab96b42016-09-09 18:35:01 -0700351
Jeff Haoea7c6292016-11-14 18:10:16 -0800352 uint32_t map_list_offset_ = 0;
Jeff Haoa8621002016-10-04 18:13:44 +0000353
Jeff Hao3ab96b42016-09-09 18:35:01 -0700354 DISALLOW_COPY_AND_ASSIGN(Collections);
355};
356
David Sehr7629f602016-08-07 16:01:51 -0700357class Item {
358 public:
Jeff Hao3ab96b42016-09-09 18:35:01 -0700359 Item() { }
David Sehr7629f602016-08-07 16:01:51 -0700360 virtual ~Item() { }
David Sehr853a8e12016-09-01 13:03:50 -0700361
David Sehr7629f602016-08-07 16:01:51 -0700362 uint32_t GetOffset() const { return offset_; }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700363 uint32_t GetSize() const { return size_; }
David Sehr7629f602016-08-07 16:01:51 -0700364 void SetOffset(uint32_t offset) { offset_ = offset; }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700365 void SetSize(uint32_t size) { size_ = size; }
David Sehr853a8e12016-09-01 13:03:50 -0700366
David Sehr7629f602016-08-07 16:01:51 -0700367 protected:
Jeff Hao3ab96b42016-09-09 18:35:01 -0700368 Item(uint32_t offset, uint32_t size) : offset_(offset), size_(size) { }
369
David Sehr7629f602016-08-07 16:01:51 -0700370 uint32_t offset_ = 0;
Jeff Hao3ab96b42016-09-09 18:35:01 -0700371 uint32_t size_ = 0;
372};
373
374class IndexedItem : public Item {
375 public:
376 IndexedItem() { }
377 virtual ~IndexedItem() { }
378
379 uint32_t GetIndex() const { return index_; }
380 void SetIndex(uint32_t index) { index_ = index; }
381
382 protected:
383 IndexedItem(uint32_t offset, uint32_t size, uint32_t index)
384 : Item(offset, size), index_(index) { }
385
386 uint32_t index_ = 0;
David Sehr7629f602016-08-07 16:01:51 -0700387};
388
389class Header : public Item {
390 public:
David Sehr853a8e12016-09-01 13:03:50 -0700391 Header(const uint8_t* magic,
392 uint32_t checksum,
393 const uint8_t* signature,
394 uint32_t endian_tag,
395 uint32_t file_size,
396 uint32_t header_size,
397 uint32_t link_size,
398 uint32_t link_offset,
399 uint32_t data_size,
400 uint32_t data_offset)
Jeff Hao3ab96b42016-09-09 18:35:01 -0700401 : Item(0, kHeaderItemSize),
402 checksum_(checksum),
David Sehr853a8e12016-09-01 13:03:50 -0700403 endian_tag_(endian_tag),
404 file_size_(file_size),
405 header_size_(header_size),
406 link_size_(link_size),
407 link_offset_(link_offset),
408 data_size_(data_size),
409 data_offset_(data_offset) {
410 memcpy(magic_, magic, sizeof(magic_));
411 memcpy(signature_, signature, sizeof(signature_));
412 }
David Sehr7629f602016-08-07 16:01:51 -0700413 ~Header() OVERRIDE { }
414
Jeff Hao3ab96b42016-09-09 18:35:01 -0700415 static size_t ItemSize() { return kHeaderItemSize; }
416
David Sehr7629f602016-08-07 16:01:51 -0700417 const uint8_t* Magic() const { return magic_; }
418 uint32_t Checksum() const { return checksum_; }
419 const uint8_t* Signature() const { return signature_; }
420 uint32_t EndianTag() const { return endian_tag_; }
421 uint32_t FileSize() const { return file_size_; }
422 uint32_t HeaderSize() const { return header_size_; }
423 uint32_t LinkSize() const { return link_size_; }
424 uint32_t LinkOffset() const { return link_offset_; }
425 uint32_t DataSize() const { return data_size_; }
426 uint32_t DataOffset() const { return data_offset_; }
427
428 void SetChecksum(uint32_t new_checksum) { checksum_ = new_checksum; }
429 void SetSignature(const uint8_t* new_signature) {
430 memcpy(signature_, new_signature, sizeof(signature_));
431 }
432 void SetFileSize(uint32_t new_file_size) { file_size_ = new_file_size; }
433 void SetHeaderSize(uint32_t new_header_size) { header_size_ = new_header_size; }
434 void SetLinkSize(uint32_t new_link_size) { link_size_ = new_link_size; }
435 void SetLinkOffset(uint32_t new_link_offset) { link_offset_ = new_link_offset; }
436 void SetDataSize(uint32_t new_data_size) { data_size_ = new_data_size; }
437 void SetDataOffset(uint32_t new_data_offset) { data_offset_ = new_data_offset; }
438
Jeff Hao3ab96b42016-09-09 18:35:01 -0700439 Collections& GetCollections() { return collections_; }
Jeff Haoc3acfc52016-08-29 14:18:26 -0700440
David Sehr7629f602016-08-07 16:01:51 -0700441 void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); }
442
443 private:
David Sehr7629f602016-08-07 16:01:51 -0700444 uint8_t magic_[8];
445 uint32_t checksum_;
446 uint8_t signature_[DexFile::kSha1DigestSize];
447 uint32_t endian_tag_;
448 uint32_t file_size_;
449 uint32_t header_size_;
450 uint32_t link_size_;
451 uint32_t link_offset_;
452 uint32_t data_size_;
453 uint32_t data_offset_;
454
Jeff Hao3ab96b42016-09-09 18:35:01 -0700455 Collections collections_;
456
David Sehr7629f602016-08-07 16:01:51 -0700457 DISALLOW_COPY_AND_ASSIGN(Header);
458};
459
Jeff Hao3ab96b42016-09-09 18:35:01 -0700460class StringData : public Item {
David Sehr7629f602016-08-07 16:01:51 -0700461 public:
Jeff Hao3ab96b42016-09-09 18:35:01 -0700462 explicit StringData(const char* data) : data_(strdup(data)) {
Jeff Haoa8621002016-10-04 18:13:44 +0000463 size_ = UnsignedLeb128Size(CountModifiedUtf8Chars(data)) + strlen(data);
Jeff Hao3ab96b42016-09-09 18:35:01 -0700464 }
David Sehr7629f602016-08-07 16:01:51 -0700465
466 const char* Data() const { return data_.get(); }
467
468 void Accept(AbstractDispatcher* dispatch) const { dispatch->Dispatch(this); }
469
470 private:
Jeff Haoa8621002016-10-04 18:13:44 +0000471 UniqueCPtr<const char> data_;
Jeff Hao3ab96b42016-09-09 18:35:01 -0700472
473 DISALLOW_COPY_AND_ASSIGN(StringData);
474};
475
476class StringId : public IndexedItem {
477 public:
478 explicit StringId(StringData* string_data) : string_data_(string_data) {
479 size_ = kStringIdItemSize;
480 }
481 ~StringId() OVERRIDE { }
482
483 static size_t ItemSize() { return kStringIdItemSize; }
484
485 const char* Data() const { return string_data_->Data(); }
486 StringData* DataItem() const { return string_data_; }
487
488 void Accept(AbstractDispatcher* dispatch) const { dispatch->Dispatch(this); }
489
490 private:
491 StringData* string_data_;
492
David Sehr7629f602016-08-07 16:01:51 -0700493 DISALLOW_COPY_AND_ASSIGN(StringId);
494};
495
Jeff Hao3ab96b42016-09-09 18:35:01 -0700496class TypeId : public IndexedItem {
David Sehr7629f602016-08-07 16:01:51 -0700497 public:
Jeff Hao3ab96b42016-09-09 18:35:01 -0700498 explicit TypeId(StringId* string_id) : string_id_(string_id) { size_ = kTypeIdItemSize; }
David Sehr7629f602016-08-07 16:01:51 -0700499 ~TypeId() OVERRIDE { }
500
Jeff Hao3ab96b42016-09-09 18:35:01 -0700501 static size_t ItemSize() { return kTypeIdItemSize; }
502
David Sehr7629f602016-08-07 16:01:51 -0700503 StringId* GetStringId() const { return string_id_; }
504
505 void Accept(AbstractDispatcher* dispatch) const { dispatch->Dispatch(this); }
506
507 private:
508 StringId* string_id_;
Jeff Hao3ab96b42016-09-09 18:35:01 -0700509
David Sehr7629f602016-08-07 16:01:51 -0700510 DISALLOW_COPY_AND_ASSIGN(TypeId);
511};
512
David Sehr853a8e12016-09-01 13:03:50 -0700513using TypeIdVector = std::vector<const TypeId*>;
514
Jeff Hao3ab96b42016-09-09 18:35:01 -0700515class TypeList : public Item {
David Sehr7629f602016-08-07 16:01:51 -0700516 public:
Jeff Hao3ab96b42016-09-09 18:35:01 -0700517 explicit TypeList(TypeIdVector* type_list) : type_list_(type_list) {
518 size_ = sizeof(uint32_t) + (type_list->size() * sizeof(uint16_t));
519 }
520 ~TypeList() OVERRIDE { }
521
522 const TypeIdVector* GetTypeList() const { return type_list_.get(); }
523
524 private:
525 std::unique_ptr<TypeIdVector> type_list_;
526
527 DISALLOW_COPY_AND_ASSIGN(TypeList);
528};
529
530class ProtoId : public IndexedItem {
531 public:
532 ProtoId(const StringId* shorty, const TypeId* return_type, TypeList* parameters)
533 : shorty_(shorty), return_type_(return_type), parameters_(parameters)
534 { size_ = kProtoIdItemSize; }
David Sehr7629f602016-08-07 16:01:51 -0700535 ~ProtoId() OVERRIDE { }
536
Jeff Hao3ab96b42016-09-09 18:35:01 -0700537 static size_t ItemSize() { return kProtoIdItemSize; }
538
David Sehr7629f602016-08-07 16:01:51 -0700539 const StringId* Shorty() const { return shorty_; }
540 const TypeId* ReturnType() const { return return_type_; }
Jeff Haoa8621002016-10-04 18:13:44 +0000541 const TypeList* Parameters() const { return parameters_; }
David Sehr7629f602016-08-07 16:01:51 -0700542
543 void Accept(AbstractDispatcher* dispatch) const { dispatch->Dispatch(this); }
544
545 private:
546 const StringId* shorty_;
547 const TypeId* return_type_;
Jeff Haoa8621002016-10-04 18:13:44 +0000548 TypeList* parameters_; // This can be nullptr.
Jeff Hao3ab96b42016-09-09 18:35:01 -0700549
David Sehr7629f602016-08-07 16:01:51 -0700550 DISALLOW_COPY_AND_ASSIGN(ProtoId);
551};
552
Jeff Hao3ab96b42016-09-09 18:35:01 -0700553class FieldId : public IndexedItem {
David Sehr7629f602016-08-07 16:01:51 -0700554 public:
David Sehr853a8e12016-09-01 13:03:50 -0700555 FieldId(const TypeId* klass, const TypeId* type, const StringId* name)
Jeff Hao3ab96b42016-09-09 18:35:01 -0700556 : class_(klass), type_(type), name_(name) { size_ = kFieldIdItemSize; }
David Sehr7629f602016-08-07 16:01:51 -0700557 ~FieldId() OVERRIDE { }
558
Jeff Hao3ab96b42016-09-09 18:35:01 -0700559 static size_t ItemSize() { return kFieldIdItemSize; }
560
David Sehr7629f602016-08-07 16:01:51 -0700561 const TypeId* Class() const { return class_; }
562 const TypeId* Type() const { return type_; }
563 const StringId* Name() const { return name_; }
564
565 void Accept(AbstractDispatcher* dispatch) const { dispatch->Dispatch(this); }
566
567 private:
568 const TypeId* class_;
569 const TypeId* type_;
570 const StringId* name_;
Jeff Hao3ab96b42016-09-09 18:35:01 -0700571
David Sehr7629f602016-08-07 16:01:51 -0700572 DISALLOW_COPY_AND_ASSIGN(FieldId);
573};
574
Jeff Hao3ab96b42016-09-09 18:35:01 -0700575class MethodId : public IndexedItem {
David Sehr7629f602016-08-07 16:01:51 -0700576 public:
David Sehr853a8e12016-09-01 13:03:50 -0700577 MethodId(const TypeId* klass, const ProtoId* proto, const StringId* name)
Jeff Hao3ab96b42016-09-09 18:35:01 -0700578 : class_(klass), proto_(proto), name_(name) { size_ = kMethodIdItemSize; }
David Sehr7629f602016-08-07 16:01:51 -0700579 ~MethodId() OVERRIDE { }
580
Jeff Hao3ab96b42016-09-09 18:35:01 -0700581 static size_t ItemSize() { return kMethodIdItemSize; }
582
David Sehr7629f602016-08-07 16:01:51 -0700583 const TypeId* Class() const { return class_; }
584 const ProtoId* Proto() const { return proto_; }
585 const StringId* Name() const { return name_; }
586
587 void Accept(AbstractDispatcher* dispatch) const { dispatch->Dispatch(this); }
588
589 private:
590 const TypeId* class_;
591 const ProtoId* proto_;
592 const StringId* name_;
Jeff Hao3ab96b42016-09-09 18:35:01 -0700593
David Sehr7629f602016-08-07 16:01:51 -0700594 DISALLOW_COPY_AND_ASSIGN(MethodId);
595};
596
597class FieldItem : public Item {
598 public:
David Sehr853a8e12016-09-01 13:03:50 -0700599 FieldItem(uint32_t access_flags, const FieldId* field_id)
600 : access_flags_(access_flags), field_id_(field_id) { }
David Sehr7629f602016-08-07 16:01:51 -0700601 ~FieldItem() OVERRIDE { }
602
603 uint32_t GetAccessFlags() const { return access_flags_; }
604 const FieldId* GetFieldId() const { return field_id_; }
605
606 void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); }
607
608 private:
609 uint32_t access_flags_;
610 const FieldId* field_id_;
Jeff Hao3ab96b42016-09-09 18:35:01 -0700611
David Sehr7629f602016-08-07 16:01:51 -0700612 DISALLOW_COPY_AND_ASSIGN(FieldItem);
613};
614
David Sehr853a8e12016-09-01 13:03:50 -0700615using FieldItemVector = std::vector<std::unique_ptr<FieldItem>>;
616
David Sehr7629f602016-08-07 16:01:51 -0700617class MethodItem : public Item {
618 public:
Jeff Haoea7c6292016-11-14 18:10:16 -0800619 MethodItem(uint32_t access_flags, const MethodId* method_id, CodeItem* code)
David Sehr853a8e12016-09-01 13:03:50 -0700620 : access_flags_(access_flags), method_id_(method_id), code_(code) { }
David Sehr7629f602016-08-07 16:01:51 -0700621 ~MethodItem() OVERRIDE { }
622
623 uint32_t GetAccessFlags() const { return access_flags_; }
624 const MethodId* GetMethodId() const { return method_id_; }
Jeff Haoea7c6292016-11-14 18:10:16 -0800625 CodeItem* GetCodeItem() { return code_; }
David Sehr7629f602016-08-07 16:01:51 -0700626
627 void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); }
628
629 private:
630 uint32_t access_flags_;
631 const MethodId* method_id_;
Jeff Haoea7c6292016-11-14 18:10:16 -0800632 CodeItem* code_; // This can be nullptr.
Jeff Hao3ab96b42016-09-09 18:35:01 -0700633
David Sehr7629f602016-08-07 16:01:51 -0700634 DISALLOW_COPY_AND_ASSIGN(MethodItem);
635};
636
David Sehr853a8e12016-09-01 13:03:50 -0700637using MethodItemVector = std::vector<std::unique_ptr<MethodItem>>;
638
Jeff Hao3ab96b42016-09-09 18:35:01 -0700639class EncodedValue {
David Sehr7629f602016-08-07 16:01:51 -0700640 public:
Jeff Hao3ab96b42016-09-09 18:35:01 -0700641 explicit EncodedValue(uint8_t type) : type_(type) { }
David Sehr7629f602016-08-07 16:01:51 -0700642
643 int8_t Type() const { return type_; }
David Sehr7629f602016-08-07 16:01:51 -0700644
Jeff Hao3ab96b42016-09-09 18:35:01 -0700645 void SetBoolean(bool z) { u_.bool_val_ = z; }
646 void SetByte(int8_t b) { u_.byte_val_ = b; }
647 void SetShort(int16_t s) { u_.short_val_ = s; }
648 void SetChar(uint16_t c) { u_.char_val_ = c; }
649 void SetInt(int32_t i) { u_.int_val_ = i; }
650 void SetLong(int64_t l) { u_.long_val_ = l; }
651 void SetFloat(float f) { u_.float_val_ = f; }
652 void SetDouble(double d) { u_.double_val_ = d; }
653 void SetStringId(StringId* string_id) { u_.string_val_ = string_id; }
654 void SetTypeId(TypeId* type_id) { u_.type_val_ = type_id; }
Jeff Hao5daee902017-04-27 18:00:38 -0700655 void SetProtoId(ProtoId* proto_id) { u_.proto_val_ = proto_id; }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700656 void SetFieldId(FieldId* field_id) { u_.field_val_ = field_id; }
657 void SetMethodId(MethodId* method_id) { u_.method_val_ = method_id; }
Jeff Hao5daee902017-04-27 18:00:38 -0700658 void SetMethodHandle(MethodHandleItem* method_handle) { u_.method_handle_val_ = method_handle; }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700659 void SetEncodedArray(EncodedArrayItem* encoded_array) { encoded_array_.reset(encoded_array); }
660 void SetEncodedAnnotation(EncodedAnnotation* encoded_annotation)
661 { encoded_annotation_.reset(encoded_annotation); }
662
663 bool GetBoolean() const { return u_.bool_val_; }
664 int8_t GetByte() const { return u_.byte_val_; }
665 int16_t GetShort() const { return u_.short_val_; }
666 uint16_t GetChar() const { return u_.char_val_; }
667 int32_t GetInt() const { return u_.int_val_; }
668 int64_t GetLong() const { return u_.long_val_; }
669 float GetFloat() const { return u_.float_val_; }
670 double GetDouble() const { return u_.double_val_; }
671 StringId* GetStringId() const { return u_.string_val_; }
672 TypeId* GetTypeId() const { return u_.type_val_; }
Jeff Hao5daee902017-04-27 18:00:38 -0700673 ProtoId* GetProtoId() const { return u_.proto_val_; }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700674 FieldId* GetFieldId() const { return u_.field_val_; }
675 MethodId* GetMethodId() const { return u_.method_val_; }
Jeff Hao5daee902017-04-27 18:00:38 -0700676 MethodHandleItem* GetMethodHandle() const { return u_.method_handle_val_; }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700677 EncodedArrayItem* GetEncodedArray() const { return encoded_array_.get(); }
678 EncodedAnnotation* GetEncodedAnnotation() const { return encoded_annotation_.get(); }
679
680 EncodedAnnotation* ReleaseEncodedAnnotation() { return encoded_annotation_.release(); }
David Sehr7629f602016-08-07 16:01:51 -0700681
682 private:
David Sehr7629f602016-08-07 16:01:51 -0700683 uint8_t type_;
Jeff Hao3ab96b42016-09-09 18:35:01 -0700684 union {
685 bool bool_val_;
686 int8_t byte_val_;
687 int16_t short_val_;
688 uint16_t char_val_;
689 int32_t int_val_;
690 int64_t long_val_;
691 float float_val_;
692 double double_val_;
693 StringId* string_val_;
694 TypeId* type_val_;
Jeff Hao5daee902017-04-27 18:00:38 -0700695 ProtoId* proto_val_;
Jeff Hao3ab96b42016-09-09 18:35:01 -0700696 FieldId* field_val_;
697 MethodId* method_val_;
Jeff Hao5daee902017-04-27 18:00:38 -0700698 MethodHandleItem* method_handle_val_;
Jeff Hao3ab96b42016-09-09 18:35:01 -0700699 } u_;
700 std::unique_ptr<EncodedArrayItem> encoded_array_;
701 std::unique_ptr<EncodedAnnotation> encoded_annotation_;
702
703 DISALLOW_COPY_AND_ASSIGN(EncodedValue);
David Sehr7629f602016-08-07 16:01:51 -0700704};
705
Jeff Hao3ab96b42016-09-09 18:35:01 -0700706using EncodedValueVector = std::vector<std::unique_ptr<EncodedValue>>;
707
708class AnnotationElement {
709 public:
710 AnnotationElement(StringId* name, EncodedValue* value) : name_(name), value_(value) { }
711
712 StringId* GetName() const { return name_; }
713 EncodedValue* GetValue() const { return value_.get(); }
714
715 private:
716 StringId* name_;
717 std::unique_ptr<EncodedValue> value_;
718
719 DISALLOW_COPY_AND_ASSIGN(AnnotationElement);
720};
721
722using AnnotationElementVector = std::vector<std::unique_ptr<AnnotationElement>>;
723
724class EncodedAnnotation {
725 public:
726 EncodedAnnotation(TypeId* type, AnnotationElementVector* elements)
727 : type_(type), elements_(elements) { }
728
729 TypeId* GetType() const { return type_; }
730 AnnotationElementVector* GetAnnotationElements() const { return elements_.get(); }
731
732 private:
733 TypeId* type_;
734 std::unique_ptr<AnnotationElementVector> elements_;
735
736 DISALLOW_COPY_AND_ASSIGN(EncodedAnnotation);
737};
738
739class EncodedArrayItem : public Item {
740 public:
741 explicit EncodedArrayItem(EncodedValueVector* encoded_values)
742 : encoded_values_(encoded_values) { }
743
744 EncodedValueVector* GetEncodedValues() const { return encoded_values_.get(); }
745
746 private:
747 std::unique_ptr<EncodedValueVector> encoded_values_;
748
749 DISALLOW_COPY_AND_ASSIGN(EncodedArrayItem);
750};
David Sehr853a8e12016-09-01 13:03:50 -0700751
David Sehr7629f602016-08-07 16:01:51 -0700752class ClassData : public Item {
753 public:
David Sehr853a8e12016-09-01 13:03:50 -0700754 ClassData(FieldItemVector* static_fields,
755 FieldItemVector* instance_fields,
756 MethodItemVector* direct_methods,
757 MethodItemVector* virtual_methods)
758 : static_fields_(static_fields),
759 instance_fields_(instance_fields),
760 direct_methods_(direct_methods),
761 virtual_methods_(virtual_methods) { }
762
David Sehr7629f602016-08-07 16:01:51 -0700763 ~ClassData() OVERRIDE = default;
David Sehr853a8e12016-09-01 13:03:50 -0700764 FieldItemVector* StaticFields() { return static_fields_.get(); }
765 FieldItemVector* InstanceFields() { return instance_fields_.get(); }
766 MethodItemVector* DirectMethods() { return direct_methods_.get(); }
767 MethodItemVector* VirtualMethods() { return virtual_methods_.get(); }
David Sehr7629f602016-08-07 16:01:51 -0700768
769 void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); }
770
771 private:
David Sehr853a8e12016-09-01 13:03:50 -0700772 std::unique_ptr<FieldItemVector> static_fields_;
773 std::unique_ptr<FieldItemVector> instance_fields_;
774 std::unique_ptr<MethodItemVector> direct_methods_;
775 std::unique_ptr<MethodItemVector> virtual_methods_;
Jeff Hao3ab96b42016-09-09 18:35:01 -0700776
David Sehr7629f602016-08-07 16:01:51 -0700777 DISALLOW_COPY_AND_ASSIGN(ClassData);
778};
779
Jeff Hao3ab96b42016-09-09 18:35:01 -0700780class ClassDef : public IndexedItem {
David Sehr7629f602016-08-07 16:01:51 -0700781 public:
David Sehr853a8e12016-09-01 13:03:50 -0700782 ClassDef(const TypeId* class_type,
783 uint32_t access_flags,
784 const TypeId* superclass,
Jeff Hao3ab96b42016-09-09 18:35:01 -0700785 TypeList* interfaces,
David Sehr853a8e12016-09-01 13:03:50 -0700786 const StringId* source_file,
787 AnnotationsDirectoryItem* annotations,
Jeff Hao3ab96b42016-09-09 18:35:01 -0700788 EncodedArrayItem* static_values,
David Sehr853a8e12016-09-01 13:03:50 -0700789 ClassData* class_data)
790 : class_type_(class_type),
791 access_flags_(access_flags),
792 superclass_(superclass),
793 interfaces_(interfaces),
David Sehr853a8e12016-09-01 13:03:50 -0700794 source_file_(source_file),
795 annotations_(annotations),
Jeff Haoa8621002016-10-04 18:13:44 +0000796 class_data_(class_data),
797 static_values_(static_values) { size_ = kClassDefItemSize; }
David Sehr853a8e12016-09-01 13:03:50 -0700798
David Sehr7629f602016-08-07 16:01:51 -0700799 ~ClassDef() OVERRIDE { }
800
Jeff Hao3ab96b42016-09-09 18:35:01 -0700801 static size_t ItemSize() { return kClassDefItemSize; }
802
David Sehr7629f602016-08-07 16:01:51 -0700803 const TypeId* ClassType() const { return class_type_; }
804 uint32_t GetAccessFlags() const { return access_flags_; }
805 const TypeId* Superclass() const { return superclass_; }
Jeff Haocc829592017-03-14 16:13:39 -0700806 const TypeList* Interfaces() { return interfaces_; }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700807 uint32_t InterfacesOffset() { return interfaces_ == nullptr ? 0 : interfaces_->GetOffset(); }
David Sehr7629f602016-08-07 16:01:51 -0700808 const StringId* SourceFile() const { return source_file_; }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700809 AnnotationsDirectoryItem* Annotations() const { return annotations_; }
Nicolas Geoffrayfd1a6c22016-10-04 11:01:17 +0000810 ClassData* GetClassData() { return class_data_; }
Jeff Haoa8621002016-10-04 18:13:44 +0000811 EncodedArrayItem* StaticValues() { return static_values_; }
David Sehr7629f602016-08-07 16:01:51 -0700812
Jeff Haoc3acfc52016-08-29 14:18:26 -0700813 MethodItem* GenerateMethodItem(Header& header, ClassDataItemIterator& cdii);
814
David Sehr7629f602016-08-07 16:01:51 -0700815 void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); }
816
817 private:
818 const TypeId* class_type_;
819 uint32_t access_flags_;
Jeff Haoa8621002016-10-04 18:13:44 +0000820 const TypeId* superclass_; // This can be nullptr.
821 TypeList* interfaces_; // This can be nullptr.
822 const StringId* source_file_; // This can be nullptr.
823 AnnotationsDirectoryItem* annotations_; // This can be nullptr.
824 ClassData* class_data_; // This can be nullptr.
825 EncodedArrayItem* static_values_; // This can be nullptr.
Jeff Hao3ab96b42016-09-09 18:35:01 -0700826
David Sehr7629f602016-08-07 16:01:51 -0700827 DISALLOW_COPY_AND_ASSIGN(ClassDef);
828};
829
Jeff Haoa8621002016-10-04 18:13:44 +0000830class TypeAddrPair {
David Sehr853a8e12016-09-01 13:03:50 -0700831 public:
Jeff Haoa8621002016-10-04 18:13:44 +0000832 TypeAddrPair(const TypeId* type_id, uint32_t address) : type_id_(type_id), address_(address) { }
David Sehr853a8e12016-09-01 13:03:50 -0700833
834 const TypeId* GetTypeId() const { return type_id_; }
835 uint32_t GetAddress() const { return address_; }
836
837 private:
Jeff Haocc829592017-03-14 16:13:39 -0700838 const TypeId* type_id_; // This can be nullptr.
David Sehr853a8e12016-09-01 13:03:50 -0700839 uint32_t address_;
Jeff Hao3ab96b42016-09-09 18:35:01 -0700840
Jeff Haoa8621002016-10-04 18:13:44 +0000841 DISALLOW_COPY_AND_ASSIGN(TypeAddrPair);
842};
843
844using TypeAddrPairVector = std::vector<std::unique_ptr<const TypeAddrPair>>;
845
846class CatchHandler {
847 public:
848 explicit CatchHandler(bool catch_all, uint16_t list_offset, TypeAddrPairVector* handlers)
849 : catch_all_(catch_all), list_offset_(list_offset), handlers_(handlers) { }
850
851 bool HasCatchAll() const { return catch_all_; }
852 uint16_t GetListOffset() const { return list_offset_; }
853 TypeAddrPairVector* GetHandlers() const { return handlers_.get(); }
854
855 private:
856 bool catch_all_;
857 uint16_t list_offset_;
858 std::unique_ptr<TypeAddrPairVector> handlers_;
859
David Sehr853a8e12016-09-01 13:03:50 -0700860 DISALLOW_COPY_AND_ASSIGN(CatchHandler);
861};
862
863using CatchHandlerVector = std::vector<std::unique_ptr<const CatchHandler>>;
864
865class TryItem : public Item {
866 public:
Jeff Haoa8621002016-10-04 18:13:44 +0000867 TryItem(uint32_t start_addr, uint16_t insn_count, const CatchHandler* handlers)
David Sehr853a8e12016-09-01 13:03:50 -0700868 : start_addr_(start_addr), insn_count_(insn_count), handlers_(handlers) { }
869 ~TryItem() OVERRIDE { }
870
871 uint32_t StartAddr() const { return start_addr_; }
872 uint16_t InsnCount() const { return insn_count_; }
Jeff Haoa8621002016-10-04 18:13:44 +0000873 const CatchHandler* GetHandlers() const { return handlers_; }
David Sehr853a8e12016-09-01 13:03:50 -0700874
875 void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); }
876
877 private:
878 uint32_t start_addr_;
879 uint16_t insn_count_;
Jeff Haoa8621002016-10-04 18:13:44 +0000880 const CatchHandler* handlers_;
Jeff Hao3ab96b42016-09-09 18:35:01 -0700881
David Sehr853a8e12016-09-01 13:03:50 -0700882 DISALLOW_COPY_AND_ASSIGN(TryItem);
883};
884
885using TryItemVector = std::vector<std::unique_ptr<const TryItem>>;
886
David Sehrd1e44e22016-10-06 17:09:32 -0700887class CodeFixups {
888 public:
889 CodeFixups(std::vector<TypeId*>* type_ids,
890 std::vector<StringId*>* string_ids,
891 std::vector<MethodId*>* method_ids,
892 std::vector<FieldId*>* field_ids)
893 : type_ids_(type_ids),
894 string_ids_(string_ids),
895 method_ids_(method_ids),
896 field_ids_(field_ids) { }
897
898 std::vector<TypeId*>* TypeIds() const { return type_ids_.get(); }
899 std::vector<StringId*>* StringIds() const { return string_ids_.get(); }
900 std::vector<MethodId*>* MethodIds() const { return method_ids_.get(); }
901 std::vector<FieldId*>* FieldIds() const { return field_ids_.get(); }
902
903 private:
904 std::unique_ptr<std::vector<TypeId*>> type_ids_;
905 std::unique_ptr<std::vector<StringId*>> string_ids_;
906 std::unique_ptr<std::vector<MethodId*>> method_ids_;
907 std::unique_ptr<std::vector<FieldId*>> field_ids_;
908
909 DISALLOW_COPY_AND_ASSIGN(CodeFixups);
910};
911
David Sehr7629f602016-08-07 16:01:51 -0700912class CodeItem : public Item {
913 public:
David Sehr853a8e12016-09-01 13:03:50 -0700914 CodeItem(uint16_t registers_size,
915 uint16_t ins_size,
916 uint16_t outs_size,
917 DebugInfoItem* debug_info,
918 uint32_t insns_size,
919 uint16_t* insns,
Jeff Haoa8621002016-10-04 18:13:44 +0000920 TryItemVector* tries,
921 CatchHandlerVector* handlers)
David Sehr853a8e12016-09-01 13:03:50 -0700922 : registers_size_(registers_size),
923 ins_size_(ins_size),
924 outs_size_(outs_size),
925 debug_info_(debug_info),
926 insns_size_(insns_size),
927 insns_(insns),
Jeff Haoa8621002016-10-04 18:13:44 +0000928 tries_(tries),
929 handlers_(handlers) { }
David Sehr853a8e12016-09-01 13:03:50 -0700930
David Sehr7629f602016-08-07 16:01:51 -0700931 ~CodeItem() OVERRIDE { }
932
933 uint16_t RegistersSize() const { return registers_size_; }
934 uint16_t InsSize() const { return ins_size_; }
935 uint16_t OutsSize() const { return outs_size_; }
David Sehr853a8e12016-09-01 13:03:50 -0700936 uint16_t TriesSize() const { return tries_ == nullptr ? 0 : tries_->size(); }
Jeff Hao3ab96b42016-09-09 18:35:01 -0700937 DebugInfoItem* DebugInfo() const { return debug_info_; }
David Sehr7629f602016-08-07 16:01:51 -0700938 uint32_t InsnsSize() const { return insns_size_; }
939 uint16_t* Insns() const { return insns_.get(); }
David Sehr853a8e12016-09-01 13:03:50 -0700940 TryItemVector* Tries() const { return tries_.get(); }
Jeff Haoa8621002016-10-04 18:13:44 +0000941 CatchHandlerVector* Handlers() const { return handlers_.get(); }
David Sehr7629f602016-08-07 16:01:51 -0700942
David Sehrd1e44e22016-10-06 17:09:32 -0700943 void SetCodeFixups(CodeFixups* fixups) { fixups_.reset(fixups); }
944 CodeFixups* GetCodeFixups() const { return fixups_.get(); }
945
David Sehr7629f602016-08-07 16:01:51 -0700946 void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); }
947
948 private:
949 uint16_t registers_size_;
950 uint16_t ins_size_;
951 uint16_t outs_size_;
Jeff Haoa8621002016-10-04 18:13:44 +0000952 DebugInfoItem* debug_info_; // This can be nullptr.
David Sehr7629f602016-08-07 16:01:51 -0700953 uint32_t insns_size_;
954 std::unique_ptr<uint16_t[]> insns_;
Jeff Haoa8621002016-10-04 18:13:44 +0000955 std::unique_ptr<TryItemVector> tries_; // This can be nullptr.
956 std::unique_ptr<CatchHandlerVector> handlers_; // This can be nullptr.
David Sehrd1e44e22016-10-06 17:09:32 -0700957 std::unique_ptr<CodeFixups> fixups_; // This can be nullptr.
Jeff Hao3ab96b42016-09-09 18:35:01 -0700958
David Sehr7629f602016-08-07 16:01:51 -0700959 DISALLOW_COPY_AND_ASSIGN(CodeItem);
960};
961
David Sehr7629f602016-08-07 16:01:51 -0700962struct PositionInfo {
963 PositionInfo(uint32_t address, uint32_t line) : address_(address), line_(line) { }
964
965 uint32_t address_;
966 uint32_t line_;
967};
968
David Sehr853a8e12016-09-01 13:03:50 -0700969using PositionInfoVector = std::vector<std::unique_ptr<PositionInfo>>;
970
David Sehr7629f602016-08-07 16:01:51 -0700971struct LocalInfo {
David Sehr853a8e12016-09-01 13:03:50 -0700972 LocalInfo(const char* name,
973 const char* descriptor,
974 const char* signature,
975 uint32_t start_address,
976 uint32_t end_address,
977 uint16_t reg)
978 : name_(name),
979 descriptor_(descriptor),
980 signature_(signature),
981 start_address_(start_address),
982 end_address_(end_address),
983 reg_(reg) { }
David Sehr7629f602016-08-07 16:01:51 -0700984
985 std::string name_;
986 std::string descriptor_;
987 std::string signature_;
988 uint32_t start_address_;
989 uint32_t end_address_;
990 uint16_t reg_;
991};
992
David Sehr853a8e12016-09-01 13:03:50 -0700993using LocalInfoVector = std::vector<std::unique_ptr<LocalInfo>>;
994
David Sehr7629f602016-08-07 16:01:51 -0700995class DebugInfoItem : public Item {
996 public:
Jeff Haoa8621002016-10-04 18:13:44 +0000997 DebugInfoItem(uint32_t debug_info_size, uint8_t* debug_info)
998 : debug_info_size_(debug_info_size), debug_info_(debug_info) { }
999
1000 uint32_t GetDebugInfoSize() const { return debug_info_size_; }
1001 uint8_t* GetDebugInfo() const { return debug_info_.get(); }
David Sehr7629f602016-08-07 16:01:51 -07001002
David Sehr853a8e12016-09-01 13:03:50 -07001003 PositionInfoVector& GetPositionInfo() { return positions_; }
1004 LocalInfoVector& GetLocalInfo() { return locals_; }
David Sehr7629f602016-08-07 16:01:51 -07001005
1006 private:
Jeff Haoa8621002016-10-04 18:13:44 +00001007 uint32_t debug_info_size_;
1008 std::unique_ptr<uint8_t[]> debug_info_;
1009
David Sehr853a8e12016-09-01 13:03:50 -07001010 PositionInfoVector positions_;
1011 LocalInfoVector locals_;
Jeff Hao3ab96b42016-09-09 18:35:01 -07001012
David Sehr7629f602016-08-07 16:01:51 -07001013 DISALLOW_COPY_AND_ASSIGN(DebugInfoItem);
1014};
1015
Jeff Hao3ab96b42016-09-09 18:35:01 -07001016class AnnotationItem : public Item {
David Sehr853a8e12016-09-01 13:03:50 -07001017 public:
Jeff Hao3ab96b42016-09-09 18:35:01 -07001018 AnnotationItem(uint8_t visibility, EncodedAnnotation* annotation)
1019 : visibility_(visibility), annotation_(annotation) { }
David Sehr853a8e12016-09-01 13:03:50 -07001020
1021 uint8_t GetVisibility() const { return visibility_; }
Jeff Hao3ab96b42016-09-09 18:35:01 -07001022 EncodedAnnotation* GetAnnotation() const { return annotation_.get(); }
David Sehr7629f602016-08-07 16:01:51 -07001023
1024 void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); }
1025
1026 private:
Jeff Hao3ab96b42016-09-09 18:35:01 -07001027 uint8_t visibility_;
1028 std::unique_ptr<EncodedAnnotation> annotation_;
1029
1030 DISALLOW_COPY_AND_ASSIGN(AnnotationItem);
1031};
1032
1033class AnnotationSetItem : public Item {
1034 public:
1035 explicit AnnotationSetItem(std::vector<AnnotationItem*>* items) : items_(items) {
1036 size_ = sizeof(uint32_t) + items->size() * sizeof(uint32_t);
1037 }
1038 ~AnnotationSetItem() OVERRIDE { }
1039
1040 std::vector<AnnotationItem*>* GetItems() { return items_.get(); }
1041
1042 void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); }
1043
1044 private:
1045 std::unique_ptr<std::vector<AnnotationItem*>> items_;
1046
David Sehr7629f602016-08-07 16:01:51 -07001047 DISALLOW_COPY_AND_ASSIGN(AnnotationSetItem);
1048};
1049
Jeff Hao3ab96b42016-09-09 18:35:01 -07001050class AnnotationSetRefList : public Item {
1051 public:
1052 explicit AnnotationSetRefList(std::vector<AnnotationSetItem*>* items) : items_(items) {
1053 size_ = sizeof(uint32_t) + items->size() * sizeof(uint32_t);
1054 }
1055 ~AnnotationSetRefList() OVERRIDE { }
1056
1057 std::vector<AnnotationSetItem*>* GetItems() { return items_.get(); }
1058
1059 void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); }
1060
1061 private:
Jeff Haoa8621002016-10-04 18:13:44 +00001062 std::unique_ptr<std::vector<AnnotationSetItem*>> items_; // Elements of vector can be nullptr.
Jeff Hao3ab96b42016-09-09 18:35:01 -07001063
1064 DISALLOW_COPY_AND_ASSIGN(AnnotationSetRefList);
1065};
David Sehr853a8e12016-09-01 13:03:50 -07001066
1067class FieldAnnotation {
1068 public:
1069 FieldAnnotation(FieldId* field_id, AnnotationSetItem* annotation_set_item)
1070 : field_id_(field_id), annotation_set_item_(annotation_set_item) { }
1071
1072 FieldId* GetFieldId() const { return field_id_; }
Jeff Hao3ab96b42016-09-09 18:35:01 -07001073 AnnotationSetItem* GetAnnotationSetItem() const { return annotation_set_item_; }
David Sehr853a8e12016-09-01 13:03:50 -07001074
1075 private:
1076 FieldId* field_id_;
Jeff Hao3ab96b42016-09-09 18:35:01 -07001077 AnnotationSetItem* annotation_set_item_;
1078
David Sehr853a8e12016-09-01 13:03:50 -07001079 DISALLOW_COPY_AND_ASSIGN(FieldAnnotation);
1080};
1081
1082using FieldAnnotationVector = std::vector<std::unique_ptr<FieldAnnotation>>;
1083
1084class MethodAnnotation {
1085 public:
1086 MethodAnnotation(MethodId* method_id, AnnotationSetItem* annotation_set_item)
1087 : method_id_(method_id), annotation_set_item_(annotation_set_item) { }
1088
1089 MethodId* GetMethodId() const { return method_id_; }
Jeff Hao3ab96b42016-09-09 18:35:01 -07001090 AnnotationSetItem* GetAnnotationSetItem() const { return annotation_set_item_; }
David Sehr853a8e12016-09-01 13:03:50 -07001091
1092 private:
1093 MethodId* method_id_;
Jeff Hao3ab96b42016-09-09 18:35:01 -07001094 AnnotationSetItem* annotation_set_item_;
1095
David Sehr853a8e12016-09-01 13:03:50 -07001096 DISALLOW_COPY_AND_ASSIGN(MethodAnnotation);
1097};
1098
1099using MethodAnnotationVector = std::vector<std::unique_ptr<MethodAnnotation>>;
1100
1101class ParameterAnnotation {
1102 public:
Jeff Hao3ab96b42016-09-09 18:35:01 -07001103 ParameterAnnotation(MethodId* method_id, AnnotationSetRefList* annotations)
David Sehr853a8e12016-09-01 13:03:50 -07001104 : method_id_(method_id), annotations_(annotations) { }
1105
1106 MethodId* GetMethodId() const { return method_id_; }
Jeff Hao3ab96b42016-09-09 18:35:01 -07001107 AnnotationSetRefList* GetAnnotations() { return annotations_; }
David Sehr853a8e12016-09-01 13:03:50 -07001108
1109 private:
1110 MethodId* method_id_;
Jeff Hao3ab96b42016-09-09 18:35:01 -07001111 AnnotationSetRefList* annotations_;
1112
David Sehr853a8e12016-09-01 13:03:50 -07001113 DISALLOW_COPY_AND_ASSIGN(ParameterAnnotation);
1114};
1115
1116using ParameterAnnotationVector = std::vector<std::unique_ptr<ParameterAnnotation>>;
1117
David Sehr7629f602016-08-07 16:01:51 -07001118class AnnotationsDirectoryItem : public Item {
1119 public:
David Sehr853a8e12016-09-01 13:03:50 -07001120 AnnotationsDirectoryItem(AnnotationSetItem* class_annotation,
1121 FieldAnnotationVector* field_annotations,
1122 MethodAnnotationVector* method_annotations,
1123 ParameterAnnotationVector* parameter_annotations)
1124 : class_annotation_(class_annotation),
1125 field_annotations_(field_annotations),
1126 method_annotations_(method_annotations),
1127 parameter_annotations_(parameter_annotations) { }
David Sehr7629f602016-08-07 16:01:51 -07001128
Jeff Hao3ab96b42016-09-09 18:35:01 -07001129 AnnotationSetItem* GetClassAnnotation() const { return class_annotation_; }
David Sehr853a8e12016-09-01 13:03:50 -07001130 FieldAnnotationVector* GetFieldAnnotations() { return field_annotations_.get(); }
1131 MethodAnnotationVector* GetMethodAnnotations() { return method_annotations_.get(); }
1132 ParameterAnnotationVector* GetParameterAnnotations() { return parameter_annotations_.get(); }
David Sehr7629f602016-08-07 16:01:51 -07001133
1134 void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); }
1135
1136 private:
Jeff Haoa8621002016-10-04 18:13:44 +00001137 AnnotationSetItem* class_annotation_; // This can be nullptr.
1138 std::unique_ptr<FieldAnnotationVector> field_annotations_; // This can be nullptr.
1139 std::unique_ptr<MethodAnnotationVector> method_annotations_; // This can be nullptr.
1140 std::unique_ptr<ParameterAnnotationVector> parameter_annotations_; // This can be nullptr.
Jeff Hao3ab96b42016-09-09 18:35:01 -07001141
David Sehr7629f602016-08-07 16:01:51 -07001142 DISALLOW_COPY_AND_ASSIGN(AnnotationsDirectoryItem);
1143};
1144
Jeff Hao5daee902017-04-27 18:00:38 -07001145class CallSiteId : public IndexedItem {
1146 public:
1147 explicit CallSiteId(EncodedArrayItem* call_site_item) : call_site_item_(call_site_item) {
1148 size_ = kCallSiteIdItemSize;
1149 }
1150 ~CallSiteId() OVERRIDE { }
1151
1152 static size_t ItemSize() { return kCallSiteIdItemSize; }
1153
1154 EncodedArrayItem* CallSiteItem() const { return call_site_item_; }
1155
1156 void Accept(AbstractDispatcher* dispatch) const { dispatch->Dispatch(this); }
1157
1158 private:
1159 EncodedArrayItem* call_site_item_;
1160
1161 DISALLOW_COPY_AND_ASSIGN(CallSiteId);
1162};
1163
1164class MethodHandleItem : public IndexedItem {
1165 public:
1166 MethodHandleItem(DexFile::MethodHandleType method_handle_type, IndexedItem* field_or_method_id)
1167 : method_handle_type_(method_handle_type),
1168 field_or_method_id_(field_or_method_id) {
1169 size_ = kMethodHandleItemSize;
1170 }
1171 ~MethodHandleItem() OVERRIDE { }
1172
1173 static size_t ItemSize() { return kMethodHandleItemSize; }
1174
1175 DexFile::MethodHandleType GetMethodHandleType() const { return method_handle_type_; }
1176 IndexedItem* GetFieldOrMethodId() const { return field_or_method_id_; }
1177
1178 void Accept(AbstractDispatcher* dispatch) const { dispatch->Dispatch(this); }
1179
1180 private:
1181 DexFile::MethodHandleType method_handle_type_;
1182 IndexedItem* field_or_method_id_;
1183
1184 DISALLOW_COPY_AND_ASSIGN(MethodHandleItem);
1185};
1186
David Sehr7629f602016-08-07 16:01:51 -07001187// TODO(sehr): implement MapList.
1188class MapList : public Item {
1189 public:
1190 void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); }
1191
1192 private:
1193 DISALLOW_COPY_AND_ASSIGN(MapList);
1194};
1195
1196class MapItem : public Item {
1197 public:
1198 void Accept(AbstractDispatcher* dispatch) { dispatch->Dispatch(this); }
1199
1200 private:
1201 DISALLOW_COPY_AND_ASSIGN(MapItem);
1202};
1203
David Sehr9037a3a2017-03-30 17:50:24 -07001204// Interface for building a vector of file sections for use by other clients.
1205struct DexFileSection {
1206 public:
1207 DexFileSection(const std::string& name, uint16_t type, uint32_t size, uint32_t offset)
1208 : name(name), type(type), size(size), offset(offset) { }
1209 std::string name;
1210 // The type (DexFile::MapItemType).
1211 uint16_t type;
1212 // The size (in elements, not bytes).
1213 uint32_t size;
1214 // The byte offset from the start of the file.
1215 uint32_t offset;
1216};
1217
1218enum class SortDirection {
1219 kSortAscending,
1220 kSortDescending
1221};
1222
1223std::vector<DexFileSection> GetSortedDexFileSections(dex_ir::Header* header,
1224 SortDirection direction);
1225
David Sehr7629f602016-08-07 16:01:51 -07001226} // namespace dex_ir
1227} // namespace art
1228
1229#endif // ART_DEXLAYOUT_DEX_IR_H_