From ffafa54703d239414e616d88633736ced71b63a5 Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Tue, 13 Dec 2022 22:46:39 -0500 Subject: Add instruction attributes to IL instructions --- mediumlevelilinstruction.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'mediumlevelilinstruction.cpp') diff --git a/mediumlevelilinstruction.cpp b/mediumlevelilinstruction.cpp index 0cdda81e..ee4ed9e4 100644 --- a/mediumlevelilinstruction.cpp +++ b/mediumlevelilinstruction.cpp @@ -887,6 +887,7 @@ MediumLevelILOperandList::operator vector() const MediumLevelILInstruction::MediumLevelILInstruction() { operation = MLIL_UNDEF; + attributes = 0; sourceOperand = BN_INVALID_OPERAND; size = 0; address = 0; @@ -900,6 +901,7 @@ MediumLevelILInstruction::MediumLevelILInstruction( MediumLevelILFunction* func, const BNMediumLevelILInstruction& instr, size_t expr, size_t instrIdx) { operation = instr.operation; + attributes = instr.attributes; sourceOperand = instr.sourceOperand; size = instr.size; operands[0] = instr.operands[0]; @@ -917,6 +919,7 @@ MediumLevelILInstruction::MediumLevelILInstruction( MediumLevelILInstruction::MediumLevelILInstruction(const MediumLevelILInstructionBase& instr) { operation = instr.operation; + attributes = instr.attributes; sourceOperand = instr.sourceOperand; size = instr.size; operands[0] = instr.operands[0]; @@ -1328,6 +1331,44 @@ void MediumLevelILInstructionBase::Replace(ExprId expr) } +void MediumLevelILInstructionBase::SetAttributes(uint32_t attributes) +{ + function->SetExprAttributes(exprIndex, attributes); +} + + +void MediumLevelILInstructionBase::SetAttribute(BNILInstructionAttribute attribute, bool state) +{ + uint32_t newAttributes = attributes; + if (state) + { + newAttributes |= attribute; + switch (attribute) + { + case ILAllowDeadStoreElimination: + newAttributes &= ~ILPreventDeadStoreElimination; + break; + case ILPreventDeadStoreElimination: + newAttributes &= ~ILAllowDeadStoreElimination; + break; + default: + break; + } + } + else + { + newAttributes &= ~attribute; + } + SetAttributes(newAttributes); +} + + +void MediumLevelILInstructionBase::ClearAttribute(BNILInstructionAttribute attribute) +{ + SetAttribute(attribute, false); +} + + void MediumLevelILInstruction::VisitExprs(const std::function& func) const { if (!func(*this)) -- cgit v1.3.1