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 #include "guard_options.h"
17
18 #include <regex>
19 #include "utils/logger.h"
20
21 #include "util/assert_util.h"
22 #include "util/file_util.h"
23 #include "util/json_util.h"
24 #include "util/string_util.h"
25
26 namespace {
27 constexpr std::string_view TAG = "[Guard_Options]";
28
29 constexpr std::string_view ABC_FILE_PATH = "abcFilePath";
30 constexpr std::string_view OBF_ABC_FILE_PATH = "obfAbcFilePath";
31 constexpr std::string_view OBF_PA_FILE_PATH = "obfPaFilePath";
32 constexpr std::string_view COMPILE_SDK_VERSION = "compileSdkVersion";
33 constexpr std::string_view TARGET_API_VERSION = "targetApiVersion";
34 constexpr std::string_view TARGET_API_SUB_VERSION = "targetApiSubVersion";
35 constexpr std::string_view FILES_INFO_PATH = "filesInfoPath";
36 constexpr std::string_view SOURCE_MAPS_PATH = "sourceMapsPath";
37 constexpr std::string_view ENTRY_PACKAGE_INFO = "entryPackageInfo";
38 constexpr std::string_view DEFAULT_NAME_CACHE_PATH = "defaultNameCachePath";
39 constexpr std::string_view SKIPPED_REMOTE_HAR_LIST = "skippedRemoteHarList";
40 constexpr std::string_view USE_NORMALIZED_OHM_URL = "useNormalizedOHMUrl";
41 constexpr std::string_view OBFUSCATION_RULES = "obfuscationRules";
42 constexpr std::string_view DISABLE_OBFUSCATION = "disableObfuscation";
43 constexpr std::string_view ENABLE_EXPORT_OBFUSCATION = "enableExportObfuscation";
44 constexpr std::string_view ENABLE_REMOVE_LOG = "enableRemoveLog";
45 constexpr std::string_view ENABLE_DECORATOR_OBFUSCATION = "enableDecoratorObfuscation";
46 constexpr std::string_view COMPACT = "compact";
47 constexpr std::string_view PRINT_NAME_CACHE = "printNameCache";
48 constexpr std::string_view APPLY_NAME_CACHE = "applyNameCache";
49 constexpr std::string_view RESERVED_NAMES = "reservedNames";
50 constexpr std::string_view ENABLE = "enable";
51 constexpr std::string_view PROPERTY_OBFUSCATION = "propertyObfuscation";
52 constexpr std::string_view RESERVED_PROPERTIES = "reservedProperties";
53 constexpr std::string_view UNIVERSAL_RESERVED_PROPERTIES = "universalReservedProperties";
54 constexpr std::string_view TOPLEVEL_OBFUSCATION = "toplevelObfuscation";
55 constexpr std::string_view RESERVED_TOPLEVEL_NAMES = "reservedToplevelNames";
56 constexpr std::string_view UNIVERSAL_RESERVED_TOPLEVEL_NAMES = "universalReservedToplevelNames";
57 constexpr std::string_view FILE_NAME_OBFUSCATION = "fileNameObfuscation";
58 constexpr std::string_view RESERVED_FILE_NAMES = "reservedFileNames";
59 constexpr std::string_view UNIVERSAL_RESERVED_FILE_NAMES = "universalReservedFileNames";
60 constexpr std::string_view RESERVED_REMOTE_HAR_PKG_NAMES = "reservedRemoteHarPkgNames";
61 constexpr std::string_view KEEP_OPTIONS = "keepOptions";
62 constexpr std::string_view KEEP_PATHS = "keepPaths";
63
64 constexpr std::string_view FILES_INFO_DELIMITER = ";";
65 constexpr size_t FILES_INFO_INDEX_1_RECORD_NAME = 1;
66 constexpr size_t FILES_INFO_INDEX_3_SOURCE_KEY = 3;
67 const std::string_view SOURCE_MAPS_SOURCES = "sources";
68
ParseObfuscationOption(const panda::JsonObject * object,const std::string_view & objKey,const std::string_view & reservedKey,const std::string_view & universalKey,panda::guard::ObfuscationOption & option)69 void ParseObfuscationOption(const panda::JsonObject *object, const std::string_view &objKey,
70 const std::string_view &reservedKey, const std::string_view &universalKey,
71 panda::guard::ObfuscationOption &option)
72 {
73 auto innerObj = panda::guard::JsonUtil::GetJsonObject(object, objKey);
74 if (!innerObj) {
75 LOG(INFO, PANDAGUARD) << TAG << "fail to obtain object field :" << objKey << " from json object";
76 return;
77 }
78 option.enable = panda::guard::JsonUtil::GetBoolValue(innerObj, ENABLE);
79 option.reservedList = panda::guard::JsonUtil::GetArrayStringValue(innerObj, reservedKey);
80 option.universalReservedList = panda::guard::JsonUtil::GetArrayStringValue(innerObj, universalKey);
81 for (auto &str : option.universalReservedList) {
82 panda::guard::StringUtil::RemoveSlashFromBothEnds(str);
83 }
84 }
85
ParsePropertyOption(const panda::JsonObject * obj,panda::guard::ObfuscationOption & option)86 void ParsePropertyOption(const panda::JsonObject *obj, panda::guard::ObfuscationOption &option)
87 {
88 ParseObfuscationOption(obj, PROPERTY_OBFUSCATION, RESERVED_PROPERTIES, UNIVERSAL_RESERVED_PROPERTIES, option);
89 }
90
ParseToplevelOption(const panda::JsonObject * obj,panda::guard::ObfuscationOption & option)91 void ParseToplevelOption(const panda::JsonObject *obj, panda::guard::ObfuscationOption &option)
92 {
93 ParseObfuscationOption(obj, TOPLEVEL_OBFUSCATION, RESERVED_TOPLEVEL_NAMES, UNIVERSAL_RESERVED_TOPLEVEL_NAMES,
94 option);
95 }
96
ParseFileNameOption(const panda::JsonObject * obj,panda::guard::FileNameOption & option)97 void ParseFileNameOption(const panda::JsonObject *obj, panda::guard::FileNameOption &option)
98 {
99 auto innerObj = panda::guard::JsonUtil::GetJsonObject(obj, FILE_NAME_OBFUSCATION);
100 if (!innerObj) {
101 LOG(INFO, PANDAGUARD) << TAG << "fail to obtain object field :" << FILE_NAME_OBFUSCATION << " from json object";
102 return;
103 }
104 option.enable = panda::guard::JsonUtil::GetBoolValue(innerObj, ENABLE);
105 option.reservedFileNames = panda::guard::JsonUtil::GetArrayStringValue(innerObj, RESERVED_FILE_NAMES);
106 option.universalReservedFileNames =
107 panda::guard::JsonUtil::GetArrayStringValue(innerObj, UNIVERSAL_RESERVED_FILE_NAMES);
108 for (auto &str : option.universalReservedFileNames) {
109 panda::guard::StringUtil::RemoveSlashFromBothEnds(str);
110 }
111 option.reservedRemoteHarPkgNames =
112 panda::guard::JsonUtil::GetArrayStringValue(innerObj, RESERVED_REMOTE_HAR_PKG_NAMES);
113 }
114
ParseKeepOption(const panda::JsonObject * obj,panda::guard::KeepOption & option)115 void ParseKeepOption(const panda::JsonObject *obj, panda::guard::KeepOption &option)
116 {
117 auto innerObj = panda::guard::JsonUtil::GetJsonObject(obj, KEEP_OPTIONS);
118 if (!innerObj) {
119 LOG(INFO, PANDAGUARD) << TAG << "fail to obtain object field :" << KEEP_OPTIONS << " from json object";
120 return;
121 }
122 option.enable = panda::guard::JsonUtil::GetBoolValue(innerObj, ENABLE);
123 option.keepPaths = panda::guard::JsonUtil::GetArrayStringValue(innerObj, KEEP_PATHS);
124 }
125
ParseObfuscationConfigFile(const std::string & content,panda::guard::ObfuscationConfig & obfConfig)126 void ParseObfuscationConfigFile(const std::string &content, panda::guard::ObfuscationConfig &obfConfig)
127 {
128 panda::JsonObject configObj(content);
129 PANDA_GUARD_ASSERT_PRINT(!configObj.IsValid(), TAG, panda::guard::ErrorCode::CONFIG_FILE_FORMAT_ERROR,
130 "the config file is not a valid json");
131
132 obfConfig.abcFilePath = panda::guard::JsonUtil::GetStringValue(&configObj, ABC_FILE_PATH, false);
133 obfConfig.obfAbcFilePath = panda::guard::JsonUtil::GetStringValue(&configObj, OBF_ABC_FILE_PATH, false);
134 obfConfig.obfPaFilePath = panda::guard::JsonUtil::GetStringValue(&configObj, OBF_PA_FILE_PATH);
135 obfConfig.compileSdkVersion = panda::guard::JsonUtil::GetStringValue(&configObj, COMPILE_SDK_VERSION, false);
136 obfConfig.targetApiVersion = (uint8_t)panda::guard::JsonUtil::GetDoubleValue(&configObj, TARGET_API_VERSION, false);
137 obfConfig.targetApiSubVersion = panda::guard::JsonUtil::GetStringValue(&configObj, TARGET_API_SUB_VERSION);
138 obfConfig.filesInfoPath = panda::guard::JsonUtil::GetStringValue(&configObj, FILES_INFO_PATH);
139 obfConfig.sourceMapsPath = panda::guard::JsonUtil::GetStringValue(&configObj, SOURCE_MAPS_PATH);
140 obfConfig.entryPackageInfo = panda::guard::JsonUtil::GetStringValue(&configObj, ENTRY_PACKAGE_INFO, false);
141 obfConfig.defaultNameCachePath = panda::guard::JsonUtil::GetStringValue(&configObj, DEFAULT_NAME_CACHE_PATH, false);
142 obfConfig.skippedRemoteHarList = panda::guard::JsonUtil::GetArrayStringValue(&configObj, SKIPPED_REMOTE_HAR_LIST);
143 obfConfig.useNormalizedOHMUrl = panda::guard::JsonUtil::GetBoolValue(&configObj, USE_NORMALIZED_OHM_URL);
144
145 auto rulesObj = panda::guard::JsonUtil::GetJsonObject(&configObj, OBFUSCATION_RULES);
146 PANDA_GUARD_ASSERT_PRINT(!rulesObj, TAG, panda::guard::ErrorCode::NOT_CONFIGURED_OBFUSCATION_RULES,
147 "there is no confusion rule configured in the config file");
148
149 auto obfRule = &obfConfig.obfuscationRules;
150 obfRule->disableObfuscation = panda::guard::JsonUtil::GetBoolValue(rulesObj, DISABLE_OBFUSCATION);
151 obfRule->enableExportObfuscation = panda::guard::JsonUtil::GetBoolValue(rulesObj, ENABLE_EXPORT_OBFUSCATION);
152 obfRule->enableRemoveLog = panda::guard::JsonUtil::GetBoolValue(rulesObj, ENABLE_REMOVE_LOG);
153 obfRule->enableDecorator = panda::guard::JsonUtil::GetBoolValue(rulesObj, ENABLE_DECORATOR_OBFUSCATION);
154 obfRule->enableCompact = panda::guard::JsonUtil::GetBoolValue(rulesObj, COMPACT);
155 obfRule->printNameCache = panda::guard::JsonUtil::GetStringValue(rulesObj, PRINT_NAME_CACHE);
156 obfRule->applyNameCache = panda::guard::JsonUtil::GetStringValue(rulesObj, APPLY_NAME_CACHE);
157 obfRule->reservedNames = panda::guard::JsonUtil::GetArrayStringValue(rulesObj, RESERVED_NAMES);
158 ParsePropertyOption(rulesObj, obfRule->propertyOption);
159 ParseToplevelOption(rulesObj, obfRule->toplevelOption);
160 ParseFileNameOption(rulesObj, obfRule->fileNameOption);
161 ParseKeepOption(rulesObj, obfRule->keepOption);
162 }
163
NeedToBeReserved(const std::vector<std::string> & reservedNames,const std::vector<std::string> & universalReservedNames,const std::string & name)164 bool NeedToBeReserved(const std::vector<std::string> &reservedNames,
165 const std::vector<std::string> &universalReservedNames, const std::string &name)
166 {
167 if (std::any_of(reservedNames.begin(), reservedNames.end(), [&](const auto &field) { return field == name; })) {
168 return true;
169 }
170
171 return std::any_of(universalReservedNames.begin(), universalReservedNames.end(), [&](const auto &field) {
172 std::regex pattern(field);
173 return std::regex_search(name, pattern);
174 });
175 }
176
ParseFilesInfo(const std::string & filesInfoPath,std::unordered_map<std::string,std::string> & filesInfoTable)177 void ParseFilesInfo(const std::string &filesInfoPath, std::unordered_map<std::string, std::string> &filesInfoTable)
178 {
179 if (filesInfoPath.empty()) {
180 LOG(INFO, PANDAGUARD) << TAG << "filesInfoPath is empty";
181 return;
182 }
183 auto lineDataList = panda::guard::FileUtil::GetLineDataFromFile(filesInfoPath);
184 if (lineDataList.empty()) {
185 LOG(WARNING, PANDAGUARD) << TAG << "fail to get line data from filesInfoPath";
186 return;
187 }
188 for (const auto &line : lineDataList) {
189 auto infoList = panda::guard::StringUtil::StrictSplit(line, FILES_INFO_DELIMITER.data());
190 if (infoList.size() < (FILES_INFO_INDEX_3_SOURCE_KEY + 1)) {
191 LOG(WARNING, PANDAGUARD) << TAG << "line info is not of normal size : " << line;
192 continue;
193 }
194 filesInfoTable.emplace(infoList[FILES_INFO_INDEX_1_RECORD_NAME], infoList[FILES_INFO_INDEX_3_SOURCE_KEY]);
195 }
196 }
197
ParseSourceMaps(const std::string & sourceMapsPath,std::unordered_map<std::string,std::string> & sourceMapsTable)198 void ParseSourceMaps(const std::string &sourceMapsPath, std::unordered_map<std::string, std::string> &sourceMapsTable)
199 {
200 if (sourceMapsPath.empty()) {
201 LOG(INFO, PANDAGUARD) << TAG << "sourceMapsPath is empty";
202 return;
203 }
204 std::string content = panda::guard::FileUtil::GetFileContent(sourceMapsPath);
205 if (content.empty()) {
206 LOG(WARNING, PANDAGUARD) << TAG << "get sourceMaps file content failed";
207 return;
208 }
209 panda::JsonObject sourceMapsObj(content);
210 if (!sourceMapsObj.IsValid()) {
211 LOG(WARNING, PANDAGUARD) << TAG << "the sourceMaps file is not a valid json";
212 return;
213 }
214 for (size_t idx = 0; idx < sourceMapsObj.GetSize(); idx++) {
215 auto key = sourceMapsObj.GetKeyByIndex(idx);
216 auto sourceObj = panda::guard::JsonUtil::GetJsonObject(&sourceMapsObj, key);
217 if (!sourceObj) {
218 LOG(WARNING, PANDAGUARD) << TAG << "failed to obtain object field :" << key << " from sourceMaps file";
219 continue;
220 }
221 auto sources = panda::guard::JsonUtil::GetArrayStringValue(sourceObj, SOURCE_MAPS_SOURCES);
222 if (sources.empty()) {
223 LOG(WARNING, PANDAGUARD) << TAG << "the array field :" << key << " in the sourceMaps file is empty";
224 continue;
225 }
226 sourceMapsTable.emplace(key, sources[0]);
227 }
228 }
229
ParseFilesInfoAndSourceMaps(const std::string & filesInfoPath,const std::string & sourceMapsPath,std::unordered_map<std::string,std::string> & sourceNameTable)230 void ParseFilesInfoAndSourceMaps(const std::string &filesInfoPath, const std::string &sourceMapsPath,
231 std::unordered_map<std::string, std::string> &sourceNameTable)
232 {
233 std::unordered_map<std::string, std::string> filesInfoTable;
234 ParseFilesInfo(filesInfoPath, filesInfoTable);
235 if (filesInfoTable.empty()) {
236 return;
237 }
238
239 std::unordered_map<std::string, std::string> sourceMapsTable;
240 ParseSourceMaps(sourceMapsPath, sourceMapsTable);
241 if (sourceMapsTable.empty()) {
242 return;
243 }
244
245 for (const auto &[recordName, sourceMapsKey] : filesInfoTable) {
246 auto item = sourceMapsTable.find(sourceMapsKey);
247 if (item == sourceMapsTable.end()) {
248 LOG(WARNING, PANDAGUARD) << TAG << sourceMapsKey << " in filesInfo, but not in sourceMaps";
249 continue;
250 }
251 sourceNameTable.emplace(recordName, item->second);
252 }
253 }
254 } // namespace
255
Load(const std::string & configFilePath)256 void panda::guard::GuardOptions::Load(const std::string &configFilePath)
257 {
258 std::string fileContent = FileUtil::GetFileContent(configFilePath);
259 PANDA_GUARD_ASSERT_PRINT(fileContent.empty(), TAG, ErrorCode::CONFIG_FILE_CONTENT_EMPTY, "config file is empty");
260
261 ParseObfuscationConfigFile(fileContent, this->obfConfig_);
262 PANDA_GUARD_ASSERT_PRINT(obfConfig_.abcFilePath.empty(), TAG, ErrorCode::NOT_CONFIGURED_ABC_FILE_PATH,
263 "the value of field abcFilePath in the configuration file is invalid");
264 PANDA_GUARD_ASSERT_PRINT(obfConfig_.obfAbcFilePath.empty(), TAG, ErrorCode::NOT_CONFIGURED_OBF_ABC_FILE_PATH,
265 "the value of field obfAbcFilePath in the configuration file is invalid");
266 PANDA_GUARD_ASSERT_PRINT((obfConfig_.targetApiVersion == 0), TAG, ErrorCode::NOT_CONFIGURED_TARGET_API_VERSION,
267 "the value of field targetApiVersion in the configuration file is invalid");
268
269 LOG(INFO, PANDAGUARD) << TAG << "disableObfuscation_:" << obfConfig_.obfuscationRules.disableObfuscation;
270 LOG(INFO, PANDAGUARD) << TAG << "export obfuscation:" << obfConfig_.obfuscationRules.enableExportObfuscation;
271 LOG(INFO, PANDAGUARD) << TAG << "removeLog obfuscation:" << obfConfig_.obfuscationRules.enableRemoveLog;
272 LOG(INFO, PANDAGUARD) << TAG << "property obfuscation:" << obfConfig_.obfuscationRules.propertyOption.enable;
273 LOG(INFO, PANDAGUARD) << TAG << "topLevel obfuscation:" << obfConfig_.obfuscationRules.toplevelOption.enable;
274 LOG(INFO, PANDAGUARD) << TAG << "fileName obfuscation:" << obfConfig_.obfuscationRules.fileNameOption.enable;
275
276 ParseFilesInfoAndSourceMaps(obfConfig_.filesInfoPath, obfConfig_.sourceMapsPath, this->sourceNameTable_);
277 }
278
GetAbcFilePath() const279 const std::string &panda::guard::GuardOptions::GetAbcFilePath() const
280 {
281 return obfConfig_.abcFilePath;
282 }
283
GetObfAbcFilePath() const284 const std::string &panda::guard::GuardOptions::GetObfAbcFilePath() const
285 {
286 return obfConfig_.obfAbcFilePath;
287 }
288
GetObfPaFilePath() const289 const std::string &panda::guard::GuardOptions::GetObfPaFilePath() const
290 {
291 return obfConfig_.obfPaFilePath;
292 }
293
GetCompileSdkVersion() const294 const std::string &panda::guard::GuardOptions::GetCompileSdkVersion() const
295 {
296 return obfConfig_.compileSdkVersion;
297 }
298
GetTargetApiVersion() const299 uint8_t panda::guard::GuardOptions::GetTargetApiVersion() const
300 {
301 return obfConfig_.targetApiVersion;
302 }
303
GetTargetApiSubVersion() const304 const std::string &panda::guard::GuardOptions::GetTargetApiSubVersion() const
305 {
306 return obfConfig_.targetApiSubVersion;
307 }
308
GetEntryPackageInfo() const309 const std::string &panda::guard::GuardOptions::GetEntryPackageInfo() const
310 {
311 return obfConfig_.entryPackageInfo;
312 }
313
GetDefaultNameCachePath() const314 const std::string &panda::guard::GuardOptions::GetDefaultNameCachePath() const
315 {
316 return obfConfig_.defaultNameCachePath;
317 }
318
DisableObfuscation() const319 bool panda::guard::GuardOptions::DisableObfuscation() const
320 {
321 return obfConfig_.obfuscationRules.disableObfuscation;
322 }
323
IsExportObfEnabled() const324 bool panda::guard::GuardOptions::IsExportObfEnabled() const
325 {
326 return obfConfig_.obfuscationRules.enableExportObfuscation;
327 }
328
IsRemoveLogObfEnabled() const329 bool panda::guard::GuardOptions::IsRemoveLogObfEnabled() const
330 {
331 return obfConfig_.obfuscationRules.enableRemoveLog;
332 }
333
IsDecoratorObfEnabled() const334 bool panda::guard::GuardOptions::IsDecoratorObfEnabled() const
335 {
336 return obfConfig_.obfuscationRules.enableDecorator;
337 }
338
IsCompactObfEnabled() const339 bool panda::guard::GuardOptions::IsCompactObfEnabled() const
340 {
341 return obfConfig_.obfuscationRules.enableCompact;
342 }
343
GetPrintNameCache() const344 const std::string &panda::guard::GuardOptions::GetPrintNameCache() const
345 {
346 return obfConfig_.obfuscationRules.printNameCache;
347 }
348
GetApplyNameCache() const349 const std::string &panda::guard::GuardOptions::GetApplyNameCache() const
350 {
351 return obfConfig_.obfuscationRules.applyNameCache;
352 }
353
IsPropertyObfEnabled() const354 bool panda::guard::GuardOptions::IsPropertyObfEnabled() const
355 {
356 return obfConfig_.obfuscationRules.propertyOption.enable;
357 }
358
IsToplevelObfEnabled() const359 bool panda::guard::GuardOptions::IsToplevelObfEnabled() const
360 {
361 return obfConfig_.obfuscationRules.toplevelOption.enable;
362 }
363
IsFileNameObfEnabled() const364 bool panda::guard::GuardOptions::IsFileNameObfEnabled() const
365 {
366 return obfConfig_.obfuscationRules.fileNameOption.enable;
367 }
368
IsKeepPath(const std::string & path) const369 bool panda::guard::GuardOptions::IsKeepPath(const std::string &path) const
370 {
371 const auto keepOption = &obfConfig_.obfuscationRules.keepOption;
372 if (!keepOption->enable || path.empty()) {
373 return false;
374 }
375
376 std::vector<std::string> universalKeepPaths; // keep paths not have universal
377 return NeedToBeReserved(keepOption->keepPaths, universalKeepPaths, path);
378 }
379
IsReservedNames(const std::string & name) const380 bool panda::guard::GuardOptions::IsReservedNames(const std::string &name) const
381 {
382 std::vector<std::string> universalReservedNames; // names not have universal
383 return NeedToBeReserved(obfConfig_.obfuscationRules.reservedNames, universalReservedNames, name);
384 }
385
IsReservedProperties(const std::string & name) const386 bool panda::guard::GuardOptions::IsReservedProperties(const std::string &name) const
387 {
388 return NeedToBeReserved(obfConfig_.obfuscationRules.propertyOption.reservedList,
389 obfConfig_.obfuscationRules.propertyOption.universalReservedList, name);
390 }
391
IsReservedToplevelNames(const std::string & name) const392 bool panda::guard::GuardOptions::IsReservedToplevelNames(const std::string &name) const
393 {
394 return NeedToBeReserved(obfConfig_.obfuscationRules.toplevelOption.reservedList,
395 obfConfig_.obfuscationRules.toplevelOption.universalReservedList, name);
396 }
397
IsReservedFileNames(const std::string & name) const398 bool panda::guard::GuardOptions::IsReservedFileNames(const std::string &name) const
399 {
400 return NeedToBeReserved(obfConfig_.obfuscationRules.fileNameOption.reservedFileNames,
401 obfConfig_.obfuscationRules.fileNameOption.universalReservedFileNames, name);
402 }
403
GetSourceName(const std::string & name) const404 const std::string &panda::guard::GuardOptions::GetSourceName(const std::string &name) const
405 {
406 auto item = this->sourceNameTable_.find(name);
407 if (item == this->sourceNameTable_.end()) {
408 return name;
409 }
410 return item->second;
411 }
412
IsSkippedRemoteHar(const std::string & pkgName) const413 bool panda::guard::GuardOptions::IsSkippedRemoteHar(const std::string &pkgName) const
414 {
415 return std::any_of(
416 obfConfig_.skippedRemoteHarList.begin(), obfConfig_.skippedRemoteHarList.end(),
417 [pkgName](const std::string &remoteHar) { return StringUtil::IsSuffixMatched(remoteHar, pkgName); });
418 }
419
IsUseNormalizedOhmUrl() const420 bool panda::guard::GuardOptions::IsUseNormalizedOhmUrl() const
421 {
422 return obfConfig_.useNormalizedOHMUrl;
423 }
424
IsReservedRemoteHarPkgNames(const std::string & name) const425 bool panda::guard::GuardOptions::IsReservedRemoteHarPkgNames(const std::string &name) const
426 {
427 return std::any_of(obfConfig_.obfuscationRules.fileNameOption.reservedRemoteHarPkgNames.begin(),
428 obfConfig_.obfuscationRules.fileNameOption.reservedRemoteHarPkgNames.end(),
429 [name](const std::string &remoteHar) { return remoteHar == name; });
430 }
431