Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define ATRACE_TAG ATRACE_TAG_RESOURCES |
| 18 | |
| 19 | #include "androidfw/Idmap.h" |
| 20 | |
| 21 | #include "android-base/logging.h" |
| 22 | #include "android-base/stringprintf.h" |
Ryan Mitchell | a909305 | 2020-03-26 17:15:01 -0700 | [diff] [blame] | 23 | #include "androidfw/misc.h" |
Ryan Mitchell | 8a891d8 | 2019-07-01 09:48:23 -0700 | [diff] [blame] | 24 | #include "androidfw/ResourceTypes.h" |
| 25 | #include "androidfw/Util.h" |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 26 | #include "utils/ByteOrder.h" |
| 27 | #include "utils/Trace.h" |
| 28 | |
| 29 | #ifdef _WIN32 |
| 30 | #ifdef ERROR |
| 31 | #undef ERROR |
| 32 | #endif |
| 33 | #endif |
| 34 | |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 35 | using ::android::base::StringPrintf; |
| 36 | |
| 37 | namespace android { |
| 38 | |
Ryan Mitchell | 0699f1d | 2020-12-03 15:41:42 -0800 | [diff] [blame^] | 39 | // See frameworks/base/cmds/idmap2/include/idmap2/Idmap.h for full idmap file format specification. |
| 40 | struct Idmap_header { |
| 41 | // Always 0x504D4449 ('IDMP') |
| 42 | uint32_t magic; |
| 43 | uint32_t version; |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 44 | |
Ryan Mitchell | 0699f1d | 2020-12-03 15:41:42 -0800 | [diff] [blame^] | 45 | uint32_t target_crc32; |
| 46 | uint32_t overlay_crc32; |
| 47 | |
| 48 | uint32_t fulfilled_policies; |
| 49 | uint32_t enforce_overlayable; |
| 50 | |
| 51 | // overlay_path, target_path, and other string values encoded in the idmap header and read and |
| 52 | // stored in separate structures. This allows the idmap header data to be casted to this struct |
| 53 | // without having to read/store each header entry separately. |
| 54 | }; |
| 55 | |
| 56 | struct Idmap_data_header { |
| 57 | uint8_t target_package_id; |
| 58 | uint8_t overlay_package_id; |
| 59 | |
| 60 | // Padding to ensure 4 byte alignment for target_entry_count |
| 61 | uint16_t p0; |
| 62 | |
| 63 | uint32_t target_entry_count; |
| 64 | uint32_t target_inline_entry_count; |
| 65 | uint32_t overlay_entry_count; |
| 66 | |
| 67 | uint32_t string_pool_index_offset; |
| 68 | }; |
| 69 | |
| 70 | struct Idmap_target_entry { |
| 71 | uint32_t target_id; |
| 72 | uint32_t overlay_id; |
| 73 | }; |
| 74 | |
| 75 | struct Idmap_target_entry_inline { |
| 76 | uint32_t target_id; |
| 77 | Res_value value; |
| 78 | }; |
| 79 | |
| 80 | struct Idmap_overlay_entry { |
| 81 | uint32_t overlay_id; |
| 82 | uint32_t target_id; |
| 83 | }; |
MÃ¥rten Kongstad | d7e8a53 | 2019-10-11 08:32:04 +0200 | [diff] [blame] | 84 | |
Ryan Mitchell | 8a891d8 | 2019-07-01 09:48:23 -0700 | [diff] [blame] | 85 | OverlayStringPool::OverlayStringPool(const LoadedIdmap* loaded_idmap) |
Ryan Mitchell | 73bfe41 | 2019-11-12 16:22:04 -0800 | [diff] [blame] | 86 | : data_header_(loaded_idmap->data_header_), |
| 87 | idmap_string_pool_(loaded_idmap->string_pool_.get()) { }; |
Ryan Mitchell | 8a891d8 | 2019-07-01 09:48:23 -0700 | [diff] [blame] | 88 | |
| 89 | OverlayStringPool::~OverlayStringPool() { |
| 90 | uninit(); |
| 91 | } |
| 92 | |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 93 | base::expected<StringPiece16, NullOrIOError> OverlayStringPool::stringAt(size_t idx) const { |
Ryan Mitchell | 8a891d8 | 2019-07-01 09:48:23 -0700 | [diff] [blame] | 94 | const size_t offset = dtohl(data_header_->string_pool_index_offset); |
Ryan Mitchell | df9e732 | 2019-12-12 10:23:54 -0800 | [diff] [blame] | 95 | if (idmap_string_pool_ != nullptr && idx >= ResStringPool::size() && idx >= offset) { |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 96 | return idmap_string_pool_->stringAt(idx - offset); |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 99 | return ResStringPool::stringAt(idx); |
Ryan Mitchell | 8a891d8 | 2019-07-01 09:48:23 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 102 | base::expected<StringPiece, NullOrIOError> OverlayStringPool::string8At(size_t idx) const { |
Ryan Mitchell | 8a891d8 | 2019-07-01 09:48:23 -0700 | [diff] [blame] | 103 | const size_t offset = dtohl(data_header_->string_pool_index_offset); |
Ryan Mitchell | df9e732 | 2019-12-12 10:23:54 -0800 | [diff] [blame] | 104 | if (idmap_string_pool_ != nullptr && idx >= ResStringPool::size() && idx >= offset) { |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 105 | return idmap_string_pool_->string8At(idx - offset); |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 108 | return ResStringPool::string8At(idx); |
Ryan Mitchell | 8a891d8 | 2019-07-01 09:48:23 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Ryan Mitchell | df9e732 | 2019-12-12 10:23:54 -0800 | [diff] [blame] | 111 | size_t OverlayStringPool::size() const { |
| 112 | return ResStringPool::size() + (idmap_string_pool_ != nullptr ? idmap_string_pool_->size() : 0U); |
| 113 | } |
| 114 | |
Ryan Mitchell | 8a891d8 | 2019-07-01 09:48:23 -0700 | [diff] [blame] | 115 | OverlayDynamicRefTable::OverlayDynamicRefTable(const Idmap_data_header* data_header, |
| 116 | const Idmap_overlay_entry* entries, |
| 117 | uint8_t target_assigned_package_id) |
| 118 | : data_header_(data_header), |
| 119 | entries_(entries), |
| 120 | target_assigned_package_id_(target_assigned_package_id) { }; |
| 121 | |
| 122 | status_t OverlayDynamicRefTable::lookupResourceId(uint32_t* resId) const { |
| 123 | const Idmap_overlay_entry* first_entry = entries_; |
| 124 | const Idmap_overlay_entry* end_entry = entries_ + dtohl(data_header_->overlay_entry_count); |
Ryan Mitchell | bf1f45b | 2020-09-29 17:22:52 -0700 | [diff] [blame] | 125 | auto entry = std::lower_bound(first_entry, end_entry, *resId, |
| 126 | [](const Idmap_overlay_entry& e1, const uint32_t overlay_id) { |
| 127 | return dtohl(e1.overlay_id) < overlay_id; |
| 128 | }); |
Ryan Mitchell | 8a891d8 | 2019-07-01 09:48:23 -0700 | [diff] [blame] | 129 | |
| 130 | if (entry == end_entry || dtohl(entry->overlay_id) != *resId) { |
| 131 | // A mapping for the target resource id could not be found. |
| 132 | return DynamicRefTable::lookupResourceId(resId); |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 133 | } |
Ryan Mitchell | 8a891d8 | 2019-07-01 09:48:23 -0700 | [diff] [blame] | 134 | |
| 135 | *resId = (0x00FFFFFFU & dtohl(entry->target_id)) |
Ryan Mitchell | bf1f45b | 2020-09-29 17:22:52 -0700 | [diff] [blame] | 136 | | (((uint32_t) target_assigned_package_id_) << 24U); |
Ryan Mitchell | 8a891d8 | 2019-07-01 09:48:23 -0700 | [diff] [blame] | 137 | return NO_ERROR; |
| 138 | } |
| 139 | |
| 140 | status_t OverlayDynamicRefTable::lookupResourceIdNoRewrite(uint32_t* resId) const { |
| 141 | return DynamicRefTable::lookupResourceId(resId); |
| 142 | } |
| 143 | |
| 144 | IdmapResMap::IdmapResMap(const Idmap_data_header* data_header, |
| 145 | const Idmap_target_entry* entries, |
Ryan Mitchell | bf1f45b | 2020-09-29 17:22:52 -0700 | [diff] [blame] | 146 | const Idmap_target_entry_inline* inline_entries, |
Ryan Mitchell | 8a891d8 | 2019-07-01 09:48:23 -0700 | [diff] [blame] | 147 | uint8_t target_assigned_package_id, |
| 148 | const OverlayDynamicRefTable* overlay_ref_table) |
| 149 | : data_header_(data_header), |
| 150 | entries_(entries), |
Ryan Mitchell | bf1f45b | 2020-09-29 17:22:52 -0700 | [diff] [blame] | 151 | inline_entries_(inline_entries), |
Ryan Mitchell | 8a891d8 | 2019-07-01 09:48:23 -0700 | [diff] [blame] | 152 | target_assigned_package_id_(target_assigned_package_id), |
Ryan Mitchell | bf1f45b | 2020-09-29 17:22:52 -0700 | [diff] [blame] | 153 | overlay_ref_table_(overlay_ref_table) { } |
Ryan Mitchell | 8a891d8 | 2019-07-01 09:48:23 -0700 | [diff] [blame] | 154 | |
| 155 | IdmapResMap::Result IdmapResMap::Lookup(uint32_t target_res_id) const { |
Ryan Mitchell | bf1f45b | 2020-09-29 17:22:52 -0700 | [diff] [blame] | 156 | if ((target_res_id >> 24U) != target_assigned_package_id_) { |
Ryan Mitchell | 8a891d8 | 2019-07-01 09:48:23 -0700 | [diff] [blame] | 157 | // The resource id must have the same package id as the target package. |
| 158 | return {}; |
| 159 | } |
| 160 | |
| 161 | // The resource ids encoded within the idmap are build-time resource ids. |
| 162 | target_res_id = (0x00FFFFFFU & target_res_id) |
Ryan Mitchell | bf1f45b | 2020-09-29 17:22:52 -0700 | [diff] [blame] | 163 | | (((uint32_t) data_header_->target_package_id) << 24U); |
Ryan Mitchell | 8a891d8 | 2019-07-01 09:48:23 -0700 | [diff] [blame] | 164 | |
Ryan Mitchell | bf1f45b | 2020-09-29 17:22:52 -0700 | [diff] [blame] | 165 | // Check if the target resource is mapped to an overlay resource. |
| 166 | auto first_entry = entries_; |
| 167 | auto end_entry = entries_ + dtohl(data_header_->target_entry_count); |
| 168 | auto entry = std::lower_bound(first_entry, end_entry, target_res_id, |
| 169 | [](const Idmap_target_entry &e, const uint32_t target_id) { |
| 170 | return dtohl(e.target_id) < target_id; |
| 171 | }); |
Ryan Mitchell | 8a891d8 | 2019-07-01 09:48:23 -0700 | [diff] [blame] | 172 | |
Ryan Mitchell | bf1f45b | 2020-09-29 17:22:52 -0700 | [diff] [blame] | 173 | if (entry != end_entry && dtohl(entry->target_id) == target_res_id) { |
| 174 | uint32_t overlay_resource_id = dtohl(entry->overlay_id); |
Ryan Mitchell | 8a891d8 | 2019-07-01 09:48:23 -0700 | [diff] [blame] | 175 | // Lookup the resource without rewriting the overlay resource id back to the target resource id |
| 176 | // being looked up. |
| 177 | overlay_ref_table_->lookupResourceIdNoRewrite(&overlay_resource_id); |
| 178 | return Result(overlay_resource_id); |
| 179 | } |
| 180 | |
Ryan Mitchell | bf1f45b | 2020-09-29 17:22:52 -0700 | [diff] [blame] | 181 | // Check if the target resources is mapped to an inline table entry. |
| 182 | auto first_inline_entry = inline_entries_; |
| 183 | auto end_inline_entry = inline_entries_ + dtohl(data_header_->target_inline_entry_count); |
| 184 | auto inline_entry = std::lower_bound(first_inline_entry, end_inline_entry, target_res_id, |
| 185 | [](const Idmap_target_entry_inline &e, |
| 186 | const uint32_t target_id) { |
| 187 | return dtohl(e.target_id) < target_id; |
| 188 | }); |
Ryan Mitchell | 8a891d8 | 2019-07-01 09:48:23 -0700 | [diff] [blame] | 189 | |
Ryan Mitchell | bf1f45b | 2020-09-29 17:22:52 -0700 | [diff] [blame] | 190 | if (inline_entry != end_inline_entry && dtohl(inline_entry->target_id) == target_res_id) { |
| 191 | return Result(inline_entry->value); |
| 192 | } |
| 193 | return {}; |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Ryan Mitchell | 0699f1d | 2020-12-03 15:41:42 -0800 | [diff] [blame^] | 196 | namespace { |
| 197 | template <typename T> |
| 198 | const T* ReadType(const uint8_t** in_out_data_ptr, size_t* in_out_size, const std::string& label, |
| 199 | size_t count = 1) { |
| 200 | if (!util::IsFourByteAligned(*in_out_data_ptr)) { |
| 201 | LOG(ERROR) << "Idmap " << label << " is not word aligned."; |
| 202 | return {}; |
| 203 | } |
| 204 | if ((*in_out_size / sizeof(T)) < count) { |
| 205 | LOG(ERROR) << "Idmap too small for the number of " << label << " entries (" |
| 206 | << count << ")."; |
| 207 | return nullptr; |
| 208 | } |
| 209 | auto data_ptr = *in_out_data_ptr; |
| 210 | const size_t read_size = sizeof(T) * count; |
| 211 | *in_out_data_ptr += read_size; |
| 212 | *in_out_size -= read_size; |
| 213 | return reinterpret_cast<const T*>(data_ptr); |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 214 | } |
| 215 | |
Ryan Mitchell | 0699f1d | 2020-12-03 15:41:42 -0800 | [diff] [blame^] | 216 | std::optional<std::string_view> ReadString(const uint8_t** in_out_data_ptr, size_t* in_out_size, |
| 217 | const std::string& label) { |
| 218 | const auto* len = ReadType<uint32_t>(in_out_data_ptr, in_out_size, label + " length"); |
| 219 | if (len == nullptr) { |
| 220 | return {}; |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 221 | } |
Ryan Mitchell | 0699f1d | 2020-12-03 15:41:42 -0800 | [diff] [blame^] | 222 | const auto* data = ReadType<char>(in_out_data_ptr, in_out_size, label, *len); |
| 223 | if (data == nullptr) { |
| 224 | return {}; |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 225 | } |
Ryan Mitchell | 0699f1d | 2020-12-03 15:41:42 -0800 | [diff] [blame^] | 226 | // Strings are padded to the next 4 byte boundary. |
| 227 | const uint32_t padding_size = (4U - ((size_t)*in_out_data_ptr & 0x3U)) % 4U; |
| 228 | for (uint32_t i = 0; i < padding_size; i++) { |
| 229 | if (**in_out_data_ptr != 0) { |
| 230 | LOG(ERROR) << " Idmap padding of " << label << " is non-zero."; |
| 231 | return {}; |
| 232 | } |
| 233 | *in_out_data_ptr += sizeof(uint8_t); |
| 234 | *in_out_size -= sizeof(uint8_t); |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 235 | } |
Ryan Mitchell | 0699f1d | 2020-12-03 15:41:42 -0800 | [diff] [blame^] | 236 | return std::string_view(data, *len); |
| 237 | } |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 238 | } |
| 239 | |
Ryan Mitchell | a909305 | 2020-03-26 17:15:01 -0700 | [diff] [blame] | 240 | LoadedIdmap::LoadedIdmap(std::string&& idmap_path, |
Ryan Mitchell | a909305 | 2020-03-26 17:15:01 -0700 | [diff] [blame] | 241 | const Idmap_header* header, |
Ryan Mitchell | 8a891d8 | 2019-07-01 09:48:23 -0700 | [diff] [blame] | 242 | const Idmap_data_header* data_header, |
| 243 | const Idmap_target_entry* target_entries, |
Ryan Mitchell | bf1f45b | 2020-09-29 17:22:52 -0700 | [diff] [blame] | 244 | const Idmap_target_entry_inline* target_inline_entries, |
Ryan Mitchell | 8a891d8 | 2019-07-01 09:48:23 -0700 | [diff] [blame] | 245 | const Idmap_overlay_entry* overlay_entries, |
Ryan Mitchell | 0699f1d | 2020-12-03 15:41:42 -0800 | [diff] [blame^] | 246 | std::unique_ptr<ResStringPool>&& string_pool, |
| 247 | std::string_view overlay_apk_path, |
| 248 | std::string_view target_apk_path) |
Ryan Mitchell | 73bfe41 | 2019-11-12 16:22:04 -0800 | [diff] [blame] | 249 | : header_(header), |
| 250 | data_header_(data_header), |
| 251 | target_entries_(target_entries), |
Ryan Mitchell | bf1f45b | 2020-09-29 17:22:52 -0700 | [diff] [blame] | 252 | target_inline_entries_(target_inline_entries), |
Ryan Mitchell | 73bfe41 | 2019-11-12 16:22:04 -0800 | [diff] [blame] | 253 | overlay_entries_(overlay_entries), |
Ryan Mitchell | 0699f1d | 2020-12-03 15:41:42 -0800 | [diff] [blame^] | 254 | string_pool_(std::move(string_pool)), |
Ryan Mitchell | a909305 | 2020-03-26 17:15:01 -0700 | [diff] [blame] | 255 | idmap_path_(std::move(idmap_path)), |
Ryan Mitchell | 0699f1d | 2020-12-03 15:41:42 -0800 | [diff] [blame^] | 256 | overlay_apk_path_(overlay_apk_path), |
| 257 | target_apk_path_(target_apk_path), |
| 258 | idmap_last_mod_time_(getFileModDate(idmap_path_.data())) {} |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 259 | |
Ryan Mitchell | a909305 | 2020-03-26 17:15:01 -0700 | [diff] [blame] | 260 | std::unique_ptr<const LoadedIdmap> LoadedIdmap::Load(const StringPiece& idmap_path, |
| 261 | const StringPiece& idmap_data) { |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 262 | ATRACE_CALL(); |
Ryan Mitchell | 0699f1d | 2020-12-03 15:41:42 -0800 | [diff] [blame^] | 263 | size_t data_size = idmap_data.size(); |
| 264 | auto data_ptr = reinterpret_cast<const uint8_t*>(idmap_data.data()); |
| 265 | |
| 266 | // Parse the idmap header |
| 267 | auto header = ReadType<Idmap_header>(&data_ptr, &data_size, "header"); |
| 268 | if (header == nullptr) { |
| 269 | return {}; |
| 270 | } |
| 271 | if (dtohl(header->magic) != kIdmapMagic) { |
| 272 | LOG(ERROR) << StringPrintf("Invalid Idmap file: bad magic value (was 0x%08x, expected 0x%08x)", |
| 273 | dtohl(header->magic), kIdmapMagic); |
| 274 | return {}; |
| 275 | } |
| 276 | if (dtohl(header->version) != kIdmapCurrentVersion) { |
| 277 | // We are strict about versions because files with this format are generated at runtime and |
| 278 | // don't need backwards compatibility. |
| 279 | LOG(ERROR) << StringPrintf("Version mismatch in Idmap (was 0x%08x, expected 0x%08x)", |
| 280 | dtohl(header->version), kIdmapCurrentVersion); |
| 281 | return {}; |
| 282 | } |
| 283 | std::optional<std::string_view> overlay_path = ReadString(&data_ptr, &data_size, "overlay path"); |
| 284 | if (!overlay_path) { |
| 285 | return {}; |
| 286 | } |
| 287 | std::optional<std::string_view> target_path = ReadString(&data_ptr, &data_size, "target path"); |
| 288 | if (!target_path) { |
| 289 | return {}; |
| 290 | } |
| 291 | if (!ReadString(&data_ptr, &data_size, "debug info")) { |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 292 | return {}; |
| 293 | } |
| 294 | |
Ryan Mitchell | 0699f1d | 2020-12-03 15:41:42 -0800 | [diff] [blame^] | 295 | // Parse the idmap data blocks. Currently idmap2 can only generate one data block. |
| 296 | auto data_header = ReadType<Idmap_data_header>(&data_ptr, &data_size, "data header"); |
| 297 | if (data_header == nullptr) { |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 298 | return {}; |
| 299 | } |
Ryan Mitchell | 0699f1d | 2020-12-03 15:41:42 -0800 | [diff] [blame^] | 300 | auto target_entries = ReadType<Idmap_target_entry>(&data_ptr, &data_size, "target", |
| 301 | dtohl(data_header->target_entry_count)); |
| 302 | if (target_entries == nullptr) { |
Ryan Mitchell | bf1f45b | 2020-09-29 17:22:52 -0700 | [diff] [blame] | 303 | return {}; |
| 304 | } |
Ryan Mitchell | 0699f1d | 2020-12-03 15:41:42 -0800 | [diff] [blame^] | 305 | auto target_inline_entries = ReadType<Idmap_target_entry_inline>( |
| 306 | &data_ptr, &data_size, "target inline", dtohl(data_header->target_inline_entry_count)); |
| 307 | if (target_inline_entries == nullptr) { |
Ryan Mitchell | 8a891d8 | 2019-07-01 09:48:23 -0700 | [diff] [blame] | 308 | return {}; |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 309 | } |
Ryan Mitchell | 0699f1d | 2020-12-03 15:41:42 -0800 | [diff] [blame^] | 310 | auto overlay_entries = ReadType<Idmap_overlay_entry>(&data_ptr, &data_size, "target inline", |
| 311 | dtohl(data_header->overlay_entry_count)); |
| 312 | if (overlay_entries == nullptr) { |
Ryan Mitchell | 8a891d8 | 2019-07-01 09:48:23 -0700 | [diff] [blame] | 313 | return {}; |
| 314 | } |
Ryan Mitchell | 0699f1d | 2020-12-03 15:41:42 -0800 | [diff] [blame^] | 315 | std::optional<std::string_view> string_pool = ReadString(&data_ptr, &data_size, "string pool"); |
| 316 | if (!string_pool) { |
| 317 | return {}; |
| 318 | } |
Ryan Mitchell | 8a891d8 | 2019-07-01 09:48:23 -0700 | [diff] [blame] | 319 | auto idmap_string_pool = util::make_unique<ResStringPool>(); |
Ryan Mitchell | 0699f1d | 2020-12-03 15:41:42 -0800 | [diff] [blame^] | 320 | if (!string_pool->empty()) { |
| 321 | const status_t err = idmap_string_pool->setTo(string_pool->data(), string_pool->size()); |
Ryan Mitchell | 8a891d8 | 2019-07-01 09:48:23 -0700 | [diff] [blame] | 322 | if (err != NO_ERROR) { |
| 323 | LOG(ERROR) << "idmap string pool corrupt."; |
| 324 | return {}; |
| 325 | } |
| 326 | } |
| 327 | |
Ryan Mitchell | 73bfe41 | 2019-11-12 16:22:04 -0800 | [diff] [blame] | 328 | // Can't use make_unique because LoadedIdmap constructor is private. |
Ryan Mitchell | 0699f1d | 2020-12-03 15:41:42 -0800 | [diff] [blame^] | 329 | return std::unique_ptr<LoadedIdmap>( |
| 330 | new LoadedIdmap(idmap_path.to_string(), header, data_header, target_entries, |
| 331 | target_inline_entries, overlay_entries, std::move(idmap_string_pool), |
| 332 | *target_path, *overlay_path)); |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Ryan Mitchell | a909305 | 2020-03-26 17:15:01 -0700 | [diff] [blame] | 335 | bool LoadedIdmap::IsUpToDate() const { |
| 336 | return idmap_last_mod_time_ == getFileModDate(idmap_path_.c_str()); |
| 337 | } |
| 338 | |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 339 | } // namespace android |