• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2024 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 "verification/config/context/context.h"
17 
18 #include "utils/logger.h"
19 
20 namespace ark::verifier::debug {
21 
AddWhitelistMethodConfig(WhitelistKind kind,const PandaString & name)22 void DebugConfig::AddWhitelistMethodConfig(WhitelistKind kind, const PandaString &name)
23 {
24     whitelistNames[static_cast<size_t>(kind)].push_back(name);
25     whitelistNotEmpty = true;
26 }
27 
InWhitelist(WhitelistKind kind,uint64_t id) const28 bool DebugContext::InWhitelist(WhitelistKind kind, uint64_t id) const
29 {
30     return config->whitelistNotEmpty && whitelist.id[static_cast<size_t>(kind)]->count(id) > 0;
31 }
32 
InsertIntoWhitelist(const PandaString & name,bool isClassName,Method::UniqId id)33 void DebugContext::InsertIntoWhitelist(const PandaString &name, bool isClassName, Method::UniqId id)
34 {
35     auto kindsToAdd = isClassName
36                           ? std::initializer_list<WhitelistKind> {WhitelistKind::CLASS}
37                           : std::initializer_list<WhitelistKind> {WhitelistKind::METHOD, WhitelistKind::METHOD_CALL};
38 
39     for (auto kind : kindsToAdd) {
40         auto k = static_cast<size_t>(kind);
41         auto &ids = whitelist.id[k];
42         auto &names = config->whitelistNames[k];
43         if (std::find(names.begin(), names.end(), name) != names.end()) {
44             ids->insert(id);
45             LOG(DEBUG, VERIFIER) << "Method with " << (isClassName ? "class " : "") << "name " << name << ", id 0x"
46                                  << std::hex << id << " was added to whitelist";
47         }
48     }
49 }
50 
51 }  // namespace ark::verifier::debug
52