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 #ifndef ART_LIBDEXFILE_DEX_ART_DEX_FILE_LOADER_H_ 18 #define ART_LIBDEXFILE_DEX_ART_DEX_FILE_LOADER_H_ 19 20 #include <cstdint> 21 #include <memory> 22 #include <string> 23 #include <vector> 24 25 #include "base/macros.h" 26 #include "dex/dex_file_loader.h" 27 28 namespace art { 29 30 class DexFile; 31 class DexFileContainer; 32 class MemMap; 33 class OatDexFile; 34 class ZipArchive; 35 36 // Class that is used to open dex files and deal with corresponding multidex and location logic. 37 class ArtDexFileLoader : public DexFileLoader { 38 public: 39 using DexFileLoader::DexFileLoader; ~ArtDexFileLoader()40 virtual ~ArtDexFileLoader() { } 41 42 // Returns the checksums of a file for comparison with GetLocationChecksum(). 43 // For .dex files, this is the single header checksum. 44 // For zip files, this is the zip entry CRC32 checksum for classes.dex and 45 // each additional multidex entry classes2.dex, classes3.dex, etc. 46 // If a valid zip_fd is provided the file content will be read directly from 47 // the descriptor and `filename` will be used as alias for error logging. If 48 // zip_fd is -1, the method will try to open the `filename` and read the 49 // content from it. 50 // 51 // The dex_locations vector will be populated with the corresponding multidex 52 // locations. 53 // 54 // Return true if the checksums could be found, false otherwise. 55 static bool GetMultiDexChecksums(const char* filename, 56 std::vector<uint32_t>* checksums, 57 std::vector<std::string>* dex_locations, 58 std::string* error_msg, 59 int zip_fd = -1, 60 bool* only_contains_uncompressed_dex = nullptr); 61 62 // Don't shadow overloads from base class. 63 using DexFileLoader::Open; 64 65 // Old signature preserved for app-compat. 66 std::unique_ptr<const DexFile> Open(const uint8_t* base, 67 size_t size, 68 const std::string& location, 69 uint32_t location_checksum, 70 const OatDexFile* oat_dex_file, 71 bool verify, 72 bool verify_checksum, 73 std::string* error_msg, 74 std::unique_ptr<DexFileContainer> container) const; 75 76 // Old signature preserved for app-compat. 77 std::unique_ptr<const DexFile> Open(const std::string& location, 78 uint32_t location_checksum, 79 MemMap&& mem_map, 80 bool verify, 81 bool verify_checksum, 82 std::string* error_msg) const; 83 84 // Old signature preserved for app-compat. 85 bool Open(const char* filename, 86 const std::string& location, 87 bool verify, 88 bool verify_checksum, 89 std::string* error_msg, 90 std::vector<std::unique_ptr<const DexFile>>* dex_files) const; 91 }; 92 93 } // namespace art 94 95 #endif // ART_LIBDEXFILE_DEX_ART_DEX_FILE_LOADER_H_ 96