Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 1 | /* |
| 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 Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 16 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 17 | #include "dex_file.h" |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 18 | |
| 19 | #include <fcntl.h> |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 20 | #include <limits.h> |
Brian Carlstrom | b0460ea | 2011-07-29 10:08:05 -0700 | [diff] [blame] | 21 | #include <stdio.h> |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 22 | #include <stdlib.h> |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 23 | #include <string.h> |
Brian Carlstrom | b0460ea | 2011-07-29 10:08:05 -0700 | [diff] [blame] | 24 | #include <sys/file.h> |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 25 | #include <sys/stat.h> |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 26 | |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 27 | #include <memory> |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 28 | #include <sstream> |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 29 | #include <type_traits> |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 30 | |
Andreas Gampe | 46ee31b | 2016-12-14 10:11:49 -0800 | [diff] [blame] | 31 | #include "android-base/stringprintf.h" |
| 32 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 33 | #include "base/enums.h" |
Vladimir Marko | 5096e66 | 2015-12-08 19:25:49 +0000 | [diff] [blame] | 34 | #include "base/file_magic.h" |
Elliott Hughes | 07ed66b | 2012-12-12 18:34:25 -0800 | [diff] [blame] | 35 | #include "base/logging.h" |
Mathieu Chartier | 32ce2ad | 2016-03-04 14:58:03 -0800 | [diff] [blame] | 36 | #include "base/systrace.h" |
Andreas Gampe | 43e10b0 | 2016-07-15 17:17:34 -0700 | [diff] [blame] | 37 | #include "base/unix_file/fd_file.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 38 | #include "dex_file-inl.h" |
jeffhao | 10037c8 | 2012-01-23 15:06:23 -0800 | [diff] [blame] | 39 | #include "dex_file_verifier.h" |
Vladimir Marko | 3a21e38 | 2016-09-02 12:38:38 +0100 | [diff] [blame] | 40 | #include "jvalue.h" |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 41 | #include "leb128.h" |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 42 | #include "os.h" |
Ian Rogers | a672490 | 2013-09-23 09:23:37 -0700 | [diff] [blame] | 43 | #include "utf-inl.h" |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 44 | #include "utils.h" |
Brian Carlstrom | b0460ea | 2011-07-29 10:08:05 -0700 | [diff] [blame] | 45 | #include "zip_archive.h" |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 46 | |
| 47 | namespace art { |
| 48 | |
Andreas Gampe | 46ee31b | 2016-12-14 10:11:49 -0800 | [diff] [blame] | 49 | using android::base::StringPrintf; |
| 50 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 51 | static_assert(sizeof(dex::StringIndex) == sizeof(uint32_t), "StringIndex size is wrong"); |
| 52 | static_assert(std::is_trivially_copyable<dex::StringIndex>::value, "StringIndex not trivial"); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 53 | static_assert(sizeof(dex::TypeIndex) == sizeof(uint16_t), "TypeIndex size is wrong"); |
| 54 | static_assert(std::is_trivially_copyable<dex::TypeIndex>::value, "TypeIndex not trivial"); |
| 55 | |
David Sehr | 733ddb2 | 2016-09-19 15:02:18 -0700 | [diff] [blame] | 56 | static constexpr OatDexFile* kNoOatDexFile = nullptr; |
| 57 | |
| 58 | const char* DexFile::kClassesDex = "classes.dex"; |
| 59 | |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 60 | const uint8_t DexFile::kDexMagic[] = { 'd', 'e', 'x', '\n' }; |
Alex Light | c496181 | 2016-03-23 10:20:41 -0700 | [diff] [blame] | 61 | const uint8_t DexFile::kDexMagicVersions[DexFile::kNumDexVersions][DexFile::kDexVersionLen] = { |
| 62 | {'0', '3', '5', '\0'}, |
| 63 | // Dex version 036 skipped because of an old dalvik bug on some versions of android where dex |
| 64 | // files with that version number would erroneously be accepted and run. |
Narayan Kamath | 52e6650 | 2016-08-01 14:20:31 +0100 | [diff] [blame] | 65 | {'0', '3', '7', '\0'}, |
| 66 | // Dex version 038: Android "O" and beyond. |
| 67 | {'0', '3', '8', '\0'} |
Alex Light | c496181 | 2016-03-23 10:20:41 -0700 | [diff] [blame] | 68 | }; |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 69 | |
Vladimir Marko | 3a21e38 | 2016-09-02 12:38:38 +0100 | [diff] [blame] | 70 | struct DexFile::AnnotationValue { |
| 71 | JValue value_; |
| 72 | uint8_t type_; |
| 73 | }; |
| 74 | |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 75 | bool DexFile::GetChecksum(const char* filename, uint32_t* checksum, std::string* error_msg) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 76 | CHECK(checksum != nullptr); |
Brian Carlstrom | 7c3d13a | 2013-09-04 17:15:11 -0700 | [diff] [blame] | 77 | uint32_t magic; |
Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 78 | |
| 79 | // Strip ":...", which is the location |
| 80 | const char* zip_entry_name = kClassesDex; |
| 81 | const char* file_part = filename; |
Vladimir Marko | aa4497d | 2014-09-05 14:01:17 +0100 | [diff] [blame] | 82 | std::string file_part_storage; |
Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 83 | |
Vladimir Marko | aa4497d | 2014-09-05 14:01:17 +0100 | [diff] [blame] | 84 | if (DexFile::IsMultiDexLocation(filename)) { |
| 85 | file_part_storage = GetBaseLocation(filename); |
| 86 | file_part = file_part_storage.c_str(); |
| 87 | zip_entry_name = filename + file_part_storage.size() + 1; |
| 88 | DCHECK_EQ(zip_entry_name[-1], kMultiDexSeparator); |
Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Andreas Gampe | 43e10b0 | 2016-07-15 17:17:34 -0700 | [diff] [blame] | 91 | File fd = OpenAndReadMagic(file_part, &magic, error_msg); |
| 92 | if (fd.Fd() == -1) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 93 | DCHECK(!error_msg->empty()); |
Brian Carlstrom | 7c3d13a | 2013-09-04 17:15:11 -0700 | [diff] [blame] | 94 | return false; |
| 95 | } |
| 96 | if (IsZipMagic(magic)) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 97 | std::unique_ptr<ZipArchive> zip_archive( |
Andreas Gampe | 43e10b0 | 2016-07-15 17:17:34 -0700 | [diff] [blame] | 98 | ZipArchive::OpenFromFd(fd.Release(), filename, error_msg)); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 99 | if (zip_archive.get() == nullptr) { |
Andreas Gampe | 0b3ed3d | 2015-03-04 15:38:51 -0800 | [diff] [blame] | 100 | *error_msg = StringPrintf("Failed to open zip archive '%s' (error msg: %s)", file_part, |
| 101 | error_msg->c_str()); |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 102 | return false; |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 103 | } |
Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 104 | std::unique_ptr<ZipEntry> zip_entry(zip_archive->Find(zip_entry_name, error_msg)); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 105 | if (zip_entry.get() == nullptr) { |
Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 106 | *error_msg = StringPrintf("Zip archive '%s' doesn't contain %s (error msg: %s)", file_part, |
| 107 | zip_entry_name, error_msg->c_str()); |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 108 | return false; |
| 109 | } |
Brian Carlstrom | 7c3d13a | 2013-09-04 17:15:11 -0700 | [diff] [blame] | 110 | *checksum = zip_entry->GetCrc32(); |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 111 | return true; |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 112 | } |
Brian Carlstrom | 7c3d13a | 2013-09-04 17:15:11 -0700 | [diff] [blame] | 113 | if (IsDexMagic(magic)) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 114 | std::unique_ptr<const DexFile> dex_file( |
Andreas Gampe | 43e10b0 | 2016-07-15 17:17:34 -0700 | [diff] [blame] | 115 | DexFile::OpenFile(fd.Release(), filename, false, false, error_msg)); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 116 | if (dex_file.get() == nullptr) { |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 117 | return false; |
| 118 | } |
Brian Carlstrom | 7c3d13a | 2013-09-04 17:15:11 -0700 | [diff] [blame] | 119 | *checksum = dex_file->GetHeader().checksum_; |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 120 | return true; |
| 121 | } |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 122 | *error_msg = StringPrintf("Expected valid zip or dex file: '%s'", filename); |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 123 | return false; |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 126 | int DexFile::GetPermissions() const { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 127 | if (mem_map_.get() == nullptr) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 128 | return 0; |
| 129 | } else { |
| 130 | return mem_map_->GetProtect(); |
| 131 | } |
| 132 | } |
| 133 | |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 134 | bool DexFile::IsReadOnly() const { |
| 135 | return GetPermissions() == PROT_READ; |
| 136 | } |
| 137 | |
Brian Carlstrom | e0948e1 | 2013-08-29 09:36:15 -0700 | [diff] [blame] | 138 | bool DexFile::EnableWrite() const { |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 139 | CHECK(IsReadOnly()); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 140 | if (mem_map_.get() == nullptr) { |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 141 | return false; |
| 142 | } else { |
Brian Carlstrom | e0948e1 | 2013-08-29 09:36:15 -0700 | [diff] [blame] | 143 | return mem_map_->Protect(PROT_READ | PROT_WRITE); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 144 | } |
| 145 | } |
| 146 | |
Brian Carlstrom | e0948e1 | 2013-08-29 09:36:15 -0700 | [diff] [blame] | 147 | bool DexFile::DisableWrite() const { |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 148 | CHECK(!IsReadOnly()); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 149 | if (mem_map_.get() == nullptr) { |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 150 | return false; |
| 151 | } else { |
Brian Carlstrom | e0948e1 | 2013-08-29 09:36:15 -0700 | [diff] [blame] | 152 | return mem_map_->Protect(PROT_READ); |
Sebastien Hertz | 2d6ba51 | 2013-05-17 11:31:37 +0200 | [diff] [blame] | 153 | } |
| 154 | } |
| 155 | |
David Sehr | 733ddb2 | 2016-09-19 15:02:18 -0700 | [diff] [blame] | 156 | |
| 157 | std::unique_ptr<const DexFile> DexFile::Open(const uint8_t* base, |
| 158 | size_t size, |
Andreas Gampe | 3a2bd29 | 2016-01-26 17:23:47 -0800 | [diff] [blame] | 159 | const std::string& location, |
| 160 | uint32_t location_checksum, |
| 161 | const OatDexFile* oat_dex_file, |
| 162 | bool verify, |
Aart Bik | 37d6a3b | 2016-06-21 18:30:10 -0700 | [diff] [blame] | 163 | bool verify_checksum, |
Andreas Gampe | 3a2bd29 | 2016-01-26 17:23:47 -0800 | [diff] [blame] | 164 | std::string* error_msg) { |
Mathieu Chartier | 32ce2ad | 2016-03-04 14:58:03 -0800 | [diff] [blame] | 165 | ScopedTrace trace(std::string("Open dex file from RAM ") + location); |
David Sehr | 733ddb2 | 2016-09-19 15:02:18 -0700 | [diff] [blame] | 166 | return OpenCommon(base, |
| 167 | size, |
| 168 | location, |
| 169 | location_checksum, |
| 170 | oat_dex_file, |
| 171 | verify, |
| 172 | verify_checksum, |
| 173 | error_msg); |
Orion Hodson | a4c2a05 | 2016-08-17 10:51:42 +0100 | [diff] [blame] | 174 | } |
Andreas Gampe | 3a2bd29 | 2016-01-26 17:23:47 -0800 | [diff] [blame] | 175 | |
Orion Hodson | a4c2a05 | 2016-08-17 10:51:42 +0100 | [diff] [blame] | 176 | std::unique_ptr<const DexFile> DexFile::Open(const std::string& location, |
| 177 | uint32_t location_checksum, |
David Sehr | 733ddb2 | 2016-09-19 15:02:18 -0700 | [diff] [blame] | 178 | std::unique_ptr<MemMap> map, |
Orion Hodson | a4c2a05 | 2016-08-17 10:51:42 +0100 | [diff] [blame] | 179 | bool verify, |
| 180 | bool verify_checksum, |
| 181 | std::string* error_msg) { |
| 182 | ScopedTrace trace(std::string("Open dex file from mapped-memory ") + location); |
David Sehr | 733ddb2 | 2016-09-19 15:02:18 -0700 | [diff] [blame] | 183 | CHECK(map.get() != nullptr); |
| 184 | std::unique_ptr<DexFile> dex_file = OpenCommon(map->Begin(), |
| 185 | map->Size(), |
| 186 | location, |
| 187 | location_checksum, |
| 188 | kNoOatDexFile, |
| 189 | verify, |
| 190 | verify_checksum, |
| 191 | error_msg); |
| 192 | if (dex_file != nullptr) { |
| 193 | dex_file->mem_map_.reset(map.release()); |
Orion Hodson | a4c2a05 | 2016-08-17 10:51:42 +0100 | [diff] [blame] | 194 | } |
Andreas Gampe | 3a2bd29 | 2016-01-26 17:23:47 -0800 | [diff] [blame] | 195 | return dex_file; |
| 196 | } |
| 197 | |
David Sehr | 733ddb2 | 2016-09-19 15:02:18 -0700 | [diff] [blame] | 198 | bool DexFile::Open(const char* filename, |
| 199 | const std::string& location, |
| 200 | bool verify_checksum, |
| 201 | std::string* error_msg, |
| 202 | std::vector<std::unique_ptr<const DexFile>>* dex_files) { |
| 203 | ScopedTrace trace(std::string("Open dex file ") + std::string(location)); |
| 204 | DCHECK(dex_files != nullptr) << "DexFile::Open: out-param is nullptr"; |
| 205 | uint32_t magic; |
| 206 | File fd = OpenAndReadMagic(filename, &magic, error_msg); |
| 207 | if (fd.Fd() == -1) { |
| 208 | DCHECK(!error_msg->empty()); |
| 209 | return false; |
| 210 | } |
| 211 | if (IsZipMagic(magic)) { |
| 212 | return DexFile::OpenZip(fd.Release(), location, verify_checksum, error_msg, dex_files); |
| 213 | } |
| 214 | if (IsDexMagic(magic)) { |
| 215 | std::unique_ptr<const DexFile> dex_file(DexFile::OpenFile(fd.Release(), |
| 216 | location, |
| 217 | /* verify */ true, |
| 218 | verify_checksum, |
| 219 | error_msg)); |
| 220 | if (dex_file.get() != nullptr) { |
| 221 | dex_files->push_back(std::move(dex_file)); |
| 222 | return true; |
| 223 | } else { |
| 224 | return false; |
Vladimir Marko | fd99576 | 2013-11-06 16:36:36 +0000 | [diff] [blame] | 225 | } |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 226 | } |
David Sehr | 733ddb2 | 2016-09-19 15:02:18 -0700 | [diff] [blame] | 227 | *error_msg = StringPrintf("Expected valid zip or dex file: '%s'", filename); |
| 228 | return false; |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 229 | } |
| 230 | |
David Sehr | 733ddb2 | 2016-09-19 15:02:18 -0700 | [diff] [blame] | 231 | std::unique_ptr<const DexFile> DexFile::OpenDex(int fd, |
| 232 | const std::string& location, |
| 233 | bool verify_checksum, |
| 234 | std::string* error_msg) { |
| 235 | ScopedTrace trace("Open dex file " + std::string(location)); |
| 236 | return OpenFile(fd, location, true /* verify */, verify_checksum, error_msg); |
| 237 | } |
Brian Carlstrom | b0460ea | 2011-07-29 10:08:05 -0700 | [diff] [blame] | 238 | |
Aart Bik | 37d6a3b | 2016-06-21 18:30:10 -0700 | [diff] [blame] | 239 | bool DexFile::OpenZip(int fd, |
| 240 | const std::string& location, |
| 241 | bool verify_checksum, |
| 242 | std::string* error_msg, |
Richard Uhler | fbef44d | 2014-12-23 09:48:51 -0800 | [diff] [blame] | 243 | std::vector<std::unique_ptr<const DexFile>>* dex_files) { |
Mathieu Chartier | 32ce2ad | 2016-03-04 14:58:03 -0800 | [diff] [blame] | 244 | ScopedTrace trace("Dex file open Zip " + std::string(location)); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 245 | DCHECK(dex_files != nullptr) << "DexFile::OpenZip: out-param is nullptr"; |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 246 | std::unique_ptr<ZipArchive> zip_archive(ZipArchive::OpenFromFd(fd, location.c_str(), error_msg)); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 247 | if (zip_archive.get() == nullptr) { |
| 248 | DCHECK(!error_msg->empty()); |
Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 249 | return false; |
Brian Carlstrom | b0460ea | 2011-07-29 10:08:05 -0700 | [diff] [blame] | 250 | } |
David Sehr | 733ddb2 | 2016-09-19 15:02:18 -0700 | [diff] [blame] | 251 | return DexFile::OpenAllDexFilesFromZip(*zip_archive, |
| 252 | location, |
| 253 | verify_checksum, |
| 254 | error_msg, |
| 255 | dex_files); |
Brian Carlstrom | a6cc893 | 2012-01-04 14:44:07 -0800 | [diff] [blame] | 256 | } |
| 257 | |
David Sehr | 733ddb2 | 2016-09-19 15:02:18 -0700 | [diff] [blame] | 258 | std::unique_ptr<const DexFile> DexFile::OpenFile(int fd, |
| 259 | const std::string& location, |
| 260 | bool verify, |
| 261 | bool verify_checksum, |
| 262 | std::string* error_msg) { |
| 263 | ScopedTrace trace(std::string("Open dex file ") + std::string(location)); |
| 264 | CHECK(!location.empty()); |
| 265 | std::unique_ptr<MemMap> map; |
| 266 | { |
| 267 | File delayed_close(fd, /* check_usage */ false); |
| 268 | struct stat sbuf; |
| 269 | memset(&sbuf, 0, sizeof(sbuf)); |
| 270 | if (fstat(fd, &sbuf) == -1) { |
| 271 | *error_msg = StringPrintf("DexFile: fstat '%s' failed: %s", location.c_str(), |
| 272 | strerror(errno)); |
| 273 | return nullptr; |
| 274 | } |
| 275 | if (S_ISDIR(sbuf.st_mode)) { |
| 276 | *error_msg = StringPrintf("Attempt to mmap directory '%s'", location.c_str()); |
| 277 | return nullptr; |
| 278 | } |
| 279 | size_t length = sbuf.st_size; |
| 280 | map.reset(MemMap::MapFile(length, |
| 281 | PROT_READ, |
| 282 | MAP_PRIVATE, |
| 283 | fd, |
| 284 | 0, |
| 285 | /*low_4gb*/false, |
| 286 | location.c_str(), |
| 287 | error_msg)); |
| 288 | if (map == nullptr) { |
| 289 | DCHECK(!error_msg->empty()); |
| 290 | return nullptr; |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | if (map->Size() < sizeof(DexFile::Header)) { |
| 295 | *error_msg = StringPrintf( |
| 296 | "DexFile: failed to open dex file '%s' that is too short to have a header", |
| 297 | location.c_str()); |
| 298 | return nullptr; |
| 299 | } |
| 300 | |
| 301 | const Header* dex_header = reinterpret_cast<const Header*>(map->Begin()); |
| 302 | |
| 303 | std::unique_ptr<DexFile> dex_file = OpenCommon(map->Begin(), |
| 304 | map->Size(), |
| 305 | location, |
| 306 | dex_header->checksum_, |
| 307 | kNoOatDexFile, |
| 308 | verify, |
| 309 | verify_checksum, |
| 310 | error_msg); |
| 311 | if (dex_file != nullptr) { |
| 312 | dex_file->mem_map_.reset(map.release()); |
| 313 | } |
| 314 | |
| 315 | return dex_file; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 316 | } |
| 317 | |
David Sehr | 733ddb2 | 2016-09-19 15:02:18 -0700 | [diff] [blame] | 318 | std::unique_ptr<const DexFile> DexFile::OpenOneDexFileFromZip(const ZipArchive& zip_archive, |
| 319 | const char* entry_name, |
| 320 | const std::string& location, |
| 321 | bool verify_checksum, |
| 322 | std::string* error_msg, |
| 323 | ZipOpenErrorCode* error_code) { |
Mathieu Chartier | 32ce2ad | 2016-03-04 14:58:03 -0800 | [diff] [blame] | 324 | ScopedTrace trace("Dex file open from Zip Archive " + std::string(location)); |
Brian Carlstrom | a004aa9 | 2012-02-08 18:05:09 -0800 | [diff] [blame] | 325 | CHECK(!location.empty()); |
Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 326 | std::unique_ptr<ZipEntry> zip_entry(zip_archive.Find(entry_name, error_msg)); |
David Sehr | 9fddd36 | 2016-09-22 14:05:37 -0700 | [diff] [blame] | 327 | if (zip_entry == nullptr) { |
Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 328 | *error_code = ZipOpenErrorCode::kEntryNotFound; |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 329 | return nullptr; |
Brian Carlstrom | b0460ea | 2011-07-29 10:08:05 -0700 | [diff] [blame] | 330 | } |
ganxiaolin | cd16d0a | 2016-07-18 11:21:44 +0800 | [diff] [blame] | 331 | if (zip_entry->GetUncompressedLength() == 0) { |
| 332 | *error_msg = StringPrintf("Dex file '%s' has zero length", location.c_str()); |
| 333 | *error_code = ZipOpenErrorCode::kDexFileError; |
| 334 | return nullptr; |
| 335 | } |
Nicolas Geoffray | 960b2af | 2017-02-12 15:48:07 +0000 | [diff] [blame] | 336 | std::unique_ptr<MemMap> map(zip_entry->ExtractToMemMap(location.c_str(), entry_name, error_msg)); |
David Sehr | 9fddd36 | 2016-09-22 14:05:37 -0700 | [diff] [blame] | 337 | if (map == nullptr) { |
Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 338 | *error_msg = StringPrintf("Failed to extract '%s' from '%s': %s", entry_name, location.c_str(), |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 339 | error_msg->c_str()); |
Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 340 | *error_code = ZipOpenErrorCode::kExtractToMemoryError; |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 341 | return nullptr; |
Brian Carlstrom | b0460ea | 2011-07-29 10:08:05 -0700 | [diff] [blame] | 342 | } |
David Sehr | 733ddb2 | 2016-09-19 15:02:18 -0700 | [diff] [blame] | 343 | VerifyResult verify_result; |
| 344 | std::unique_ptr<DexFile> dex_file = OpenCommon(map->Begin(), |
| 345 | map->Size(), |
| 346 | location, |
| 347 | zip_entry->GetCrc32(), |
| 348 | kNoOatDexFile, |
| 349 | /* verify */ true, |
| 350 | verify_checksum, |
| 351 | error_msg, |
| 352 | &verify_result); |
David Sehr | 9fddd36 | 2016-09-22 14:05:37 -0700 | [diff] [blame] | 353 | if (dex_file == nullptr) { |
| 354 | if (verify_result == VerifyResult::kVerifyNotAttempted) { |
| 355 | *error_code = ZipOpenErrorCode::kDexFileError; |
| 356 | } else { |
| 357 | *error_code = ZipOpenErrorCode::kVerifyError; |
| 358 | } |
| 359 | return nullptr; |
jeffhao | f6174e8 | 2012-01-31 16:14:17 -0800 | [diff] [blame] | 360 | } |
David Sehr | 9fddd36 | 2016-09-22 14:05:37 -0700 | [diff] [blame] | 361 | dex_file->mem_map_.reset(map.release()); |
Brian Carlstrom | e0948e1 | 2013-08-29 09:36:15 -0700 | [diff] [blame] | 362 | if (!dex_file->DisableWrite()) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 363 | *error_msg = StringPrintf("Failed to make dex file '%s' read only", location.c_str()); |
Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 364 | *error_code = ZipOpenErrorCode::kMakeReadOnlyError; |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 365 | return nullptr; |
Brian Carlstrom | e0948e1 | 2013-08-29 09:36:15 -0700 | [diff] [blame] | 366 | } |
| 367 | CHECK(dex_file->IsReadOnly()) << location; |
David Sehr | 733ddb2 | 2016-09-19 15:02:18 -0700 | [diff] [blame] | 368 | if (verify_result != VerifyResult::kVerifySucceeded) { |
Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 369 | *error_code = ZipOpenErrorCode::kVerifyError; |
Brian Carlstrom | d6cec90 | 2014-05-25 16:08:51 -0700 | [diff] [blame] | 370 | return nullptr; |
| 371 | } |
Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 372 | *error_code = ZipOpenErrorCode::kNoError; |
Richard Uhler | fbef44d | 2014-12-23 09:48:51 -0800 | [diff] [blame] | 373 | return dex_file; |
Brian Carlstrom | b0460ea | 2011-07-29 10:08:05 -0700 | [diff] [blame] | 374 | } |
| 375 | |
Andreas Gampe | 90e3404 | 2015-04-27 20:01:52 -0700 | [diff] [blame] | 376 | // Technically we do not have a limitation with respect to the number of dex files that can be in a |
| 377 | // multidex APK. However, it's bad practice, as each dex file requires its own tables for symbols |
| 378 | // (types, classes, methods, ...) and dex caches. So warn the user that we open a zip with what |
| 379 | // seems an excessive number. |
| 380 | static constexpr size_t kWarnOnManyDexFilesThreshold = 100; |
| 381 | |
David Sehr | 733ddb2 | 2016-09-19 15:02:18 -0700 | [diff] [blame] | 382 | bool DexFile::OpenAllDexFilesFromZip(const ZipArchive& zip_archive, |
| 383 | const std::string& location, |
| 384 | bool verify_checksum, |
| 385 | std::string* error_msg, |
| 386 | std::vector<std::unique_ptr<const DexFile>>* dex_files) { |
Mathieu Chartier | 32ce2ad | 2016-03-04 14:58:03 -0800 | [diff] [blame] | 387 | ScopedTrace trace("Dex file open from Zip " + std::string(location)); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 388 | DCHECK(dex_files != nullptr) << "DexFile::OpenFromZip: out-param is nullptr"; |
Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 389 | ZipOpenErrorCode error_code; |
David Sehr | 733ddb2 | 2016-09-19 15:02:18 -0700 | [diff] [blame] | 390 | std::unique_ptr<const DexFile> dex_file(OpenOneDexFileFromZip(zip_archive, |
| 391 | kClassesDex, |
| 392 | location, |
| 393 | verify_checksum, |
| 394 | error_msg, |
| 395 | &error_code)); |
Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 396 | if (dex_file.get() == nullptr) { |
| 397 | return false; |
| 398 | } else { |
| 399 | // Had at least classes.dex. |
Richard Uhler | fbef44d | 2014-12-23 09:48:51 -0800 | [diff] [blame] | 400 | dex_files->push_back(std::move(dex_file)); |
Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 401 | |
| 402 | // Now try some more. |
Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 403 | |
| 404 | // We could try to avoid std::string allocations by working on a char array directly. As we |
| 405 | // do not expect a lot of iterations, this seems too involved and brittle. |
| 406 | |
Andreas Gampe | 90e3404 | 2015-04-27 20:01:52 -0700 | [diff] [blame] | 407 | for (size_t i = 1; ; ++i) { |
| 408 | std::string name = GetMultiDexClassesDexName(i); |
| 409 | std::string fake_location = GetMultiDexLocation(i, location.c_str()); |
David Sehr | 733ddb2 | 2016-09-19 15:02:18 -0700 | [diff] [blame] | 410 | std::unique_ptr<const DexFile> next_dex_file(OpenOneDexFileFromZip(zip_archive, |
| 411 | name.c_str(), |
| 412 | fake_location, |
| 413 | verify_checksum, |
| 414 | error_msg, |
| 415 | &error_code)); |
Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 416 | if (next_dex_file.get() == nullptr) { |
| 417 | if (error_code != ZipOpenErrorCode::kEntryNotFound) { |
David Sehr | c922922 | 2017-02-14 10:57:47 -0800 | [diff] [blame^] | 418 | LOG(WARNING) << "Zip open failed: " << *error_msg; |
Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 419 | } |
| 420 | break; |
| 421 | } else { |
Richard Uhler | fbef44d | 2014-12-23 09:48:51 -0800 | [diff] [blame] | 422 | dex_files->push_back(std::move(next_dex_file)); |
Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 423 | } |
| 424 | |
Andreas Gampe | 90e3404 | 2015-04-27 20:01:52 -0700 | [diff] [blame] | 425 | if (i == kWarnOnManyDexFilesThreshold) { |
| 426 | LOG(WARNING) << location << " has in excess of " << kWarnOnManyDexFilesThreshold |
| 427 | << " dex files. Please consider coalescing and shrinking the number to " |
| 428 | " avoid runtime overhead."; |
| 429 | } |
| 430 | |
| 431 | if (i == std::numeric_limits<size_t>::max()) { |
| 432 | LOG(ERROR) << "Overflow in number of dex files!"; |
| 433 | break; |
| 434 | } |
Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | return true; |
| 438 | } |
| 439 | } |
| 440 | |
David Sehr | 733ddb2 | 2016-09-19 15:02:18 -0700 | [diff] [blame] | 441 | std::unique_ptr<DexFile> DexFile::OpenCommon(const uint8_t* base, |
| 442 | size_t size, |
| 443 | const std::string& location, |
| 444 | uint32_t location_checksum, |
| 445 | const OatDexFile* oat_dex_file, |
| 446 | bool verify, |
| 447 | bool verify_checksum, |
| 448 | std::string* error_msg, |
| 449 | VerifyResult* verify_result) { |
David Sehr | 9fddd36 | 2016-09-22 14:05:37 -0700 | [diff] [blame] | 450 | if (verify_result != nullptr) { |
| 451 | *verify_result = VerifyResult::kVerifyNotAttempted; |
| 452 | } |
David Sehr | 733ddb2 | 2016-09-19 15:02:18 -0700 | [diff] [blame] | 453 | std::unique_ptr<DexFile> dex_file(new DexFile(base, |
| 454 | size, |
| 455 | location, |
| 456 | location_checksum, |
| 457 | oat_dex_file)); |
| 458 | if (dex_file == nullptr) { |
| 459 | *error_msg = StringPrintf("Failed to open dex file '%s' from memory: %s", location.c_str(), |
| 460 | error_msg->c_str()); |
| 461 | return nullptr; |
| 462 | } |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 463 | if (!dex_file->Init(error_msg)) { |
Richard Uhler | fbef44d | 2014-12-23 09:48:51 -0800 | [diff] [blame] | 464 | dex_file.reset(); |
David Sehr | 733ddb2 | 2016-09-19 15:02:18 -0700 | [diff] [blame] | 465 | return nullptr; |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 466 | } |
David Sehr | 733ddb2 | 2016-09-19 15:02:18 -0700 | [diff] [blame] | 467 | if (verify && !DexFileVerifier::Verify(dex_file.get(), |
| 468 | dex_file->Begin(), |
| 469 | dex_file->Size(), |
| 470 | location.c_str(), |
| 471 | verify_checksum, |
| 472 | error_msg)) { |
| 473 | if (verify_result != nullptr) { |
| 474 | *verify_result = VerifyResult::kVerifyFailed; |
| 475 | } |
| 476 | return nullptr; |
| 477 | } |
| 478 | if (verify_result != nullptr) { |
| 479 | *verify_result = VerifyResult::kVerifySucceeded; |
| 480 | } |
| 481 | return dex_file; |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 482 | } |
| 483 | |
David Sehr | 733ddb2 | 2016-09-19 15:02:18 -0700 | [diff] [blame] | 484 | DexFile::DexFile(const uint8_t* base, |
| 485 | size_t size, |
Brian Carlstrom | 0d6adac | 2014-02-05 17:39:16 -0800 | [diff] [blame] | 486 | const std::string& location, |
| 487 | uint32_t location_checksum, |
Richard Uhler | 07b3c23 | 2015-03-31 15:57:54 -0700 | [diff] [blame] | 488 | const OatDexFile* oat_dex_file) |
Brian Carlstrom | 0d6adac | 2014-02-05 17:39:16 -0800 | [diff] [blame] | 489 | : begin_(base), |
| 490 | size_(size), |
| 491 | location_(location), |
| 492 | location_checksum_(location_checksum), |
Brian Carlstrom | 0d6adac | 2014-02-05 17:39:16 -0800 | [diff] [blame] | 493 | header_(reinterpret_cast<const Header*>(base)), |
| 494 | string_ids_(reinterpret_cast<const StringId*>(base + header_->string_ids_off_)), |
| 495 | type_ids_(reinterpret_cast<const TypeId*>(base + header_->type_ids_off_)), |
| 496 | field_ids_(reinterpret_cast<const FieldId*>(base + header_->field_ids_off_)), |
| 497 | method_ids_(reinterpret_cast<const MethodId*>(base + header_->method_ids_off_)), |
| 498 | proto_ids_(reinterpret_cast<const ProtoId*>(base + header_->proto_ids_off_)), |
Ian Rogers | 68b5685 | 2014-08-29 20:19:11 -0700 | [diff] [blame] | 499 | class_defs_(reinterpret_cast<const ClassDef*>(base + header_->class_defs_off_)), |
Richard Uhler | 07b3c23 | 2015-03-31 15:57:54 -0700 | [diff] [blame] | 500 | oat_dex_file_(oat_dex_file) { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 501 | CHECK(begin_ != nullptr) << GetLocation(); |
Brian Carlstrom | 0d6adac | 2014-02-05 17:39:16 -0800 | [diff] [blame] | 502 | CHECK_GT(size_, 0U) << GetLocation(); |
| 503 | } |
| 504 | |
Jesse Wilson | 6bf1915 | 2011-09-29 13:12:33 -0400 | [diff] [blame] | 505 | DexFile::~DexFile() { |
Elliott Hughes | 8cef0b8 | 2011-10-11 19:24:00 -0700 | [diff] [blame] | 506 | // We don't call DeleteGlobalRef on dex_object_ because we're only called by DestroyJavaVM, and |
| 507 | // that's only called after DetachCurrentThread, which means there's no JNIEnv. We could |
| 508 | // re-attach, but cleaning up these global references is not obviously useful. It's not as if |
| 509 | // the global reference table is otherwise empty! |
Jesse Wilson | 6bf1915 | 2011-09-29 13:12:33 -0400 | [diff] [blame] | 510 | } |
| 511 | |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 512 | bool DexFile::Init(std::string* error_msg) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 513 | if (!CheckMagicAndVersion(error_msg)) { |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 514 | return false; |
| 515 | } |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 516 | return true; |
| 517 | } |
| 518 | |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 519 | bool DexFile::CheckMagicAndVersion(std::string* error_msg) const { |
Brian Carlstrom | 6e3b1d9 | 2012-01-11 01:36:32 -0800 | [diff] [blame] | 520 | if (!IsMagicValid(header_->magic_)) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 521 | std::ostringstream oss; |
| 522 | oss << "Unrecognized magic number in " << GetLocation() << ":" |
Brian Carlstrom | 6e3b1d9 | 2012-01-11 01:36:32 -0800 | [diff] [blame] | 523 | << " " << header_->magic_[0] |
| 524 | << " " << header_->magic_[1] |
| 525 | << " " << header_->magic_[2] |
| 526 | << " " << header_->magic_[3]; |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 527 | *error_msg = oss.str(); |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 528 | return false; |
| 529 | } |
Brian Carlstrom | 6e3b1d9 | 2012-01-11 01:36:32 -0800 | [diff] [blame] | 530 | if (!IsVersionValid(header_->magic_)) { |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 531 | std::ostringstream oss; |
| 532 | oss << "Unrecognized version number in " << GetLocation() << ":" |
Brian Carlstrom | 6e3b1d9 | 2012-01-11 01:36:32 -0800 | [diff] [blame] | 533 | << " " << header_->magic_[4] |
| 534 | << " " << header_->magic_[5] |
| 535 | << " " << header_->magic_[6] |
| 536 | << " " << header_->magic_[7]; |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 537 | *error_msg = oss.str(); |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 538 | return false; |
| 539 | } |
| 540 | return true; |
| 541 | } |
| 542 | |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 543 | bool DexFile::IsMagicValid(const uint8_t* magic) { |
Brian Carlstrom | 6e3b1d9 | 2012-01-11 01:36:32 -0800 | [diff] [blame] | 544 | return (memcmp(magic, kDexMagic, sizeof(kDexMagic)) == 0); |
| 545 | } |
| 546 | |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 547 | bool DexFile::IsVersionValid(const uint8_t* magic) { |
| 548 | const uint8_t* version = &magic[sizeof(kDexMagic)]; |
Alex Light | c496181 | 2016-03-23 10:20:41 -0700 | [diff] [blame] | 549 | for (uint32_t i = 0; i < kNumDexVersions; i++) { |
| 550 | if (memcmp(version, kDexMagicVersions[i], kDexVersionLen) == 0) { |
| 551 | return true; |
| 552 | } |
| 553 | } |
| 554 | return false; |
Brian Carlstrom | 6e3b1d9 | 2012-01-11 01:36:32 -0800 | [diff] [blame] | 555 | } |
| 556 | |
Andreas Gampe | 76ed99d | 2016-03-28 18:31:29 -0700 | [diff] [blame] | 557 | uint32_t DexFile::Header::GetVersion() const { |
| 558 | const char* version = reinterpret_cast<const char*>(&magic_[sizeof(kDexMagic)]); |
Ian Rogers | d81871c | 2011-10-03 13:57:23 -0700 | [diff] [blame] | 559 | return atoi(version); |
| 560 | } |
| 561 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 562 | const DexFile::ClassDef* DexFile::FindClassDef(dex::TypeIndex type_idx) const { |
David Sehr | 9aa352e | 2016-09-15 18:13:52 -0700 | [diff] [blame] | 563 | size_t num_class_defs = NumClassDefs(); |
Roland Levillain | ab880f4 | 2016-05-12 16:24:36 +0100 | [diff] [blame] | 564 | // Fast path for rare no class defs case. |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 565 | if (num_class_defs == 0) { |
Ian Rogers | 68b5685 | 2014-08-29 20:19:11 -0700 | [diff] [blame] | 566 | return nullptr; |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 567 | } |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 568 | for (size_t i = 0; i < num_class_defs; ++i) { |
| 569 | const ClassDef& class_def = GetClassDef(i); |
| 570 | if (class_def.class_idx_ == type_idx) { |
| 571 | return &class_def; |
| 572 | } |
Brian Carlstrom | e24fa61 | 2011-09-29 00:53:55 -0700 | [diff] [blame] | 573 | } |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 574 | return nullptr; |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 575 | } |
| 576 | |
Alex Light | 9c20a14 | 2016-08-23 15:05:12 -0700 | [diff] [blame] | 577 | uint32_t DexFile::FindCodeItemOffset(const DexFile::ClassDef& class_def, |
| 578 | uint32_t method_idx) const { |
| 579 | const uint8_t* class_data = GetClassData(class_def); |
| 580 | CHECK(class_data != nullptr); |
| 581 | ClassDataItemIterator it(*this, class_data); |
| 582 | // Skip fields |
| 583 | while (it.HasNextStaticField()) { |
| 584 | it.Next(); |
| 585 | } |
| 586 | while (it.HasNextInstanceField()) { |
| 587 | it.Next(); |
| 588 | } |
| 589 | while (it.HasNextDirectMethod()) { |
| 590 | if (it.GetMemberIndex() == method_idx) { |
| 591 | return it.GetMethodCodeItemOffset(); |
| 592 | } |
| 593 | it.Next(); |
| 594 | } |
| 595 | while (it.HasNextVirtualMethod()) { |
| 596 | if (it.GetMemberIndex() == method_idx) { |
| 597 | return it.GetMethodCodeItemOffset(); |
| 598 | } |
| 599 | it.Next(); |
| 600 | } |
| 601 | LOG(FATAL) << "Unable to find method " << method_idx; |
| 602 | UNREACHABLE(); |
| 603 | } |
| 604 | |
Ian Rogers | 9b1a4f4 | 2011-11-14 18:35:10 -0800 | [diff] [blame] | 605 | const DexFile::FieldId* DexFile::FindFieldId(const DexFile::TypeId& declaring_klass, |
Roland Levillain | ab880f4 | 2016-05-12 16:24:36 +0100 | [diff] [blame] | 606 | const DexFile::StringId& name, |
| 607 | const DexFile::TypeId& type) const { |
Ian Rogers | 9b1a4f4 | 2011-11-14 18:35:10 -0800 | [diff] [blame] | 608 | // Binary search MethodIds knowing that they are sorted by class_idx, name_idx then proto_idx |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 609 | const dex::TypeIndex class_idx = GetIndexForTypeId(declaring_klass); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 610 | const dex::StringIndex name_idx = GetIndexForStringId(name); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 611 | const dex::TypeIndex type_idx = GetIndexForTypeId(type); |
Ian Rogers | f8582c3 | 2013-05-29 16:33:03 -0700 | [diff] [blame] | 612 | int32_t lo = 0; |
| 613 | int32_t hi = NumFieldIds() - 1; |
Ian Rogers | 9b1a4f4 | 2011-11-14 18:35:10 -0800 | [diff] [blame] | 614 | while (hi >= lo) { |
Ian Rogers | f8582c3 | 2013-05-29 16:33:03 -0700 | [diff] [blame] | 615 | int32_t mid = (hi + lo) / 2; |
Ian Rogers | 9b1a4f4 | 2011-11-14 18:35:10 -0800 | [diff] [blame] | 616 | const DexFile::FieldId& field = GetFieldId(mid); |
| 617 | if (class_idx > field.class_idx_) { |
| 618 | lo = mid + 1; |
| 619 | } else if (class_idx < field.class_idx_) { |
| 620 | hi = mid - 1; |
| 621 | } else { |
| 622 | if (name_idx > field.name_idx_) { |
| 623 | lo = mid + 1; |
| 624 | } else if (name_idx < field.name_idx_) { |
| 625 | hi = mid - 1; |
| 626 | } else { |
| 627 | if (type_idx > field.type_idx_) { |
| 628 | lo = mid + 1; |
| 629 | } else if (type_idx < field.type_idx_) { |
| 630 | hi = mid - 1; |
| 631 | } else { |
| 632 | return &field; |
| 633 | } |
| 634 | } |
| 635 | } |
| 636 | } |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 637 | return nullptr; |
Ian Rogers | 9b1a4f4 | 2011-11-14 18:35:10 -0800 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | const DexFile::MethodId* DexFile::FindMethodId(const DexFile::TypeId& declaring_klass, |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 641 | const DexFile::StringId& name, |
| 642 | const DexFile::ProtoId& signature) const { |
| 643 | // Binary search MethodIds knowing that they are sorted by class_idx, name_idx then proto_idx |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 644 | const dex::TypeIndex class_idx = GetIndexForTypeId(declaring_klass); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 645 | const dex::StringIndex name_idx = GetIndexForStringId(name); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 646 | const uint16_t proto_idx = GetIndexForProtoId(signature); |
Ian Rogers | f8582c3 | 2013-05-29 16:33:03 -0700 | [diff] [blame] | 647 | int32_t lo = 0; |
| 648 | int32_t hi = NumMethodIds() - 1; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 649 | while (hi >= lo) { |
Ian Rogers | f8582c3 | 2013-05-29 16:33:03 -0700 | [diff] [blame] | 650 | int32_t mid = (hi + lo) / 2; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 651 | const DexFile::MethodId& method = GetMethodId(mid); |
| 652 | if (class_idx > method.class_idx_) { |
| 653 | lo = mid + 1; |
| 654 | } else if (class_idx < method.class_idx_) { |
| 655 | hi = mid - 1; |
| 656 | } else { |
| 657 | if (name_idx > method.name_idx_) { |
| 658 | lo = mid + 1; |
| 659 | } else if (name_idx < method.name_idx_) { |
| 660 | hi = mid - 1; |
| 661 | } else { |
| 662 | if (proto_idx > method.proto_idx_) { |
| 663 | lo = mid + 1; |
| 664 | } else if (proto_idx < method.proto_idx_) { |
| 665 | hi = mid - 1; |
| 666 | } else { |
| 667 | return &method; |
| 668 | } |
| 669 | } |
| 670 | } |
| 671 | } |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 672 | return nullptr; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 673 | } |
| 674 | |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 675 | const DexFile::StringId* DexFile::FindStringId(const char* string) const { |
Ian Rogers | f8582c3 | 2013-05-29 16:33:03 -0700 | [diff] [blame] | 676 | int32_t lo = 0; |
| 677 | int32_t hi = NumStringIds() - 1; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 678 | while (hi >= lo) { |
Ian Rogers | f8582c3 | 2013-05-29 16:33:03 -0700 | [diff] [blame] | 679 | int32_t mid = (hi + lo) / 2; |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 680 | const DexFile::StringId& str_id = GetStringId(dex::StringIndex(mid)); |
Ian Rogers | cf5077a | 2013-10-31 12:37:54 -0700 | [diff] [blame] | 681 | const char* str = GetStringData(str_id); |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 682 | int compare = CompareModifiedUtf8ToModifiedUtf8AsUtf16CodePointValues(string, str); |
| 683 | if (compare > 0) { |
| 684 | lo = mid + 1; |
| 685 | } else if (compare < 0) { |
| 686 | hi = mid - 1; |
| 687 | } else { |
| 688 | return &str_id; |
| 689 | } |
| 690 | } |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 691 | return nullptr; |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 692 | } |
| 693 | |
Artem Udovichenko | d9786b0 | 2015-10-14 16:36:55 +0300 | [diff] [blame] | 694 | const DexFile::TypeId* DexFile::FindTypeId(const char* string) const { |
| 695 | int32_t lo = 0; |
| 696 | int32_t hi = NumTypeIds() - 1; |
| 697 | while (hi >= lo) { |
| 698 | int32_t mid = (hi + lo) / 2; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 699 | const TypeId& type_id = GetTypeId(dex::TypeIndex(mid)); |
Artem Udovichenko | d9786b0 | 2015-10-14 16:36:55 +0300 | [diff] [blame] | 700 | const DexFile::StringId& str_id = GetStringId(type_id.descriptor_idx_); |
| 701 | const char* str = GetStringData(str_id); |
| 702 | int compare = CompareModifiedUtf8ToModifiedUtf8AsUtf16CodePointValues(string, str); |
| 703 | if (compare > 0) { |
| 704 | lo = mid + 1; |
| 705 | } else if (compare < 0) { |
| 706 | hi = mid - 1; |
| 707 | } else { |
| 708 | return &type_id; |
| 709 | } |
| 710 | } |
| 711 | return nullptr; |
| 712 | } |
| 713 | |
Vladimir Marko | a48aef4 | 2014-12-03 17:53:53 +0000 | [diff] [blame] | 714 | const DexFile::StringId* DexFile::FindStringId(const uint16_t* string, size_t length) const { |
Ian Rogers | 637c65b | 2013-05-31 11:46:00 -0700 | [diff] [blame] | 715 | int32_t lo = 0; |
| 716 | int32_t hi = NumStringIds() - 1; |
| 717 | while (hi >= lo) { |
| 718 | int32_t mid = (hi + lo) / 2; |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 719 | const DexFile::StringId& str_id = GetStringId(dex::StringIndex(mid)); |
Ian Rogers | cf5077a | 2013-10-31 12:37:54 -0700 | [diff] [blame] | 720 | const char* str = GetStringData(str_id); |
Vladimir Marko | a48aef4 | 2014-12-03 17:53:53 +0000 | [diff] [blame] | 721 | int compare = CompareModifiedUtf8ToUtf16AsCodePointValues(str, string, length); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 722 | if (compare > 0) { |
| 723 | lo = mid + 1; |
| 724 | } else if (compare < 0) { |
| 725 | hi = mid - 1; |
| 726 | } else { |
| 727 | return &str_id; |
| 728 | } |
| 729 | } |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 730 | return nullptr; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 731 | } |
| 732 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 733 | const DexFile::TypeId* DexFile::FindTypeId(dex::StringIndex string_idx) const { |
Ian Rogers | f8582c3 | 2013-05-29 16:33:03 -0700 | [diff] [blame] | 734 | int32_t lo = 0; |
| 735 | int32_t hi = NumTypeIds() - 1; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 736 | while (hi >= lo) { |
Ian Rogers | f8582c3 | 2013-05-29 16:33:03 -0700 | [diff] [blame] | 737 | int32_t mid = (hi + lo) / 2; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 738 | const TypeId& type_id = GetTypeId(dex::TypeIndex(mid)); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 739 | if (string_idx > type_id.descriptor_idx_) { |
| 740 | lo = mid + 1; |
| 741 | } else if (string_idx < type_id.descriptor_idx_) { |
| 742 | hi = mid - 1; |
| 743 | } else { |
| 744 | return &type_id; |
| 745 | } |
| 746 | } |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 747 | return nullptr; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 748 | } |
| 749 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 750 | const DexFile::ProtoId* DexFile::FindProtoId(dex::TypeIndex return_type_idx, |
| 751 | const dex::TypeIndex* signature_type_idxs, |
Vladimir Marko | 5c96e6b | 2013-11-14 15:34:17 +0000 | [diff] [blame] | 752 | uint32_t signature_length) const { |
Ian Rogers | f8582c3 | 2013-05-29 16:33:03 -0700 | [diff] [blame] | 753 | int32_t lo = 0; |
| 754 | int32_t hi = NumProtoIds() - 1; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 755 | while (hi >= lo) { |
Ian Rogers | f8582c3 | 2013-05-29 16:33:03 -0700 | [diff] [blame] | 756 | int32_t mid = (hi + lo) / 2; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 757 | const DexFile::ProtoId& proto = GetProtoId(mid); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 758 | int compare = return_type_idx.index_ - proto.return_type_idx_.index_; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 759 | if (compare == 0) { |
| 760 | DexFileParameterIterator it(*this, proto); |
| 761 | size_t i = 0; |
Vladimir Marko | 5c96e6b | 2013-11-14 15:34:17 +0000 | [diff] [blame] | 762 | while (it.HasNext() && i < signature_length && compare == 0) { |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 763 | compare = signature_type_idxs[i].index_ - it.GetTypeIdx().index_; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 764 | it.Next(); |
| 765 | i++; |
| 766 | } |
| 767 | if (compare == 0) { |
| 768 | if (it.HasNext()) { |
| 769 | compare = -1; |
Vladimir Marko | 5c96e6b | 2013-11-14 15:34:17 +0000 | [diff] [blame] | 770 | } else if (i < signature_length) { |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 771 | compare = 1; |
| 772 | } |
| 773 | } |
| 774 | } |
| 775 | if (compare > 0) { |
| 776 | lo = mid + 1; |
| 777 | } else if (compare < 0) { |
| 778 | hi = mid - 1; |
| 779 | } else { |
| 780 | return &proto; |
| 781 | } |
| 782 | } |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 783 | return nullptr; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | // Given a signature place the type ids into the given vector |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 787 | bool DexFile::CreateTypeList(const StringPiece& signature, |
| 788 | dex::TypeIndex* return_type_idx, |
| 789 | std::vector<dex::TypeIndex>* param_type_idxs) const { |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 790 | if (signature[0] != '(') { |
| 791 | return false; |
| 792 | } |
| 793 | size_t offset = 1; |
| 794 | size_t end = signature.size(); |
| 795 | bool process_return = false; |
| 796 | while (offset < end) { |
Vladimir Marko | e9c36b3 | 2013-11-21 15:49:16 +0000 | [diff] [blame] | 797 | size_t start_offset = offset; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 798 | char c = signature[offset]; |
| 799 | offset++; |
| 800 | if (c == ')') { |
| 801 | process_return = true; |
| 802 | continue; |
| 803 | } |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 804 | while (c == '[') { // process array prefix |
| 805 | if (offset >= end) { // expect some descriptor following [ |
| 806 | return false; |
| 807 | } |
| 808 | c = signature[offset]; |
| 809 | offset++; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 810 | } |
| 811 | if (c == 'L') { // process type descriptors |
| 812 | do { |
| 813 | if (offset >= end) { // unexpected early termination of descriptor |
| 814 | return false; |
| 815 | } |
| 816 | c = signature[offset]; |
| 817 | offset++; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 818 | } while (c != ';'); |
| 819 | } |
Vladimir Marko | e9c36b3 | 2013-11-21 15:49:16 +0000 | [diff] [blame] | 820 | // TODO: avoid creating a std::string just to get a 0-terminated char array |
| 821 | std::string descriptor(signature.data() + start_offset, offset - start_offset); |
Mathieu Chartier | 9507fa2 | 2015-10-29 15:08:57 -0700 | [diff] [blame] | 822 | const DexFile::TypeId* type_id = FindTypeId(descriptor.c_str()); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 823 | if (type_id == nullptr) { |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 824 | return false; |
| 825 | } |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 826 | dex::TypeIndex type_idx = GetIndexForTypeId(*type_id); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 827 | if (!process_return) { |
| 828 | param_type_idxs->push_back(type_idx); |
| 829 | } else { |
| 830 | *return_type_idx = type_idx; |
| 831 | return offset == end; // return true if the signature had reached a sensible end |
| 832 | } |
| 833 | } |
| 834 | return false; // failed to correctly parse return type |
| 835 | } |
| 836 | |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 837 | const Signature DexFile::CreateSignature(const StringPiece& signature) const { |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 838 | dex::TypeIndex return_type_idx; |
| 839 | std::vector<dex::TypeIndex> param_type_indices; |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 840 | bool success = CreateTypeList(signature, &return_type_idx, ¶m_type_indices); |
| 841 | if (!success) { |
| 842 | return Signature::NoSignature(); |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 843 | } |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 844 | const ProtoId* proto_id = FindProtoId(return_type_idx, param_type_indices); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 845 | if (proto_id == nullptr) { |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 846 | return Signature::NoSignature(); |
Brian Carlstrom | 20cfffa | 2011-08-26 02:31:27 -0700 | [diff] [blame] | 847 | } |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 848 | return Signature(this, *proto_id); |
Carl Shapiro | 419ec7b | 2011-08-03 14:48:33 -0700 | [diff] [blame] | 849 | } |
| 850 | |
Ian Rogers | dbbc99d | 2013-04-18 16:51:54 -0700 | [diff] [blame] | 851 | int32_t DexFile::FindTryItem(const CodeItem &code_item, uint32_t address) { |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 852 | // Note: Signed type is important for max and min. |
| 853 | int32_t min = 0; |
Ian Rogers | dbbc99d | 2013-04-18 16:51:54 -0700 | [diff] [blame] | 854 | int32_t max = code_item.tries_size_ - 1; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 855 | |
Ian Rogers | dbbc99d | 2013-04-18 16:51:54 -0700 | [diff] [blame] | 856 | while (min <= max) { |
| 857 | int32_t mid = min + ((max - min) / 2); |
| 858 | |
| 859 | const art::DexFile::TryItem* ti = GetTryItems(code_item, mid); |
| 860 | uint32_t start = ti->start_addr_; |
| 861 | uint32_t end = start + ti->insn_count_; |
| 862 | |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 863 | if (address < start) { |
| 864 | max = mid - 1; |
Ian Rogers | dbbc99d | 2013-04-18 16:51:54 -0700 | [diff] [blame] | 865 | } else if (address >= end) { |
| 866 | min = mid + 1; |
| 867 | } else { // We have a winner! |
| 868 | return mid; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 869 | } |
| 870 | } |
| 871 | // No match. |
| 872 | return -1; |
| 873 | } |
| 874 | |
Ian Rogers | dbbc99d | 2013-04-18 16:51:54 -0700 | [diff] [blame] | 875 | int32_t DexFile::FindCatchHandlerOffset(const CodeItem &code_item, uint32_t address) { |
| 876 | int32_t try_item = FindTryItem(code_item, address); |
| 877 | if (try_item == -1) { |
| 878 | return -1; |
| 879 | } else { |
| 880 | return DexFile::GetTryItems(code_item, try_item)->handler_off_; |
| 881 | } |
| 882 | } |
| 883 | |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 884 | bool DexFile::DecodeDebugLocalInfo(const CodeItem* code_item, bool is_static, uint32_t method_idx, |
| 885 | DexDebugNewLocalCb local_cb, void* context) const { |
| 886 | DCHECK(local_cb != nullptr); |
| 887 | if (code_item == nullptr) { |
| 888 | return false; |
| 889 | } |
| 890 | const uint8_t* stream = GetDebugInfoStream(code_item); |
| 891 | if (stream == nullptr) { |
| 892 | return false; |
| 893 | } |
| 894 | std::vector<LocalInfo> local_in_reg(code_item->registers_size_); |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 895 | |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 896 | uint16_t arg_reg = code_item->registers_size_ - code_item->ins_size_; |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 897 | if (!is_static) { |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 898 | const char* descriptor = GetMethodDeclaringClassDescriptor(GetMethodId(method_idx)); |
| 899 | local_in_reg[arg_reg].name_ = "this"; |
| 900 | local_in_reg[arg_reg].descriptor_ = descriptor; |
| 901 | local_in_reg[arg_reg].signature_ = nullptr; |
| 902 | local_in_reg[arg_reg].start_address_ = 0; |
| 903 | local_in_reg[arg_reg].reg_ = arg_reg; |
| 904 | local_in_reg[arg_reg].is_live_ = true; |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 905 | arg_reg++; |
| 906 | } |
| 907 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 908 | DexFileParameterIterator it(*this, GetMethodPrototype(GetMethodId(method_idx))); |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 909 | DecodeUnsignedLeb128(&stream); // Line. |
| 910 | uint32_t parameters_size = DecodeUnsignedLeb128(&stream); |
| 911 | uint32_t i; |
| 912 | for (i = 0; i < parameters_size && it.HasNext(); ++i, it.Next()) { |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 913 | if (arg_reg >= code_item->registers_size_) { |
jeffhao | f872887 | 2011-10-28 19:11:13 -0700 | [diff] [blame] | 914 | LOG(ERROR) << "invalid stream - arg reg >= reg size (" << arg_reg |
Brian Carlstrom | 2aab947 | 2011-12-12 15:21:43 -0800 | [diff] [blame] | 915 | << " >= " << code_item->registers_size_ << ") in " << GetLocation(); |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 916 | return false; |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 917 | } |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 918 | uint32_t name_idx = DecodeUnsignedLeb128P1(&stream); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 919 | const char* descriptor = it.GetDescriptor(); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 920 | local_in_reg[arg_reg].name_ = StringDataByIdx(dex::StringIndex(name_idx)); |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 921 | local_in_reg[arg_reg].descriptor_ = descriptor; |
| 922 | local_in_reg[arg_reg].signature_ = nullptr; |
| 923 | local_in_reg[arg_reg].start_address_ = 0; |
| 924 | local_in_reg[arg_reg].reg_ = arg_reg; |
| 925 | local_in_reg[arg_reg].is_live_ = true; |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 926 | switch (*descriptor) { |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 927 | case 'D': |
| 928 | case 'J': |
| 929 | arg_reg += 2; |
| 930 | break; |
| 931 | default: |
| 932 | arg_reg += 1; |
| 933 | break; |
| 934 | } |
| 935 | } |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 936 | if (i != parameters_size || it.HasNext()) { |
Brian Carlstrom | f79fccb | 2014-02-20 08:55:10 -0800 | [diff] [blame] | 937 | LOG(ERROR) << "invalid stream - problem with parameter iterator in " << GetLocation() |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 938 | << " for method " << this->PrettyMethod(method_idx); |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 939 | return false; |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 940 | } |
| 941 | |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 942 | uint32_t address = 0; |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 943 | for (;;) { |
| 944 | uint8_t opcode = *stream++; |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 945 | switch (opcode) { |
| 946 | case DBG_END_SEQUENCE: |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 947 | // Emit all variables which are still alive at the end of the method. |
| 948 | for (uint16_t reg = 0; reg < code_item->registers_size_; reg++) { |
| 949 | if (local_in_reg[reg].is_live_) { |
| 950 | local_in_reg[reg].end_address_ = code_item->insns_size_in_code_units_; |
| 951 | local_cb(context, local_in_reg[reg]); |
| 952 | } |
| 953 | } |
| 954 | return true; |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 955 | case DBG_ADVANCE_PC: |
| 956 | address += DecodeUnsignedLeb128(&stream); |
| 957 | break; |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 958 | case DBG_ADVANCE_LINE: |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 959 | DecodeSignedLeb128(&stream); // Line. |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 960 | break; |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 961 | case DBG_START_LOCAL: |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 962 | case DBG_START_LOCAL_EXTENDED: { |
| 963 | uint16_t reg = DecodeUnsignedLeb128(&stream); |
| 964 | if (reg >= code_item->registers_size_) { |
| 965 | LOG(ERROR) << "invalid stream - reg >= reg size (" << reg << " >= " |
Brian Carlstrom | 2aab947 | 2011-12-12 15:21:43 -0800 | [diff] [blame] | 966 | << code_item->registers_size_ << ") in " << GetLocation(); |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 967 | return false; |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 968 | } |
| 969 | |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 970 | uint32_t name_idx = DecodeUnsignedLeb128P1(&stream); |
| 971 | uint32_t descriptor_idx = DecodeUnsignedLeb128P1(&stream); |
| 972 | uint32_t signature_idx = kDexNoIndex; |
jeffhao | f872887 | 2011-10-28 19:11:13 -0700 | [diff] [blame] | 973 | if (opcode == DBG_START_LOCAL_EXTENDED) { |
| 974 | signature_idx = DecodeUnsignedLeb128P1(&stream); |
| 975 | } |
| 976 | |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 977 | // Emit what was previously there, if anything |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 978 | if (local_in_reg[reg].is_live_) { |
| 979 | local_in_reg[reg].end_address_ = address; |
| 980 | local_cb(context, local_in_reg[reg]); |
| 981 | } |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 982 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 983 | local_in_reg[reg].name_ = StringDataByIdx(dex::StringIndex(name_idx)); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 984 | local_in_reg[reg].descriptor_ = |
| 985 | StringByTypeIdx(dex::TypeIndex(dchecked_integral_cast<uint16_t>(descriptor_idx)));; |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 986 | local_in_reg[reg].signature_ = StringDataByIdx(dex::StringIndex(signature_idx)); |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 987 | local_in_reg[reg].start_address_ = address; |
| 988 | local_in_reg[reg].reg_ = reg; |
| 989 | local_in_reg[reg].is_live_ = true; |
| 990 | break; |
| 991 | } |
| 992 | case DBG_END_LOCAL: { |
| 993 | uint16_t reg = DecodeUnsignedLeb128(&stream); |
| 994 | if (reg >= code_item->registers_size_) { |
| 995 | LOG(ERROR) << "invalid stream - reg >= reg size (" << reg << " >= " |
| 996 | << code_item->registers_size_ << ") in " << GetLocation(); |
| 997 | return false; |
| 998 | } |
| 999 | if (!local_in_reg[reg].is_live_) { |
| 1000 | LOG(ERROR) << "invalid stream - end without start in " << GetLocation(); |
| 1001 | return false; |
| 1002 | } |
| 1003 | local_in_reg[reg].end_address_ = address; |
| 1004 | local_cb(context, local_in_reg[reg]); |
| 1005 | local_in_reg[reg].is_live_ = false; |
| 1006 | break; |
| 1007 | } |
| 1008 | case DBG_RESTART_LOCAL: { |
| 1009 | uint16_t reg = DecodeUnsignedLeb128(&stream); |
| 1010 | if (reg >= code_item->registers_size_) { |
| 1011 | LOG(ERROR) << "invalid stream - reg >= reg size (" << reg << " >= " |
| 1012 | << code_item->registers_size_ << ") in " << GetLocation(); |
| 1013 | return false; |
| 1014 | } |
| 1015 | // If the register is live, the "restart" is superfluous, |
| 1016 | // and we don't want to mess with the existing start address. |
| 1017 | if (!local_in_reg[reg].is_live_) { |
Elliott Hughes | 3064683 | 2011-10-13 16:59:46 -0700 | [diff] [blame] | 1018 | local_in_reg[reg].start_address_ = address; |
| 1019 | local_in_reg[reg].is_live_ = true; |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 1020 | } |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 1021 | break; |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 1022 | } |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 1023 | case DBG_SET_PROLOGUE_END: |
| 1024 | case DBG_SET_EPILOGUE_BEGIN: |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 1025 | break; |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 1026 | case DBG_SET_FILE: |
| 1027 | DecodeUnsignedLeb128P1(&stream); // name. |
| 1028 | break; |
| 1029 | default: |
| 1030 | address += (opcode - DBG_FIRST_SPECIAL) / DBG_LINE_RANGE; |
| 1031 | break; |
| 1032 | } |
| 1033 | } |
| 1034 | } |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 1035 | |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 1036 | bool DexFile::DecodeDebugPositionInfo(const CodeItem* code_item, DexDebugNewPositionCb position_cb, |
| 1037 | void* context) const { |
| 1038 | DCHECK(position_cb != nullptr); |
| 1039 | if (code_item == nullptr) { |
| 1040 | return false; |
| 1041 | } |
| 1042 | const uint8_t* stream = GetDebugInfoStream(code_item); |
| 1043 | if (stream == nullptr) { |
| 1044 | return false; |
| 1045 | } |
| 1046 | |
| 1047 | PositionInfo entry = PositionInfo(); |
| 1048 | entry.line_ = DecodeUnsignedLeb128(&stream); |
| 1049 | uint32_t parameters_size = DecodeUnsignedLeb128(&stream); |
| 1050 | for (uint32_t i = 0; i < parameters_size; ++i) { |
| 1051 | DecodeUnsignedLeb128P1(&stream); // Parameter name. |
| 1052 | } |
| 1053 | |
| 1054 | for (;;) { |
| 1055 | uint8_t opcode = *stream++; |
| 1056 | switch (opcode) { |
| 1057 | case DBG_END_SEQUENCE: |
| 1058 | return true; // end of stream. |
| 1059 | case DBG_ADVANCE_PC: |
| 1060 | entry.address_ += DecodeUnsignedLeb128(&stream); |
| 1061 | break; |
| 1062 | case DBG_ADVANCE_LINE: |
| 1063 | entry.line_ += DecodeSignedLeb128(&stream); |
| 1064 | break; |
| 1065 | case DBG_START_LOCAL: |
| 1066 | DecodeUnsignedLeb128(&stream); // reg. |
| 1067 | DecodeUnsignedLeb128P1(&stream); // name. |
| 1068 | DecodeUnsignedLeb128P1(&stream); // descriptor. |
| 1069 | break; |
| 1070 | case DBG_START_LOCAL_EXTENDED: |
| 1071 | DecodeUnsignedLeb128(&stream); // reg. |
| 1072 | DecodeUnsignedLeb128P1(&stream); // name. |
| 1073 | DecodeUnsignedLeb128P1(&stream); // descriptor. |
| 1074 | DecodeUnsignedLeb128P1(&stream); // signature. |
| 1075 | break; |
| 1076 | case DBG_END_LOCAL: |
| 1077 | case DBG_RESTART_LOCAL: |
| 1078 | DecodeUnsignedLeb128(&stream); // reg. |
| 1079 | break; |
| 1080 | case DBG_SET_PROLOGUE_END: |
| 1081 | entry.prologue_end_ = true; |
| 1082 | break; |
| 1083 | case DBG_SET_EPILOGUE_BEGIN: |
| 1084 | entry.epilogue_begin_ = true; |
| 1085 | break; |
| 1086 | case DBG_SET_FILE: { |
| 1087 | uint32_t name_idx = DecodeUnsignedLeb128P1(&stream); |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 1088 | entry.source_file_ = StringDataByIdx(dex::StringIndex(name_idx)); |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 1089 | break; |
| 1090 | } |
Shih-wei Liao | 8e1b4ff | 2011-10-15 15:43:51 -0700 | [diff] [blame] | 1091 | default: { |
| 1092 | int adjopcode = opcode - DBG_FIRST_SPECIAL; |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 1093 | entry.address_ += adjopcode / DBG_LINE_RANGE; |
| 1094 | entry.line_ += DBG_LINE_BASE + (adjopcode % DBG_LINE_RANGE); |
| 1095 | if (position_cb(context, entry)) { |
| 1096 | return true; // early exit. |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 1097 | } |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 1098 | entry.prologue_end_ = false; |
| 1099 | entry.epilogue_begin_ = false; |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 1100 | break; |
Shih-wei Liao | 8e1b4ff | 2011-10-15 15:43:51 -0700 | [diff] [blame] | 1101 | } |
Shih-wei Liao | 195487c | 2011-08-20 13:29:04 -0700 | [diff] [blame] | 1102 | } |
| 1103 | } |
| 1104 | } |
| 1105 | |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 1106 | bool DexFile::LineNumForPcCb(void* raw_context, const PositionInfo& entry) { |
Elliott Hughes | 2435a57 | 2012-02-17 16:07:41 -0800 | [diff] [blame] | 1107 | LineNumFromPcContext* context = reinterpret_cast<LineNumFromPcContext*>(raw_context); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1108 | |
| 1109 | // We know that this callback will be called in |
| 1110 | // ascending address order, so keep going until we find |
| 1111 | // a match or we've just gone past it. |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 1112 | if (entry.address_ > context->address_) { |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1113 | // The line number from the previous positions callback |
| 1114 | // wil be the final result. |
| 1115 | return true; |
| 1116 | } else { |
David Srbecky | b06e28e | 2015-12-10 13:15:00 +0000 | [diff] [blame] | 1117 | context->line_num_ = entry.line_; |
| 1118 | return entry.address_ == context->address_; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1119 | } |
| 1120 | } |
| 1121 | |
Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 1122 | bool DexFile::IsMultiDexLocation(const char* location) { |
| 1123 | return strrchr(location, kMultiDexSeparator) != nullptr; |
| 1124 | } |
| 1125 | |
Andreas Gampe | 90e3404 | 2015-04-27 20:01:52 -0700 | [diff] [blame] | 1126 | std::string DexFile::GetMultiDexClassesDexName(size_t index) { |
| 1127 | if (index == 0) { |
| 1128 | return "classes.dex"; |
| 1129 | } else { |
| 1130 | return StringPrintf("classes%zu.dex", index + 1); |
| 1131 | } |
| 1132 | } |
| 1133 | |
| 1134 | std::string DexFile::GetMultiDexLocation(size_t index, const char* dex_location) { |
| 1135 | if (index == 0) { |
Calin Juravle | 4e1d579 | 2014-07-15 23:56:47 +0100 | [diff] [blame] | 1136 | return dex_location; |
| 1137 | } else { |
Andreas Gampe | 90e3404 | 2015-04-27 20:01:52 -0700 | [diff] [blame] | 1138 | return StringPrintf("%s" kMultiDexSeparatorString "classes%zu.dex", dex_location, index + 1); |
Calin Juravle | 4e1d579 | 2014-07-15 23:56:47 +0100 | [diff] [blame] | 1139 | } |
| 1140 | } |
| 1141 | |
| 1142 | std::string DexFile::GetDexCanonicalLocation(const char* dex_location) { |
| 1143 | CHECK_NE(dex_location, static_cast<const char*>(nullptr)); |
Vladimir Marko | aa4497d | 2014-09-05 14:01:17 +0100 | [diff] [blame] | 1144 | std::string base_location = GetBaseLocation(dex_location); |
| 1145 | const char* suffix = dex_location + base_location.size(); |
| 1146 | DCHECK(suffix[0] == 0 || suffix[0] == kMultiDexSeparator); |
| 1147 | UniqueCPtr<const char[]> path(realpath(base_location.c_str(), nullptr)); |
| 1148 | if (path != nullptr && path.get() != base_location) { |
| 1149 | return std::string(path.get()) + suffix; |
| 1150 | } else if (suffix[0] == 0) { |
| 1151 | return base_location; |
Calin Juravle | 4e1d579 | 2014-07-15 23:56:47 +0100 | [diff] [blame] | 1152 | } else { |
Vladimir Marko | aa4497d | 2014-09-05 14:01:17 +0100 | [diff] [blame] | 1153 | return dex_location; |
Calin Juravle | 4e1d579 | 2014-07-15 23:56:47 +0100 | [diff] [blame] | 1154 | } |
Calin Juravle | 4e1d579 | 2014-07-15 23:56:47 +0100 | [diff] [blame] | 1155 | } |
| 1156 | |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 1157 | // Read a signed integer. "zwidth" is the zero-based byte count. |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 1158 | int32_t DexFile::ReadSignedInt(const uint8_t* ptr, int zwidth) { |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 1159 | int32_t val = 0; |
| 1160 | for (int i = zwidth; i >= 0; --i) { |
| 1161 | val = ((uint32_t)val >> 8) | (((int32_t)*ptr++) << 24); |
| 1162 | } |
| 1163 | val >>= (3 - zwidth) * 8; |
| 1164 | return val; |
| 1165 | } |
| 1166 | |
| 1167 | // Read an unsigned integer. "zwidth" is the zero-based byte count, |
| 1168 | // "fill_on_right" indicates which side we want to zero-fill from. |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 1169 | uint32_t DexFile::ReadUnsignedInt(const uint8_t* ptr, int zwidth, bool fill_on_right) { |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 1170 | uint32_t val = 0; |
| 1171 | for (int i = zwidth; i >= 0; --i) { |
| 1172 | val = (val >> 8) | (((uint32_t)*ptr++) << 24); |
| 1173 | } |
| 1174 | if (!fill_on_right) { |
| 1175 | val >>= (3 - zwidth) * 8; |
| 1176 | } |
| 1177 | return val; |
| 1178 | } |
| 1179 | |
| 1180 | // Read a signed long. "zwidth" is the zero-based byte count. |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 1181 | int64_t DexFile::ReadSignedLong(const uint8_t* ptr, int zwidth) { |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 1182 | int64_t val = 0; |
| 1183 | for (int i = zwidth; i >= 0; --i) { |
| 1184 | val = ((uint64_t)val >> 8) | (((int64_t)*ptr++) << 56); |
| 1185 | } |
| 1186 | val >>= (7 - zwidth) * 8; |
| 1187 | return val; |
| 1188 | } |
| 1189 | |
| 1190 | // Read an unsigned long. "zwidth" is the zero-based byte count, |
| 1191 | // "fill_on_right" indicates which side we want to zero-fill from. |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 1192 | uint64_t DexFile::ReadUnsignedLong(const uint8_t* ptr, int zwidth, bool fill_on_right) { |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 1193 | uint64_t val = 0; |
| 1194 | for (int i = zwidth; i >= 0; --i) { |
| 1195 | val = (val >> 8) | (((uint64_t)*ptr++) << 56); |
| 1196 | } |
| 1197 | if (!fill_on_right) { |
| 1198 | val >>= (7 - zwidth) * 8; |
| 1199 | } |
| 1200 | return val; |
| 1201 | } |
| 1202 | |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 1203 | std::string DexFile::PrettyMethod(uint32_t method_idx, bool with_signature) const { |
| 1204 | if (method_idx >= NumMethodIds()) { |
| 1205 | return StringPrintf("<<invalid-method-idx-%d>>", method_idx); |
| 1206 | } |
| 1207 | const DexFile::MethodId& method_id = GetMethodId(method_idx); |
| 1208 | std::string result(PrettyDescriptor(GetMethodDeclaringClassDescriptor(method_id))); |
| 1209 | result += '.'; |
| 1210 | result += GetMethodName(method_id); |
| 1211 | if (with_signature) { |
| 1212 | const Signature signature = GetMethodSignature(method_id); |
| 1213 | std::string sig_as_string(signature.ToString()); |
| 1214 | if (signature == Signature::NoSignature()) { |
| 1215 | return result + sig_as_string; |
| 1216 | } |
| 1217 | result = PrettyReturnType(sig_as_string.c_str()) + " " + result + |
| 1218 | PrettyArguments(sig_as_string.c_str()); |
| 1219 | } |
| 1220 | return result; |
| 1221 | } |
| 1222 | |
| 1223 | std::string DexFile::PrettyField(uint32_t field_idx, bool with_type) const { |
| 1224 | if (field_idx >= NumFieldIds()) { |
| 1225 | return StringPrintf("<<invalid-field-idx-%d>>", field_idx); |
| 1226 | } |
| 1227 | const DexFile::FieldId& field_id = GetFieldId(field_idx); |
| 1228 | std::string result; |
| 1229 | if (with_type) { |
| 1230 | result += GetFieldTypeDescriptor(field_id); |
| 1231 | result += ' '; |
| 1232 | } |
| 1233 | result += PrettyDescriptor(GetFieldDeclaringClassDescriptor(field_id)); |
| 1234 | result += '.'; |
| 1235 | result += GetFieldName(field_id); |
| 1236 | return result; |
| 1237 | } |
| 1238 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 1239 | std::string DexFile::PrettyType(dex::TypeIndex type_idx) const { |
| 1240 | if (type_idx.index_ >= NumTypeIds()) { |
| 1241 | return StringPrintf("<<invalid-type-idx-%d>>", type_idx.index_); |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 1242 | } |
| 1243 | const DexFile::TypeId& type_id = GetTypeId(type_idx); |
| 1244 | return PrettyDescriptor(GetTypeDescriptor(type_id)); |
| 1245 | } |
| 1246 | |
Jeff Hao | 3d08086 | 2016-05-26 18:39:17 -0700 | [diff] [blame] | 1247 | // Checks that visibility is as expected. Includes special behavior for M and |
| 1248 | // before to allow runtime and build visibility when expecting runtime. |
Brian Carlstrom | 0d6adac | 2014-02-05 17:39:16 -0800 | [diff] [blame] | 1249 | std::ostream& operator<<(std::ostream& os, const DexFile& dex_file) { |
| 1250 | os << StringPrintf("[DexFile: %s dex-checksum=%08x location-checksum=%08x %p-%p]", |
| 1251 | dex_file.GetLocation().c_str(), |
| 1252 | dex_file.GetHeader().checksum_, dex_file.GetLocationChecksum(), |
| 1253 | dex_file.Begin(), dex_file.Begin() + dex_file.Size()); |
| 1254 | return os; |
| 1255 | } |
Calin Juravle | 4e1d579 | 2014-07-15 23:56:47 +0100 | [diff] [blame] | 1256 | |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 1257 | std::string Signature::ToString() const { |
| 1258 | if (dex_file_ == nullptr) { |
| 1259 | CHECK(proto_id_ == nullptr); |
| 1260 | return "<no signature>"; |
| 1261 | } |
| 1262 | const DexFile::TypeList* params = dex_file_->GetProtoParameters(*proto_id_); |
| 1263 | std::string result; |
| 1264 | if (params == nullptr) { |
| 1265 | result += "()"; |
| 1266 | } else { |
| 1267 | result += "("; |
| 1268 | for (uint32_t i = 0; i < params->Size(); ++i) { |
| 1269 | result += dex_file_->StringByTypeIdx(params->GetTypeItem(i).type_idx_); |
| 1270 | } |
| 1271 | result += ")"; |
| 1272 | } |
| 1273 | result += dex_file_->StringByTypeIdx(proto_id_->return_type_idx_); |
| 1274 | return result; |
| 1275 | } |
| 1276 | |
Orion Hodson | 6c4921b | 2016-09-21 15:41:06 +0100 | [diff] [blame] | 1277 | uint32_t Signature::GetNumberOfParameters() const { |
| 1278 | const DexFile::TypeList* params = dex_file_->GetProtoParameters(*proto_id_); |
| 1279 | return (params != nullptr) ? params->Size() : 0; |
| 1280 | } |
| 1281 | |
| 1282 | bool Signature::IsVoid() const { |
| 1283 | const char* return_type = dex_file_->GetReturnTypeDescriptor(*proto_id_); |
| 1284 | return strcmp(return_type, "V") == 0; |
| 1285 | } |
| 1286 | |
Vladimir Marko | d9cffea | 2013-11-25 15:08:02 +0000 | [diff] [blame] | 1287 | bool Signature::operator==(const StringPiece& rhs) const { |
| 1288 | if (dex_file_ == nullptr) { |
| 1289 | return false; |
| 1290 | } |
| 1291 | StringPiece tail(rhs); |
| 1292 | if (!tail.starts_with("(")) { |
| 1293 | return false; // Invalid signature |
| 1294 | } |
| 1295 | tail.remove_prefix(1); // "("; |
| 1296 | const DexFile::TypeList* params = dex_file_->GetProtoParameters(*proto_id_); |
| 1297 | if (params != nullptr) { |
| 1298 | for (uint32_t i = 0; i < params->Size(); ++i) { |
| 1299 | StringPiece param(dex_file_->StringByTypeIdx(params->GetTypeItem(i).type_idx_)); |
| 1300 | if (!tail.starts_with(param)) { |
| 1301 | return false; |
| 1302 | } |
| 1303 | tail.remove_prefix(param.length()); |
| 1304 | } |
| 1305 | } |
| 1306 | if (!tail.starts_with(")")) { |
| 1307 | return false; |
| 1308 | } |
| 1309 | tail.remove_prefix(1); // ")"; |
| 1310 | return tail == dex_file_->StringByTypeIdx(proto_id_->return_type_idx_); |
| 1311 | } |
| 1312 | |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 1313 | std::ostream& operator<<(std::ostream& os, const Signature& sig) { |
| 1314 | return os << sig.ToString(); |
| 1315 | } |
| 1316 | |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1317 | // Decodes the header section from the class data bytes. |
| 1318 | void ClassDataItemIterator::ReadClassDataHeader() { |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 1319 | CHECK(ptr_pos_ != nullptr); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1320 | header_.static_fields_size_ = DecodeUnsignedLeb128(&ptr_pos_); |
| 1321 | header_.instance_fields_size_ = DecodeUnsignedLeb128(&ptr_pos_); |
| 1322 | header_.direct_methods_size_ = DecodeUnsignedLeb128(&ptr_pos_); |
| 1323 | header_.virtual_methods_size_ = DecodeUnsignedLeb128(&ptr_pos_); |
| 1324 | } |
| 1325 | |
| 1326 | void ClassDataItemIterator::ReadClassDataField() { |
| 1327 | field_.field_idx_delta_ = DecodeUnsignedLeb128(&ptr_pos_); |
| 1328 | field_.access_flags_ = DecodeUnsignedLeb128(&ptr_pos_); |
Vladimir Marko | 23682bf | 2015-06-24 14:28:03 +0100 | [diff] [blame] | 1329 | // The user of the iterator is responsible for checking if there |
| 1330 | // are unordered or duplicate indexes. |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1331 | } |
| 1332 | |
| 1333 | void ClassDataItemIterator::ReadClassDataMethod() { |
| 1334 | method_.method_idx_delta_ = DecodeUnsignedLeb128(&ptr_pos_); |
| 1335 | method_.access_flags_ = DecodeUnsignedLeb128(&ptr_pos_); |
| 1336 | method_.code_off_ = DecodeUnsignedLeb128(&ptr_pos_); |
Brian Carlstrom | 68adbe4 | 2012-05-11 17:18:08 -0700 | [diff] [blame] | 1337 | if (last_idx_ != 0 && method_.method_idx_delta_ == 0) { |
Andreas Gampe | 4fdbba0 | 2014-06-19 20:24:22 -0700 | [diff] [blame] | 1338 | LOG(WARNING) << "Duplicate method in " << dex_file_.GetLocation(); |
Brian Carlstrom | 6f29d0e | 2012-05-11 15:50:29 -0700 | [diff] [blame] | 1339 | } |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1340 | } |
| 1341 | |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 1342 | EncodedStaticFieldValueIterator::EncodedStaticFieldValueIterator(const DexFile& dex_file, |
| 1343 | const DexFile::ClassDef& class_def) |
Shinichiro Hamaji | 82863f0 | 2015-11-05 16:51:33 +0900 | [diff] [blame] | 1344 | : dex_file_(dex_file), |
Shinichiro Hamaji | 82863f0 | 2015-11-05 16:51:33 +0900 | [diff] [blame] | 1345 | array_size_(), |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 1346 | pos_(-1), |
| 1347 | type_(kByte) { |
| 1348 | ptr_ = dex_file_.GetEncodedStaticFieldValuesArray(class_def); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 1349 | if (ptr_ == nullptr) { |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1350 | array_size_ = 0; |
| 1351 | } else { |
| 1352 | array_size_ = DecodeUnsignedLeb128(&ptr_); |
| 1353 | } |
| 1354 | if (array_size_ > 0) { |
| 1355 | Next(); |
| 1356 | } |
| 1357 | } |
| 1358 | |
| 1359 | void EncodedStaticFieldValueIterator::Next() { |
| 1360 | pos_++; |
| 1361 | if (pos_ >= array_size_) { |
| 1362 | return; |
| 1363 | } |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 1364 | uint8_t value_type = *ptr_++; |
| 1365 | uint8_t value_arg = value_type >> kEncodedValueArgShift; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1366 | size_t width = value_arg + 1; // assume and correct later |
Brian Carlstrom | 88f3654 | 2012-10-16 23:24:21 -0700 | [diff] [blame] | 1367 | type_ = static_cast<ValueType>(value_type & kEncodedValueTypeMask); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1368 | switch (type_) { |
| 1369 | case kBoolean: |
| 1370 | jval_.i = (value_arg != 0) ? 1 : 0; |
| 1371 | width = 0; |
| 1372 | break; |
| 1373 | case kByte: |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 1374 | jval_.i = DexFile::ReadSignedInt(ptr_, value_arg); |
Andreas Gampe | ab1eb0d | 2015-02-13 19:23:55 -0800 | [diff] [blame] | 1375 | CHECK(IsInt<8>(jval_.i)); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1376 | break; |
| 1377 | case kShort: |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 1378 | jval_.i = DexFile::ReadSignedInt(ptr_, value_arg); |
Andreas Gampe | ab1eb0d | 2015-02-13 19:23:55 -0800 | [diff] [blame] | 1379 | CHECK(IsInt<16>(jval_.i)); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1380 | break; |
| 1381 | case kChar: |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 1382 | jval_.i = DexFile::ReadUnsignedInt(ptr_, value_arg, false); |
Andreas Gampe | ab1eb0d | 2015-02-13 19:23:55 -0800 | [diff] [blame] | 1383 | CHECK(IsUint<16>(jval_.i)); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1384 | break; |
| 1385 | case kInt: |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 1386 | jval_.i = DexFile::ReadSignedInt(ptr_, value_arg); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1387 | break; |
| 1388 | case kLong: |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 1389 | jval_.j = DexFile::ReadSignedLong(ptr_, value_arg); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1390 | break; |
| 1391 | case kFloat: |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 1392 | jval_.i = DexFile::ReadUnsignedInt(ptr_, value_arg, true); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1393 | break; |
| 1394 | case kDouble: |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 1395 | jval_.j = DexFile::ReadUnsignedLong(ptr_, value_arg, true); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1396 | break; |
| 1397 | case kString: |
| 1398 | case kType: |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 1399 | jval_.i = DexFile::ReadUnsignedInt(ptr_, value_arg, false); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1400 | break; |
| 1401 | case kField: |
Brian Carlstrom | 88f3654 | 2012-10-16 23:24:21 -0700 | [diff] [blame] | 1402 | case kMethod: |
| 1403 | case kEnum: |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1404 | case kArray: |
| 1405 | case kAnnotation: |
| 1406 | UNIMPLEMENTED(FATAL) << ": type " << type_; |
Ian Rogers | 2c4257b | 2014-10-24 14:20:06 -0700 | [diff] [blame] | 1407 | UNREACHABLE(); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1408 | case kNull: |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 1409 | jval_.l = nullptr; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1410 | width = 0; |
| 1411 | break; |
| 1412 | default: |
| 1413 | LOG(FATAL) << "Unreached"; |
Ian Rogers | 2c4257b | 2014-10-24 14:20:06 -0700 | [diff] [blame] | 1414 | UNREACHABLE(); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1415 | } |
| 1416 | ptr_ += width; |
| 1417 | } |
| 1418 | |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1419 | CatchHandlerIterator::CatchHandlerIterator(const DexFile::CodeItem& code_item, uint32_t address) { |
| 1420 | handler_.address_ = -1; |
| 1421 | int32_t offset = -1; |
| 1422 | |
| 1423 | // Short-circuit the overwhelmingly common cases. |
| 1424 | switch (code_item.tries_size_) { |
| 1425 | case 0: |
| 1426 | break; |
| 1427 | case 1: { |
| 1428 | const DexFile::TryItem* tries = DexFile::GetTryItems(code_item, 0); |
| 1429 | uint32_t start = tries->start_addr_; |
| 1430 | if (address >= start) { |
| 1431 | uint32_t end = start + tries->insn_count_; |
| 1432 | if (address < end) { |
| 1433 | offset = tries->handler_off_; |
| 1434 | } |
| 1435 | } |
| 1436 | break; |
| 1437 | } |
| 1438 | default: |
Ian Rogers | dbbc99d | 2013-04-18 16:51:54 -0700 | [diff] [blame] | 1439 | offset = DexFile::FindCatchHandlerOffset(code_item, address); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1440 | } |
Logan Chien | 736df02 | 2012-04-27 16:25:57 +0800 | [diff] [blame] | 1441 | Init(code_item, offset); |
| 1442 | } |
| 1443 | |
| 1444 | CatchHandlerIterator::CatchHandlerIterator(const DexFile::CodeItem& code_item, |
| 1445 | const DexFile::TryItem& try_item) { |
| 1446 | handler_.address_ = -1; |
| 1447 | Init(code_item, try_item.handler_off_); |
| 1448 | } |
| 1449 | |
| 1450 | void CatchHandlerIterator::Init(const DexFile::CodeItem& code_item, |
| 1451 | int32_t offset) { |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1452 | if (offset >= 0) { |
Logan Chien | 736df02 | 2012-04-27 16:25:57 +0800 | [diff] [blame] | 1453 | Init(DexFile::GetCatchHandlerData(code_item, offset)); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1454 | } else { |
| 1455 | // Not found, initialize as empty |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 1456 | current_data_ = nullptr; |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1457 | remaining_count_ = -1; |
| 1458 | catch_all_ = false; |
| 1459 | DCHECK(!HasNext()); |
| 1460 | } |
| 1461 | } |
| 1462 | |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 1463 | void CatchHandlerIterator::Init(const uint8_t* handler_data) { |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1464 | current_data_ = handler_data; |
| 1465 | remaining_count_ = DecodeSignedLeb128(¤t_data_); |
| 1466 | |
| 1467 | // If remaining_count_ is non-positive, then it is the negative of |
| 1468 | // the number of catch types, and the catches are followed by a |
| 1469 | // catch-all handler. |
| 1470 | if (remaining_count_ <= 0) { |
| 1471 | catch_all_ = true; |
| 1472 | remaining_count_ = -remaining_count_; |
| 1473 | } else { |
| 1474 | catch_all_ = false; |
| 1475 | } |
| 1476 | Next(); |
| 1477 | } |
| 1478 | |
| 1479 | void CatchHandlerIterator::Next() { |
| 1480 | if (remaining_count_ > 0) { |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 1481 | handler_.type_idx_ = dex::TypeIndex(DecodeUnsignedLeb128(¤t_data_)); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1482 | handler_.address_ = DecodeUnsignedLeb128(¤t_data_); |
| 1483 | remaining_count_--; |
| 1484 | return; |
| 1485 | } |
| 1486 | |
| 1487 | if (catch_all_) { |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 1488 | handler_.type_idx_ = dex::TypeIndex(DexFile::kDexNoIndex16); |
Ian Rogers | 0571d35 | 2011-11-03 19:51:38 -0700 | [diff] [blame] | 1489 | handler_.address_ = DecodeUnsignedLeb128(¤t_data_); |
| 1490 | catch_all_ = false; |
| 1491 | return; |
| 1492 | } |
| 1493 | |
| 1494 | // no more handler |
| 1495 | remaining_count_ = -1; |
| 1496 | } |
| 1497 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 1498 | namespace dex { |
| 1499 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 1500 | std::ostream& operator<<(std::ostream& os, const StringIndex& index) { |
| 1501 | os << "StringIndex[" << index.index_ << "]"; |
| 1502 | return os; |
| 1503 | } |
| 1504 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 1505 | std::ostream& operator<<(std::ostream& os, const TypeIndex& index) { |
| 1506 | os << "TypeIndex[" << index.index_ << "]"; |
| 1507 | return os; |
| 1508 | } |
| 1509 | |
| 1510 | } // namespace dex |
| 1511 | |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1512 | } // namespace art |