1 /** 2 * Copyright (c) 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_GUARD_CONFIGS_GUARD_OPTIONS_H 17 #define PANDA_GUARD_CONFIGS_GUARD_OPTIONS_H 18 19 #include <cstdint> 20 #include <string> 21 #include <unordered_map> 22 #include <vector> 23 24 namespace panda::guard { 25 26 struct ObfuscationOption { 27 bool enable = false; 28 std::vector<std::string> reservedList; 29 std::vector<std::string> universalReservedList; 30 }; 31 32 struct FileNameOption { 33 bool enable = false; 34 std::vector<std::string> reservedFileNames; 35 std::vector<std::string> universalReservedFileNames; 36 std::vector<std::string> reservedRemoteHarPkgNames; 37 }; 38 39 struct KeepOption { 40 bool enable = false; 41 std::vector<std::string> keepPaths; 42 }; 43 44 struct ObfuscationRules { 45 bool disableObfuscation = false; 46 bool enableExportObfuscation = false; 47 bool enableRemoveLog = false; 48 bool enableDecorator = false; 49 bool enableCompact = false; 50 std::string printNameCache; 51 std::string applyNameCache; 52 std::vector<std::string> reservedNames; 53 ObfuscationOption propertyOption; 54 ObfuscationOption toplevelOption; 55 FileNameOption fileNameOption; 56 KeepOption keepOption; 57 }; 58 59 struct ObfuscationConfig { 60 std::string abcFilePath; 61 std::string obfAbcFilePath; 62 std::string obfPaFilePath; 63 std::string compileSdkVersion; 64 uint8_t targetApiVersion; 65 std::string targetApiSubVersion; // This field represents compatibleSdkVersions Stage 66 std::string filesInfoPath; 67 std::string sourceMapsPath; 68 std::string entryPackageInfo; 69 std::string defaultNameCachePath; 70 std::vector<std::string> skippedRemoteHarList; 71 bool useNormalizedOHMUrl; 72 ObfuscationRules obfuscationRules; 73 }; 74 75 class GuardOptions { 76 public: 77 void Load(const std::string &configFilePath); 78 79 [[nodiscard]] const std::string &GetAbcFilePath() const; 80 81 [[nodiscard]] const std::string &GetObfAbcFilePath() const; 82 83 [[nodiscard]] const std::string &GetObfPaFilePath() const; 84 85 [[nodiscard]] const std::string &GetCompileSdkVersion() const; 86 87 [[nodiscard]] uint8_t GetTargetApiVersion() const; 88 89 [[nodiscard]] const std::string &GetTargetApiSubVersion() const; 90 91 [[nodiscard]] const std::string &GetEntryPackageInfo() const; 92 93 [[nodiscard]] const std::string &GetDefaultNameCachePath() const; 94 95 [[nodiscard]] const std::string &GetPrintNameCache() const; 96 97 [[nodiscard]] const std::string &GetApplyNameCache() const; 98 99 [[nodiscard]] bool DisableObfuscation() const; 100 101 [[nodiscard]] bool IsExportObfEnabled() const; 102 103 [[nodiscard]] bool IsRemoveLogObfEnabled() const; 104 105 [[nodiscard]] bool IsDecoratorObfEnabled() const; 106 107 [[nodiscard]] bool IsCompactObfEnabled() const; 108 109 [[nodiscard]] bool IsPropertyObfEnabled() const; 110 111 [[nodiscard]] bool IsToplevelObfEnabled() const; 112 113 [[nodiscard]] bool IsFileNameObfEnabled() const; 114 115 [[nodiscard]] bool IsKeepPath(const std::string &path) const; 116 117 [[nodiscard]] bool IsReservedNames(const std::string &name) const; 118 119 [[nodiscard]] bool IsReservedProperties(const std::string &name) const; 120 121 [[nodiscard]] bool IsReservedToplevelNames(const std::string &name) const; 122 123 [[nodiscard]] bool IsReservedFileNames(const std::string &name) const; 124 125 [[nodiscard]] const std::string &GetSourceName(const std::string &name) const; 126 127 [[nodiscard]] bool IsSkippedRemoteHar(const std::string &pkgName) const; 128 129 [[nodiscard]] bool IsUseNormalizedOhmUrl() const; 130 131 [[nodiscard]] bool IsReservedRemoteHarPkgNames(const std::string &name) const; 132 133 private: 134 ObfuscationConfig obfConfig_ {}; 135 136 std::unordered_map<std::string, std::string> sourceNameTable_ {}; 137 }; 138 139 } // namespace panda::guard 140 141 #endif // PANDA_GUARD_CONFIGS_GUARD_OPTIONS_H 142