| 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 |  | 
|  | 22 | #include <memory> | 
|  | 23 | #include <string> | 
|  | 24 | #include <vector> | 
|  | 25 |  | 
|  | 26 | #include <dex/dex_file-inl.h> | 
|  | 27 |  | 
|  | 28 | namespace unwindstack { | 
| Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 29 |  | 
| Christopher Ferris | d70ea5e | 2018-01-30 19:47:24 -0800 | [diff] [blame] | 30 | class DexFile { | 
| Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 31 | public: | 
| Christopher Ferris | d70ea5e | 2018-01-30 19:47:24 -0800 | [diff] [blame] | 32 | DexFile() = default; | 
|  | 33 | virtual ~DexFile() = default; | 
| Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 34 |  | 
| Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 35 | 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] | 36 |  | 
| Christopher Ferris | d70ea5e | 2018-01-30 19:47:24 -0800 | [diff] [blame] | 37 | static DexFile* Create(uint64_t dex_file_offset_in_memory, Memory* memory, MapInfo* info); | 
| Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 38 |  | 
|  | 39 | protected: | 
|  | 40 | std::unique_ptr<const art::DexFile> dex_file_; | 
|  | 41 | }; | 
|  | 42 |  | 
| Christopher Ferris | d70ea5e | 2018-01-30 19:47:24 -0800 | [diff] [blame] | 43 | class DexFileFromFile : public DexFile { | 
| Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 44 | public: | 
| Christopher Ferris | d70ea5e | 2018-01-30 19:47:24 -0800 | [diff] [blame] | 45 | DexFileFromFile() = default; | 
|  | 46 | virtual ~DexFileFromFile(); | 
| Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 47 |  | 
|  | 48 | bool Open(uint64_t dex_file_offset_in_file, const std::string& name); | 
|  | 49 |  | 
|  | 50 | private: | 
|  | 51 | void* mapped_memory_ = nullptr; | 
|  | 52 | size_t size_ = 0; | 
|  | 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: | 
| Christopher Ferris | d70ea5e | 2018-01-30 19:47:24 -0800 | [diff] [blame] | 57 | DexFileFromMemory() = default; | 
|  | 58 | virtual ~DexFileFromMemory() = default; | 
| Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 59 |  | 
| Christopher Ferris | d70ea5e | 2018-01-30 19:47:24 -0800 | [diff] [blame] | 60 | bool Open(uint64_t dex_file_offset_in_memory, Memory* memory); | 
| Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 61 |  | 
|  | 62 | private: | 
|  | 63 | std::vector<uint8_t> memory_; | 
|  | 64 | }; | 
|  | 65 |  | 
| Christopher Ferris | d70ea5e | 2018-01-30 19:47:24 -0800 | [diff] [blame] | 66 | }  // namespace unwindstack | 
|  | 67 |  | 
|  | 68 | #endif  // _LIBUNWINDSTACK_DEX_FILE_H |