1 /* 2 * Copyright (C) 2018 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 _LIBUNWINDSTACK_DEX_FILE_H 18 #define _LIBUNWINDSTACK_DEX_FILE_H 19 20 #include <stdint.h> 21 22 #include <map> 23 #include <memory> 24 #include <string> 25 #include <utility> 26 #include <vector> 27 28 #include <art_api/dex_file_support.h> 29 30 namespace unwindstack { 31 32 class DexFile : protected art_api::dex::DexFile { 33 public: 34 virtual ~DexFile() = default; 35 36 bool GetMethodInformation(uint64_t dex_offset, std::string* method_name, uint64_t* method_offset); 37 38 static std::unique_ptr<DexFile> Create(uint64_t dex_file_offset_in_memory, Memory* memory, 39 MapInfo* info); 40 41 protected: DexFile(std::unique_ptr<art_api::dex::DexFile> & art_dex_file)42 DexFile(std::unique_ptr<art_api::dex::DexFile>& art_dex_file) 43 : art_api::dex::DexFile(art_dex_file) {} 44 }; 45 46 class DexFileFromFile : public DexFile { 47 public: 48 static std::unique_ptr<DexFileFromFile> Create(uint64_t dex_file_offset_in_file, 49 const std::string& file); 50 51 private: DexFileFromFile(std::unique_ptr<art_api::dex::DexFile> & art_dex_file)52 DexFileFromFile(std::unique_ptr<art_api::dex::DexFile>& art_dex_file) : DexFile(art_dex_file) {} 53 }; 54 55 class DexFileFromMemory : public DexFile { 56 public: 57 static std::unique_ptr<DexFileFromMemory> Create(uint64_t dex_file_offset_in_memory, 58 Memory* memory, const std::string& name, 59 size_t max_size); 60 61 private: DexFileFromMemory(std::unique_ptr<art_api::dex::DexFile> & art_dex_file,std::vector<uint8_t> && memory)62 DexFileFromMemory(std::unique_ptr<art_api::dex::DexFile>& art_dex_file, 63 std::vector<uint8_t>&& memory) 64 : DexFile(art_dex_file), memory_(std::move(memory)) {} 65 66 std::vector<uint8_t> memory_; 67 }; 68 69 } // namespace unwindstack 70 71 #endif // _LIBUNWINDSTACK_DEX_FILE_H 72