• 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_METHOD_H
17 #define PANDA_GUARD_OBFUSCATE_METHOD_H
18 
19 #include "function.h"
20 
21 namespace panda::guard {
22 
23 class Method final : public Function {
24 public:
Method(Program * program,const std::string & idx)25     Method(Program *program, const std::string &idx) : Function(program, idx) {}
26 
27 protected:
28     void RefreshNeedUpdate() override;
29 
30     void WriteFileCache(const std::string &filePath) override;
31 
32     void WritePropertyCache() override;
33 
34 private:
35     void InitNameCacheScope() override;
36 
37     void UpdateDefine() const override;
38 
39 public:
40     std::string literalArrayIdx_;
41     std::string className_;
42     bool static_ = false;
43     size_t idxIndex_ = 0;
44     size_t nameIndex_ = 0;
45 };
46 
47 class OuterMethod final : public Function {
48 public:
OuterMethod(Program * program,const std::string & idx)49     OuterMethod(Program *program, const std::string &idx) : Function(program, idx) {}
50 
51     /**
52      * 设置 内容是否应该混淆
53      */
54     void SetContentNeedUpdate(bool toUpdate);
55 
56     std::string GetName() const override;
57 
58     std::string GetObfName() const override;
59 
60     void Build() override;
61 
62 protected:
63     void Update() override;
64 
65     void WriteFileCache(const std::string &filePath) override;
66 
67     void WritePropertyCache() override;
68 
69     bool IsNameObfuscated() const override;
70 
71 private:
72     void RefreshNeedUpdate() override;
73 
74     void UpdateNameDefine();
75 
76 public:
77     std::string className_;
78     std::string nameDefine_;
79     std::string obfNameDefine_;
80     InstructionInfo nameInfo_ {};
81 };
82 
83 class PropertyMethod final : public Function {
84 public:
PropertyMethod(Program * program,const std::string & idx)85     PropertyMethod(Program *program, const std::string &idx) : Function(program, idx) {}
86 
87     /**
88      * Should the setting content be confused
89      */
90     void SetContentNeedUpdate(bool toUpdate);
91 
92 private:
93     void RefreshNeedUpdate() override;
94 };
95 
96 }  // namespace panda::guard
97 
98 #endif  // PANDA_GUARD_OBFUSCATE_METHOD_H
99