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 #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 ark::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 &bootPandaFiles = options.GetBootPandaFiles(); 28 size_t filesLen = options.GetPandaFiles().empty() ? bootPandaFiles.size() - 1 : bootPandaFiles.size(); 29 for (size_t i = 0; i < filesLen; i++) { 30 if (name == bootPandaFiles[i]) { 31 return true; 32 } 33 } 34 return false; 35 } 36 37 template <bool INCLUDE_SYNTHETIC_CLASSES = false> IsSystemClass(Class const * klass)38bool IsSystemClass(Class const *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(Class const * klass)47inline bool IsSystemOrSyntheticClass(Class const *klass) 48 { 49 return IsSystemClass<true>(klass); 50 } 51 52 } // namespace ark::verifier 53 #endif // PANDA_VERIFICATION_UTIL_IS_SYSTEM_H 54