Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define ATRACE_TAG ATRACE_TAG_RESOURCES |
| 18 | |
| 19 | #include "androidfw/LoadedArsc.h" |
| 20 | |
Adam Lesinski | 73f6f9d | 2017-11-14 10:18:05 -0800 | [diff] [blame] | 21 | #include <algorithm> |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 22 | #include <cstddef> |
| 23 | #include <limits> |
| 24 | |
| 25 | #include "android-base/logging.h" |
| 26 | #include "android-base/stringprintf.h" |
| 27 | #include "utils/ByteOrder.h" |
| 28 | #include "utils/Trace.h" |
| 29 | |
| 30 | #ifdef _WIN32 |
| 31 | #ifdef ERROR |
| 32 | #undef ERROR |
| 33 | #endif |
| 34 | #endif |
| 35 | |
Adam Lesinski | da431a2 | 2016-12-29 16:08:16 -0500 | [diff] [blame] | 36 | #include "androidfw/Chunk.h" |
Adam Lesinski | 929d651 | 2017-01-16 19:11:19 -0800 | [diff] [blame] | 37 | #include "androidfw/ResourceUtils.h" |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 38 | #include "androidfw/Util.h" |
| 39 | |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 40 | using android::base::StringPrintf; |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 41 | |
| 42 | namespace android { |
| 43 | |
Adam Lesinski | da431a2 | 2016-12-29 16:08:16 -0500 | [diff] [blame] | 44 | constexpr const static int kAppPackageId = 0x7f; |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 45 | |
Adam Lesinski | da431a2 | 2016-12-29 16:08:16 -0500 | [diff] [blame] | 46 | namespace { |
| 47 | |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 48 | // Builder that helps accumulate Type structs and then create a single |
| 49 | // contiguous block of memory to store both the TypeSpec struct and |
| 50 | // the Type structs. |
Ryan Mitchell | 14e8ade | 2021-01-11 16:01:35 -0800 | [diff] [blame] | 51 | struct TypeSpecBuilder { |
| 52 | explicit TypeSpecBuilder(incfs::verified_map_ptr<ResTable_typeSpec> header) : header_(header) {} |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 53 | |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 54 | void AddType(incfs::verified_map_ptr<ResTable_type> type) { |
Ryan Mitchell | 14e8ade | 2021-01-11 16:01:35 -0800 | [diff] [blame] | 55 | TypeSpec::TypeEntry& entry = type_entries.emplace_back(); |
| 56 | entry.config.copyFromDtoH(type->config); |
| 57 | entry.type = type; |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Ryan Mitchell | 14e8ade | 2021-01-11 16:01:35 -0800 | [diff] [blame] | 60 | TypeSpec Build() { |
| 61 | return {header_, std::move(type_entries)}; |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | private: |
Ryan Mitchell | 14e8ade | 2021-01-11 16:01:35 -0800 | [diff] [blame] | 65 | DISALLOW_COPY_AND_ASSIGN(TypeSpecBuilder); |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 66 | |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 67 | incfs::verified_map_ptr<ResTable_typeSpec> header_; |
Ryan Mitchell | 14e8ade | 2021-01-11 16:01:35 -0800 | [diff] [blame] | 68 | std::vector<TypeSpec::TypeEntry> type_entries; |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | } // namespace |
| 72 | |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 73 | LoadedPackage::LoadedPackage() = default; |
| 74 | LoadedPackage::~LoadedPackage() = default; |
| 75 | |
| 76 | // Precondition: The header passed in has already been verified, so reading any fields and trusting |
| 77 | // the ResChunk_header is safe. |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 78 | static bool VerifyResTableType(incfs::map_ptr<ResTable_type> header) { |
Adam Lesinski | 498f605 | 2017-11-29 13:24:29 -0800 | [diff] [blame] | 79 | if (header->id == 0) { |
| 80 | LOG(ERROR) << "RES_TABLE_TYPE_TYPE has invalid ID 0."; |
| 81 | return false; |
| 82 | } |
| 83 | |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 84 | const size_t entry_count = dtohl(header->entryCount); |
| 85 | if (entry_count > std::numeric_limits<uint16_t>::max()) { |
Adam Lesinski | 498f605 | 2017-11-29 13:24:29 -0800 | [diff] [blame] | 86 | LOG(ERROR) << "RES_TABLE_TYPE_TYPE has too many entries (" << entry_count << ")."; |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 87 | return false; |
| 88 | } |
| 89 | |
| 90 | // Make sure that there is enough room for the entry offsets. |
| 91 | const size_t offsets_offset = dtohs(header->header.headerSize); |
| 92 | const size_t entries_offset = dtohl(header->entriesStart); |
| 93 | const size_t offsets_length = sizeof(uint32_t) * entry_count; |
| 94 | |
| 95 | if (offsets_offset > entries_offset || entries_offset - offsets_offset < offsets_length) { |
Adam Lesinski | 498f605 | 2017-11-29 13:24:29 -0800 | [diff] [blame] | 96 | LOG(ERROR) << "RES_TABLE_TYPE_TYPE entry offsets overlap actual entry data."; |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 97 | return false; |
| 98 | } |
| 99 | |
| 100 | if (entries_offset > dtohl(header->header.size)) { |
Adam Lesinski | 498f605 | 2017-11-29 13:24:29 -0800 | [diff] [blame] | 101 | LOG(ERROR) << "RES_TABLE_TYPE_TYPE entry offsets extend beyond chunk."; |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 102 | return false; |
| 103 | } |
| 104 | |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 105 | if (entries_offset & 0x03U) { |
Adam Lesinski | 498f605 | 2017-11-29 13:24:29 -0800 | [diff] [blame] | 106 | LOG(ERROR) << "RES_TABLE_TYPE_TYPE entries start at unaligned address."; |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 107 | return false; |
| 108 | } |
| 109 | return true; |
| 110 | } |
| 111 | |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 112 | static base::expected<std::monostate, NullOrIOError> VerifyResTableEntry( |
| 113 | incfs::verified_map_ptr<ResTable_type> type, uint32_t entry_offset) { |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 114 | // Check that the offset is aligned. |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 115 | if (UNLIKELY(entry_offset & 0x03U)) { |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 116 | LOG(ERROR) << "Entry at offset " << entry_offset << " is not 4-byte aligned."; |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 117 | return base::unexpected(std::nullopt); |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | // Check that the offset doesn't overflow. |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 121 | if (UNLIKELY(entry_offset > std::numeric_limits<uint32_t>::max() - dtohl(type->entriesStart))) { |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 122 | // Overflow in offset. |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 123 | LOG(ERROR) << "Entry at offset " << entry_offset << " is too large."; |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 124 | return base::unexpected(std::nullopt); |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | const size_t chunk_size = dtohl(type->header.size); |
| 128 | |
| 129 | entry_offset += dtohl(type->entriesStart); |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 130 | if (UNLIKELY(entry_offset > chunk_size - sizeof(ResTable_entry))) { |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 131 | LOG(ERROR) << "Entry at offset " << entry_offset |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 132 | << " is too large. No room for ResTable_entry."; |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 133 | return base::unexpected(std::nullopt); |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 136 | auto entry = type.offset(entry_offset).convert<ResTable_entry>(); |
| 137 | if (UNLIKELY(!entry)) { |
| 138 | return base::unexpected(IOError::PAGES_MISSING); |
| 139 | } |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 140 | |
| 141 | const size_t entry_size = dtohs(entry->size); |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 142 | if (UNLIKELY(entry_size < sizeof(entry.value()))) { |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 143 | LOG(ERROR) << "ResTable_entry size " << entry_size << " at offset " << entry_offset |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 144 | << " is too small."; |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 145 | return base::unexpected(std::nullopt); |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 146 | } |
| 147 | |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 148 | if (UNLIKELY(entry_size > chunk_size || entry_offset > chunk_size - entry_size)) { |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 149 | LOG(ERROR) << "ResTable_entry size " << entry_size << " at offset " << entry_offset |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 150 | << " is too large."; |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 151 | return base::unexpected(std::nullopt); |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | if (entry_size < sizeof(ResTable_map_entry)) { |
| 155 | // There needs to be room for one Res_value struct. |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 156 | if (UNLIKELY(entry_offset + entry_size > chunk_size - sizeof(Res_value))) { |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 157 | LOG(ERROR) << "No room for Res_value after ResTable_entry at offset " << entry_offset |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 158 | << " for type " << (int)type->id << "."; |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 159 | return base::unexpected(std::nullopt); |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 162 | auto value = entry.offset(entry_size).convert<Res_value>(); |
| 163 | if (UNLIKELY(!value)) { |
| 164 | return base::unexpected(IOError::PAGES_MISSING); |
| 165 | } |
| 166 | |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 167 | const size_t value_size = dtohs(value->size); |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 168 | if (UNLIKELY(value_size < sizeof(Res_value))) { |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 169 | LOG(ERROR) << "Res_value at offset " << entry_offset << " is too small."; |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 170 | return base::unexpected(std::nullopt); |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 173 | if (UNLIKELY(value_size > chunk_size || entry_offset + entry_size > chunk_size - value_size)) { |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 174 | LOG(ERROR) << "Res_value size " << value_size << " at offset " << entry_offset |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 175 | << " is too large."; |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 176 | return base::unexpected(std::nullopt); |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 177 | } |
| 178 | } else { |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 179 | auto map = entry.convert<ResTable_map_entry>(); |
| 180 | if (UNLIKELY(!map)) { |
| 181 | return base::unexpected(IOError::PAGES_MISSING); |
| 182 | } |
| 183 | |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 184 | const size_t map_entry_count = dtohl(map->count); |
| 185 | size_t map_entries_start = entry_offset + entry_size; |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 186 | if (UNLIKELY(map_entries_start & 0x03U)) { |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 187 | LOG(ERROR) << "Map entries at offset " << entry_offset << " start at unaligned offset."; |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 188 | return base::unexpected(std::nullopt); |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | // Each entry is sizeof(ResTable_map) big. |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 192 | if (UNLIKELY(map_entry_count > ((chunk_size - map_entries_start) / sizeof(ResTable_map)))) { |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 193 | LOG(ERROR) << "Too many map entries in ResTable_map_entry at offset " << entry_offset << "."; |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 194 | return base::unexpected(std::nullopt); |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 195 | } |
| 196 | } |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 197 | return {}; |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 198 | } |
| 199 | |
MÃ¥rten Kongstad | 3f1f4fc | 2018-03-02 09:34:18 +0100 | [diff] [blame] | 200 | LoadedPackage::iterator::iterator(const LoadedPackage* lp, size_t ti, size_t ei) |
| 201 | : loadedPackage_(lp), |
| 202 | typeIndex_(ti), |
| 203 | entryIndex_(ei), |
| 204 | typeIndexEnd_(lp->resource_ids_.size() + 1) { |
| 205 | while (typeIndex_ < typeIndexEnd_ && loadedPackage_->resource_ids_[typeIndex_] == 0) { |
| 206 | typeIndex_++; |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | LoadedPackage::iterator& LoadedPackage::iterator::operator++() { |
| 211 | while (typeIndex_ < typeIndexEnd_) { |
| 212 | if (entryIndex_ + 1 < loadedPackage_->resource_ids_[typeIndex_]) { |
| 213 | entryIndex_++; |
| 214 | break; |
| 215 | } |
| 216 | entryIndex_ = 0; |
| 217 | typeIndex_++; |
| 218 | if (typeIndex_ < typeIndexEnd_ && loadedPackage_->resource_ids_[typeIndex_] != 0) { |
| 219 | break; |
| 220 | } |
| 221 | } |
| 222 | return *this; |
| 223 | } |
| 224 | |
| 225 | uint32_t LoadedPackage::iterator::operator*() const { |
| 226 | if (typeIndex_ >= typeIndexEnd_) { |
| 227 | return 0; |
| 228 | } |
| 229 | return make_resid(loadedPackage_->package_id_, typeIndex_ + loadedPackage_->type_id_offset_, |
| 230 | entryIndex_); |
| 231 | } |
| 232 | |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 233 | base::expected<incfs::map_ptr<ResTable_entry>, NullOrIOError> LoadedPackage::GetEntry( |
| 234 | incfs::verified_map_ptr<ResTable_type> type_chunk, uint16_t entry_index) { |
| 235 | base::expected<uint32_t, NullOrIOError> entry_offset = GetEntryOffset(type_chunk, entry_index); |
| 236 | if (UNLIKELY(!entry_offset.has_value())) { |
| 237 | return base::unexpected(entry_offset.error()); |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 238 | } |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 239 | return GetEntryFromOffset(type_chunk, entry_offset.value()); |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 240 | } |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 241 | |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 242 | base::expected<uint32_t, NullOrIOError> LoadedPackage::GetEntryOffset( |
| 243 | incfs::verified_map_ptr<ResTable_type> type_chunk, uint16_t entry_index) { |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 244 | // The configuration matches and is better than the previous selection. |
| 245 | // Find the entry value if it exists for this configuration. |
| 246 | const size_t entry_count = dtohl(type_chunk->entryCount); |
| 247 | const size_t offsets_offset = dtohs(type_chunk->header.headerSize); |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 248 | |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 249 | // Check if there is the desired entry in this type. |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 250 | if (type_chunk->flags & ResTable_type::FLAG_SPARSE) { |
| 251 | // This is encoded as a sparse map, so perform a binary search. |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 252 | bool error = false; |
| 253 | auto sparse_indices = type_chunk.offset(offsets_offset) |
| 254 | .convert<ResTable_sparseTypeEntry>().iterator(); |
| 255 | auto sparse_indices_end = sparse_indices + entry_count; |
| 256 | auto result = std::lower_bound(sparse_indices, sparse_indices_end, entry_index, |
| 257 | [&error](const incfs::map_ptr<ResTable_sparseTypeEntry>& entry, |
| 258 | uint16_t entry_idx) { |
| 259 | if (UNLIKELY(!entry)) { |
| 260 | return error = true; |
| 261 | } |
| 262 | return dtohs(entry->idx) < entry_idx; |
| 263 | }); |
Adam Lesinski | 73f6f9d | 2017-11-14 10:18:05 -0800 | [diff] [blame] | 264 | |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 265 | if (result == sparse_indices_end) { |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 266 | // No entry found. |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 267 | return base::unexpected(std::nullopt); |
| 268 | } |
| 269 | |
| 270 | const incfs::verified_map_ptr<ResTable_sparseTypeEntry> entry = (*result).verified(); |
| 271 | if (dtohs(entry->idx) != entry_index) { |
| 272 | if (error) { |
| 273 | return base::unexpected(IOError::PAGES_MISSING); |
| 274 | } |
| 275 | return base::unexpected(std::nullopt); |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 276 | } |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 277 | |
| 278 | // Extract the offset from the entry. Each offset must be a multiple of 4 so we store it as |
| 279 | // the real offset divided by 4. |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 280 | return uint32_t{dtohs(entry->offset)} * 4u; |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 281 | } |
| 282 | |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 283 | // This type is encoded as a dense array. |
| 284 | if (entry_index >= entry_count) { |
| 285 | // This entry cannot be here. |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 286 | return base::unexpected(std::nullopt); |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 289 | const auto entry_offset_ptr = type_chunk.offset(offsets_offset).convert<uint32_t>() + entry_index; |
| 290 | if (UNLIKELY(!entry_offset_ptr)) { |
| 291 | return base::unexpected(IOError::PAGES_MISSING); |
Ryan Mitchell | c75c2e0 | 2020-08-17 08:42:48 -0700 | [diff] [blame] | 292 | } |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 293 | |
| 294 | const uint32_t value = dtohl(entry_offset_ptr.value()); |
| 295 | if (value == ResTable_type::NO_ENTRY) { |
| 296 | return base::unexpected(std::nullopt); |
| 297 | } |
| 298 | |
| 299 | return value; |
Ryan Mitchell | c75c2e0 | 2020-08-17 08:42:48 -0700 | [diff] [blame] | 300 | } |
| 301 | |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 302 | base::expected<incfs::map_ptr<ResTable_entry>, NullOrIOError> LoadedPackage::GetEntryFromOffset( |
| 303 | incfs::verified_map_ptr<ResTable_type> type_chunk, uint32_t offset) { |
| 304 | auto valid = VerifyResTableEntry(type_chunk, offset); |
| 305 | if (UNLIKELY(!valid.has_value())) { |
| 306 | return base::unexpected(valid.error()); |
| 307 | } |
| 308 | return type_chunk.offset(offset + dtohl(type_chunk->entriesStart)).convert<ResTable_entry>(); |
| 309 | } |
| 310 | |
| 311 | base::expected<std::monostate, IOError> LoadedPackage::CollectConfigurations( |
Ryan Mitchell | 14e8ade | 2021-01-11 16:01:35 -0800 | [diff] [blame] | 312 | bool exclude_mipmap, std::set<ResTable_config>* out_configs) const {\ |
| 313 | for (const auto& type_spec : type_specs_) { |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 314 | if (exclude_mipmap) { |
Ryan Mitchell | 14e8ade | 2021-01-11 16:01:35 -0800 | [diff] [blame] | 315 | const int type_idx = type_spec.first - 1; |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 316 | const auto type_name16 = type_string_pool_.stringAt(type_idx); |
| 317 | if (UNLIKELY(IsIOError(type_name16))) { |
| 318 | return base::unexpected(GetIOError(type_name16.error())); |
| 319 | } |
| 320 | if (type_name16.has_value()) { |
| 321 | if (strncmp16(type_name16->data(), u"mipmap", type_name16->size()) == 0) { |
| 322 | // This is a mipmap type, skip collection. |
| 323 | continue; |
Adam Lesinski | 0c40524 | 2017-01-13 20:47:26 -0800 | [diff] [blame] | 324 | } |
| 325 | } |
| 326 | |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 327 | const auto type_name = type_string_pool_.string8At(type_idx); |
| 328 | if (UNLIKELY(IsIOError(type_name))) { |
| 329 | return base::unexpected(GetIOError(type_name.error())); |
| 330 | } |
| 331 | if (type_name.has_value()) { |
| 332 | if (strncmp(type_name->data(), "mipmap", type_name->size()) == 0) { |
| 333 | // This is a mipmap type, skip collection. |
| 334 | continue; |
| 335 | } |
Ryan Mitchell | c75c2e0 | 2020-08-17 08:42:48 -0700 | [diff] [blame] | 336 | } |
Ryan Mitchell | c75c2e0 | 2020-08-17 08:42:48 -0700 | [diff] [blame] | 337 | } |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 338 | |
Ryan Mitchell | 14e8ade | 2021-01-11 16:01:35 -0800 | [diff] [blame] | 339 | for (const auto& type_entry : type_spec.second.type_entries) { |
| 340 | out_configs->insert(type_entry.config); |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 341 | } |
Adam Lesinski | 0c40524 | 2017-01-13 20:47:26 -0800 | [diff] [blame] | 342 | } |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 343 | return {}; |
Adam Lesinski | 0c40524 | 2017-01-13 20:47:26 -0800 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | void LoadedPackage::CollectLocales(bool canonicalize, std::set<std::string>* out_locales) const { |
| 347 | char temp_locale[RESTABLE_MAX_LOCALE_LEN]; |
Ryan Mitchell | 14e8ade | 2021-01-11 16:01:35 -0800 | [diff] [blame] | 348 | for (const auto& type_spec : type_specs_) { |
| 349 | for (const auto& type_entry : type_spec.second.type_entries) { |
| 350 | if (type_entry.config.locale != 0) { |
| 351 | type_entry.config.getBcp47Locale(temp_locale, canonicalize); |
| 352 | std::string locale(temp_locale); |
| 353 | out_locales->insert(std::move(locale)); |
Adam Lesinski | 0c40524 | 2017-01-13 20:47:26 -0800 | [diff] [blame] | 354 | } |
| 355 | } |
| 356 | } |
| 357 | } |
| 358 | |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 359 | base::expected<uint32_t, NullOrIOError> LoadedPackage::FindEntryByName( |
| 360 | const std::u16string& type_name, const std::u16string& entry_name) const { |
| 361 | const base::expected<size_t, NullOrIOError> type_idx = type_string_pool_.indexOfString( |
| 362 | type_name.data(), type_name.size()); |
| 363 | if (!type_idx.has_value()) { |
| 364 | return base::unexpected(type_idx.error()); |
Adam Lesinski | 929d651 | 2017-01-16 19:11:19 -0800 | [diff] [blame] | 365 | } |
| 366 | |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 367 | const base::expected<size_t, NullOrIOError> key_idx = key_string_pool_.indexOfString( |
| 368 | entry_name.data(), entry_name.size()); |
| 369 | if (!key_idx.has_value()) { |
| 370 | return base::unexpected(key_idx.error()); |
Adam Lesinski | 929d651 | 2017-01-16 19:11:19 -0800 | [diff] [blame] | 371 | } |
| 372 | |
Ryan Mitchell | 14e8ade | 2021-01-11 16:01:35 -0800 | [diff] [blame] | 373 | const TypeSpec* type_spec = GetTypeSpecByTypeIndex(*type_idx); |
Adam Lesinski | 929d651 | 2017-01-16 19:11:19 -0800 | [diff] [blame] | 374 | if (type_spec == nullptr) { |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 375 | return base::unexpected(std::nullopt); |
Adam Lesinski | 929d651 | 2017-01-16 19:11:19 -0800 | [diff] [blame] | 376 | } |
| 377 | |
Ryan Mitchell | 14e8ade | 2021-01-11 16:01:35 -0800 | [diff] [blame] | 378 | for (const auto& type_entry : type_spec->type_entries) { |
| 379 | const incfs::verified_map_ptr<ResTable_type>& type = type_entry.type; |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 380 | |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 381 | size_t entry_count = dtohl(type->entryCount); |
Adam Lesinski | 929d651 | 2017-01-16 19:11:19 -0800 | [diff] [blame] | 382 | for (size_t entry_idx = 0; entry_idx < entry_count; entry_idx++) { |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 383 | auto entry_offset_ptr = type.offset(dtohs(type->header.headerSize)).convert<uint32_t>() + |
| 384 | entry_idx; |
| 385 | if (!entry_offset_ptr) { |
| 386 | return base::unexpected(IOError::PAGES_MISSING); |
| 387 | } |
| 388 | |
| 389 | auto offset = dtohl(entry_offset_ptr.value()); |
Adam Lesinski | 929d651 | 2017-01-16 19:11:19 -0800 | [diff] [blame] | 390 | if (offset != ResTable_type::NO_ENTRY) { |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 391 | auto entry = type.offset(dtohl(type->entriesStart) + offset).convert<ResTable_entry>(); |
| 392 | if (!entry) { |
| 393 | return base::unexpected(IOError::PAGES_MISSING); |
| 394 | } |
| 395 | |
| 396 | if (dtohl(entry->key.index) == static_cast<uint32_t>(*key_idx)) { |
Adam Lesinski | 929d651 | 2017-01-16 19:11:19 -0800 | [diff] [blame] | 397 | // The package ID will be overridden by the caller (due to runtime assignment of package |
| 398 | // IDs for shared libraries). |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 399 | return make_resid(0x00, *type_idx + type_id_offset_ + 1, entry_idx); |
Adam Lesinski | 929d651 | 2017-01-16 19:11:19 -0800 | [diff] [blame] | 400 | } |
| 401 | } |
| 402 | } |
| 403 | } |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 404 | return base::unexpected(std::nullopt); |
Adam Lesinski | 929d651 | 2017-01-16 19:11:19 -0800 | [diff] [blame] | 405 | } |
| 406 | |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 407 | const LoadedPackage* LoadedArsc::GetPackageById(uint8_t package_id) const { |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 408 | for (const auto& loaded_package : packages_) { |
| 409 | if (loaded_package->GetPackageId() == package_id) { |
| 410 | return loaded_package.get(); |
| 411 | } |
| 412 | } |
| 413 | return nullptr; |
| 414 | } |
| 415 | |
| 416 | std::unique_ptr<const LoadedPackage> LoadedPackage::Load(const Chunk& chunk, |
Ryan Mitchell | 73bfe41 | 2019-11-12 16:22:04 -0800 | [diff] [blame] | 417 | package_property_t property_flags) { |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 418 | ATRACE_NAME("LoadedPackage::Load"); |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 419 | std::unique_ptr<LoadedPackage> loaded_package(new LoadedPackage()); |
Adam Lesinski | da431a2 | 2016-12-29 16:08:16 -0500 | [diff] [blame] | 420 | |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 421 | // typeIdOffset was added at some point, but we still must recognize apps built before this |
| 422 | // was added. |
Adam Lesinski | 33af6c7 | 2017-03-29 13:00:35 -0700 | [diff] [blame] | 423 | constexpr size_t kMinPackageSize = |
| 424 | sizeof(ResTable_package) - sizeof(ResTable_package::typeIdOffset); |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 425 | const incfs::map_ptr<ResTable_package> header = chunk.header<ResTable_package, kMinPackageSize>(); |
| 426 | if (!header) { |
Adam Lesinski | 498f605 | 2017-11-29 13:24:29 -0800 | [diff] [blame] | 427 | LOG(ERROR) << "RES_TABLE_PACKAGE_TYPE too small."; |
Adam Lesinski | da431a2 | 2016-12-29 16:08:16 -0500 | [diff] [blame] | 428 | return {}; |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 429 | } |
| 430 | |
Ryan Mitchell | 73bfe41 | 2019-11-12 16:22:04 -0800 | [diff] [blame] | 431 | if ((property_flags & PROPERTY_SYSTEM) != 0) { |
| 432 | loaded_package->property_flags_ |= PROPERTY_SYSTEM; |
| 433 | } |
| 434 | |
| 435 | if ((property_flags & PROPERTY_LOADER) != 0) { |
| 436 | loaded_package->property_flags_ |= PROPERTY_LOADER; |
| 437 | } |
| 438 | |
| 439 | if ((property_flags & PROPERTY_OVERLAY) != 0) { |
| 440 | // Overlay resources must have an exclusive resource id space for referencing internal |
| 441 | // resources. |
| 442 | loaded_package->property_flags_ |= PROPERTY_OVERLAY | PROPERTY_DYNAMIC; |
| 443 | } |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 444 | |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 445 | loaded_package->package_id_ = dtohl(header->id); |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 446 | if (loaded_package->package_id_ == 0 || |
Ryan Mitchell | 73bfe41 | 2019-11-12 16:22:04 -0800 | [diff] [blame] | 447 | (loaded_package->package_id_ == kAppPackageId && (property_flags & PROPERTY_DYNAMIC) != 0)) { |
| 448 | loaded_package->property_flags_ |= PROPERTY_DYNAMIC; |
Winson | 9947f1e | 2019-08-16 10:20:39 -0700 | [diff] [blame] | 449 | } |
| 450 | |
Adam Lesinski | c6aada9 | 2017-01-13 15:34:14 -0800 | [diff] [blame] | 451 | if (header->header.headerSize >= sizeof(ResTable_package)) { |
| 452 | uint32_t type_id_offset = dtohl(header->typeIdOffset); |
| 453 | if (type_id_offset > std::numeric_limits<uint8_t>::max()) { |
Adam Lesinski | 498f605 | 2017-11-29 13:24:29 -0800 | [diff] [blame] | 454 | LOG(ERROR) << "RES_TABLE_PACKAGE_TYPE type ID offset too large."; |
Adam Lesinski | c6aada9 | 2017-01-13 15:34:14 -0800 | [diff] [blame] | 455 | return {}; |
| 456 | } |
| 457 | loaded_package->type_id_offset_ = static_cast<int>(type_id_offset); |
| 458 | } |
| 459 | |
Adam Lesinski | da431a2 | 2016-12-29 16:08:16 -0500 | [diff] [blame] | 460 | util::ReadUtf16StringFromDevice(header->name, arraysize(header->name), |
| 461 | &loaded_package->package_name_); |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 462 | |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 463 | // A map of TypeSpec builders, each associated with an type index. |
| 464 | // We use these to accumulate the set of Types available for a TypeSpec, and later build a single, |
| 465 | // contiguous block of memory that holds all the Types together with the TypeSpec. |
Ryan Mitchell | 14e8ade | 2021-01-11 16:01:35 -0800 | [diff] [blame] | 466 | std::unordered_map<int, std::unique_ptr<TypeSpecBuilder>> type_builder_map; |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 467 | |
| 468 | ChunkIterator iter(chunk.data_ptr(), chunk.data_size()); |
| 469 | while (iter.HasNext()) { |
| 470 | const Chunk child_chunk = iter.Next(); |
| 471 | switch (child_chunk.type()) { |
| 472 | case RES_STRING_POOL_TYPE: { |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 473 | const auto pool_address = child_chunk.header<ResChunk_header>(); |
| 474 | if (!pool_address) { |
| 475 | LOG(ERROR) << "RES_STRING_POOL_TYPE is incomplete due to incremental installation."; |
| 476 | return {}; |
| 477 | } |
| 478 | |
| 479 | if (pool_address == header.offset(dtohl(header->typeStrings)).convert<ResChunk_header>()) { |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 480 | // This string pool is the type string pool. |
| 481 | status_t err = loaded_package->type_string_pool_.setTo( |
| 482 | child_chunk.header<ResStringPool_header>(), child_chunk.size()); |
| 483 | if (err != NO_ERROR) { |
Adam Lesinski | 498f605 | 2017-11-29 13:24:29 -0800 | [diff] [blame] | 484 | LOG(ERROR) << "RES_STRING_POOL_TYPE for types corrupt."; |
Adam Lesinski | da431a2 | 2016-12-29 16:08:16 -0500 | [diff] [blame] | 485 | return {}; |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 486 | } |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 487 | } else if (pool_address == header.offset(dtohl(header->keyStrings)) |
| 488 | .convert<ResChunk_header>()) { |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 489 | // This string pool is the key string pool. |
| 490 | status_t err = loaded_package->key_string_pool_.setTo( |
| 491 | child_chunk.header<ResStringPool_header>(), child_chunk.size()); |
| 492 | if (err != NO_ERROR) { |
Adam Lesinski | 498f605 | 2017-11-29 13:24:29 -0800 | [diff] [blame] | 493 | LOG(ERROR) << "RES_STRING_POOL_TYPE for keys corrupt."; |
Adam Lesinski | da431a2 | 2016-12-29 16:08:16 -0500 | [diff] [blame] | 494 | return {}; |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 495 | } |
| 496 | } else { |
Adam Lesinski | 498f605 | 2017-11-29 13:24:29 -0800 | [diff] [blame] | 497 | LOG(WARNING) << "Too many RES_STRING_POOL_TYPEs found in RES_TABLE_PACKAGE_TYPE."; |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 498 | } |
| 499 | } break; |
| 500 | |
| 501 | case RES_TABLE_TYPE_SPEC_TYPE: { |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 502 | const auto type_spec = child_chunk.header<ResTable_typeSpec>(); |
| 503 | if (!type_spec) { |
Adam Lesinski | 498f605 | 2017-11-29 13:24:29 -0800 | [diff] [blame] | 504 | LOG(ERROR) << "RES_TABLE_TYPE_SPEC_TYPE too small."; |
Adam Lesinski | da431a2 | 2016-12-29 16:08:16 -0500 | [diff] [blame] | 505 | return {}; |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | if (type_spec->id == 0) { |
Adam Lesinski | 498f605 | 2017-11-29 13:24:29 -0800 | [diff] [blame] | 509 | LOG(ERROR) << "RES_TABLE_TYPE_SPEC_TYPE has invalid ID 0."; |
Adam Lesinski | da431a2 | 2016-12-29 16:08:16 -0500 | [diff] [blame] | 510 | return {}; |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 511 | } |
| 512 | |
Adam Lesinski | c6aada9 | 2017-01-13 15:34:14 -0800 | [diff] [blame] | 513 | if (loaded_package->type_id_offset_ + static_cast<int>(type_spec->id) > |
| 514 | std::numeric_limits<uint8_t>::max()) { |
Adam Lesinski | 498f605 | 2017-11-29 13:24:29 -0800 | [diff] [blame] | 515 | LOG(ERROR) << "RES_TABLE_TYPE_SPEC_TYPE has out of range ID."; |
Adam Lesinski | c6aada9 | 2017-01-13 15:34:14 -0800 | [diff] [blame] | 516 | return {}; |
| 517 | } |
| 518 | |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 519 | // The data portion of this chunk contains entry_count 32bit entries, |
| 520 | // each one representing a set of flags. |
| 521 | // Here we only validate that the chunk is well formed. |
| 522 | const size_t entry_count = dtohl(type_spec->entryCount); |
| 523 | |
| 524 | // There can only be 2^16 entries in a type, because that is the ID |
| 525 | // space for entries (EEEE) in the resource ID 0xPPTTEEEE. |
| 526 | if (entry_count > std::numeric_limits<uint16_t>::max()) { |
Adam Lesinski | 498f605 | 2017-11-29 13:24:29 -0800 | [diff] [blame] | 527 | LOG(ERROR) << "RES_TABLE_TYPE_SPEC_TYPE has too many entries (" << entry_count << ")."; |
Adam Lesinski | da431a2 | 2016-12-29 16:08:16 -0500 | [diff] [blame] | 528 | return {}; |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | if (entry_count * sizeof(uint32_t) > chunk.data_size()) { |
Adam Lesinski | 498f605 | 2017-11-29 13:24:29 -0800 | [diff] [blame] | 532 | LOG(ERROR) << "RES_TABLE_TYPE_SPEC_TYPE too small to hold entries."; |
Adam Lesinski | da431a2 | 2016-12-29 16:08:16 -0500 | [diff] [blame] | 533 | return {}; |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 534 | } |
| 535 | |
Ryan Mitchell | 14e8ade | 2021-01-11 16:01:35 -0800 | [diff] [blame] | 536 | std::unique_ptr<TypeSpecBuilder>& builder_ptr = type_builder_map[type_spec->id]; |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 537 | if (builder_ptr == nullptr) { |
Ryan Mitchell | 14e8ade | 2021-01-11 16:01:35 -0800 | [diff] [blame] | 538 | builder_ptr = util::make_unique<TypeSpecBuilder>(type_spec.verified()); |
MÃ¥rten Kongstad | 3f1f4fc | 2018-03-02 09:34:18 +0100 | [diff] [blame] | 539 | loaded_package->resource_ids_.set(type_spec->id, entry_count); |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 540 | } else { |
| 541 | LOG(WARNING) << StringPrintf("RES_TABLE_TYPE_SPEC_TYPE already defined for ID %02x", |
| 542 | type_spec->id); |
| 543 | } |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 544 | } break; |
| 545 | |
| 546 | case RES_TABLE_TYPE_TYPE: { |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 547 | const auto type = child_chunk.header<ResTable_type, kResTableTypeMinSize>(); |
| 548 | if (!type) { |
Adam Lesinski | 498f605 | 2017-11-29 13:24:29 -0800 | [diff] [blame] | 549 | LOG(ERROR) << "RES_TABLE_TYPE_TYPE too small."; |
Adam Lesinski | da431a2 | 2016-12-29 16:08:16 -0500 | [diff] [blame] | 550 | return {}; |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 551 | } |
| 552 | |
Adam Lesinski | 498f605 | 2017-11-29 13:24:29 -0800 | [diff] [blame] | 553 | if (!VerifyResTableType(type)) { |
Adam Lesinski | da431a2 | 2016-12-29 16:08:16 -0500 | [diff] [blame] | 554 | return {}; |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | // Type chunks must be preceded by their TypeSpec chunks. |
Ryan Mitchell | 14e8ade | 2021-01-11 16:01:35 -0800 | [diff] [blame] | 558 | std::unique_ptr<TypeSpecBuilder>& builder_ptr = type_builder_map[type->id]; |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 559 | if (builder_ptr != nullptr) { |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 560 | builder_ptr->AddType(type.verified()); |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 561 | } else { |
| 562 | LOG(ERROR) << StringPrintf( |
| 563 | "RES_TABLE_TYPE_TYPE with ID %02x found without preceding RES_TABLE_TYPE_SPEC_TYPE.", |
| 564 | type->id); |
Adam Lesinski | da431a2 | 2016-12-29 16:08:16 -0500 | [diff] [blame] | 565 | return {}; |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 566 | } |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 567 | } break; |
| 568 | |
Adam Lesinski | da431a2 | 2016-12-29 16:08:16 -0500 | [diff] [blame] | 569 | case RES_TABLE_LIBRARY_TYPE: { |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 570 | const auto lib = child_chunk.header<ResTable_lib_header>(); |
| 571 | if (!lib) { |
Adam Lesinski | 498f605 | 2017-11-29 13:24:29 -0800 | [diff] [blame] | 572 | LOG(ERROR) << "RES_TABLE_LIBRARY_TYPE too small."; |
Adam Lesinski | da431a2 | 2016-12-29 16:08:16 -0500 | [diff] [blame] | 573 | return {}; |
| 574 | } |
| 575 | |
| 576 | if (child_chunk.data_size() / sizeof(ResTable_lib_entry) < dtohl(lib->count)) { |
Adam Lesinski | 498f605 | 2017-11-29 13:24:29 -0800 | [diff] [blame] | 577 | LOG(ERROR) << "RES_TABLE_LIBRARY_TYPE too small to hold entries."; |
Adam Lesinski | da431a2 | 2016-12-29 16:08:16 -0500 | [diff] [blame] | 578 | return {}; |
| 579 | } |
| 580 | |
| 581 | loaded_package->dynamic_package_map_.reserve(dtohl(lib->count)); |
| 582 | |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 583 | const auto entry_begin = child_chunk.data_ptr().convert<ResTable_lib_entry>(); |
| 584 | const auto entry_end = entry_begin + dtohl(lib->count); |
Adam Lesinski | da431a2 | 2016-12-29 16:08:16 -0500 | [diff] [blame] | 585 | for (auto entry_iter = entry_begin; entry_iter != entry_end; ++entry_iter) { |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 586 | if (!entry_iter) { |
| 587 | return {}; |
| 588 | } |
| 589 | |
Adam Lesinski | da431a2 | 2016-12-29 16:08:16 -0500 | [diff] [blame] | 590 | std::string package_name; |
| 591 | util::ReadUtf16StringFromDevice(entry_iter->packageName, |
| 592 | arraysize(entry_iter->packageName), &package_name); |
| 593 | |
| 594 | if (dtohl(entry_iter->packageId) >= std::numeric_limits<uint8_t>::max()) { |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 595 | LOG(ERROR) << StringPrintf( |
Adam Lesinski | da431a2 | 2016-12-29 16:08:16 -0500 | [diff] [blame] | 596 | "Package ID %02x in RES_TABLE_LIBRARY_TYPE too large for package '%s'.", |
| 597 | dtohl(entry_iter->packageId), package_name.c_str()); |
| 598 | return {}; |
| 599 | } |
| 600 | |
| 601 | loaded_package->dynamic_package_map_.emplace_back(std::move(package_name), |
| 602 | dtohl(entry_iter->packageId)); |
| 603 | } |
Ryan Mitchell | 75e20dd | 2018-11-06 16:39:36 -0800 | [diff] [blame] | 604 | } break; |
Adam Lesinski | da431a2 | 2016-12-29 16:08:16 -0500 | [diff] [blame] | 605 | |
Ryan Mitchell | 75e20dd | 2018-11-06 16:39:36 -0800 | [diff] [blame] | 606 | case RES_TABLE_OVERLAYABLE_TYPE: { |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 607 | const auto overlayable = child_chunk.header<ResTable_overlayable_header>(); |
| 608 | if (!overlayable) { |
Ryan Mitchell | 75e20dd | 2018-11-06 16:39:36 -0800 | [diff] [blame] | 609 | LOG(ERROR) << "RES_TABLE_OVERLAYABLE_TYPE too small."; |
| 610 | return {}; |
| 611 | } |
| 612 | |
Ryan Mitchell | ef5673a | 2018-12-12 18:45:34 -0800 | [diff] [blame] | 613 | std::string name; |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 614 | util::ReadUtf16StringFromDevice(overlayable->name, arraysize(overlayable->name), &name); |
Ryan Mitchell | ef5673a | 2018-12-12 18:45:34 -0800 | [diff] [blame] | 615 | std::string actor; |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 616 | util::ReadUtf16StringFromDevice(overlayable->actor, arraysize(overlayable->actor), &actor); |
Ryan Mitchell | ef5673a | 2018-12-12 18:45:34 -0800 | [diff] [blame] | 617 | |
MÃ¥rten Kongstad | c92c4dd | 2019-02-05 01:29:59 +0100 | [diff] [blame] | 618 | if (loaded_package->overlayable_map_.find(name) != |
| 619 | loaded_package->overlayable_map_.end()) { |
| 620 | LOG(ERROR) << "Multiple <overlayable> blocks with the same name '" << name << "'."; |
| 621 | return {}; |
| 622 | } |
| 623 | loaded_package->overlayable_map_.emplace(name, actor); |
| 624 | |
Ryan Mitchell | ef5673a | 2018-12-12 18:45:34 -0800 | [diff] [blame] | 625 | // Iterate over the overlayable policy chunks contained within the overlayable chunk data |
Ryan Mitchell | 75e20dd | 2018-11-06 16:39:36 -0800 | [diff] [blame] | 626 | ChunkIterator overlayable_iter(child_chunk.data_ptr(), child_chunk.data_size()); |
| 627 | while (overlayable_iter.HasNext()) { |
| 628 | const Chunk overlayable_child_chunk = overlayable_iter.Next(); |
| 629 | |
| 630 | switch (overlayable_child_chunk.type()) { |
| 631 | case RES_TABLE_OVERLAYABLE_POLICY_TYPE: { |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 632 | const auto policy_header = |
Ryan Mitchell | 75e20dd | 2018-11-06 16:39:36 -0800 | [diff] [blame] | 633 | overlayable_child_chunk.header<ResTable_overlayable_policy_header>(); |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 634 | if (!policy_header) { |
Ryan Mitchell | 75e20dd | 2018-11-06 16:39:36 -0800 | [diff] [blame] | 635 | LOG(ERROR) << "RES_TABLE_OVERLAYABLE_POLICY_TYPE too small."; |
| 636 | return {}; |
| 637 | } |
| 638 | |
| 639 | if ((overlayable_child_chunk.data_size() / sizeof(ResTable_ref)) |
| 640 | < dtohl(policy_header->entry_count)) { |
| 641 | LOG(ERROR) << "RES_TABLE_OVERLAYABLE_POLICY_TYPE too small to hold entries."; |
| 642 | return {}; |
| 643 | } |
| 644 | |
Ryan Mitchell | ef5673a | 2018-12-12 18:45:34 -0800 | [diff] [blame] | 645 | // Retrieve all the resource ids belonging to this policy chunk |
Ryan Mitchell | 75e20dd | 2018-11-06 16:39:36 -0800 | [diff] [blame] | 646 | std::unordered_set<uint32_t> ids; |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 647 | const auto ids_begin = overlayable_child_chunk.data_ptr().convert<ResTable_ref>(); |
Ryan Mitchell | 75e20dd | 2018-11-06 16:39:36 -0800 | [diff] [blame] | 648 | const auto ids_end = ids_begin + dtohl(policy_header->entry_count); |
| 649 | for (auto id_iter = ids_begin; id_iter != ids_end; ++id_iter) { |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 650 | if (!id_iter) { |
| 651 | return {}; |
| 652 | } |
Ryan Mitchell | 75e20dd | 2018-11-06 16:39:36 -0800 | [diff] [blame] | 653 | ids.insert(dtohl(id_iter->ident)); |
| 654 | } |
| 655 | |
Ryan Mitchell | ef5673a | 2018-12-12 18:45:34 -0800 | [diff] [blame] | 656 | // Add the pairing of overlayable properties and resource ids to the package |
Ryan Mitchell | 54237ff | 2018-12-13 15:44:29 -0800 | [diff] [blame] | 657 | OverlayableInfo overlayable_info{}; |
Ryan Mitchell | ef5673a | 2018-12-12 18:45:34 -0800 | [diff] [blame] | 658 | overlayable_info.name = name; |
| 659 | overlayable_info.actor = actor; |
Ryan Mitchell | 75e20dd | 2018-11-06 16:39:36 -0800 | [diff] [blame] | 660 | overlayable_info.policy_flags = policy_header->policy_flags; |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 661 | loaded_package->overlayable_infos_.emplace_back(overlayable_info, ids); |
Ryan Mitchell | 1982345 | 2019-01-29 12:01:24 -0800 | [diff] [blame] | 662 | loaded_package->defines_overlayable_ = true; |
Ryan Mitchell | 75e20dd | 2018-11-06 16:39:36 -0800 | [diff] [blame] | 663 | break; |
| 664 | } |
| 665 | |
| 666 | default: |
| 667 | LOG(WARNING) << StringPrintf("Unknown chunk type '%02x'.", chunk.type()); |
| 668 | break; |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | if (overlayable_iter.HadError()) { |
Ryan Mitchell | ef5673a | 2018-12-12 18:45:34 -0800 | [diff] [blame] | 673 | LOG(ERROR) << StringPrintf("Error parsing RES_TABLE_OVERLAYABLE_TYPE: %s", |
Ryan Mitchell | 75e20dd | 2018-11-06 16:39:36 -0800 | [diff] [blame] | 674 | overlayable_iter.GetLastError().c_str()); |
| 675 | if (overlayable_iter.HadFatalError()) { |
| 676 | return {}; |
| 677 | } |
| 678 | } |
Adam Lesinski | da431a2 | 2016-12-29 16:08:16 -0500 | [diff] [blame] | 679 | } break; |
| 680 | |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 681 | default: |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 682 | LOG(WARNING) << StringPrintf("Unknown chunk type '%02x'.", chunk.type()); |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 683 | break; |
| 684 | } |
| 685 | } |
| 686 | |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 687 | if (iter.HadError()) { |
| 688 | LOG(ERROR) << iter.GetLastError(); |
Todd Kennedy | 28e663c | 2018-07-12 13:15:54 -0700 | [diff] [blame] | 689 | if (iter.HadFatalError()) { |
| 690 | return {}; |
| 691 | } |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | // Flatten and construct the TypeSpecs. |
| 695 | for (auto& entry : type_builder_map) { |
Ryan Mitchell | 14e8ade | 2021-01-11 16:01:35 -0800 | [diff] [blame] | 696 | TypeSpec type_spec = entry.second->Build(); |
| 697 | uint8_t type_id = static_cast<uint8_t>(entry.first); |
| 698 | loaded_package->type_specs_[type_id] = std::move(type_spec); |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 699 | } |
| 700 | |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 701 | return std::move(loaded_package); |
| 702 | } |
| 703 | |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 704 | bool LoadedArsc::LoadTable(const Chunk& chunk, const LoadedIdmap* loaded_idmap, |
Ryan Mitchell | 73bfe41 | 2019-11-12 16:22:04 -0800 | [diff] [blame] | 705 | package_property_t property_flags) { |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 706 | incfs::map_ptr<ResTable_header> header = chunk.header<ResTable_header>(); |
| 707 | if (!header) { |
Adam Lesinski | 498f605 | 2017-11-29 13:24:29 -0800 | [diff] [blame] | 708 | LOG(ERROR) << "RES_TABLE_TYPE too small."; |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 709 | return false; |
| 710 | } |
| 711 | |
Ryan Mitchell | 8a891d8 | 2019-07-01 09:48:23 -0700 | [diff] [blame] | 712 | if (loaded_idmap != nullptr) { |
| 713 | global_string_pool_ = util::make_unique<OverlayStringPool>(loaded_idmap); |
| 714 | } |
| 715 | |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 716 | const size_t package_count = dtohl(header->packageCount); |
| 717 | size_t packages_seen = 0; |
| 718 | |
| 719 | packages_.reserve(package_count); |
| 720 | |
| 721 | ChunkIterator iter(chunk.data_ptr(), chunk.data_size()); |
| 722 | while (iter.HasNext()) { |
| 723 | const Chunk child_chunk = iter.Next(); |
| 724 | switch (child_chunk.type()) { |
| 725 | case RES_STRING_POOL_TYPE: |
| 726 | // Only use the first string pool. Ignore others. |
Ryan Mitchell | 8a891d8 | 2019-07-01 09:48:23 -0700 | [diff] [blame] | 727 | if (global_string_pool_->getError() == NO_INIT) { |
| 728 | status_t err = global_string_pool_->setTo(child_chunk.header<ResStringPool_header>(), |
| 729 | child_chunk.size()); |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 730 | if (err != NO_ERROR) { |
Adam Lesinski | 498f605 | 2017-11-29 13:24:29 -0800 | [diff] [blame] | 731 | LOG(ERROR) << "RES_STRING_POOL_TYPE corrupt."; |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 732 | return false; |
| 733 | } |
| 734 | } else { |
Adam Lesinski | 498f605 | 2017-11-29 13:24:29 -0800 | [diff] [blame] | 735 | LOG(WARNING) << "Multiple RES_STRING_POOL_TYPEs found in RES_TABLE_TYPE."; |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 736 | } |
| 737 | break; |
| 738 | |
| 739 | case RES_TABLE_PACKAGE_TYPE: { |
| 740 | if (packages_seen + 1 > package_count) { |
| 741 | LOG(ERROR) << "More package chunks were found than the " << package_count |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 742 | << " declared in the header."; |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 743 | return false; |
| 744 | } |
| 745 | packages_seen++; |
| 746 | |
Adam Lesinski | 1a1e9c2 | 2017-10-13 15:45:34 -0700 | [diff] [blame] | 747 | std::unique_ptr<const LoadedPackage> loaded_package = |
Ryan Mitchell | 73bfe41 | 2019-11-12 16:22:04 -0800 | [diff] [blame] | 748 | LoadedPackage::Load(child_chunk, property_flags); |
Adam Lesinski | da431a2 | 2016-12-29 16:08:16 -0500 | [diff] [blame] | 749 | if (!loaded_package) { |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 750 | return false; |
| 751 | } |
| 752 | packages_.push_back(std::move(loaded_package)); |
| 753 | } break; |
| 754 | |
| 755 | default: |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 756 | LOG(WARNING) << StringPrintf("Unknown chunk type '%02x'.", chunk.type()); |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 757 | break; |
| 758 | } |
| 759 | } |
| 760 | |
| 761 | if (iter.HadError()) { |
| 762 | LOG(ERROR) << iter.GetLastError(); |
Todd Kennedy | 28e663c | 2018-07-12 13:15:54 -0700 | [diff] [blame] | 763 | if (iter.HadFatalError()) { |
| 764 | return false; |
| 765 | } |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 766 | } |
| 767 | return true; |
| 768 | } |
| 769 | |
Ryan Mitchell | 1a48fa6 | 2021-01-10 08:36:36 -0800 | [diff] [blame^] | 770 | std::unique_ptr<LoadedArsc> LoadedArsc::Load(incfs::map_ptr<void> data, |
| 771 | const size_t length, |
| 772 | const LoadedIdmap* loaded_idmap, |
| 773 | const package_property_t property_flags) { |
Winson | 9947f1e | 2019-08-16 10:20:39 -0700 | [diff] [blame] | 774 | ATRACE_NAME("LoadedArsc::Load"); |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 775 | |
| 776 | // Not using make_unique because the constructor is private. |
| 777 | std::unique_ptr<LoadedArsc> loaded_arsc(new LoadedArsc()); |
| 778 | |
Ryan Mitchell | db21f09a | 2020-11-16 23:08:18 +0000 | [diff] [blame] | 779 | ChunkIterator iter(data, length); |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 780 | while (iter.HasNext()) { |
| 781 | const Chunk chunk = iter.Next(); |
| 782 | switch (chunk.type()) { |
| 783 | case RES_TABLE_TYPE: |
Ryan Mitchell | 73bfe41 | 2019-11-12 16:22:04 -0800 | [diff] [blame] | 784 | if (!loaded_arsc->LoadTable(chunk, loaded_idmap, property_flags)) { |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 785 | return {}; |
| 786 | } |
| 787 | break; |
| 788 | |
| 789 | default: |
Adam Lesinski | bebfcc4 | 2018-02-12 14:27:46 -0800 | [diff] [blame] | 790 | LOG(WARNING) << StringPrintf("Unknown chunk type '%02x'.", chunk.type()); |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 791 | break; |
| 792 | } |
| 793 | } |
| 794 | |
| 795 | if (iter.HadError()) { |
| 796 | LOG(ERROR) << iter.GetLastError(); |
Todd Kennedy | 28e663c | 2018-07-12 13:15:54 -0700 | [diff] [blame] | 797 | if (iter.HadFatalError()) { |
| 798 | return {}; |
| 799 | } |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 800 | } |
Adam Lesinski | 0c40524 | 2017-01-13 20:47:26 -0800 | [diff] [blame] | 801 | |
Ryan Mitchell | 1a48fa6 | 2021-01-10 08:36:36 -0800 | [diff] [blame^] | 802 | return loaded_arsc; |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 803 | } |
| 804 | |
Ryan Mitchell | 1a48fa6 | 2021-01-10 08:36:36 -0800 | [diff] [blame^] | 805 | std::unique_ptr<LoadedArsc> LoadedArsc::CreateEmpty() { |
Adam Lesinski | 970bd8d | 2017-09-25 13:21:55 -0700 | [diff] [blame] | 806 | return std::unique_ptr<LoadedArsc>(new LoadedArsc()); |
| 807 | } |
| 808 | |
Adam Lesinski | 7ad1110 | 2016-10-28 16:39:15 -0700 | [diff] [blame] | 809 | } // namespace android |