• 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_OBJECT_H
17 #define PANDA_GUARD_OBFUSCATE_OBJECT_H
18 
19 #include "entity.h"
20 #include "method.h"
21 #include "module_record.h"
22 
23 namespace panda::guard {
24 
25 class ObjectProperty final : public PropertyOptionEntity, public IExtractNames {
26 public:
ObjectProperty(Program * program,std::string literalArrayIdx)27     ObjectProperty(Program *program, std::string literalArrayIdx)
28         : PropertyOptionEntity(program), literalArrayIdx_(std::move(literalArrayIdx))
29     {
30     }
31 
32     void ExtractNames(std::set<std::string> &strings) const override;
33 
34     /**
35      * 设置 内容是否应该混淆
36      */
37     void SetContentNeedUpdate(bool toUpdate);
38 
39 protected:
40     void Build() override;
41 
42     void Update() override;
43 
44 public:
45     std::string literalArrayIdx_;
46     size_t index_ = 0;
47     std::shared_ptr<PropertyMethod> method_ = nullptr;
48     bool contentNeedUpdate_ = false;
49 };
50 
51 class Object final : public Entity, public IExtractNames {
52 public:
Object(Program * program,std::string literalArrayIdx)53     Object(Program *program, std::string literalArrayIdx)
54         : Entity(program), literalArrayIdx_(std::move(literalArrayIdx))
55     {
56     }
57 
58     void Build() override;
59 
60     /**
61      * 遍历所有方法
62      * @param callback 方法回调
63      */
64     void ForEachMethod(const std::function<FunctionTraver> &callback);
65 
66     void ExtractNames(std::set<std::string> &strings) const override;
67 
68     void WriteNameCache(const std::string &filePath) override;
69 
70     /**
71      * 设置 内容是否应该混淆
72      */
73     void SetContentNeedUpdate(bool toUpdate);
74 
75 protected:
76     void RefreshNeedUpdate() override;
77 
78     void Update() override;
79 
80 private:
81     void CreateProperty(const pandasm::LiteralArray &literalArray, size_t index, bool isMethod);
82 
83 public:
84     ModuleRecord *moduleRecord = nullptr;
85     bool needUpdateName_ = false;
86     bool contentNeedUpdate_ = false;
87     std::string literalArrayIdx_;
88     std::vector<ObjectProperty> properties_ {};
89     std::vector<OuterMethod> outerMethods_ {};
90     std::vector<Property> outerProperties_ {};
91 };
92 
93 }  // namespace panda::guard
94 
95 #endif  // PANDA_GUARD_OBFUSCATE_OBJECT_H
96