• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_PRECISE_HIDDEN_API_FINDER_H_
18 #define ART_TOOLS_VERIDEX_PRECISE_HIDDEN_API_FINDER_H_
19 
20 #include "class_filter.h"
21 #include "dex/method_reference.h"
22 #include "flow_analysis.h"
23 
24 #include <iostream>
25 #include <map>
26 #include <set>
27 #include <string>
28 
29 namespace art {
30 
31 class HiddenApi;
32 struct HiddenApiStats;
33 class VeridexResolver;
34 
35 /**
36  * Reports known uses of hidden APIs from reflection.
37  */
38 class PreciseHiddenApiFinder {
39  public:
PreciseHiddenApiFinder(const HiddenApi & hidden_api)40   explicit PreciseHiddenApiFinder(const HiddenApi& hidden_api) : hidden_api_(hidden_api) {}
41 
42   // Iterate over the dex files associated with the passed resolvers to report
43   // hidden API uses.
44   void Run(const std::vector<std::unique_ptr<VeridexResolver>>& app_resolvers,
45            const ClassFilter& app_class_filter);
46 
47   void Dump(std::ostream& os, HiddenApiStats* stats);
48 
49  private:
50   // Run over all methods of all dex files, and call `action` on each.
51   void RunInternal(
52       const std::vector<std::unique_ptr<VeridexResolver>>& resolvers,
53       const ClassFilter& class_filter,
54       const std::function<void(VeridexResolver*, const ClassAccessor::Method&)>& action);
55 
56   // Add uses found in method `ref`.
57   void AddUsesAt(const std::vector<ReflectAccessInfo>& accesses, MethodReference ref);
58 
59   const HiddenApi& hidden_api_;
60 
61   std::map<MethodReference, std::vector<ReflectAccessInfo>> concrete_uses_;
62   std::map<MethodReference, std::vector<ReflectAccessInfo>> abstract_uses_;
63 };
64 
65 }  // namespace art
66 
67 #endif  // ART_TOOLS_VERIDEX_PRECISE_HIDDEN_API_FINDER_H_
68