From efa3a367885c9510bb6280788241dae6f48a42bb Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Mon, 24 Feb 2020 19:42:56 -0500 Subject: Adding SSA support for HLIL --- highlevelilinstruction.h | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) (limited to 'highlevelilinstruction.h') diff --git a/highlevelilinstruction.h b/highlevelilinstruction.h index 967bafec..aa872e67 100644 --- a/highlevelilinstruction.h +++ b/highlevelilinstruction.h @@ -77,6 +77,7 @@ namespace BinaryNinja CarryExprHighLevelOperandUsage, IndexExprHighLevelOperandUsage, ConditionExprHighLevelOperandUsage, + ConditionPhiExprHighLevelOperandUsage, TrueExprHighLevelOperandUsage, FalseExprHighLevelOperandUsage, LoopExprHighLevelOperandUsage, @@ -214,8 +215,9 @@ namespace BinaryNinja { struct ListIterator { - size_t instructionIndex; HighLevelILIntegerList::const_iterator pos; + bool ast; + size_t instructionIndex; bool operator==(const ListIterator& a) const { return pos == a.pos; } bool operator!=(const ListIterator& a) const { return pos != a.pos; } bool operator<(const ListIterator& a) const { return pos < a.pos; } @@ -224,11 +226,14 @@ namespace BinaryNinja }; HighLevelILIntegerList m_list; + bool m_ast; + size_t m_instructionIndex; public: typedef ListIterator const_iterator; - HighLevelILInstructionList(HighLevelILFunction* func, const BNHighLevelILInstruction& instr, size_t count); + HighLevelILInstructionList(HighLevelILFunction* func, const BNHighLevelILInstruction& instr, + size_t count, bool asFullAst, size_t instructionIndex); const_iterator begin() const; const_iterator end() const; @@ -272,7 +277,8 @@ namespace BinaryNinja #else Ref function; #endif - size_t exprIndex; + size_t exprIndex, instructionIndex; + bool ast; static std::unordered_map operandTypeForUsage; static std::unordered_map HighLevelILInstructionAccessor& As() { @@ -359,7 +371,8 @@ namespace BinaryNinja struct HighLevelILInstruction: public HighLevelILInstructionBase { HighLevelILInstruction(); - HighLevelILInstruction(HighLevelILFunction* func, const BNHighLevelILInstruction& instr, size_t expr); + HighLevelILInstruction(HighLevelILFunction* func, const BNHighLevelILInstruction& instr, + size_t expr, bool asFullAst, size_t instructionIndex); HighLevelILInstruction(const HighLevelILInstructionBase& instr); void VisitExprs(const std::function& func) const; @@ -383,6 +396,7 @@ namespace BinaryNinja template HighLevelILInstruction GetRightExpr() const { return As().GetRightExpr(); } template HighLevelILInstruction GetCarryExpr() const { return As().GetCarryExpr(); } template HighLevelILInstruction GetIndexExpr() const { return As().GetIndexExpr(); } + template HighLevelILInstruction GetConditionPhiExpr() const { return As().GetConditionPhiExpr(); } template HighLevelILInstruction GetConditionExpr() const { return As().GetConditionExpr(); } template HighLevelILInstruction GetTrueExpr() const { return As().GetTrueExpr(); } template HighLevelILInstruction GetFalseExpr() const { return As().GetFalseExpr(); } @@ -410,6 +424,7 @@ namespace BinaryNinja template size_t GetDestMemoryVersion() const { return As().GetDestMemoryVersion(); } template void SetSSAVersion(size_t version) { As().SetSSAVersion(version); } + template void SetDestSSAVersion(size_t version) { As().SetDestSSAVersion(version); } template void SetParameterExprs(const std::vector& params) { As().SetParameterExprs(params); } template void SetParameterExprs(const std::vector& params) { As().SetParameterExprs(params); } template void SetSourceExprs(const std::vector& params) { As().SetSourceExprs(params); } @@ -439,6 +454,7 @@ namespace BinaryNinja HighLevelILInstruction GetCarryExpr() const; HighLevelILInstruction GetIndexExpr() const; HighLevelILInstruction GetConditionExpr() const; + HighLevelILInstruction GetConditionPhiExpr() const; HighLevelILInstruction GetTrueExpr() const; HighLevelILInstruction GetFalseExpr() const; HighLevelILInstruction GetLoopExpr() const; @@ -563,11 +579,23 @@ namespace BinaryNinja HighLevelILInstruction GetConditionExpr() const { return GetRawOperandAsExpr(0); } HighLevelILInstruction GetLoopExpr() const { return GetRawOperandAsExpr(1); } }; + template <> struct HighLevelILInstructionAccessor: public HighLevelILInstructionBase + { + HighLevelILInstruction GetConditionPhiExpr() const { return GetRawOperandAsExpr(0); } + HighLevelILInstruction GetConditionExpr() const { return GetRawOperandAsExpr(1); } + HighLevelILInstruction GetLoopExpr() const { return GetRawOperandAsExpr(2); } + }; template <> struct HighLevelILInstructionAccessor: public HighLevelILInstructionBase { HighLevelILInstruction GetLoopExpr() const { return GetRawOperandAsExpr(0); } HighLevelILInstruction GetConditionExpr() const { return GetRawOperandAsExpr(1); } }; + template <> struct HighLevelILInstructionAccessor: public HighLevelILInstructionBase + { + HighLevelILInstruction GetLoopExpr() const { return GetRawOperandAsExpr(0); } + HighLevelILInstruction GetConditionPhiExpr() const { return GetRawOperandAsExpr(1); } + HighLevelILInstruction GetConditionExpr() const { return GetRawOperandAsExpr(2); } + }; template <> struct HighLevelILInstructionAccessor: public HighLevelILInstructionBase { HighLevelILInstruction GetInitExpr() const { return GetRawOperandAsExpr(0); } @@ -575,6 +603,14 @@ namespace BinaryNinja HighLevelILInstruction GetUpdateExpr() const { return GetRawOperandAsExpr(2); } HighLevelILInstruction GetLoopExpr() const { return GetRawOperandAsExpr(3); } }; + template <> struct HighLevelILInstructionAccessor: public HighLevelILInstructionBase + { + HighLevelILInstruction GetInitExpr() const { return GetRawOperandAsExpr(0); } + HighLevelILInstruction GetConditionPhiExpr() const { return GetRawOperandAsExpr(1); } + HighLevelILInstruction GetConditionExpr() const { return GetRawOperandAsExpr(2); } + HighLevelILInstruction GetUpdateExpr() const { return GetRawOperandAsExpr(3); } + HighLevelILInstruction GetLoopExpr() const { return GetRawOperandAsExpr(4); } + }; template <> struct HighLevelILInstructionAccessor: public HighLevelILInstructionBase { HighLevelILInstruction GetConditionExpr() const { return GetRawOperandAsExpr(0); } @@ -614,7 +650,7 @@ namespace BinaryNinja { SSAVariable GetDestSSAVariable() const { return GetRawOperandAsSSAVariable(0); } void SetDestSSAVersion(size_t version) { UpdateRawOperand(1, version); } - HighLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(1); } + HighLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(2); } }; template <> struct HighLevelILInstructionAccessor: public HighLevelILInstructionBase { -- cgit v1.3.1