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 #include "instruction_info.h"
17 #include "program.h"
18 #include "configs/guard_context.h"
19
IsInnerReg() const20 bool panda::guard::InstructionInfo::IsInnerReg() const
21 {
22 // if regs[0] is less than regsNum, the register is v, otherwise, the register is a
23 return this->ins_->GetReg(0) < this->function_->regsNum_;
24 }
25
UpdateInsName(bool generateNewName)26 void panda::guard::InstructionInfo::UpdateInsName(bool generateNewName)
27 {
28 this->origin_ = this->ins_->GetId(0);
29 this->obfName_ = GuardContext::GetInstance()->GetNameMapping()->GetName(this->origin_, generateNewName);
30 this->ins_->GetId(0) = this->obfName_;
31 this->function_->program_->prog_->strings.emplace(this->obfName_);
32 }
33
UpdateInsFileName()34 void panda::guard::InstructionInfo::UpdateInsFileName()
35 {
36 this->origin_ = this->ins_->GetId(0);
37 ReferenceFilePath filePath(this->function_->program_);
38 filePath.SetFilePath(this->origin_);
39 filePath.Init();
40 filePath.Update();
41 this->obfName_ = filePath.obfFilePath_;
42 this->ins_->GetId(0) = this->obfName_;
43 this->function_->program_->prog_->strings.emplace(this->obfName_);
44 }
45
WriteNameCache() const46 void panda::guard::InstructionInfo::WriteNameCache() const
47 {
48 GuardContext::GetInstance()->GetNameCache()->AddObfPropertyName(this->origin_, this->obfName_);
49 }
50
IsValid() const51 bool panda::guard::InstructionInfo::IsValid() const
52 {
53 return this->ins_ != nullptr;
54 }
55
equalToOpcode(const pandasm::Opcode opcode) const56 bool panda::guard::InstructionInfo::equalToOpcode(const pandasm::Opcode opcode) const
57 {
58 return this->ins_->opcode == opcode;
59 }
60
notEqualToOpcode(const pandasm::Opcode opcode) const61 bool panda::guard::InstructionInfo::notEqualToOpcode(const pandasm::Opcode opcode) const
62 {
63 return !this->equalToOpcode(opcode);
64 }
65