| Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 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 |  | 
| Christopher Ferris | d70ea5e | 2018-01-30 19:47:24 -0800 | [diff] [blame] | 17 | #ifndef _LIBUNWINDSTACK_DEX_FILE_H | 
|  | 18 | #define _LIBUNWINDSTACK_DEX_FILE_H | 
| Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 19 |  | 
|  | 20 | #include <stdint.h> | 
|  | 21 |  | 
| David Srbecky | 02d0f79 | 2018-03-24 00:29:14 +0000 | [diff] [blame] | 22 | #include <map> | 
| Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 23 | #include <memory> | 
|  | 24 | #include <string> | 
| David Srbecky | 02d0f79 | 2018-03-24 00:29:14 +0000 | [diff] [blame] | 25 | #include <utility> | 
| Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 26 | #include <vector> | 
|  | 27 |  | 
| Martin Stjernholm | b49289b | 2018-12-14 15:26:32 +0000 | [diff] [blame] | 28 | #include <art_api/dex_file_support.h> | 
| Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 29 |  | 
|  | 30 | namespace unwindstack { | 
| Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 31 |  | 
| Martin Stjernholm | bb4f2b4 | 2018-12-19 14:28:33 +0000 | [diff] [blame] | 32 | class DexFile : protected art_api::dex::DexFile { | 
| Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 33 | public: | 
| Christopher Ferris | d70ea5e | 2018-01-30 19:47:24 -0800 | [diff] [blame] | 34 | virtual ~DexFile() = default; | 
| Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 35 |  | 
| David Srbecky | b9cc4fb | 2019-04-05 18:23:32 +0000 | [diff] [blame] | 36 | bool GetMethodInformation(uint64_t dex_offset, std::string* method_name, uint64_t* method_offset); | 
| Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 37 |  | 
| Martin Stjernholm | bb4f2b4 | 2018-12-19 14:28:33 +0000 | [diff] [blame] | 38 | static std::unique_ptr<DexFile> Create(uint64_t dex_file_offset_in_memory, Memory* memory, | 
|  | 39 | MapInfo* info); | 
| Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 40 |  | 
|  | 41 | protected: | 
| Yong Li | 489c3a8 | 2020-03-19 18:43:06 +0000 | [diff] [blame] | 42 | DexFile(std::unique_ptr<art_api::dex::DexFile>& art_dex_file) | 
|  | 43 | : art_api::dex::DexFile(art_dex_file) {} | 
| Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 44 | }; | 
|  | 45 |  | 
| Christopher Ferris | d70ea5e | 2018-01-30 19:47:24 -0800 | [diff] [blame] | 46 | class DexFileFromFile : public DexFile { | 
| Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 47 | public: | 
| Martin Stjernholm | bb4f2b4 | 2018-12-19 14:28:33 +0000 | [diff] [blame] | 48 | static std::unique_ptr<DexFileFromFile> Create(uint64_t dex_file_offset_in_file, | 
|  | 49 | const std::string& file); | 
| Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 50 |  | 
|  | 51 | private: | 
| Yong Li | 489c3a8 | 2020-03-19 18:43:06 +0000 | [diff] [blame] | 52 | DexFileFromFile(std::unique_ptr<art_api::dex::DexFile>& art_dex_file) : DexFile(art_dex_file) {} | 
| Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 53 | }; | 
|  | 54 |  | 
| Christopher Ferris | d70ea5e | 2018-01-30 19:47:24 -0800 | [diff] [blame] | 55 | class DexFileFromMemory : public DexFile { | 
| Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 56 | public: | 
| Martin Stjernholm | bb4f2b4 | 2018-12-19 14:28:33 +0000 | [diff] [blame] | 57 | static std::unique_ptr<DexFileFromMemory> Create(uint64_t dex_file_offset_in_memory, | 
|  | 58 | Memory* memory, const std::string& name); | 
| Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 59 |  | 
|  | 60 | private: | 
| Yong Li | 489c3a8 | 2020-03-19 18:43:06 +0000 | [diff] [blame] | 61 | DexFileFromMemory(std::unique_ptr<art_api::dex::DexFile>& art_dex_file, | 
|  | 62 | std::vector<uint8_t>&& memory) | 
|  | 63 | : DexFile(art_dex_file), memory_(std::move(memory)) {} | 
| Martin Stjernholm | bb4f2b4 | 2018-12-19 14:28:33 +0000 | [diff] [blame] | 64 |  | 
| Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 65 | std::vector<uint8_t> memory_; | 
|  | 66 | }; | 
|  | 67 |  | 
| Christopher Ferris | d70ea5e | 2018-01-30 19:47:24 -0800 | [diff] [blame] | 68 | }  // namespace unwindstack | 
|  | 69 |  | 
|  | 70 | #endif  // _LIBUNWINDSTACK_DEX_FILE_H |