| 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 |  | 
 | 28 | #include <dex/dex_file-inl.h> | 
 | 29 |  | 
 | 30 | namespace unwindstack { | 
| Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 31 |  | 
| Christopher Ferris | d70ea5e | 2018-01-30 19:47:24 -0800 | [diff] [blame] | 32 | class 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 |   DexFile() = default; | 
 | 35 |   virtual ~DexFile() = default; | 
| Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 36 |  | 
| Christopher Ferris | 7747b60 | 2018-01-31 19:05:19 -0800 | [diff] [blame] | 37 |   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] | 38 |  | 
| Christopher Ferris | d70ea5e | 2018-01-30 19:47:24 -0800 | [diff] [blame] | 39 |   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] | 40 |  | 
 | 41 |  protected: | 
| David Srbecky | 02d0f79 | 2018-03-24 00:29:14 +0000 | [diff] [blame] | 42 |   void Init(); | 
 | 43 |  | 
| Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 44 |   std::unique_ptr<const art::DexFile> dex_file_; | 
| David Srbecky | 02d0f79 | 2018-03-24 00:29:14 +0000 | [diff] [blame] | 45 |   std::map<uint32_t, std::pair<uint64_t, uint32_t>> method_cache_;  // dex offset to method index. | 
 | 46 |  | 
 | 47 |   uint32_t class_def_index_ = 0; | 
| Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 48 | }; | 
 | 49 |  | 
| Christopher Ferris | d70ea5e | 2018-01-30 19:47:24 -0800 | [diff] [blame] | 50 | class DexFileFromFile : public DexFile { | 
| Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 51 |  public: | 
| Christopher Ferris | d70ea5e | 2018-01-30 19:47:24 -0800 | [diff] [blame] | 52 |   DexFileFromFile() = default; | 
 | 53 |   virtual ~DexFileFromFile(); | 
| Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 54 |  | 
 | 55 |   bool Open(uint64_t dex_file_offset_in_file, const std::string& name); | 
 | 56 |  | 
 | 57 |  private: | 
 | 58 |   void* mapped_memory_ = nullptr; | 
 | 59 |   size_t size_ = 0; | 
 | 60 | }; | 
 | 61 |  | 
| Christopher Ferris | d70ea5e | 2018-01-30 19:47:24 -0800 | [diff] [blame] | 62 | class DexFileFromMemory : public DexFile { | 
| Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 63 |  public: | 
| Christopher Ferris | d70ea5e | 2018-01-30 19:47:24 -0800 | [diff] [blame] | 64 |   DexFileFromMemory() = default; | 
 | 65 |   virtual ~DexFileFromMemory() = default; | 
| Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 66 |  | 
| Christopher Ferris | d70ea5e | 2018-01-30 19:47:24 -0800 | [diff] [blame] | 67 |   bool Open(uint64_t dex_file_offset_in_memory, Memory* memory); | 
| Christopher Ferris | 0b06a59 | 2018-01-19 10:26:36 -0800 | [diff] [blame] | 68 |  | 
 | 69 |  private: | 
 | 70 |   std::vector<uint8_t> memory_; | 
 | 71 | }; | 
 | 72 |  | 
| Christopher Ferris | d70ea5e | 2018-01-30 19:47:24 -0800 | [diff] [blame] | 73 | }  // namespace unwindstack | 
 | 74 |  | 
 | 75 | #endif  // _LIBUNWINDSTACK_DEX_FILE_H |