Home | History | Annotate | Download | only in veridex
      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 
     20 #include "dex/method_reference.h"
     21 
     22 #include <iostream>
     23 #include <map>
     24 #include <set>
     25 #include <string>
     26 
     27 namespace art {
     28 
     29 class HiddenApi;
     30 struct HiddenApiStats;
     31 class VeridexResolver;
     32 
     33 /**
     34  * Reports potential uses of hidden APIs from static linking and reflection.
     35  */
     36 class HiddenApiFinder {
     37  public:
     38   explicit HiddenApiFinder(const HiddenApi& hidden_api) : hidden_api_(hidden_api) {}
     39 
     40   // Iterate over the dex files associated with the passed resolvers to report
     41   // hidden API uses.
     42   void Run(const std::vector<std::unique_ptr<VeridexResolver>>& app_resolvers);
     43 
     44   void Dump(std::ostream& os, HiddenApiStats* stats, bool dump_reflection);
     45 
     46  private:
     47   void CollectAccesses(VeridexResolver* resolver);
     48   void CheckMethod(uint32_t method_idx, VeridexResolver* resolver, MethodReference ref);
     49   void CheckField(uint32_t field_idx, VeridexResolver* resolver, MethodReference ref);
     50   void DumpReferences(std::ostream& os, const std::vector<MethodReference>& references);
     51 
     52   const HiddenApi& hidden_api_;
     53   std::set<std::string> classes_;
     54   std::set<std::string> strings_;
     55   std::map<std::string, std::vector<MethodReference>> reflection_locations_;
     56   std::map<std::string, std::vector<MethodReference>> method_locations_;
     57   std::map<std::string, std::vector<MethodReference>> field_locations_;
     58 };
     59 
     60 }  // namespace art
     61 
     62 #endif  // ART_TOOLS_VERIDEX_HIDDEN_API_FINDER_H_
     63