1 /* 2 * Copyright (C) 2016 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 __VTS_SYSFUZZER_COMMON_SPECPARSER_SPECBUILDER_H__ 18 #define __VTS_SYSFUZZER_COMMON_SPECPARSER_SPECBUILDER_H__ 19 20 #include <map> 21 #include <queue> 22 #include <string> 23 24 #include "test/vts/proto/ComponentSpecificationMessage.pb.h" 25 26 #include "fuzz_tester/FuzzerWrapper.h" 27 28 using namespace std; 29 30 #define DEFAULT_SPEC_DIR_PATH "/system/etc/" 31 #define SPEC_FILE_EXT ".vts" 32 33 namespace android { 34 namespace vts { 35 36 class FuzzerBase; 37 class InterfaceSpecification; 38 39 // Builder of an interface specification. 40 class SpecificationBuilder { 41 public: 42 // Constructor where the first argument is the path of a dir which contains 43 // all available interface specification files. 44 SpecificationBuilder(const string dir_path, int epoch_count, 45 const string& callback_socket_name); 46 47 // scans the dir and returns an interface specification for a requested 48 // component. 49 vts::ComponentSpecificationMessage* FindComponentSpecification( 50 const int target_class, const int target_type, const float target_version, 51 const string submodule_name = "", const string package = "", 52 const string component_name = ""); 53 54 vts::ComponentSpecificationMessage* 55 FindComponentSpecification(const string& component_name); 56 57 // Returns FuzzBase for a given interface specification, and adds all the 58 // found functions to the fuzzing job queue. 59 FuzzerBase* GetFuzzerBaseAndAddAllFunctionsToQueue( 60 const vts::ComponentSpecificationMessage& iface_spec_msg, 61 const char* dll_file_name); 62 63 const string& CallFunction(FunctionSpecificationMessage* func_msg); 64 65 const string& GetAttribute(FunctionSpecificationMessage* func_msg); 66 67 // Main function for the VTS system fuzzer where dll_file_name is the path of 68 // a target component, spec_lib_file_path is the path of a specification 69 // library file, and the rest three arguments are the basic information of 70 // the target component. 71 bool Process(const char* dll_file_name, const char* spec_lib_file_path, 72 int target_class, int target_type, float target_version, 73 const char* target_package, const char* target_component_name); 74 75 bool LoadTargetComponent(const char* dll_file_name, 76 const char* spec_lib_file_path, int target_class, 77 int target_type, float target_version, 78 const char* target_package, 79 const char* target_component_name, 80 const char* hw_binder_service_name, 81 const char* module_name); 82 83 FuzzerBase* GetFuzzerBase( 84 const ComponentSpecificationMessage& iface_spec_msg, 85 const char* dll_file_name, const char* target_func_name); 86 87 FuzzerBase* GetFuzzerBaseSubModule( 88 const vts::ComponentSpecificationMessage& iface_spec_msg, 89 void* object_pointer); 90 91 // Returns the loaded interface specification message. 92 ComponentSpecificationMessage* GetComponentSpecification() const; 93 94 private: 95 // A FuzzerWrapper instance. 96 FuzzerWrapper wrapper_; 97 // the path of a dir which contains interface specification ASCII proto files. 98 const string dir_path_; 99 // the total number of epochs 100 const int epoch_count_; 101 // fuzzing job queue. 102 queue<pair<FunctionSpecificationMessage*, FuzzerBase*>> job_queue_; 103 // Loaded interface specification message. 104 ComponentSpecificationMessage* if_spec_msg_; 105 // TODO: use unique_ptr 106 char* spec_lib_file_path_; 107 char* dll_file_name_; 108 char* module_name_; 109 // HW binder service name only used for HIDL HAL 110 char* hw_binder_service_name_; 111 // the server socket port # of the agent. 112 const string& callback_socket_name_; 113 // map for submodule interface specification messages. 114 map<string, ComponentSpecificationMessage*> submodule_if_spec_map_; 115 map<string, FuzzerBase*> submodule_fuzzerbase_map_; 116 }; 117 118 } // namespace vts 119 } // namespace android 120 121 #endif // __VTS_SYSFUZZER_COMMON_SPECPARSER_SPECBUILDER_H__ 122