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