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 #ifndef PANDA_VERIFICATION_UTIL_IS_SYSTEM_H 17 #define PANDA_VERIFICATION_UTIL_IS_SYSTEM_H 18 19 #include "runtime/include/runtime.h" 20 21 namespace panda::verifier { 22 IsSystemFile(const panda_file::File & file)23inline bool IsSystemFile(const panda_file::File &file) 24 { 25 const std::string &name = file.GetFilename(); 26 const RuntimeOptions &options = Runtime::GetCurrent()->GetOptions(); 27 const auto &boot_panda_files = options.GetBootPandaFiles(); 28 size_t files_len = options.GetPandaFiles().empty() ? boot_panda_files.size() - 1 : boot_panda_files.size(); 29 for (size_t i = 0; i < files_len; i++) { 30 if (name == boot_panda_files[i]) { 31 return true; 32 } 33 } 34 return false; 35 } 36 37 template <bool include_synthetic_classes = false> IsSystemClass(const Class & klass)38bool IsSystemClass(const Class &klass) 39 { 40 const auto *file = klass.GetPandaFile(); 41 if (file == nullptr) { 42 return include_synthetic_classes; 43 } 44 return IsSystemFile(*file); 45 } 46 IsSystemOrSyntheticClass(const Class & klass)47inline bool IsSystemOrSyntheticClass(const Class &klass) 48 { 49 return IsSystemClass<true>(klass); 50 } 51 52 } // namespace panda::verifier 53 #endif // PANDA_VERIFICATION_UTIL_IS_SYSTEM_H 54