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