From c9845e5a200228f20809336d9e9afee45e776d19 Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Thu, 1 Aug 2019 16:31:34 -0400 Subject: Add mem SSA to HLIL --- highlevelilinstruction.h | 126 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 118 insertions(+), 8 deletions(-) (limited to 'highlevelilinstruction.h') diff --git a/highlevelilinstruction.h b/highlevelilinstruction.h index faf287cc..9dc6a604 100644 --- a/highlevelilinstruction.h +++ b/highlevelilinstruction.h @@ -60,7 +60,8 @@ namespace BinaryNinja VariableHighLevelOperand, SSAVariableHighLevelOperand, ExprListHighLevelOperand, - SSAVariableListHighLevelOperand + SSAVariableListHighLevelOperand, + IndexListHighLevelOperand }; enum HighLevelILOperandUsage @@ -93,7 +94,10 @@ namespace BinaryNinja DestExprsHighLevelOperandUsage, BlockExprsHighLevelOperandUsage, CasesHighLevelOperandUsage, - SourceSSAVariablesHighLevelOperandUsage + SourceSSAVariablesHighLevelOperandUsage, + SourceMemoryVersionHighLevelOperandUsage, + SourceMemoryVersionsHighLevelOperandUsage, + DestMemoryVersionHighLevelOperandUsage }; } @@ -176,6 +180,33 @@ namespace BinaryNinja operator std::vector() const; }; + class HighLevelILIndexList + { + struct ListIterator + { + HighLevelILIntegerList::const_iterator pos; + 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; } + ListIterator& operator++() { ++pos; return *this; } + size_t operator*(); + }; + + HighLevelILIntegerList m_list; + + public: + typedef ListIterator const_iterator; + + HighLevelILIndexList(HighLevelILFunction* func, const BNHighLevelILInstruction& instr, size_t count); + + const_iterator begin() const; + const_iterator end() const; + size_t size() const; + size_t operator[](size_t i) const; + + operator std::vector() const; + }; + class HighLevelILInstructionList { struct ListIterator @@ -255,6 +286,7 @@ namespace BinaryNinja SSAVariable GetRawOperandAsSSAVariable(size_t operand) const; HighLevelILInstructionList GetRawOperandAsExprList(size_t operand) const; HighLevelILSSAVariableList GetRawOperandAsSSAVariableList(size_t operand) const; + HighLevelILIndexList GetRawOperandAsIndexList(size_t operand) const; void UpdateRawOperand(size_t operandIndex, ExprId value); void UpdateRawOperandAsSSAVariableList(size_t operandIndex, const std::vector& vars); @@ -358,6 +390,9 @@ namespace BinaryNinja template HighLevelILInstructionList GetBlockExprs() const { return As().GetBlockExprs(); } template HighLevelILInstructionList GetCases() const { return As().GetCases(); } template HighLevelILSSAVariableList GetSourceSSAVariables() const { return As().GetSourceSSAVariables(); } + template size_t GetSourceMemoryVersion() const { return As().GetSourceMemoryVersion(); } + template HighLevelILIndexList GetSourceMemoryVersions() const { return As().GetSourceMemoryVersions(); } + template size_t GetDestMemoryVersion() const { return As().GetDestMemoryVersion(); } template void SetSSAVersion(size_t version) { As().SetSSAVersion(version); } template void SetParameterExprs(const std::vector& params) { As().SetParameterExprs(params); } @@ -371,6 +406,8 @@ namespace BinaryNinja template void SetCases(const std::vector& params) { As().SetCases(params); } template void SetCases(const std::vector& params) { As().SetCases(params); } template void SetSourceSSAVariables(const std::vector& vars) { As().SetSourceSSAVariables(vars); } + template void SetSourceMemoryVersion(size_t version) { return As().SetSourceMemoryVersion(version); } + template void SetDestMemoryVersion(size_t version) { return As().SetDestMemoryVersion(version); } bool GetOperandIndexForUsage(HighLevelILOperandUsage usage, size_t& operandIndex) const; @@ -405,6 +442,9 @@ namespace BinaryNinja HighLevelILInstructionList GetBlockExprs() const; HighLevelILInstructionList GetCases() const; HighLevelILSSAVariableList GetSourceSSAVariables() const; + size_t GetSourceMemoryVersion() const; + HighLevelILIndexList GetSourceMemoryVersions() const; + size_t GetDestMemoryVersion() const; }; class HighLevelILOperand @@ -429,6 +469,7 @@ namespace BinaryNinja SSAVariable GetSSAVariable() const; HighLevelILInstructionList GetExprList() const; HighLevelILSSAVariableList GetSSAVariableList() const; + HighLevelILIndexList GetIndexList() const; }; class HighLevelILOperandList @@ -547,6 +588,29 @@ namespace BinaryNinja HighLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(0); } HighLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(1); } }; + template <> struct HighLevelILInstructionAccessor: public HighLevelILInstructionBase + { + HighLevelILInstructionList GetDestExprs() const { return GetRawOperandAsExprList(0); } + HighLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(2); } + }; + template <> struct HighLevelILInstructionAccessor: public HighLevelILInstructionBase + { + HighLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(0); } + size_t GetDestMemoryVersion() const { return GetRawOperandAsIndex(1); } + void SetDestMemoryVersion(size_t version) { UpdateRawOperand(1, version); } + HighLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(2); } + size_t GetSourceMemoryVersion() const { return GetRawOperandAsIndex(3); } + void SetSourceMemoryVersion(size_t version) { UpdateRawOperand(3, version); } + }; + template <> struct HighLevelILInstructionAccessor: public HighLevelILInstructionBase + { + HighLevelILInstructionList GetDestExprs() const { return GetRawOperandAsExprList(0); } + size_t GetDestMemoryVersion() const { return GetRawOperandAsIndex(2); } + void SetDestMemoryVersion(size_t version) { UpdateRawOperand(2, version); } + HighLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(3); } + size_t GetSourceMemoryVersion() const { return GetRawOperandAsIndex(4); } + void SetSourceMemoryVersion(size_t version) { UpdateRawOperand(4, version); } + }; template <> struct HighLevelILInstructionAccessor: public HighLevelILInstructionBase { @@ -558,11 +622,31 @@ namespace BinaryNinja HighLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(0); } uint64_t GetOffset() const { return GetRawOperandAsInteger(1); } }; + template <> struct HighLevelILInstructionAccessor: public HighLevelILInstructionBase + { + HighLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(0); } + size_t GetSourceMemoryVersion() const { return GetRawOperandAsIndex(1); } + void SetSourceMemoryVersion(size_t version) { UpdateRawOperand(1, version); } + }; + template <> struct HighLevelILInstructionAccessor: public HighLevelILInstructionBase + { + HighLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(0); } + size_t GetSourceMemoryVersion() const { return GetRawOperandAsIndex(1); } + void SetSourceMemoryVersion(size_t version) { UpdateRawOperand(1, version); } + uint64_t GetOffset() const { return GetRawOperandAsInteger(2); } + }; template <> struct HighLevelILInstructionAccessor: public HighLevelILInstructionBase { HighLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(0); } HighLevelILInstruction GetIndexExpr() const { return GetRawOperandAsExpr(1); } }; + template <> struct HighLevelILInstructionAccessor: public HighLevelILInstructionBase + { + HighLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(0); } + size_t GetSourceMemoryVersion() const { return GetRawOperandAsIndex(1); } + void SetSourceMemoryVersion(size_t version) { UpdateRawOperand(1, version); } + HighLevelILInstruction GetIndexExpr() const { return GetRawOperandAsExpr(2); } + }; template <> struct HighLevelILInstructionAccessor: public HighLevelILInstructionBase { HighLevelILInstruction GetHighExpr() const { return GetRawOperandAsExpr(0); } @@ -584,6 +668,12 @@ namespace BinaryNinja HighLevelILSSAVariableList GetSourceSSAVariables() const { return GetRawOperandAsSSAVariableList(2); } void SetSourceSSAVariables(const std::vector& vars) { UpdateRawOperandAsSSAVariableList(2, vars); } }; + template <> struct HighLevelILInstructionAccessor: public HighLevelILInstructionBase + { + size_t GetDestMemoryVersion() const { return GetRawOperandAsIndex(0); } + void SetDestMemoryVersion(size_t version) { UpdateRawOperand(0, version); } + HighLevelILIndexList GetSourceMemoryVersions() const { return GetRawOperandAsIndexList(1); } + }; template <> struct HighLevelILInstructionAccessor: public HighLevelILInstructionBase { @@ -604,17 +694,37 @@ namespace BinaryNinja HighLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(0); } HighLevelILInstructionList GetParameterExprs() const { return GetRawOperandAsExprList(1); } }; - - template <> struct HighLevelILInstructionAccessor: public HighLevelILInstructionBase + template <> struct HighLevelILInstructionAccessor: public HighLevelILInstructionBase { - HighLevelILInstructionList GetDestExprs() const { return GetRawOperandAsExprList(0); } - HighLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(2); } + HighLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(0); } + HighLevelILInstructionList GetParameterExprs() const { return GetRawOperandAsExprList(1); } + size_t GetDestMemoryVersion() const { return GetRawOperandAsIndex(3); } + void SetDestMemoryVersion(size_t version) { UpdateRawOperand(3, version); } + size_t GetSourceMemoryVersion() const { return GetRawOperandAsIndex(4); } + void SetSourceMemoryVersion(size_t version) { UpdateRawOperand(4, version); } + }; + template <> struct HighLevelILInstructionAccessor: public HighLevelILInstructionBase + { + HighLevelILInstructionList GetParameterExprs() const { return GetRawOperandAsExprList(0); } + size_t GetDestMemoryVersion() const { return GetRawOperandAsIndex(2); } + void SetDestMemoryVersion(size_t version) { UpdateRawOperand(2, version); } + size_t GetSourceMemoryVersion() const { return GetRawOperandAsIndex(3); } + void SetSourceMemoryVersion(size_t version) { UpdateRawOperand(3, version); } }; template <> struct HighLevelILInstructionAccessor: public HighLevelILInstructionBase { - uint32_t GetIntrinsic() const { return (uint32_t)GetRawOperandAsInteger(2); } - HighLevelILInstructionList GetParameterExprs() const { return GetRawOperandAsExprList(3); } + uint32_t GetIntrinsic() const { return (uint32_t)GetRawOperandAsInteger(0); } + HighLevelILInstructionList GetParameterExprs() const { return GetRawOperandAsExprList(1); } + }; + template <> struct HighLevelILInstructionAccessor: public HighLevelILInstructionBase + { + uint32_t GetIntrinsic() const { return (uint32_t)GetRawOperandAsInteger(0); } + HighLevelILInstructionList GetParameterExprs() const { return GetRawOperandAsExprList(1); } + size_t GetDestMemoryVersion() const { return GetRawOperandAsIndex(3); } + void SetDestMemoryVersion(size_t version) { UpdateRawOperand(3, version); } + size_t GetSourceMemoryVersion() const { return GetRawOperandAsIndex(4); } + void SetSourceMemoryVersion(size_t version) { UpdateRawOperand(4, version); } }; template <> struct HighLevelILInstructionAccessor: public HighLevelILInstructionBase -- cgit v1.3.1