1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2017 The Android Open Source Project
3*795d594fSAndroid Build Coastguard Worker *
4*795d594fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*795d594fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*795d594fSAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*795d594fSAndroid Build Coastguard Worker *
8*795d594fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*795d594fSAndroid Build Coastguard Worker *
10*795d594fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*795d594fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*795d594fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*795d594fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*795d594fSAndroid Build Coastguard Worker * limitations under the License.
15*795d594fSAndroid Build Coastguard Worker */
16*795d594fSAndroid Build Coastguard Worker
17*795d594fSAndroid Build Coastguard Worker #include "art_dex_file_loader.h"
18*795d594fSAndroid Build Coastguard Worker
19*795d594fSAndroid Build Coastguard Worker #include <sys/stat.h>
20*795d594fSAndroid Build Coastguard Worker
21*795d594fSAndroid Build Coastguard Worker #include <memory>
22*795d594fSAndroid Build Coastguard Worker
23*795d594fSAndroid Build Coastguard Worker #include "android-base/stringprintf.h"
24*795d594fSAndroid Build Coastguard Worker #include "base/file_magic.h"
25*795d594fSAndroid Build Coastguard Worker #include "base/file_utils.h"
26*795d594fSAndroid Build Coastguard Worker #include "base/logging.h"
27*795d594fSAndroid Build Coastguard Worker #include "base/mem_map.h"
28*795d594fSAndroid Build Coastguard Worker #include "base/mman.h" // For the PROT_* and MAP_* constants.
29*795d594fSAndroid Build Coastguard Worker #include "base/stl_util.h"
30*795d594fSAndroid Build Coastguard Worker #include "base/systrace.h"
31*795d594fSAndroid Build Coastguard Worker #include "base/unix_file/fd_file.h"
32*795d594fSAndroid Build Coastguard Worker #include "base/zip_archive.h"
33*795d594fSAndroid Build Coastguard Worker #include "dex/compact_dex_file.h"
34*795d594fSAndroid Build Coastguard Worker #include "dex/dex_file.h"
35*795d594fSAndroid Build Coastguard Worker #include "dex/dex_file_verifier.h"
36*795d594fSAndroid Build Coastguard Worker #include "dex/standard_dex_file.h"
37*795d594fSAndroid Build Coastguard Worker
38*795d594fSAndroid Build Coastguard Worker namespace art {
39*795d594fSAndroid Build Coastguard Worker
Open(const uint8_t * base,size_t size,const std::string & location,uint32_t location_checksum,const OatDexFile * oat_dex_file,bool verify,bool verify_checksum,std::string * error_msg,std::unique_ptr<DexFileContainer> container) const40*795d594fSAndroid Build Coastguard Worker std::unique_ptr<const DexFile> ArtDexFileLoader::Open(
41*795d594fSAndroid Build Coastguard Worker const uint8_t* base,
42*795d594fSAndroid Build Coastguard Worker size_t size,
43*795d594fSAndroid Build Coastguard Worker const std::string& location,
44*795d594fSAndroid Build Coastguard Worker uint32_t location_checksum,
45*795d594fSAndroid Build Coastguard Worker const OatDexFile* oat_dex_file,
46*795d594fSAndroid Build Coastguard Worker bool verify,
47*795d594fSAndroid Build Coastguard Worker bool verify_checksum,
48*795d594fSAndroid Build Coastguard Worker std::string* error_msg,
49*795d594fSAndroid Build Coastguard Worker std::unique_ptr<DexFileContainer> container) const {
50*795d594fSAndroid Build Coastguard Worker return OpenCommon(base,
51*795d594fSAndroid Build Coastguard Worker size,
52*795d594fSAndroid Build Coastguard Worker /*data_base=*/nullptr,
53*795d594fSAndroid Build Coastguard Worker /*data_size=*/0,
54*795d594fSAndroid Build Coastguard Worker location,
55*795d594fSAndroid Build Coastguard Worker location_checksum,
56*795d594fSAndroid Build Coastguard Worker oat_dex_file,
57*795d594fSAndroid Build Coastguard Worker verify,
58*795d594fSAndroid Build Coastguard Worker verify_checksum,
59*795d594fSAndroid Build Coastguard Worker error_msg,
60*795d594fSAndroid Build Coastguard Worker std::move(container),
61*795d594fSAndroid Build Coastguard Worker /*verify_result=*/nullptr);
62*795d594fSAndroid Build Coastguard Worker }
63*795d594fSAndroid Build Coastguard Worker
Open(const std::string & location,uint32_t location_checksum,MemMap && mem_map,bool verify,bool verify_checksum,std::string * error_msg) const64*795d594fSAndroid Build Coastguard Worker std::unique_ptr<const DexFile> ArtDexFileLoader::Open(const std::string& location,
65*795d594fSAndroid Build Coastguard Worker uint32_t location_checksum,
66*795d594fSAndroid Build Coastguard Worker MemMap&& mem_map,
67*795d594fSAndroid Build Coastguard Worker bool verify,
68*795d594fSAndroid Build Coastguard Worker bool verify_checksum,
69*795d594fSAndroid Build Coastguard Worker std::string* error_msg) const {
70*795d594fSAndroid Build Coastguard Worker ArtDexFileLoader loader(std::move(mem_map), location);
71*795d594fSAndroid Build Coastguard Worker return loader.Open(location_checksum, verify, verify_checksum, error_msg);
72*795d594fSAndroid Build Coastguard Worker }
73*795d594fSAndroid Build Coastguard Worker
Open(const char * filename,const std::string & location,bool verify,bool verify_checksum,std::string * error_msg,std::vector<std::unique_ptr<const DexFile>> * dex_files) const74*795d594fSAndroid Build Coastguard Worker bool ArtDexFileLoader::Open(const char* filename,
75*795d594fSAndroid Build Coastguard Worker const std::string& location,
76*795d594fSAndroid Build Coastguard Worker bool verify,
77*795d594fSAndroid Build Coastguard Worker bool verify_checksum,
78*795d594fSAndroid Build Coastguard Worker std::string* error_msg,
79*795d594fSAndroid Build Coastguard Worker std::vector<std::unique_ptr<const DexFile>>* dex_files) const {
80*795d594fSAndroid Build Coastguard Worker ArtDexFileLoader loader(filename, location);
81*795d594fSAndroid Build Coastguard Worker return loader.Open(verify, verify_checksum, error_msg, dex_files);
82*795d594fSAndroid Build Coastguard Worker }
83*795d594fSAndroid Build Coastguard Worker
84*795d594fSAndroid Build Coastguard Worker } // namespace art
85