blob: 1f471106df4e94493d61d57aa7b5b0dd4f64a05d [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 Carlstrom578bbdc2011-07-21 14:07:47 -070017#include "dex_file.h"
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070018
Brian Carlstrom1f870082011-08-23 16:02:11 -070019#include <limits.h>
Brian Carlstromb0460ea2011-07-29 10:08:05 -070020#include <stdio.h>
Ian Rogersd81871c2011-10-03 13:57:23 -070021#include <stdlib.h>
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070022#include <string.h>
Alex Light40528472017-03-28 09:07:36 -070023#include <zlib.h>
Ian Rogersc7dd2952014-10-21 23:31:19 -070024
Ian Rogers700a4022014-05-19 16:49:03 -070025#include <memory>
Ian Rogersc7dd2952014-10-21 23:31:19 -070026#include <sstream>
Andreas Gampea5b09a62016-11-17 15:21:22 -080027#include <type_traits>
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070028
Andreas Gampe46ee31b2016-12-14 10:11:49 -080029#include "android-base/stringprintf.h"
30
Andreas Gampe542451c2016-07-26 09:02:02 -070031#include "base/enums.h"
David Sehr67bf42e2018-02-26 16:43:04 -080032#include "base/leb128.h"
Andreas Gampe5678db52017-06-08 14:11:18 -070033#include "base/stl_util.h"
David Sehr0225f8e2018-01-31 08:52:24 +000034#include "descriptors_names.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070035#include "dex_file-inl.h"
Mathieu Chartier292567e2017-10-12 13:24:38 -070036#include "standard_dex_file.h"
Ian Rogersa6724902013-09-23 09:23:37 -070037#include "utf-inl.h"
Carl Shapiro1fb86202011-06-27 17:43:13 -070038
39namespace art {
40
Andreas Gampe46ee31b2016-12-14 10:11:49 -080041using android::base::StringPrintf;
42
Andreas Gampe8a0128a2016-11-28 07:38:35 -080043static_assert(sizeof(dex::StringIndex) == sizeof(uint32_t), "StringIndex size is wrong");
44static_assert(std::is_trivially_copyable<dex::StringIndex>::value, "StringIndex not trivial");
Andreas Gampea5b09a62016-11-17 15:21:22 -080045static_assert(sizeof(dex::TypeIndex) == sizeof(uint16_t), "TypeIndex size is wrong");
46static_assert(std::is_trivially_copyable<dex::TypeIndex>::value, "TypeIndex not trivial");
47
Alex Lightc88a0082018-02-15 17:08:29 -080048void DexFile::UnHideAccessFlags(ClassDataItemIterator& class_it) {
49 uint8_t* data = const_cast<uint8_t*>(class_it.DataPointer());
50 uint32_t new_flag = class_it.GetMemberAccessFlags();
51 bool is_method = class_it.IsAtMethod();
52 // Go back 1 uleb to start.
53 data = ReverseSearchUnsignedLeb128(data);
54 if (is_method) {
55 // Methods have another uleb field before the access flags
56 data = ReverseSearchUnsignedLeb128(data);
57 }
58 DCHECK_EQ(HiddenApiAccessFlags::RemoveFromDex(DecodeUnsignedLeb128WithoutMovingCursor(data)),
59 new_flag);
60 UpdateUnsignedLeb128(data, new_flag);
61}
62
Alex Light40528472017-03-28 09:07:36 -070063uint32_t DexFile::CalculateChecksum() const {
Mathieu Chartier2c4b0842017-12-13 11:49:51 -080064 return CalculateChecksum(Begin(), Size());
65}
66
67uint32_t DexFile::CalculateChecksum(const uint8_t* begin, size_t size) {
Mathieu Chartierc3a22aa2018-01-19 18:58:34 -080068 const uint32_t non_sum_bytes = OFFSETOF_MEMBER(DexFile::Header, signature_);
69 return ChecksumMemoryRange(begin + non_sum_bytes, size - non_sum_bytes);
70}
71
72uint32_t DexFile::ChecksumMemoryRange(const uint8_t* begin, size_t size) {
73 return adler32(adler32(0L, Z_NULL, 0), begin, size);
Alex Light40528472017-03-28 09:07:36 -070074}
75
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080076int DexFile::GetPermissions() const {
David Sehr733bd4d2017-10-26 10:39:15 -070077 CHECK(container_.get() != nullptr);
78 return container_->GetPermissions();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080079}
80
Sebastien Hertz2d6ba512013-05-17 11:31:37 +020081bool DexFile::IsReadOnly() const {
David Sehr733bd4d2017-10-26 10:39:15 -070082 CHECK(container_.get() != nullptr);
83 return container_->IsReadOnly();
Sebastien Hertz2d6ba512013-05-17 11:31:37 +020084}
85
Brian Carlstrome0948e12013-08-29 09:36:15 -070086bool DexFile::EnableWrite() const {
David Sehr733bd4d2017-10-26 10:39:15 -070087 CHECK(container_.get() != nullptr);
88 return container_->EnableWrite();
Sebastien Hertz2d6ba512013-05-17 11:31:37 +020089}
90
Brian Carlstrome0948e12013-08-29 09:36:15 -070091bool DexFile::DisableWrite() const {
David Sehr733bd4d2017-10-26 10:39:15 -070092 CHECK(container_.get() != nullptr);
93 return container_->DisableWrite();
Sebastien Hertz2d6ba512013-05-17 11:31:37 +020094}
95
David Sehr733ddb22016-09-19 15:02:18 -070096DexFile::DexFile(const uint8_t* base,
97 size_t size,
Mathieu Chartierc3a22aa2018-01-19 18:58:34 -080098 const uint8_t* data_begin,
99 size_t data_size,
Brian Carlstrom0d6adac2014-02-05 17:39:16 -0800100 const std::string& location,
101 uint32_t location_checksum,
David Sehr733bd4d2017-10-26 10:39:15 -0700102 const OatDexFile* oat_dex_file,
George Burgess IVccb00192018-02-17 23:16:39 -0800103 std::unique_ptr<DexFileContainer> container,
Mathieu Chartier69147f12017-11-06 20:02:24 -0800104 bool is_compact_dex)
Brian Carlstrom0d6adac2014-02-05 17:39:16 -0800105 : begin_(base),
106 size_(size),
Mathieu Chartierc3a22aa2018-01-19 18:58:34 -0800107 data_begin_(data_begin),
108 data_size_(data_size),
Brian Carlstrom0d6adac2014-02-05 17:39:16 -0800109 location_(location),
110 location_checksum_(location_checksum),
Brian Carlstrom0d6adac2014-02-05 17:39:16 -0800111 header_(reinterpret_cast<const Header*>(base)),
112 string_ids_(reinterpret_cast<const StringId*>(base + header_->string_ids_off_)),
113 type_ids_(reinterpret_cast<const TypeId*>(base + header_->type_ids_off_)),
114 field_ids_(reinterpret_cast<const FieldId*>(base + header_->field_ids_off_)),
115 method_ids_(reinterpret_cast<const MethodId*>(base + header_->method_ids_off_)),
116 proto_ids_(reinterpret_cast<const ProtoId*>(base + header_->proto_ids_off_)),
Ian Rogers68b56852014-08-29 20:19:11 -0700117 class_defs_(reinterpret_cast<const ClassDef*>(base + header_->class_defs_off_)),
Orion Hodson12f4ff42017-01-13 16:43:12 +0000118 method_handles_(nullptr),
119 num_method_handles_(0),
120 call_site_ids_(nullptr),
121 num_call_site_ids_(0),
David Sehr733bd4d2017-10-26 10:39:15 -0700122 oat_dex_file_(oat_dex_file),
George Burgess IVccb00192018-02-17 23:16:39 -0800123 container_(std::move(container)),
David Brazdil8e1a7cb2018-03-27 08:14:25 +0000124 is_compact_dex_(is_compact_dex),
125 is_platform_dex_(false) {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700126 CHECK(begin_ != nullptr) << GetLocation();
Brian Carlstrom0d6adac2014-02-05 17:39:16 -0800127 CHECK_GT(size_, 0U) << GetLocation();
Igor Murashkin271a0f82017-02-14 21:14:17 +0000128 // Check base (=header) alignment.
129 // Must be 4-byte aligned to avoid undefined behavior when accessing
130 // any of the sections via a pointer.
131 CHECK_ALIGNED(begin_, alignof(Header));
132
Orion Hodson12f4ff42017-01-13 16:43:12 +0000133 InitializeSectionsFromMapList();
Brian Carlstrom0d6adac2014-02-05 17:39:16 -0800134}
135
Jesse Wilson6bf19152011-09-29 13:12:33 -0400136DexFile::~DexFile() {
Elliott Hughes8cef0b82011-10-11 19:24:00 -0700137 // We don't call DeleteGlobalRef on dex_object_ because we're only called by DestroyJavaVM, and
138 // that's only called after DetachCurrentThread, which means there's no JNIEnv. We could
139 // re-attach, but cleaning up these global references is not obviously useful. It's not as if
140 // the global reference table is otherwise empty!
Jesse Wilson6bf19152011-09-29 13:12:33 -0400141}
142
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700143bool DexFile::Init(std::string* error_msg) {
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700144 if (!CheckMagicAndVersion(error_msg)) {
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700145 return false;
146 }
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700147 return true;
148}
149
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700150bool DexFile::CheckMagicAndVersion(std::string* error_msg) const {
Mathieu Chartier7b074bf2017-09-25 16:22:36 -0700151 if (!IsMagicValid()) {
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700152 std::ostringstream oss;
153 oss << "Unrecognized magic number in " << GetLocation() << ":"
Brian Carlstrom6e3b1d92012-01-11 01:36:32 -0800154 << " " << header_->magic_[0]
155 << " " << header_->magic_[1]
156 << " " << header_->magic_[2]
157 << " " << header_->magic_[3];
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700158 *error_msg = oss.str();
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700159 return false;
160 }
Mathieu Chartier7b074bf2017-09-25 16:22:36 -0700161 if (!IsVersionValid()) {
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700162 std::ostringstream oss;
163 oss << "Unrecognized version number in " << GetLocation() << ":"
Brian Carlstrom6e3b1d92012-01-11 01:36:32 -0800164 << " " << header_->magic_[4]
165 << " " << header_->magic_[5]
166 << " " << header_->magic_[6]
167 << " " << header_->magic_[7];
Ian Rogers8d31bbd2013-10-13 10:44:14 -0700168 *error_msg = oss.str();
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700169 return false;
170 }
171 return true;
172}
173
Orion Hodson12f4ff42017-01-13 16:43:12 +0000174void DexFile::InitializeSectionsFromMapList() {
Mathieu Chartierc3a22aa2018-01-19 18:58:34 -0800175 const MapList* map_list = reinterpret_cast<const MapList*>(DataBegin() + header_->map_off_);
Mathieu Chartier9b302bf2018-01-25 13:08:08 -0800176 if (header_->map_off_ == 0 || header_->map_off_ > DataSize()) {
Jeff Haoa4cd6772017-04-13 14:36:29 -0700177 // Bad offset. The dex file verifier runs after this method and will reject the file.
178 return;
179 }
Orion Hodson12f4ff42017-01-13 16:43:12 +0000180 const size_t count = map_list->size_;
181
182 size_t map_limit = header_->map_off_ + count * sizeof(MapItem);
Mathieu Chartier9b302bf2018-01-25 13:08:08 -0800183 if (header_->map_off_ >= map_limit || map_limit > DataSize()) {
Orion Hodson12f4ff42017-01-13 16:43:12 +0000184 // Overflow or out out of bounds. The dex file verifier runs after
185 // this method and will reject the file as it is malformed.
186 return;
187 }
188
189 for (size_t i = 0; i < count; ++i) {
190 const MapItem& map_item = map_list->list_[i];
191 if (map_item.type_ == kDexTypeMethodHandleItem) {
Mathieu Chartier9b302bf2018-01-25 13:08:08 -0800192 method_handles_ = reinterpret_cast<const MethodHandleItem*>(Begin() + map_item.offset_);
Orion Hodson12f4ff42017-01-13 16:43:12 +0000193 num_method_handles_ = map_item.size_;
194 } else if (map_item.type_ == kDexTypeCallSiteIdItem) {
Mathieu Chartier9b302bf2018-01-25 13:08:08 -0800195 call_site_ids_ = reinterpret_cast<const CallSiteIdItem*>(Begin() + map_item.offset_);
Orion Hodson12f4ff42017-01-13 16:43:12 +0000196 num_call_site_ids_ = map_item.size_;
197 }
198 }
199}
200
Andreas Gampe76ed99d2016-03-28 18:31:29 -0700201uint32_t DexFile::Header::GetVersion() const {
Mathieu Chartier7b074bf2017-09-25 16:22:36 -0700202 const char* version = reinterpret_cast<const char*>(&magic_[kDexMagicSize]);
Ian Rogersd81871c2011-10-03 13:57:23 -0700203 return atoi(version);
204}
205
Andreas Gampea5b09a62016-11-17 15:21:22 -0800206const DexFile::ClassDef* DexFile::FindClassDef(dex::TypeIndex type_idx) const {
David Sehr9aa352e2016-09-15 18:13:52 -0700207 size_t num_class_defs = NumClassDefs();
Roland Levillainab880f42016-05-12 16:24:36 +0100208 // Fast path for rare no class defs case.
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700209 if (num_class_defs == 0) {
Ian Rogers68b56852014-08-29 20:19:11 -0700210 return nullptr;
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700211 }
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700212 for (size_t i = 0; i < num_class_defs; ++i) {
213 const ClassDef& class_def = GetClassDef(i);
214 if (class_def.class_idx_ == type_idx) {
215 return &class_def;
216 }
Brian Carlstrome24fa612011-09-29 00:53:55 -0700217 }
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700218 return nullptr;
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700219}
220
Alex Light9c20a142016-08-23 15:05:12 -0700221uint32_t DexFile::FindCodeItemOffset(const DexFile::ClassDef& class_def,
222 uint32_t method_idx) const {
223 const uint8_t* class_data = GetClassData(class_def);
224 CHECK(class_data != nullptr);
225 ClassDataItemIterator it(*this, class_data);
Mathieu Chartiere17cf242017-06-19 11:05:51 -0700226 it.SkipAllFields();
Alex Light9c20a142016-08-23 15:05:12 -0700227 while (it.HasNextDirectMethod()) {
228 if (it.GetMemberIndex() == method_idx) {
229 return it.GetMethodCodeItemOffset();
230 }
231 it.Next();
232 }
233 while (it.HasNextVirtualMethod()) {
234 if (it.GetMemberIndex() == method_idx) {
235 return it.GetMethodCodeItemOffset();
236 }
237 it.Next();
238 }
239 LOG(FATAL) << "Unable to find method " << method_idx;
240 UNREACHABLE();
241}
242
Ian Rogers9b1a4f42011-11-14 18:35:10 -0800243const DexFile::FieldId* DexFile::FindFieldId(const DexFile::TypeId& declaring_klass,
Roland Levillainab880f42016-05-12 16:24:36 +0100244 const DexFile::StringId& name,
245 const DexFile::TypeId& type) const {
Ian Rogers9b1a4f42011-11-14 18:35:10 -0800246 // Binary search MethodIds knowing that they are sorted by class_idx, name_idx then proto_idx
Andreas Gampea5b09a62016-11-17 15:21:22 -0800247 const dex::TypeIndex class_idx = GetIndexForTypeId(declaring_klass);
Andreas Gampe8a0128a2016-11-28 07:38:35 -0800248 const dex::StringIndex name_idx = GetIndexForStringId(name);
Andreas Gampea5b09a62016-11-17 15:21:22 -0800249 const dex::TypeIndex type_idx = GetIndexForTypeId(type);
Ian Rogersf8582c32013-05-29 16:33:03 -0700250 int32_t lo = 0;
251 int32_t hi = NumFieldIds() - 1;
Ian Rogers9b1a4f42011-11-14 18:35:10 -0800252 while (hi >= lo) {
Ian Rogersf8582c32013-05-29 16:33:03 -0700253 int32_t mid = (hi + lo) / 2;
Ian Rogers9b1a4f42011-11-14 18:35:10 -0800254 const DexFile::FieldId& field = GetFieldId(mid);
255 if (class_idx > field.class_idx_) {
256 lo = mid + 1;
257 } else if (class_idx < field.class_idx_) {
258 hi = mid - 1;
259 } else {
260 if (name_idx > field.name_idx_) {
261 lo = mid + 1;
262 } else if (name_idx < field.name_idx_) {
263 hi = mid - 1;
264 } else {
265 if (type_idx > field.type_idx_) {
266 lo = mid + 1;
267 } else if (type_idx < field.type_idx_) {
268 hi = mid - 1;
269 } else {
270 return &field;
271 }
272 }
273 }
274 }
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700275 return nullptr;
Ian Rogers9b1a4f42011-11-14 18:35:10 -0800276}
277
278const DexFile::MethodId* DexFile::FindMethodId(const DexFile::TypeId& declaring_klass,
Ian Rogers0571d352011-11-03 19:51:38 -0700279 const DexFile::StringId& name,
280 const DexFile::ProtoId& signature) const {
281 // Binary search MethodIds knowing that they are sorted by class_idx, name_idx then proto_idx
Andreas Gampea5b09a62016-11-17 15:21:22 -0800282 const dex::TypeIndex class_idx = GetIndexForTypeId(declaring_klass);
Andreas Gampe8a0128a2016-11-28 07:38:35 -0800283 const dex::StringIndex name_idx = GetIndexForStringId(name);
Ian Rogers0571d352011-11-03 19:51:38 -0700284 const uint16_t proto_idx = GetIndexForProtoId(signature);
Ian Rogersf8582c32013-05-29 16:33:03 -0700285 int32_t lo = 0;
286 int32_t hi = NumMethodIds() - 1;
Ian Rogers0571d352011-11-03 19:51:38 -0700287 while (hi >= lo) {
Ian Rogersf8582c32013-05-29 16:33:03 -0700288 int32_t mid = (hi + lo) / 2;
Ian Rogers0571d352011-11-03 19:51:38 -0700289 const DexFile::MethodId& method = GetMethodId(mid);
290 if (class_idx > method.class_idx_) {
291 lo = mid + 1;
292 } else if (class_idx < method.class_idx_) {
293 hi = mid - 1;
294 } else {
295 if (name_idx > method.name_idx_) {
296 lo = mid + 1;
297 } else if (name_idx < method.name_idx_) {
298 hi = mid - 1;
299 } else {
300 if (proto_idx > method.proto_idx_) {
301 lo = mid + 1;
302 } else if (proto_idx < method.proto_idx_) {
303 hi = mid - 1;
304 } else {
305 return &method;
306 }
307 }
308 }
309 }
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700310 return nullptr;
Ian Rogers0571d352011-11-03 19:51:38 -0700311}
312
Ian Rogers637c65b2013-05-31 11:46:00 -0700313const DexFile::StringId* DexFile::FindStringId(const char* string) const {
Ian Rogersf8582c32013-05-29 16:33:03 -0700314 int32_t lo = 0;
315 int32_t hi = NumStringIds() - 1;
Ian Rogers0571d352011-11-03 19:51:38 -0700316 while (hi >= lo) {
Ian Rogersf8582c32013-05-29 16:33:03 -0700317 int32_t mid = (hi + lo) / 2;
Andreas Gampe8a0128a2016-11-28 07:38:35 -0800318 const DexFile::StringId& str_id = GetStringId(dex::StringIndex(mid));
Ian Rogerscf5077a2013-10-31 12:37:54 -0700319 const char* str = GetStringData(str_id);
Ian Rogers637c65b2013-05-31 11:46:00 -0700320 int compare = CompareModifiedUtf8ToModifiedUtf8AsUtf16CodePointValues(string, str);
321 if (compare > 0) {
322 lo = mid + 1;
323 } else if (compare < 0) {
324 hi = mid - 1;
325 } else {
326 return &str_id;
327 }
328 }
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700329 return nullptr;
Ian Rogers637c65b2013-05-31 11:46:00 -0700330}
331
Artem Udovichenkod9786b02015-10-14 16:36:55 +0300332const DexFile::TypeId* DexFile::FindTypeId(const char* string) const {
333 int32_t lo = 0;
334 int32_t hi = NumTypeIds() - 1;
335 while (hi >= lo) {
336 int32_t mid = (hi + lo) / 2;
Andreas Gampea5b09a62016-11-17 15:21:22 -0800337 const TypeId& type_id = GetTypeId(dex::TypeIndex(mid));
Artem Udovichenkod9786b02015-10-14 16:36:55 +0300338 const DexFile::StringId& str_id = GetStringId(type_id.descriptor_idx_);
339 const char* str = GetStringData(str_id);
340 int compare = CompareModifiedUtf8ToModifiedUtf8AsUtf16CodePointValues(string, str);
341 if (compare > 0) {
342 lo = mid + 1;
343 } else if (compare < 0) {
344 hi = mid - 1;
345 } else {
346 return &type_id;
347 }
348 }
349 return nullptr;
350}
351
Vladimir Markoa48aef42014-12-03 17:53:53 +0000352const DexFile::StringId* DexFile::FindStringId(const uint16_t* string, size_t length) const {
Ian Rogers637c65b2013-05-31 11:46:00 -0700353 int32_t lo = 0;
354 int32_t hi = NumStringIds() - 1;
355 while (hi >= lo) {
356 int32_t mid = (hi + lo) / 2;
Andreas Gampe8a0128a2016-11-28 07:38:35 -0800357 const DexFile::StringId& str_id = GetStringId(dex::StringIndex(mid));
Ian Rogerscf5077a2013-10-31 12:37:54 -0700358 const char* str = GetStringData(str_id);
Vladimir Markoa48aef42014-12-03 17:53:53 +0000359 int compare = CompareModifiedUtf8ToUtf16AsCodePointValues(str, string, length);
Ian Rogers0571d352011-11-03 19:51:38 -0700360 if (compare > 0) {
361 lo = mid + 1;
362 } else if (compare < 0) {
363 hi = mid - 1;
364 } else {
365 return &str_id;
366 }
367 }
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700368 return nullptr;
Ian Rogers0571d352011-11-03 19:51:38 -0700369}
370
Andreas Gampe8a0128a2016-11-28 07:38:35 -0800371const DexFile::TypeId* DexFile::FindTypeId(dex::StringIndex string_idx) const {
Ian Rogersf8582c32013-05-29 16:33:03 -0700372 int32_t lo = 0;
373 int32_t hi = NumTypeIds() - 1;
Ian Rogers0571d352011-11-03 19:51:38 -0700374 while (hi >= lo) {
Ian Rogersf8582c32013-05-29 16:33:03 -0700375 int32_t mid = (hi + lo) / 2;
Andreas Gampea5b09a62016-11-17 15:21:22 -0800376 const TypeId& type_id = GetTypeId(dex::TypeIndex(mid));
Ian Rogers0571d352011-11-03 19:51:38 -0700377 if (string_idx > type_id.descriptor_idx_) {
378 lo = mid + 1;
379 } else if (string_idx < type_id.descriptor_idx_) {
380 hi = mid - 1;
381 } else {
382 return &type_id;
383 }
384 }
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700385 return nullptr;
Ian Rogers0571d352011-11-03 19:51:38 -0700386}
387
Andreas Gampea5b09a62016-11-17 15:21:22 -0800388const DexFile::ProtoId* DexFile::FindProtoId(dex::TypeIndex return_type_idx,
389 const dex::TypeIndex* signature_type_idxs,
Vladimir Marko5c96e6b2013-11-14 15:34:17 +0000390 uint32_t signature_length) const {
Ian Rogersf8582c32013-05-29 16:33:03 -0700391 int32_t lo = 0;
392 int32_t hi = NumProtoIds() - 1;
Ian Rogers0571d352011-11-03 19:51:38 -0700393 while (hi >= lo) {
Ian Rogersf8582c32013-05-29 16:33:03 -0700394 int32_t mid = (hi + lo) / 2;
Ian Rogers0571d352011-11-03 19:51:38 -0700395 const DexFile::ProtoId& proto = GetProtoId(mid);
Andreas Gampea5b09a62016-11-17 15:21:22 -0800396 int compare = return_type_idx.index_ - proto.return_type_idx_.index_;
Ian Rogers0571d352011-11-03 19:51:38 -0700397 if (compare == 0) {
398 DexFileParameterIterator it(*this, proto);
399 size_t i = 0;
Vladimir Marko5c96e6b2013-11-14 15:34:17 +0000400 while (it.HasNext() && i < signature_length && compare == 0) {
Andreas Gampea5b09a62016-11-17 15:21:22 -0800401 compare = signature_type_idxs[i].index_ - it.GetTypeIdx().index_;
Ian Rogers0571d352011-11-03 19:51:38 -0700402 it.Next();
403 i++;
404 }
405 if (compare == 0) {
406 if (it.HasNext()) {
407 compare = -1;
Vladimir Marko5c96e6b2013-11-14 15:34:17 +0000408 } else if (i < signature_length) {
Ian Rogers0571d352011-11-03 19:51:38 -0700409 compare = 1;
410 }
411 }
412 }
413 if (compare > 0) {
414 lo = mid + 1;
415 } else if (compare < 0) {
416 hi = mid - 1;
417 } else {
418 return &proto;
419 }
420 }
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700421 return nullptr;
Ian Rogers0571d352011-11-03 19:51:38 -0700422}
423
424// Given a signature place the type ids into the given vector
Andreas Gampea5b09a62016-11-17 15:21:22 -0800425bool DexFile::CreateTypeList(const StringPiece& signature,
426 dex::TypeIndex* return_type_idx,
427 std::vector<dex::TypeIndex>* param_type_idxs) const {
Ian Rogers0571d352011-11-03 19:51:38 -0700428 if (signature[0] != '(') {
429 return false;
430 }
431 size_t offset = 1;
432 size_t end = signature.size();
433 bool process_return = false;
434 while (offset < end) {
Vladimir Markoe9c36b32013-11-21 15:49:16 +0000435 size_t start_offset = offset;
Ian Rogers0571d352011-11-03 19:51:38 -0700436 char c = signature[offset];
437 offset++;
438 if (c == ')') {
439 process_return = true;
440 continue;
441 }
Ian Rogers0571d352011-11-03 19:51:38 -0700442 while (c == '[') { // process array prefix
443 if (offset >= end) { // expect some descriptor following [
444 return false;
445 }
446 c = signature[offset];
447 offset++;
Ian Rogers0571d352011-11-03 19:51:38 -0700448 }
449 if (c == 'L') { // process type descriptors
450 do {
451 if (offset >= end) { // unexpected early termination of descriptor
452 return false;
453 }
454 c = signature[offset];
455 offset++;
Ian Rogers0571d352011-11-03 19:51:38 -0700456 } while (c != ';');
457 }
Vladimir Markoe9c36b32013-11-21 15:49:16 +0000458 // TODO: avoid creating a std::string just to get a 0-terminated char array
459 std::string descriptor(signature.data() + start_offset, offset - start_offset);
Mathieu Chartier9507fa22015-10-29 15:08:57 -0700460 const DexFile::TypeId* type_id = FindTypeId(descriptor.c_str());
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700461 if (type_id == nullptr) {
Ian Rogers0571d352011-11-03 19:51:38 -0700462 return false;
463 }
Andreas Gampea5b09a62016-11-17 15:21:22 -0800464 dex::TypeIndex type_idx = GetIndexForTypeId(*type_id);
Ian Rogers0571d352011-11-03 19:51:38 -0700465 if (!process_return) {
466 param_type_idxs->push_back(type_idx);
467 } else {
468 *return_type_idx = type_idx;
469 return offset == end; // return true if the signature had reached a sensible end
470 }
471 }
472 return false; // failed to correctly parse return type
473}
474
Ian Rogersd91d6d62013-09-25 20:26:14 -0700475const Signature DexFile::CreateSignature(const StringPiece& signature) const {
Andreas Gampea5b09a62016-11-17 15:21:22 -0800476 dex::TypeIndex return_type_idx;
477 std::vector<dex::TypeIndex> param_type_indices;
Ian Rogersd91d6d62013-09-25 20:26:14 -0700478 bool success = CreateTypeList(signature, &return_type_idx, &param_type_indices);
479 if (!success) {
480 return Signature::NoSignature();
Carl Shapiro419ec7b2011-08-03 14:48:33 -0700481 }
Ian Rogersd91d6d62013-09-25 20:26:14 -0700482 const ProtoId* proto_id = FindProtoId(return_type_idx, param_type_indices);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700483 if (proto_id == nullptr) {
Ian Rogersd91d6d62013-09-25 20:26:14 -0700484 return Signature::NoSignature();
Brian Carlstrom20cfffa2011-08-26 02:31:27 -0700485 }
Ian Rogersd91d6d62013-09-25 20:26:14 -0700486 return Signature(this, *proto_id);
Carl Shapiro419ec7b2011-08-03 14:48:33 -0700487}
488
Mathieu Chartier3da1d0f2017-11-06 20:02:24 -0800489int32_t DexFile::FindTryItem(const TryItem* try_items, uint32_t tries_size, uint32_t address) {
490 uint32_t min = 0;
491 uint32_t max = tries_size;
492 while (min < max) {
493 const uint32_t mid = (min + max) / 2;
Ian Rogers0571d352011-11-03 19:51:38 -0700494
Mathieu Chartier3da1d0f2017-11-06 20:02:24 -0800495 const art::DexFile::TryItem& ti = try_items[mid];
496 const uint32_t start = ti.start_addr_;
497 const uint32_t end = start + ti.insn_count_;
Ian Rogersdbbc99d2013-04-18 16:51:54 -0700498
Ian Rogers0571d352011-11-03 19:51:38 -0700499 if (address < start) {
Mathieu Chartier3da1d0f2017-11-06 20:02:24 -0800500 max = mid;
Ian Rogersdbbc99d2013-04-18 16:51:54 -0700501 } else if (address >= end) {
502 min = mid + 1;
503 } else { // We have a winner!
504 return mid;
Ian Rogers0571d352011-11-03 19:51:38 -0700505 }
506 }
507 // No match.
508 return -1;
509}
510
David Srbeckyb06e28e2015-12-10 13:15:00 +0000511bool DexFile::LineNumForPcCb(void* raw_context, const PositionInfo& entry) {
Elliott Hughes2435a572012-02-17 16:07:41 -0800512 LineNumFromPcContext* context = reinterpret_cast<LineNumFromPcContext*>(raw_context);
Ian Rogers0571d352011-11-03 19:51:38 -0700513
514 // We know that this callback will be called in
515 // ascending address order, so keep going until we find
516 // a match or we've just gone past it.
David Srbeckyb06e28e2015-12-10 13:15:00 +0000517 if (entry.address_ > context->address_) {
Ian Rogers0571d352011-11-03 19:51:38 -0700518 // The line number from the previous positions callback
519 // wil be the final result.
520 return true;
521 } else {
David Srbeckyb06e28e2015-12-10 13:15:00 +0000522 context->line_num_ = entry.line_;
523 return entry.address_ == context->address_;
Ian Rogers0571d352011-11-03 19:51:38 -0700524 }
525}
526
Jeff Hao13e748b2015-08-25 20:44:19 +0000527// Read a signed integer. "zwidth" is the zero-based byte count.
David Sehr9323e6e2016-09-13 08:58:35 -0700528int32_t DexFile::ReadSignedInt(const uint8_t* ptr, int zwidth) {
Jeff Hao13e748b2015-08-25 20:44:19 +0000529 int32_t val = 0;
530 for (int i = zwidth; i >= 0; --i) {
531 val = ((uint32_t)val >> 8) | (((int32_t)*ptr++) << 24);
532 }
533 val >>= (3 - zwidth) * 8;
534 return val;
535}
536
537// Read an unsigned integer. "zwidth" is the zero-based byte count,
538// "fill_on_right" indicates which side we want to zero-fill from.
David Sehr9323e6e2016-09-13 08:58:35 -0700539uint32_t DexFile::ReadUnsignedInt(const uint8_t* ptr, int zwidth, bool fill_on_right) {
Jeff Hao13e748b2015-08-25 20:44:19 +0000540 uint32_t val = 0;
541 for (int i = zwidth; i >= 0; --i) {
542 val = (val >> 8) | (((uint32_t)*ptr++) << 24);
543 }
544 if (!fill_on_right) {
545 val >>= (3 - zwidth) * 8;
546 }
547 return val;
548}
549
550// Read a signed long. "zwidth" is the zero-based byte count.
David Sehr9323e6e2016-09-13 08:58:35 -0700551int64_t DexFile::ReadSignedLong(const uint8_t* ptr, int zwidth) {
Jeff Hao13e748b2015-08-25 20:44:19 +0000552 int64_t val = 0;
553 for (int i = zwidth; i >= 0; --i) {
554 val = ((uint64_t)val >> 8) | (((int64_t)*ptr++) << 56);
555 }
556 val >>= (7 - zwidth) * 8;
557 return val;
558}
559
560// Read an unsigned long. "zwidth" is the zero-based byte count,
561// "fill_on_right" indicates which side we want to zero-fill from.
David Sehr9323e6e2016-09-13 08:58:35 -0700562uint64_t DexFile::ReadUnsignedLong(const uint8_t* ptr, int zwidth, bool fill_on_right) {
Jeff Hao13e748b2015-08-25 20:44:19 +0000563 uint64_t val = 0;
564 for (int i = zwidth; i >= 0; --i) {
565 val = (val >> 8) | (((uint64_t)*ptr++) << 56);
566 }
567 if (!fill_on_right) {
568 val >>= (7 - zwidth) * 8;
569 }
570 return val;
571}
572
David Sehr709b0702016-10-13 09:12:37 -0700573std::string DexFile::PrettyMethod(uint32_t method_idx, bool with_signature) const {
574 if (method_idx >= NumMethodIds()) {
575 return StringPrintf("<<invalid-method-idx-%d>>", method_idx);
576 }
577 const DexFile::MethodId& method_id = GetMethodId(method_idx);
Vladimir Markob8a55f82017-09-21 16:21:43 +0100578 std::string result;
579 const DexFile::ProtoId* proto_id = with_signature ? &GetProtoId(method_id.proto_idx_) : nullptr;
580 if (with_signature) {
581 AppendPrettyDescriptor(StringByTypeIdx(proto_id->return_type_idx_), &result);
582 result += ' ';
583 }
584 AppendPrettyDescriptor(GetMethodDeclaringClassDescriptor(method_id), &result);
David Sehr709b0702016-10-13 09:12:37 -0700585 result += '.';
586 result += GetMethodName(method_id);
587 if (with_signature) {
Vladimir Markob8a55f82017-09-21 16:21:43 +0100588 result += '(';
589 const DexFile::TypeList* params = GetProtoParameters(*proto_id);
590 if (params != nullptr) {
591 const char* separator = "";
592 for (uint32_t i = 0u, size = params->Size(); i != size; ++i) {
593 result += separator;
594 separator = ", ";
595 AppendPrettyDescriptor(StringByTypeIdx(params->GetTypeItem(i).type_idx_), &result);
596 }
David Sehr709b0702016-10-13 09:12:37 -0700597 }
Vladimir Markob8a55f82017-09-21 16:21:43 +0100598 result += ')';
David Sehr709b0702016-10-13 09:12:37 -0700599 }
600 return result;
601}
602
603std::string DexFile::PrettyField(uint32_t field_idx, bool with_type) const {
604 if (field_idx >= NumFieldIds()) {
605 return StringPrintf("<<invalid-field-idx-%d>>", field_idx);
606 }
607 const DexFile::FieldId& field_id = GetFieldId(field_idx);
608 std::string result;
609 if (with_type) {
610 result += GetFieldTypeDescriptor(field_id);
611 result += ' ';
612 }
Vladimir Markob8a55f82017-09-21 16:21:43 +0100613 AppendPrettyDescriptor(GetFieldDeclaringClassDescriptor(field_id), &result);
David Sehr709b0702016-10-13 09:12:37 -0700614 result += '.';
615 result += GetFieldName(field_id);
616 return result;
617}
618
Andreas Gampea5b09a62016-11-17 15:21:22 -0800619std::string DexFile::PrettyType(dex::TypeIndex type_idx) const {
620 if (type_idx.index_ >= NumTypeIds()) {
621 return StringPrintf("<<invalid-type-idx-%d>>", type_idx.index_);
David Sehr709b0702016-10-13 09:12:37 -0700622 }
623 const DexFile::TypeId& type_id = GetTypeId(type_idx);
624 return PrettyDescriptor(GetTypeDescriptor(type_id));
625}
626
Jeff Hao3d080862016-05-26 18:39:17 -0700627// Checks that visibility is as expected. Includes special behavior for M and
628// before to allow runtime and build visibility when expecting runtime.
Brian Carlstrom0d6adac2014-02-05 17:39:16 -0800629std::ostream& operator<<(std::ostream& os, const DexFile& dex_file) {
630 os << StringPrintf("[DexFile: %s dex-checksum=%08x location-checksum=%08x %p-%p]",
631 dex_file.GetLocation().c_str(),
632 dex_file.GetHeader().checksum_, dex_file.GetLocationChecksum(),
633 dex_file.Begin(), dex_file.Begin() + dex_file.Size());
634 return os;
635}
Calin Juravle4e1d5792014-07-15 23:56:47 +0100636
Ian Rogersd91d6d62013-09-25 20:26:14 -0700637std::string Signature::ToString() const {
638 if (dex_file_ == nullptr) {
639 CHECK(proto_id_ == nullptr);
640 return "<no signature>";
641 }
642 const DexFile::TypeList* params = dex_file_->GetProtoParameters(*proto_id_);
643 std::string result;
644 if (params == nullptr) {
645 result += "()";
646 } else {
647 result += "(";
648 for (uint32_t i = 0; i < params->Size(); ++i) {
649 result += dex_file_->StringByTypeIdx(params->GetTypeItem(i).type_idx_);
650 }
651 result += ")";
652 }
653 result += dex_file_->StringByTypeIdx(proto_id_->return_type_idx_);
654 return result;
655}
656
Orion Hodson6c4921b2016-09-21 15:41:06 +0100657uint32_t Signature::GetNumberOfParameters() const {
658 const DexFile::TypeList* params = dex_file_->GetProtoParameters(*proto_id_);
659 return (params != nullptr) ? params->Size() : 0;
660}
661
662bool Signature::IsVoid() const {
663 const char* return_type = dex_file_->GetReturnTypeDescriptor(*proto_id_);
664 return strcmp(return_type, "V") == 0;
665}
666
Vladimir Markod9cffea2013-11-25 15:08:02 +0000667bool Signature::operator==(const StringPiece& rhs) const {
668 if (dex_file_ == nullptr) {
669 return false;
670 }
671 StringPiece tail(rhs);
672 if (!tail.starts_with("(")) {
673 return false; // Invalid signature
674 }
675 tail.remove_prefix(1); // "(";
676 const DexFile::TypeList* params = dex_file_->GetProtoParameters(*proto_id_);
677 if (params != nullptr) {
678 for (uint32_t i = 0; i < params->Size(); ++i) {
679 StringPiece param(dex_file_->StringByTypeIdx(params->GetTypeItem(i).type_idx_));
680 if (!tail.starts_with(param)) {
681 return false;
682 }
683 tail.remove_prefix(param.length());
684 }
685 }
686 if (!tail.starts_with(")")) {
687 return false;
688 }
689 tail.remove_prefix(1); // ")";
690 return tail == dex_file_->StringByTypeIdx(proto_id_->return_type_idx_);
691}
692
Ian Rogersd91d6d62013-09-25 20:26:14 -0700693std::ostream& operator<<(std::ostream& os, const Signature& sig) {
694 return os << sig.ToString();
695}
696
Ian Rogers0571d352011-11-03 19:51:38 -0700697// Decodes the header section from the class data bytes.
698void ClassDataItemIterator::ReadClassDataHeader() {
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700699 CHECK(ptr_pos_ != nullptr);
Ian Rogers0571d352011-11-03 19:51:38 -0700700 header_.static_fields_size_ = DecodeUnsignedLeb128(&ptr_pos_);
701 header_.instance_fields_size_ = DecodeUnsignedLeb128(&ptr_pos_);
702 header_.direct_methods_size_ = DecodeUnsignedLeb128(&ptr_pos_);
703 header_.virtual_methods_size_ = DecodeUnsignedLeb128(&ptr_pos_);
704}
705
706void ClassDataItemIterator::ReadClassDataField() {
707 field_.field_idx_delta_ = DecodeUnsignedLeb128(&ptr_pos_);
708 field_.access_flags_ = DecodeUnsignedLeb128(&ptr_pos_);
Vladimir Marko23682bf2015-06-24 14:28:03 +0100709 // The user of the iterator is responsible for checking if there
710 // are unordered or duplicate indexes.
Ian Rogers0571d352011-11-03 19:51:38 -0700711}
712
713void ClassDataItemIterator::ReadClassDataMethod() {
714 method_.method_idx_delta_ = DecodeUnsignedLeb128(&ptr_pos_);
715 method_.access_flags_ = DecodeUnsignedLeb128(&ptr_pos_);
716 method_.code_off_ = DecodeUnsignedLeb128(&ptr_pos_);
Brian Carlstrom68adbe42012-05-11 17:18:08 -0700717 if (last_idx_ != 0 && method_.method_idx_delta_ == 0) {
Andreas Gampe4fdbba02014-06-19 20:24:22 -0700718 LOG(WARNING) << "Duplicate method in " << dex_file_.GetLocation();
Brian Carlstrom6f29d0e2012-05-11 15:50:29 -0700719 }
Ian Rogers0571d352011-11-03 19:51:38 -0700720}
721
Orion Hodson12f4ff42017-01-13 16:43:12 +0000722EncodedArrayValueIterator::EncodedArrayValueIterator(const DexFile& dex_file,
723 const uint8_t* array_data)
Shinichiro Hamaji82863f02015-11-05 16:51:33 +0900724 : dex_file_(dex_file),
Shinichiro Hamaji82863f02015-11-05 16:51:33 +0900725 array_size_(),
David Sehr9323e6e2016-09-13 08:58:35 -0700726 pos_(-1),
Orion Hodson12f4ff42017-01-13 16:43:12 +0000727 ptr_(array_data),
David Sehr9323e6e2016-09-13 08:58:35 -0700728 type_(kByte) {
Orion Hodson12f4ff42017-01-13 16:43:12 +0000729 array_size_ = (ptr_ != nullptr) ? DecodeUnsignedLeb128(&ptr_) : 0;
Ian Rogers0571d352011-11-03 19:51:38 -0700730 if (array_size_ > 0) {
731 Next();
732 }
733}
734
Orion Hodson12f4ff42017-01-13 16:43:12 +0000735void EncodedArrayValueIterator::Next() {
Ian Rogers0571d352011-11-03 19:51:38 -0700736 pos_++;
737 if (pos_ >= array_size_) {
738 return;
739 }
Ian Rogers13735952014-10-08 12:43:28 -0700740 uint8_t value_type = *ptr_++;
741 uint8_t value_arg = value_type >> kEncodedValueArgShift;
Ian Rogers0571d352011-11-03 19:51:38 -0700742 size_t width = value_arg + 1; // assume and correct later
Brian Carlstrom88f36542012-10-16 23:24:21 -0700743 type_ = static_cast<ValueType>(value_type & kEncodedValueTypeMask);
Ian Rogers0571d352011-11-03 19:51:38 -0700744 switch (type_) {
745 case kBoolean:
746 jval_.i = (value_arg != 0) ? 1 : 0;
747 width = 0;
748 break;
749 case kByte:
David Sehr9323e6e2016-09-13 08:58:35 -0700750 jval_.i = DexFile::ReadSignedInt(ptr_, value_arg);
Andreas Gampeab1eb0d2015-02-13 19:23:55 -0800751 CHECK(IsInt<8>(jval_.i));
Ian Rogers0571d352011-11-03 19:51:38 -0700752 break;
753 case kShort:
David Sehr9323e6e2016-09-13 08:58:35 -0700754 jval_.i = DexFile::ReadSignedInt(ptr_, value_arg);
Andreas Gampeab1eb0d2015-02-13 19:23:55 -0800755 CHECK(IsInt<16>(jval_.i));
Ian Rogers0571d352011-11-03 19:51:38 -0700756 break;
757 case kChar:
David Sehr9323e6e2016-09-13 08:58:35 -0700758 jval_.i = DexFile::ReadUnsignedInt(ptr_, value_arg, false);
Andreas Gampeab1eb0d2015-02-13 19:23:55 -0800759 CHECK(IsUint<16>(jval_.i));
Ian Rogers0571d352011-11-03 19:51:38 -0700760 break;
761 case kInt:
David Sehr9323e6e2016-09-13 08:58:35 -0700762 jval_.i = DexFile::ReadSignedInt(ptr_, value_arg);
Ian Rogers0571d352011-11-03 19:51:38 -0700763 break;
764 case kLong:
David Sehr9323e6e2016-09-13 08:58:35 -0700765 jval_.j = DexFile::ReadSignedLong(ptr_, value_arg);
Ian Rogers0571d352011-11-03 19:51:38 -0700766 break;
767 case kFloat:
David Sehr9323e6e2016-09-13 08:58:35 -0700768 jval_.i = DexFile::ReadUnsignedInt(ptr_, value_arg, true);
Ian Rogers0571d352011-11-03 19:51:38 -0700769 break;
770 case kDouble:
David Sehr9323e6e2016-09-13 08:58:35 -0700771 jval_.j = DexFile::ReadUnsignedLong(ptr_, value_arg, true);
Ian Rogers0571d352011-11-03 19:51:38 -0700772 break;
773 case kString:
774 case kType:
Orion Hodson12f4ff42017-01-13 16:43:12 +0000775 case kMethodType:
776 case kMethodHandle:
David Sehr9323e6e2016-09-13 08:58:35 -0700777 jval_.i = DexFile::ReadUnsignedInt(ptr_, value_arg, false);
Ian Rogers0571d352011-11-03 19:51:38 -0700778 break;
779 case kField:
Brian Carlstrom88f36542012-10-16 23:24:21 -0700780 case kMethod:
781 case kEnum:
Ian Rogers0571d352011-11-03 19:51:38 -0700782 case kArray:
783 case kAnnotation:
784 UNIMPLEMENTED(FATAL) << ": type " << type_;
Ian Rogers2c4257b2014-10-24 14:20:06 -0700785 UNREACHABLE();
Ian Rogers0571d352011-11-03 19:51:38 -0700786 case kNull:
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700787 jval_.l = nullptr;
Ian Rogers0571d352011-11-03 19:51:38 -0700788 width = 0;
789 break;
790 default:
791 LOG(FATAL) << "Unreached";
Ian Rogers2c4257b2014-10-24 14:20:06 -0700792 UNREACHABLE();
Ian Rogers0571d352011-11-03 19:51:38 -0700793 }
794 ptr_ += width;
795}
796
Andreas Gampea5b09a62016-11-17 15:21:22 -0800797namespace dex {
798
Andreas Gampe8a0128a2016-11-28 07:38:35 -0800799std::ostream& operator<<(std::ostream& os, const StringIndex& index) {
800 os << "StringIndex[" << index.index_ << "]";
801 return os;
802}
803
Andreas Gampea5b09a62016-11-17 15:21:22 -0800804std::ostream& operator<<(std::ostream& os, const TypeIndex& index) {
805 os << "TypeIndex[" << index.index_ << "]";
806 return os;
807}
808
809} // namespace dex
810
Carl Shapiro1fb86202011-06-27 17:43:13 -0700811} // namespace art