blob: f395e89b288809f8ca7a182615bd932507260028 [file] [log] [blame]
Nicolas Geoffray11ed0272018-03-28 18:18:48 +01001/*
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 Brazdild76e1232019-05-07 19:23:41 +010020#include "class_filter.h"
Nicolas Geoffray11ed0272018-03-28 18:18:48 +010021#include "dex/method_reference.h"
22
23#include <iostream>
24#include <map>
25#include <set>
26#include <string>
27
28namespace art {
29
30class HiddenApi;
Nicolas Geoffray2ebff052018-04-04 22:32:03 +010031struct HiddenApiStats;
Nicolas Geoffray11ed0272018-03-28 18:18:48 +010032class VeridexResolver;
33
34/**
35 * Reports potential uses of hidden APIs from static linking and reflection.
36 */
37class 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 Brazdild76e1232019-05-07 19:23:41 +010043 void Run(const std::vector<std::unique_ptr<VeridexResolver>>& app_resolvers,
44 const ClassFilter& app_class_filter);
Nicolas Geoffray11ed0272018-03-28 18:18:48 +010045
Nicolas Geoffray2ebff052018-04-04 22:32:03 +010046 void Dump(std::ostream& os, HiddenApiStats* stats, bool dump_reflection);
47
Nicolas Geoffray11ed0272018-03-28 18:18:48 +010048 private:
David Brazdild76e1232019-05-07 19:23:41 +010049 void CollectAccesses(VeridexResolver* resolver, const ClassFilter& class_filter);
Nicolas Geoffray11ed0272018-03-28 18:18:48 +010050 void CheckMethod(uint32_t method_idx, VeridexResolver* resolver, MethodReference ref);
51 void CheckField(uint32_t field_idx, VeridexResolver* resolver, MethodReference ref);
Anton Hanssonc7a6c472018-09-28 13:33:47 +010052 void DumpReferences(std::ostream& os, const std::vector<MethodReference>& references);
Nicolas Geoffray11ed0272018-03-28 18:18:48 +010053
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_