• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 KeepOption {
33     bool enable = false;
34     std::vector<std::string> keepPaths;
35 };
36 
37 struct ObfuscationRules {
38     bool disableObfuscation = false;
39     bool enableExportObfuscation = false;
40     bool enableRemoveLog = false;
41     std::string printNameCache;
42     std::string applyNameCache;
43     std::vector<std::string> reservedNames;
44     ObfuscationOption propertyOption;
45     ObfuscationOption toplevelOption;
46     ObfuscationOption fileNameOption;
47     KeepOption keepOption;
48 };
49 
50 struct ObfuscationConfig {
51     std::string abcFilePath;
52     std::string obfAbcFilePath;
53     std::string obfPaFilePath;
54     std::string compileSdkVersion;
55     uint8_t targetApiVersion;
56     std::string targetApiSubVersion;  // This field represents compatibleSdkVersions Stage
57     std::string filesInfoPath;
58     std::string sourceMapsPath;
59     std::string entryPackageInfo;
60     std::string defaultNameCachePath;
61     std::vector<std::string> skippedRemoteHarList;
62     bool useNormalizedOHMUrl;
63     ObfuscationRules obfuscationRules;
64 };
65 
66 class GuardOptions {
67 public:
68     void Load(const std::string &configFilePath);
69 
70     [[nodiscard]] const std::string &GetAbcFilePath() const;
71 
72     [[nodiscard]] const std::string &GetObfAbcFilePath() const;
73 
74     [[nodiscard]] const std::string &GetObfPaFilePath() const;
75 
76     [[nodiscard]] const std::string &GetCompileSdkVersion() const;
77 
78     [[nodiscard]] uint8_t GetTargetApiVersion() const;
79 
80     [[nodiscard]] const std::string &GetTargetApiSubVersion() const;
81 
82     [[nodiscard]] const std::string &GetEntryPackageInfo() const;
83 
84     [[nodiscard]] const std::string &GetDefaultNameCachePath() const;
85 
86     [[nodiscard]] const std::string &GetPrintNameCache() const;
87 
88     [[nodiscard]] const std::string &GetApplyNameCache() const;
89 
90     [[nodiscard]] bool DisableObfuscation() const;
91 
92     [[nodiscard]] bool IsExportObfEnabled() const;
93 
94     [[nodiscard]] bool IsRemoveLogObfEnabled() const;
95 
96     [[nodiscard]] bool IsPropertyObfEnabled() const;
97 
98     [[nodiscard]] bool IsToplevelObfEnabled() const;
99 
100     [[nodiscard]] bool IsFileNameObfEnabled() const;
101 
102     [[nodiscard]] bool IsKeepPath(const std::string &path) const;
103 
104     [[nodiscard]] bool IsReservedNames(const std::string &name) const;
105 
106     [[nodiscard]] bool IsReservedProperties(const std::string &name) const;
107 
108     [[nodiscard]] bool IsReservedToplevelNames(const std::string &name) const;
109 
110     [[nodiscard]] bool IsReservedFileNames(const std::string &name) const;
111 
112     [[nodiscard]] const std::string &GetSourceName(const std::string &name) const;
113 
114     [[nodiscard]] bool IsSkippedRemoteHar(const std::string &pkgName) const;
115 
116     [[nodiscard]] bool IsUseNormalizedOhmUrl() const;
117 
118 private:
119     ObfuscationConfig obfConfig_ {};
120 
121     std::unordered_map<std::string, std::string> sourceNameTable_ {};
122 };
123 
124 }  // namespace panda::guard
125 
126 #endif  // PANDA_GUARD_CONFIGS_GUARD_OPTIONS_H
127