1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "module_load_checker.h"
17
18 #include "utils/log.h"
19
SetModuleBlocklist(std::unordered_map<int32_t,std::unordered_set<std::string>> && blocklist)20 void ModuleLoadChecker::SetModuleBlocklist(
21 std::unordered_map<int32_t, std::unordered_set<std::string>>&& blocklist)
22 {
23 moduleBlocklist_ = std::move(blocklist);
24 HILOG_INFO("moduleBlocklist_ size = %{public}d", static_cast<int32_t>(moduleBlocklist_.size()));
25 }
26
SetProcessExtensionType(int32_t extensionType)27 void ModuleLoadChecker::SetProcessExtensionType(int32_t extensionType)
28 {
29 processExtensionType_ = extensionType;
30 }
31
GetProcessExtensionType()32 int32_t ModuleLoadChecker::GetProcessExtensionType()
33 {
34 return processExtensionType_;
35 }
36
CheckModuleLoadable(const char * moduleName)37 bool ModuleLoadChecker::CheckModuleLoadable(const char* moduleName)
38 {
39 HILOG_INFO("check blocklist, moduleName = %{public}s, processExtensionType_ = %{public}d",
40 moduleName, static_cast<int32_t>(processExtensionType_));
41 const auto& blockListIter = moduleBlocklist_.find(processExtensionType_);
42 if (blockListIter == moduleBlocklist_.end()) {
43 return true;
44 }
45 auto blackList = blockListIter->second;
46 if (blackList.find(moduleName) == blackList.end()) {
47 return true;
48 }
49 return false;
50 }