Nicolas Geoffray | dd96ed3 | 2018-03-21 11:00:14 +0000 | [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 | |
| 17 | #ifndef ART_TOOLS_VERIDEX_RESOLVER_H_ |
| 18 | #define ART_TOOLS_VERIDEX_RESOLVER_H_ |
| 19 | |
| 20 | #include "dex/dex_file.h" |
| 21 | #include "veridex.h" |
| 22 | |
| 23 | namespace art { |
| 24 | |
Nicolas Geoffray | e826477 | 2018-03-22 22:16:41 +0000 | [diff] [blame^] | 25 | class VeridexResolver; |
| 26 | |
| 27 | /** |
| 28 | * Map from the start of a dex file (ie DexFile::Begin()), to |
| 29 | * its corresponding resolver. |
| 30 | */ |
| 31 | using DexResolverMap = std::map<uintptr_t, VeridexResolver*>; |
| 32 | |
Nicolas Geoffray | dd96ed3 | 2018-03-21 11:00:14 +0000 | [diff] [blame] | 33 | class VeridexResolver { |
| 34 | public: |
Nicolas Geoffray | e826477 | 2018-03-22 22:16:41 +0000 | [diff] [blame^] | 35 | VeridexResolver(const DexFile& dex_file, |
| 36 | const DexResolverMap& dex_resolvers, |
| 37 | TypeMap& type_map) |
Nicolas Geoffray | dd96ed3 | 2018-03-21 11:00:14 +0000 | [diff] [blame] | 38 | : dex_file_(dex_file), |
| 39 | type_map_(type_map), |
Nicolas Geoffray | e826477 | 2018-03-22 22:16:41 +0000 | [diff] [blame^] | 40 | dex_resolvers_(dex_resolvers), |
Nicolas Geoffray | dd96ed3 | 2018-03-21 11:00:14 +0000 | [diff] [blame] | 41 | type_infos_(dex_file.NumTypeIds(), VeriClass()), |
| 42 | method_infos_(dex_file.NumMethodIds(), nullptr), |
| 43 | field_infos_(dex_file.NumFieldIds(), nullptr) {} |
| 44 | |
Nicolas Geoffray | e826477 | 2018-03-22 22:16:41 +0000 | [diff] [blame^] | 45 | // Run on the defined classes of that dex file and populate our |
| 46 | // local type cache. |
Nicolas Geoffray | dd96ed3 | 2018-03-21 11:00:14 +0000 | [diff] [blame] | 47 | void Run(); |
| 48 | |
Nicolas Geoffray | e826477 | 2018-03-22 22:16:41 +0000 | [diff] [blame^] | 49 | // Return the class declared at `index`. |
| 50 | VeriClass* GetVeriClass(dex::TypeIndex index); |
| 51 | |
| 52 | // Return the method declared at `method_index`. |
| 53 | VeriMethod GetMethod(uint32_t method_index); |
| 54 | |
| 55 | // Return the field declared at `field_index`. |
| 56 | VeriField GetField(uint32_t field_index); |
| 57 | |
| 58 | // Do a JLS lookup in `kls` to find a method. |
| 59 | VeriMethod LookupMethodIn(const VeriClass& kls, |
| 60 | const char* method_name, |
| 61 | const Signature& method_signature); |
| 62 | |
| 63 | // Do a JLS lookup in `kls` to find a field. |
| 64 | VeriField LookupFieldIn(const VeriClass& kls, |
| 65 | const char* field_name, |
| 66 | const char* field_type); |
| 67 | |
| 68 | // Resolve all type_id/method_id/field_id. |
| 69 | void ResolveAll(); |
| 70 | |
Nicolas Geoffray | dd96ed3 | 2018-03-21 11:00:14 +0000 | [diff] [blame] | 71 | private: |
Nicolas Geoffray | e826477 | 2018-03-22 22:16:41 +0000 | [diff] [blame^] | 72 | // Return the resolver where `kls` is from. |
| 73 | VeridexResolver* GetResolverOf(const VeriClass& kls) const; |
| 74 | |
Nicolas Geoffray | dd96ed3 | 2018-03-21 11:00:14 +0000 | [diff] [blame] | 75 | const DexFile& dex_file_; |
| 76 | TypeMap& type_map_; |
Nicolas Geoffray | e826477 | 2018-03-22 22:16:41 +0000 | [diff] [blame^] | 77 | const DexResolverMap& dex_resolvers_; |
Nicolas Geoffray | dd96ed3 | 2018-03-21 11:00:14 +0000 | [diff] [blame] | 78 | std::vector<VeriClass> type_infos_; |
| 79 | std::vector<VeriMethod> method_infos_; |
| 80 | std::vector<VeriField> field_infos_; |
| 81 | }; |
| 82 | |
| 83 | } // namespace art |
| 84 | |
| 85 | #endif // ART_TOOLS_VERIDEX_RESOLVER_H_ |