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_GRAPH_ANALYZER_H 17 #define PANDA_GUARD_OBFUSCATE_GRAPH_ANALYZER_H 18 19 #include "entity.h" 20 21 namespace panda::guard { 22 23 class GraphAnalyzer { 24 public: 25 GraphAnalyzer() = delete; 26 27 ~GraphAnalyzer() = delete; 28 NO_COPY_SEMANTIC(GraphAnalyzer); 29 30 /** 31 * Get Related Lda.Str instruction 32 * @param inIns origin inst 33 * @param outIns related Lda.Str inst; if not found, outIns.ins_ will be nullptr 34 * @param index reg index, -1 as using default value 35 */ 36 static void GetLdaStr(const InstructionInfo &inIns, InstructionInfo &outIns, int index = -1); 37 38 /** 39 * Get Related instruction of DefineMethod 40 * @param inIns input ins: definemethod 41 * @param defineIns ins info of define method 42 * @param nameIns ins info of name define 43 */ 44 static void HandleDefineMethod(const InstructionInfo &inIns, InstructionInfo &defineIns, InstructionInfo &nameIns); 45 46 /** 47 * Get Related instruction of definepropertybyname 48 * @param inIns input ins 49 * @param defineIns related define ins 50 */ 51 static void HandleDefineProperty(const InstructionInfo &inIns, InstructionInfo &defineIns); 52 53 /** 54 * Get class is component 55 * 56 * @Component 57 * struct ClassName{} 58 * 59 * @ComponentV2 60 * struct ClassName{} 61 * 62 * @param inIns defineclasswithbuffer instruction 63 * @return is component class 64 */ 65 static bool IsComponentClass(const InstructionInfo &inIns); 66 67 /** 68 * get stmodulevar bind define instruction 69 * @param inIns input ins (stmodulevar or wide.stdmodulevar) 70 * @param defineIns bind define instruction 71 */ 72 static void GetStModuleVarDefineIns(const InstructionInfo &inIns, InstructionInfo &defineIns); 73 74 /** 75 * get stobjbyname bind define instruction 76 * @param inIns input ins (stobjbyname) 77 * @param defineIns bind define instruction 78 */ 79 static void GetStObjByNameDefineIns(const InstructionInfo &inIns, InstructionInfo &defineIns); 80 81 /** 82 * Get the predecessor instruction associated with the stobjbyname instruction and check if it is one of the 83 * following commands NEWOBTRANSAGE, CALLTHIS2, CALLTHIS3, If it meets the requirements, return the corresponding 84 * pre-instruction information 85 * @param inIns stobjbyname ins 86 * @param out related input ins 87 */ 88 static void GetStObjByNameInput(const InstructionInfo &inIns, InstructionInfo &out); 89 90 /** 91 * Get the object name followed by the tryldglobalbyname instruction associated with the newobjrange instruction, 92 * as well as the ldastr parameter associated with the newobjrange instruction 93 * @param inIns newobjrange ins 94 * @param name newobjrange ins name 95 * @param out related ins 96 */ 97 static void GetNewObjRangeInfo(const InstructionInfo &inIns, std::string &name, InstructionInfo &out); 98 99 /** 100 * Get call instruction object name 101 * @param inIns call ins 102 */ 103 static std::string GetCallName(const InstructionInfo &inIns); 104 105 /** 106 * Get Related ldaStr instruction of call ins 107 * @param inIns call ins 108 * @param paramIndex call param index 109 * @param out param ins 110 */ 111 static void GetCallLdaStrParam(const InstructionInfo &inIns, uint32_t paramIndex, InstructionInfo &out); 112 113 /** 114 * Get Related tryLdGlobalByName instruction of call ins 115 * @param inIns call ins 116 * @param paramIndex call param index 117 * @param out param ins 118 */ 119 static void GetCallTryLdGlobalByNameParam(const InstructionInfo &inIns, uint32_t paramIndex, InstructionInfo &out); 120 121 /** 122 * Get Related ldobjbyname instruction of call ins 123 * @param inIns call ins 124 * @param paramIndex call param index 125 * @param out param ins 126 */ 127 static void GetCallLdObjByNameParam(const InstructionInfo &inIns, uint32_t paramIndex, InstructionInfo &out); 128 129 /** 130 * Get Related instruction of isin ins 131 * @param inIns isin ins 132 * @param out related ins array 133 */ 134 static void GetIsInInfo(const InstructionInfo &inIns, std::vector<InstructionInfo> &out); 135 136 /** 137 * Get Related createobjectwithbuffer instruction of call ins 138 * @param inIns call ins 139 * @param paramIndex call param index 140 * @param out object ins 141 */ 142 static void GetCallCreateObjectWithBufferParam(const InstructionInfo &inIns, uint32_t paramIndex, 143 InstructionInfo &out); 144 145 /** 146 * Get Related definefunc instruction in acc of definepropertybyname ins 147 * @param inIns call ins 148 * @param out function ins 149 */ 150 static void GetDefinePropertyByNameFunction(const InstructionInfo &inIns, InstructionInfo &out); 151 }; 152 153 } // namespace panda::guard 154 155 #endif // PANDA_GUARD_OBFUSCATE_GRAPH_ANALYZER_H 156