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_INSTRUCTION_INFO_H 17 #define PANDA_GUARD_OBFUSCATE_INSTRUCTION_INFO_H 18 19 #include "assembly-program.h" 20 21 namespace panda::guard { 22 23 class Function; 24 25 /** 26 * Instruction information 27 * Due to STL's memory reallocation mechanism, internal pointers are only accessible during traversal 28 */ 29 class InstructionInfo { 30 public: 31 explicit InstructionInfo() = default; 32 InstructionInfo(Function * function,pandasm::Ins * ins,const size_t index)33 InstructionInfo(Function *function, pandasm::Ins *ins, const size_t index) 34 : function_(function), ins_(ins), index_(index) 35 { 36 } 37 38 /** 39 * Determine whether the instruction uses registers within the function 40 */ 41 [[nodiscard]] bool IsInnerReg() const; 42 43 /** 44 * Determine whether it is valid instruction information 45 */ 46 [[nodiscard]] bool IsValid() const; 47 48 /** 49 * update ins name 50 * @param generateNewName true:generate new name false:use origin name 51 */ 52 void UpdateInsName(bool generateNewName = true); 53 54 /** 55 * update dynamic import ins filename 56 */ 57 void UpdateInsFileName(); 58 59 /** 60 * write name cache 61 */ 62 void WriteNameCache() const; 63 64 /** 65 * compare opcode is equal to input instruction 66 * @param opcode input opcode 67 * @return ins_.opcode == opcode 68 */ 69 [[nodiscard]] bool equalToOpcode(pandasm::Opcode opcode) const; 70 71 /** 72 * compare opcode is not equal to input instruction 73 * @param opcode input opcode 74 * @return ins_.opcode != opcode 75 */ 76 [[nodiscard]] bool notEqualToOpcode(pandasm::Opcode opcode) const; 77 78 Function *function_ = nullptr; 79 pandasm::Ins *ins_ = nullptr; 80 size_t index_ = 0; 81 82 private: 83 std::string origin_ {}; 84 std::string obfName_ {}; 85 }; 86 } // namespace panda::guard 87 88 #endif // PANDA_GUARD_OBFUSCATE_INSTRUCTION_INFO_H 89