1 /*
2 * Copyright (c) 2021 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 "allowlist_private.h"
17
18 #include "verification/debug/context/context.h"
19
20 #include "utils/logger.h"
21
22 namespace panda::verifier::debug {
23
InAllowlist(AllowlistKind kind,uint64_t id)24 bool InAllowlist(AllowlistKind kind, uint64_t id)
25 {
26 auto &id_local = DebugContext::GetCurrent().Allowlist.Id;
27 return id_local[static_cast<size_t>(kind)]->count(id) > 0;
28 }
29
AddAllowlistMethodConfig(AllowlistKind kind,uint32_t name_hash)30 void AddAllowlistMethodConfig(AllowlistKind kind, uint32_t name_hash)
31 {
32 auto &name_hash_local = DebugContext::GetCurrent().Allowlist.NameHash;
33 name_hash_local[static_cast<size_t>(kind)]->insert(name_hash);
34 }
35
AllowlistMethodIdCalculationHandler(uint32_t class_hash,uint32_t method_hash,uint64_t id)36 void AllowlistMethodIdCalculationHandler(uint32_t class_hash, uint32_t method_hash, uint64_t id)
37 {
38 auto &allowlist = DebugContext::GetCurrent().Allowlist;
39 auto &id_local = allowlist.Id;
40 auto &name_hash_local = allowlist.NameHash;
41 for (size_t k = 0; k < static_cast<size_t>(AllowlistKind::__LAST__); ++k) {
42 if (static_cast<AllowlistKind>(k) == AllowlistKind::CLASS) {
43 if (name_hash_local[k]->count(class_hash) > 0) {
44 LOG(DEBUG, VERIFIER) << "Method with class hash 0x" << std::hex << class_hash << ", id 0x" << id
45 << " was succesfully added to allowlist";
46 id_local[k]->insert(id);
47 }
48 } else {
49 if (name_hash_local[k]->count(method_hash) > 0) {
50 LOG(DEBUG, VERIFIER) << "Method with hash 0x" << std::hex << method_hash << ", id 0x" << id
51 << " was succesfully added to allowlist";
52 id_local[k]->insert(id);
53 }
54 }
55 }
56 }
57
58 } // namespace panda::verifier::debug
59