Ethan Yonker | 941a899 | 2016-12-05 09:04:30 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 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 | #include <stdlib.h> |
| 18 | #include <string> |
| 19 | #include <vector> |
| 20 | |
| 21 | #ifdef AB_OTA_UPDATER |
Ethan Yonker | d9918b7 | 2017-09-15 08:17:42 -0500 | [diff] [blame] | 22 | #include <inttypes.h> |
Ethan Yonker | 941a899 | 2016-12-05 09:04:30 -0600 | [diff] [blame] | 23 | #include <map> |
| 24 | #include <android-base/parseint.h> |
| 25 | #include <android-base/stringprintf.h> |
| 26 | #include <android-base/strings.h> |
| 27 | #endif |
| 28 | #include <cutils/properties.h> |
| 29 | |
| 30 | #include "common.h" |
| 31 | #include "installcommand.h" |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 32 | #include <ziparchive/zip_archive.h> |
bigbiff | 1f9e484 | 2020-10-31 11:33:15 -0400 | [diff] [blame] | 33 | #include "twinstall/install.h" |
Ethan Yonker | 941a899 | 2016-12-05 09:04:30 -0600 | [diff] [blame] | 34 | |
| 35 | #ifdef AB_OTA_UPDATER |
| 36 | |
| 37 | static constexpr const char* AB_OTA_PAYLOAD_PROPERTIES = "payload_properties.txt"; |
| 38 | static constexpr const char* AB_OTA_PAYLOAD = "payload.bin"; |
| 39 | static constexpr const char* METADATA_PATH = "META-INF/com/android/metadata"; |
| 40 | |
| 41 | // This function parses and returns the build.version.incremental |
| 42 | static int parse_build_number(std::string str) { |
| 43 | size_t pos = str.find("="); |
| 44 | if (pos != std::string::npos) { |
| 45 | std::string num_string = android::base::Trim(str.substr(pos+1)); |
| 46 | int build_number; |
| 47 | if (android::base::ParseInt(num_string.c_str(), &build_number, 0)) { |
| 48 | return build_number; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | printf("Failed to parse build number in %s.\n", str.c_str()); |
| 53 | return -1; |
| 54 | } |
| 55 | |
bigbiff | 1f9e484 | 2020-10-31 11:33:15 -0400 | [diff] [blame] | 56 | bool read_metadata_from_package(ZipArchiveHandle zip, std::string* meta_data) { |
bigbiff | 673c7ae | 2020-12-02 19:44:56 -0500 | [diff] [blame] | 57 | std::string binary_name(METADATA_PATH); |
GarfieldHan | d216188 | 2021-11-29 00:04:53 +0800 | [diff] [blame] | 58 | ZipEntry64 binary_entry; |
bigbiff | 1f9e484 | 2020-10-31 11:33:15 -0400 | [diff] [blame] | 59 | if (FindEntry(zip, binary_name, &binary_entry) == 0) { |
| 60 | long size = binary_entry.uncompressed_length; |
| 61 | if (size <= 0) |
| 62 | return false; |
Ethan Yonker | 941a899 | 2016-12-05 09:04:30 -0600 | [diff] [blame] | 63 | |
bigbiff | 1f9e484 | 2020-10-31 11:33:15 -0400 | [diff] [blame] | 64 | meta_data->resize(size, '\0'); |
| 65 | int32_t ret = ExtractToMemory(zip, &binary_entry, reinterpret_cast<uint8_t*>(&(*meta_data)[0]), |
| 66 | size); |
| 67 | if (ret != 0) { |
| 68 | printf("Failed to read metadata in update package.\n"); |
bigbiff | 1f9e484 | 2020-10-31 11:33:15 -0400 | [diff] [blame] | 69 | return false; |
| 70 | } |
| 71 | return true; |
| 72 | } |
| 73 | return false; |
Ethan Yonker | 941a899 | 2016-12-05 09:04:30 -0600 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | // Read the build.version.incremental of src/tgt from the metadata and log it to last_install. |
bigbiff | 1f9e484 | 2020-10-31 11:33:15 -0400 | [diff] [blame] | 77 | void read_source_target_build(ZipArchiveHandle zip/*, std::vector<std::string>& log_buffer*/) { |
Ethan Yonker | 941a899 | 2016-12-05 09:04:30 -0600 | [diff] [blame] | 78 | std::string meta_data; |
| 79 | if (!read_metadata_from_package(zip, &meta_data)) { |
| 80 | return; |
| 81 | } |
| 82 | // Examples of the pre-build and post-build strings in metadata: |
| 83 | // pre-build-incremental=2943039 |
| 84 | // post-build-incremental=2951741 |
| 85 | std::vector<std::string> lines = android::base::Split(meta_data, "\n"); |
| 86 | for (const std::string& line : lines) { |
| 87 | std::string str = android::base::Trim(line); |
| 88 | if (android::base::StartsWith(str, "pre-build-incremental")){ |
| 89 | int source_build = parse_build_number(str); |
| 90 | if (source_build != -1) { |
Ethan Yonker | 58f2132 | 2018-08-24 11:17:36 -0500 | [diff] [blame] | 91 | printf("source_build: %d\n", source_build); |
| 92 | /*log_buffer.push_back(android::base::StringPrintf("source_build: %d", |
| 93 | source_build));*/ |
Ethan Yonker | 941a899 | 2016-12-05 09:04:30 -0600 | [diff] [blame] | 94 | } |
| 95 | } else if (android::base::StartsWith(str, "post-build-incremental")) { |
| 96 | int target_build = parse_build_number(str); |
| 97 | if (target_build != -1) { |
Ethan Yonker | 58f2132 | 2018-08-24 11:17:36 -0500 | [diff] [blame] | 98 | printf("target_build: %d\n", target_build); |
| 99 | /*log_buffer.push_back(android::base::StringPrintf("target_build: %d", |
| 100 | target_build));*/ |
Ethan Yonker | 941a899 | 2016-12-05 09:04:30 -0600 | [diff] [blame] | 101 | } |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | // Parses the metadata of the OTA package in |zip| and checks whether we are |
| 107 | // allowed to accept this A/B package. Downgrading is not allowed unless |
| 108 | // explicitly enabled in the package and only for incremental packages. |
bigbiff | 1f9e484 | 2020-10-31 11:33:15 -0400 | [diff] [blame] | 109 | static int check_newer_ab_build(ZipArchiveHandle zip) |
Ethan Yonker | 941a899 | 2016-12-05 09:04:30 -0600 | [diff] [blame] | 110 | { |
| 111 | std::string metadata_str; |
| 112 | if (!read_metadata_from_package(zip, &metadata_str)) { |
| 113 | return INSTALL_CORRUPT; |
| 114 | } |
| 115 | std::map<std::string, std::string> metadata; |
| 116 | for (const std::string& line : android::base::Split(metadata_str, "\n")) { |
| 117 | size_t eq = line.find('='); |
| 118 | if (eq != std::string::npos) { |
| 119 | metadata[line.substr(0, eq)] = line.substr(eq + 1); |
| 120 | } |
| 121 | } |
| 122 | char value[PROPERTY_VALUE_MAX]; |
mauronofrio | c79f86e | 2020-05-18 16:08:12 -0400 | [diff] [blame] | 123 | char propmodel[PROPERTY_VALUE_MAX]; |
| 124 | char propname[PROPERTY_VALUE_MAX]; |
Ethan Yonker | 941a899 | 2016-12-05 09:04:30 -0600 | [diff] [blame] | 125 | |
| 126 | property_get("ro.product.device", value, ""); |
mauronofrio | c79f86e | 2020-05-18 16:08:12 -0400 | [diff] [blame] | 127 | property_get("ro.product.model", propmodel, ""); |
| 128 | property_get("ro.product.name", propname, ""); |
Ethan Yonker | 941a899 | 2016-12-05 09:04:30 -0600 | [diff] [blame] | 129 | const std::string& pkg_device = metadata["pre-device"]; |
mauronofrio | c79f86e | 2020-05-18 16:08:12 -0400 | [diff] [blame] | 130 | |
Darth9 | 728ca7e | 2022-04-28 08:37:06 +0100 | [diff] [blame] | 131 | std::vector<std::string> assertResults = android::base::Split(pkg_device, "[,|]"); |
mauronofrio | c79f86e | 2020-05-18 16:08:12 -0400 | [diff] [blame] | 132 | |
| 133 | bool deviceExists = false; |
| 134 | |
DarthJabba9 | 7cd3abb | 2021-11-28 01:09:44 +0530 | [diff] [blame] | 135 | // twrp.target.devices |
| 136 | bool has_target_devices = false; |
| 137 | char tw_devices[PROPERTY_VALUE_MAX * 2]; |
| 138 | property_get("ro.twrp.target.devices", tw_devices, ""); |
Darth9 | 728ca7e | 2022-04-28 08:37:06 +0100 | [diff] [blame] | 139 | std::vector<std::string> TWRP_devices = android::base::Split(tw_devices, "[,|]"); |
DarthJabba9 | 7cd3abb | 2021-11-28 01:09:44 +0530 | [diff] [blame] | 140 | if (strlen(tw_devices) > 1) { |
| 141 | has_target_devices = true; |
| 142 | } |
| 143 | |
mauronofrio | c79f86e | 2020-05-18 16:08:12 -0400 | [diff] [blame] | 144 | for(const std::string& deviceAssert : assertResults) |
| 145 | { |
| 146 | std::string assertName = android::base::Trim(deviceAssert); |
| 147 | if ((assertName == value || assertName == propmodel || assertName == propname ) && !assertName.empty()) { |
| 148 | deviceExists = true; |
| 149 | break; |
| 150 | } |
DarthJabba9 | 7cd3abb | 2021-11-28 01:09:44 +0530 | [diff] [blame] | 151 | // twrp.target.devices |
| 152 | else if (has_target_devices) { |
| 153 | for(const std::string& twrpDevice_x : TWRP_devices) { |
| 154 | std::string twrpName = android::base::Trim(twrpDevice_x); |
| 155 | if (!twrpName.empty() && !assertName.empty() && assertName == twrpName) { |
| 156 | deviceExists = true; |
| 157 | printf("Package is for product %s. The selected TWRP target device is %s\n", pkg_device.c_str(), twrpName.c_str()); |
| 158 | break; |
| 159 | } |
| 160 | } |
| 161 | } |
mauronofrio | c79f86e | 2020-05-18 16:08:12 -0400 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | if (!deviceExists) { |
Ethan Yonker | 941a899 | 2016-12-05 09:04:30 -0600 | [diff] [blame] | 165 | printf("Package is for product %s but expected %s\n", |
mauronofrio | c79f86e | 2020-05-18 16:08:12 -0400 | [diff] [blame] | 166 | pkg_device.c_str(), value); |
Ethan Yonker | 941a899 | 2016-12-05 09:04:30 -0600 | [diff] [blame] | 167 | return INSTALL_ERROR; |
| 168 | } |
| 169 | |
| 170 | // We allow the package to not have any serialno, but if it has a non-empty |
| 171 | // value it should match. |
| 172 | property_get("ro.serialno", value, ""); |
| 173 | const std::string& pkg_serial_no = metadata["serialno"]; |
| 174 | if (!pkg_serial_no.empty() && pkg_serial_no != value) { |
| 175 | printf("Package is for serial %s\n", pkg_serial_no.c_str()); |
| 176 | return INSTALL_ERROR; |
| 177 | } |
| 178 | |
| 179 | if (metadata["ota-type"] != "AB") { |
| 180 | printf("Package is not A/B\n"); |
| 181 | return INSTALL_ERROR; |
| 182 | } |
| 183 | |
| 184 | // Incremental updates should match the current build. |
| 185 | property_get("ro.build.version.incremental", value, ""); |
| 186 | const std::string& pkg_pre_build = metadata["pre-build-incremental"]; |
| 187 | if (!pkg_pre_build.empty() && pkg_pre_build != value) { |
| 188 | printf("Package is for source build %s but expected %s\n", |
| 189 | pkg_pre_build.c_str(), value); |
| 190 | return INSTALL_ERROR; |
| 191 | } |
| 192 | property_get("ro.build.fingerprint", value, ""); |
| 193 | const std::string& pkg_pre_build_fingerprint = metadata["pre-build"]; |
| 194 | if (!pkg_pre_build_fingerprint.empty() && |
| 195 | pkg_pre_build_fingerprint != value) { |
| 196 | printf("Package is for source build %s but expected %s\n", |
| 197 | pkg_pre_build_fingerprint.c_str(), value); |
| 198 | return INSTALL_ERROR; |
| 199 | } |
| 200 | |
Ethan Yonker | 941a899 | 2016-12-05 09:04:30 -0600 | [diff] [blame] | 201 | return 0; |
| 202 | } |
| 203 | |
| 204 | int |
bigbiff | 1f9e484 | 2020-10-31 11:33:15 -0400 | [diff] [blame] | 205 | abupdate_binary_command(const char* path, int retry_count __unused, |
Ethan Yonker | 941a899 | 2016-12-05 09:04:30 -0600 | [diff] [blame] | 206 | int status_fd, std::vector<std::string>* cmd) |
| 207 | { |
bigbiff | 1f9e484 | 2020-10-31 11:33:15 -0400 | [diff] [blame] | 208 | auto package = Package::CreateMemoryPackage(path); |
| 209 | if (!package) { |
| 210 | return INSTALL_CORRUPT; |
| 211 | } |
| 212 | |
| 213 | ZipArchiveHandle Zip = package->GetZipArchiveHandle(); |
| 214 | read_source_target_build(Zip); |
| 215 | int ret = check_newer_ab_build(Zip); |
Ethan Yonker | 941a899 | 2016-12-05 09:04:30 -0600 | [diff] [blame] | 216 | if (ret) { |
| 217 | return ret; |
| 218 | } |
| 219 | |
| 220 | // For A/B updates we extract the payload properties to a buffer and obtain |
| 221 | // the RAW payload offset in the zip file. |
bigbiff | 1f9e484 | 2020-10-31 11:33:15 -0400 | [diff] [blame] | 222 | // if (!Zip->EntryExists(AB_OTA_PAYLOAD_PROPERTIES)) { |
bigbiff | 673c7ae | 2020-12-02 19:44:56 -0500 | [diff] [blame] | 223 | std::string binary_name(AB_OTA_PAYLOAD_PROPERTIES); |
GarfieldHan | d216188 | 2021-11-29 00:04:53 +0800 | [diff] [blame] | 224 | ZipEntry64 binary_entry; |
bigbiff | 1f9e484 | 2020-10-31 11:33:15 -0400 | [diff] [blame] | 225 | if (FindEntry(Zip, binary_name, &binary_entry) != 0) { |
Ethan Yonker | 941a899 | 2016-12-05 09:04:30 -0600 | [diff] [blame] | 226 | printf("Can't find %s\n", AB_OTA_PAYLOAD_PROPERTIES); |
| 227 | return INSTALL_CORRUPT; |
| 228 | } |
| 229 | std::vector<unsigned char> payload_properties( |
bigbiff | 1f9e484 | 2020-10-31 11:33:15 -0400 | [diff] [blame] | 230 | binary_entry.uncompressed_length); |
| 231 | int32_t extract_ret = ExtractToMemory(Zip, &binary_entry, reinterpret_cast<uint8_t*>(payload_properties.data()), |
| 232 | binary_entry.uncompressed_length); |
| 233 | if (extract_ret != 0) { |
Ethan Yonker | 941a899 | 2016-12-05 09:04:30 -0600 | [diff] [blame] | 234 | printf("Can't extract %s\n", AB_OTA_PAYLOAD_PROPERTIES); |
bigbiff | 1f9e484 | 2020-10-31 11:33:15 -0400 | [diff] [blame] | 235 | return false; |
Ethan Yonker | 941a899 | 2016-12-05 09:04:30 -0600 | [diff] [blame] | 236 | } |
| 237 | |
bigbiff | 673c7ae | 2020-12-02 19:44:56 -0500 | [diff] [blame] | 238 | std::string ab_ota_payload(AB_OTA_PAYLOAD); |
GarfieldHan | d216188 | 2021-11-29 00:04:53 +0800 | [diff] [blame] | 239 | ZipEntry64 ab_ota_payload_entry; |
bigbiff | 1f9e484 | 2020-10-31 11:33:15 -0400 | [diff] [blame] | 240 | if (FindEntry(Zip, ab_ota_payload, &ab_ota_payload_entry) != 0) { |
Ethan Yonker | 941a899 | 2016-12-05 09:04:30 -0600 | [diff] [blame] | 241 | printf("Can't find %s\n", AB_OTA_PAYLOAD); |
| 242 | return INSTALL_CORRUPT; |
| 243 | } |
bigbiff | 1f9e484 | 2020-10-31 11:33:15 -0400 | [diff] [blame] | 244 | // long payload_offset = Zip->GetEntryOffset(AB_OTA_PAYLOAD); |
| 245 | long payload_offset = ab_ota_payload_entry.offset; |
Ethan Yonker | 941a899 | 2016-12-05 09:04:30 -0600 | [diff] [blame] | 246 | *cmd = { |
bigbiff | ad58e1b | 2020-07-06 20:24:34 -0400 | [diff] [blame] | 247 | "/system/bin/update_engine_sideload", |
Ethan Yonker | 941a899 | 2016-12-05 09:04:30 -0600 | [diff] [blame] | 248 | android::base::StringPrintf("--payload=file://%s", path), |
| 249 | android::base::StringPrintf("--offset=%ld", payload_offset), |
| 250 | "--headers=" + std::string(payload_properties.begin(), |
| 251 | payload_properties.end()), |
| 252 | android::base::StringPrintf("--status_fd=%d", status_fd), |
| 253 | }; |
| 254 | return INSTALL_SUCCESS; |
| 255 | } |
| 256 | |
| 257 | #else |
| 258 | |
bigbiff | 1f9e484 | 2020-10-31 11:33:15 -0400 | [diff] [blame] | 259 | void read_source_target_build(ZipArchiveHandle zip __unused /*, std::vector<std::string>& log_buffer*/) {return;} |
Ethan Yonker | 58f2132 | 2018-08-24 11:17:36 -0500 | [diff] [blame] | 260 | |
Ethan Yonker | 941a899 | 2016-12-05 09:04:30 -0600 | [diff] [blame] | 261 | int |
bigbiff | 1f9e484 | 2020-10-31 11:33:15 -0400 | [diff] [blame] | 262 | abupdate_binary_command(__unused const char* path, __unused int retry_count, |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 263 | __unused int status_fd, __unused std::vector<std::string>* cmd) |
Ethan Yonker | 941a899 | 2016-12-05 09:04:30 -0600 | [diff] [blame] | 264 | { |
| 265 | printf("No support for AB OTA zips included\n"); |
| 266 | return INSTALL_CORRUPT; |
| 267 | } |
| 268 | |
| 269 | #endif |
| 270 | |
| 271 | int |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 272 | update_binary_command(const char* path, int retry_count, |
Ethan Yonker | 941a899 | 2016-12-05 09:04:30 -0600 | [diff] [blame] | 273 | int status_fd, std::vector<std::string>* cmd) |
| 274 | { |
| 275 | char charfd[16]; |
| 276 | sprintf(charfd, "%i", status_fd); |
| 277 | cmd->push_back(TMP_UPDATER_BINARY_PATH); |
| 278 | cmd->push_back(EXPAND(RECOVERY_API_VERSION)); |
| 279 | cmd->push_back(charfd); |
| 280 | cmd->push_back(path); |
| 281 | /**cmd = { |
| 282 | TMP_UPDATER_BINARY_PATH, |
| 283 | EXPAND(RECOVERY_API_VERSION), // defined in Android.mk |
| 284 | charfd, |
| 285 | path, |
| 286 | };*/ |
| 287 | if (retry_count > 0) |
| 288 | cmd->push_back("retry"); |
| 289 | return 0; |
| 290 | } |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 291 | |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 292 | // Verifes the compatibility info in a Treble-compatible package. Returns true directly if the |
| 293 | // entry doesn't exist. Note that the compatibility info is packed in a zip file inside the OTA |
| 294 | // package. |
bigbiff | 1f9e484 | 2020-10-31 11:33:15 -0400 | [diff] [blame] | 295 | bool verify_package_compatibility(ZipArchiveHandle zw) { |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 296 | printf("Verifying package compatibility...\n"); |
| 297 | |
| 298 | static constexpr const char* COMPATIBILITY_ZIP_ENTRY = "compatibility.zip"; |
bigbiff | 673c7ae | 2020-12-02 19:44:56 -0500 | [diff] [blame] | 299 | std::string compatibility_entry_name(COMPATIBILITY_ZIP_ENTRY); |
GarfieldHan | d216188 | 2021-11-29 00:04:53 +0800 | [diff] [blame] | 300 | ZipEntry64 compatibility_entry; |
bigbiff | 1f9e484 | 2020-10-31 11:33:15 -0400 | [diff] [blame] | 301 | if (FindEntry(zw, compatibility_entry_name, &compatibility_entry) != 0) { |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 302 | printf("Package doesn't contain %s entry\n", COMPATIBILITY_ZIP_ENTRY); |
| 303 | return true; |
| 304 | } |
| 305 | |
| 306 | std::string zip_content(compatibility_entry.uncompressed_length, '\0'); |
| 307 | int32_t ret; |
bigbiff | 1f9e484 | 2020-10-31 11:33:15 -0400 | [diff] [blame] | 308 | if ((ret = ExtractToMemory(zw, &compatibility_entry, |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 309 | reinterpret_cast<uint8_t*>(&zip_content[0]), |
| 310 | compatibility_entry.uncompressed_length)) != 0) { |
| 311 | printf("Failed to read %s: %s\n", COMPATIBILITY_ZIP_ENTRY, ErrorCodeString(ret)); |
| 312 | return false; |
| 313 | } |
| 314 | |
| 315 | ZipArchiveHandle zip_handle; |
| 316 | ret = OpenArchiveFromMemory(static_cast<void*>(const_cast<char*>(zip_content.data())), |
| 317 | zip_content.size(), COMPATIBILITY_ZIP_ENTRY, &zip_handle); |
| 318 | if (ret != 0) { |
| 319 | printf("Failed to OpenArchiveFromMemory: %s\n", ErrorCodeString(ret)); |
| 320 | return false; |
| 321 | } |
| 322 | |
| 323 | // Iterate all the entries inside COMPATIBILITY_ZIP_ENTRY and read the contents. |
| 324 | void* cookie; |
sekaiacg | 837e537 | 2021-12-11 09:28:55 +0800 | [diff] [blame] | 325 | ret = StartIteration(zip_handle, &cookie); |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 326 | if (ret != 0) { |
| 327 | printf("Failed to start iterating zip entries: %s\n", ErrorCodeString(ret)); |
| 328 | CloseArchive(zip_handle); |
| 329 | return false; |
| 330 | } |
| 331 | std::unique_ptr<void, decltype(&EndIteration)> guard(cookie, EndIteration); |
| 332 | |
| 333 | std::vector<std::string> compatibility_info; |
GarfieldHan | d216188 | 2021-11-29 00:04:53 +0800 | [diff] [blame] | 334 | ZipEntry64 info_entry; |
bigbiff | 673c7ae | 2020-12-02 19:44:56 -0500 | [diff] [blame] | 335 | std::string info_name; |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 336 | while (Next(cookie, &info_entry, &info_name) == 0) { |
| 337 | std::string content(info_entry.uncompressed_length, '\0'); |
| 338 | int32_t ret = ExtractToMemory(zip_handle, &info_entry, reinterpret_cast<uint8_t*>(&content[0]), |
| 339 | info_entry.uncompressed_length); |
| 340 | if (ret != 0) { |
bigbiff | 673c7ae | 2020-12-02 19:44:56 -0500 | [diff] [blame] | 341 | printf("Failed to read %s: %s\n", info_name.c_str(), ErrorCodeString(ret)); |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 342 | CloseArchive(zip_handle); |
| 343 | return false; |
| 344 | } |
| 345 | compatibility_info.emplace_back(std::move(content)); |
| 346 | } |
| 347 | CloseArchive(zip_handle); |
| 348 | |
bigbiff | 673c7ae | 2020-12-02 19:44:56 -0500 | [diff] [blame] | 349 | return true; |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 350 | } |