• 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_OBFUSCATE_FILE_PATH_H
17 #define PANDA_GUARD_OBFUSCATE_FILE_PATH_H
18 
19 #include "entity.h"
20 
21 namespace panda::guard {
22 
23 struct FilePath {
24     std::string prePart;
25     std::string name;
26     std::string obfName;
27     std::string postPart;
28 };
29 
30 enum class FilePathType {
31     LOCAL_FILE_NO_PREFIX,
32     LOCAL_FILE_WITH_PREFIX,
33     EXTERNAL_DEPENDENCE,
34 };
35 
36 class ReferenceFilePath {
37 public:
ReferenceFilePath(Program * program)38     explicit ReferenceFilePath(Program *program) : program_(program) {}
39 
40     void Init();
41 
42     void SetFilePath(const std::string &filePath);
43 
44     void Update();
45 
46     [[nodiscard]] std::string GetRawPath() const;
47 
48 private:
49     void DeterminePathType();
50 
51     void UpdateObfFilePath();
52 
53 public:
54     Program *program_ = nullptr;
55     std::string filePath_;
56     std::string obfFilePath_;
57     std::string prefix_;
58     std::string rawName_;
59     uint32_t filePathIndex_ = 0;
60     bool isRemoteFile_ = false;  // Remote har && External dependence
61     FilePathType pathType_ = FilePathType::LOCAL_FILE_NO_PREFIX;
62 };
63 
64 }  // namespace panda::guard
65 
66 #endif  // PANDA_GUARD_OBFUSCATE_FILE_PATH_H
67