| 382 | } |
| 383 | |
| 384 | std::unique_ptr<const DexFile> DexFileLoader::OpenOneDexFileFromZip( |
| 385 | const DexZipArchive& zip_archive, |
| 386 | const char* entry_name, |
| 387 | const std::string& location, |
| 388 | bool verify, |
| 389 | bool verify_checksum, |
| 390 | std::string* error_msg, |
| 391 | ZipOpenErrorCode* error_code) const { |
| 392 | CHECK(!location.empty()); |
| 393 | std::unique_ptr<DexZipEntry> zip_entry(zip_archive.Find(entry_name, error_msg)); |
| 394 | if (zip_entry == nullptr) { |
| 395 | *error_code = ZipOpenErrorCode::kEntryNotFound; |
| 396 | return nullptr; |
| 397 | } |
| 398 | if (zip_entry->GetUncompressedLength() == 0) { |
| 399 | *error_msg = StringPrintf("Dex file '%s' has zero length", location.c_str()); |
| 400 | *error_code = ZipOpenErrorCode::kDexFileError; |
| 401 | return nullptr; |
| 402 | } |
| 403 | |
| 404 | std::vector<uint8_t> map(zip_entry->Extract(error_msg)); |
| 405 | if (map.size() == 0) { |
| 406 | *error_msg = StringPrintf("Failed to extract '%s' from '%s': %s", entry_name, location.c_str(), |
| 407 | error_msg->c_str()); |
| 408 | *error_code = ZipOpenErrorCode::kExtractToMemoryError; |
| 409 | return nullptr; |
| 410 | } |
| 411 | VerifyResult verify_result; |
| 412 | std::unique_ptr<const DexFile> dex_file = OpenCommon( |
| 413 | map.data(), |
| 414 | map.size(), |
| 415 | /*data_base*/ nullptr, |
| 416 | /*data_size*/ 0u, |
| 417 | location, |
| 418 | zip_entry->GetCrc32(), |
| 419 | /*oat_dex_file*/ nullptr, |
| 420 | verify, |
| 421 | verify_checksum, |
| 422 | error_msg, |
| 423 | std::make_unique<VectorContainer>(std::move(map)), |
| 424 | &verify_result); |
| 425 | if (dex_file == nullptr) { |
| 426 | if (verify_result == VerifyResult::kVerifyNotAttempted) { |
| 427 | *error_code = ZipOpenErrorCode::kDexFileError; |
| 428 | } else { |
| 429 | *error_code = ZipOpenErrorCode::kVerifyError; |
| 430 | } |
| 431 | return nullptr; |
| 432 | } |
| 433 | if (verify_result != VerifyResult::kVerifySucceeded) { |
| 434 | *error_code = ZipOpenErrorCode::kVerifyError; |
| 435 | return nullptr; |
| 436 | } |
| 437 | *error_code = ZipOpenErrorCode::kNoError; |
| 438 | return dex_file; |
| 439 | } |
| 440 | |
| 441 | // Technically we do not have a limitation with respect to the number of dex files that can be in a |
nothing calls this directly
no test coverage detected