Nicolas Geoffray | 11ed027 | 2018-03-28 18:18:48 +0100 | [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_HIDDEN_API_FINDER_H_ |
| 18 | #define ART_TOOLS_VERIDEX_HIDDEN_API_FINDER_H_ |
| 19 | |
David Brazdil | d76e123 | 2019-05-07 19:23:41 +0100 | [diff] [blame] | 20 | #include "class_filter.h" |
Nicolas Geoffray | 11ed027 | 2018-03-28 18:18:48 +0100 | [diff] [blame] | 21 | #include "dex/method_reference.h" |
| 22 | |
| 23 | #include <iostream> |
| 24 | #include <map> |
| 25 | #include <set> |
| 26 | #include <string> |
| 27 | |
| 28 | namespace art { |
| 29 | |
| 30 | class HiddenApi; |
Nicolas Geoffray | 2ebff05 | 2018-04-04 22:32:03 +0100 | [diff] [blame] | 31 | struct HiddenApiStats; |
Nicolas Geoffray | 11ed027 | 2018-03-28 18:18:48 +0100 | [diff] [blame] | 32 | class VeridexResolver; |
| 33 | |
| 34 | /** |
| 35 | * Reports potential uses of hidden APIs from static linking and reflection. |
| 36 | */ |
| 37 | class HiddenApiFinder { |
| 38 | public: |
| 39 | explicit HiddenApiFinder(const HiddenApi& hidden_api) : hidden_api_(hidden_api) {} |
| 40 | |
| 41 | // Iterate over the dex files associated with the passed resolvers to report |
| 42 | // hidden API uses. |
David Brazdil | d76e123 | 2019-05-07 19:23:41 +0100 | [diff] [blame] | 43 | void Run(const std::vector<std::unique_ptr<VeridexResolver>>& app_resolvers, |
| 44 | const ClassFilter& app_class_filter); |
Nicolas Geoffray | 11ed027 | 2018-03-28 18:18:48 +0100 | [diff] [blame] | 45 | |
Nicolas Geoffray | 2ebff05 | 2018-04-04 22:32:03 +0100 | [diff] [blame] | 46 | void Dump(std::ostream& os, HiddenApiStats* stats, bool dump_reflection); |
| 47 | |
Nicolas Geoffray | 11ed027 | 2018-03-28 18:18:48 +0100 | [diff] [blame] | 48 | private: |
David Brazdil | d76e123 | 2019-05-07 19:23:41 +0100 | [diff] [blame] | 49 | void CollectAccesses(VeridexResolver* resolver, const ClassFilter& class_filter); |
Nicolas Geoffray | 11ed027 | 2018-03-28 18:18:48 +0100 | [diff] [blame] | 50 | void CheckMethod(uint32_t method_idx, VeridexResolver* resolver, MethodReference ref); |
| 51 | void CheckField(uint32_t field_idx, VeridexResolver* resolver, MethodReference ref); |
Anton Hansson | c7a6c47 | 2018-09-28 13:33:47 +0100 | [diff] [blame] | 52 | void DumpReferences(std::ostream& os, const std::vector<MethodReference>& references); |
Nicolas Geoffray | 11ed027 | 2018-03-28 18:18:48 +0100 | [diff] [blame] | 53 | |
| 54 | const HiddenApi& hidden_api_; |
| 55 | std::set<std::string> classes_; |
| 56 | std::set<std::string> strings_; |
| 57 | std::map<std::string, std::vector<MethodReference>> reflection_locations_; |
| 58 | std::map<std::string, std::vector<MethodReference>> method_locations_; |
| 59 | std::map<std::string, std::vector<MethodReference>> field_locations_; |
| 60 | }; |
| 61 | |
| 62 | } // namespace art |
| 63 | |
| 64 | #endif // ART_TOOLS_VERIDEX_HIDDEN_API_FINDER_H_ |