// Copyright (c) 2019-2026 Vector 35 Inc // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. #pragma once #include "base/function_ref.h" #include "mediumlevelilinstruction.h" #ifdef BINARYNINJACORE_LIBRARY #include "variable.h" #include "ilsourcelocation.h" #else #include "binaryninjaapi.h" #endif #include #include #include #ifdef BINARYNINJACORE_LIBRARY namespace BinaryNinjaCore #else namespace BinaryNinja #endif { class HighLevelILFunction; /*! \ingroup highlevelil */ template struct HighLevelILInstructionAccessor {}; struct HighLevelILInstruction; struct HighLevelILConstantInstruction; struct HighLevelILConstantDataInstruction; struct HighLevelILOneOperandInstruction; struct HighLevelILTwoOperandInstruction; struct HighLevelILTwoOperandWithCarryInstruction; struct HighLevelILDoublePrecisionInstruction; struct MediumLevelILInstruction; class HighLevelILOperand; class HighLevelILOperandList; /*! \ingroup highlevelil */ enum HighLevelILOperandType : uint8_t { IntegerHighLevelOperand, ConstantDataHighLevelOperand, IndexHighLevelOperand, IntrinsicHighLevelOperand, ExprHighLevelOperand, VariableHighLevelOperand, SSAVariableHighLevelOperand, ExprListHighLevelOperand, SSAVariableListHighLevelOperand, IndexListHighLevelOperand }; /*! \ingroup highlevelil */ enum HighLevelILOperandUsage : uint8_t { SourceExprHighLevelOperandUsage, VariableHighLevelOperandUsage, DestVariableHighLevelOperandUsage, SSAVariableHighLevelOperandUsage, DestSSAVariableHighLevelOperandUsage, DestExprHighLevelOperandUsage, LeftExprHighLevelOperandUsage, RightExprHighLevelOperandUsage, CarryExprHighLevelOperandUsage, IndexExprHighLevelOperandUsage, ConditionExprHighLevelOperandUsage, ConditionPhiExprHighLevelOperandUsage, TrueExprHighLevelOperandUsage, FalseExprHighLevelOperandUsage, LoopExprHighLevelOperandUsage, InitExprHighLevelOperandUsage, UpdateExprHighLevelOperandUsage, DefaultExprHighLevelOperandUsage, HighExprHighLevelOperandUsage, LowExprHighLevelOperandUsage, OffsetHighLevelOperandUsage, MemberIndexHighLevelOperandUsage, ConstantHighLevelOperandUsage, ConstantDataHighLevelOperandUsage, VectorHighLevelOperandUsage, IntrinsicHighLevelOperandUsage, TargetHighLevelOperandUsage, ParameterExprsHighLevelOperandUsage, SourceExprsHighLevelOperandUsage, DestExprsHighLevelOperandUsage, BlockExprsHighLevelOperandUsage, CasesHighLevelOperandUsage, ValueExprsHighLevelOperandUsage, SourceSSAVariablesHighLevelOperandUsage, SourceMemoryVersionHighLevelOperandUsage, SourceMemoryVersionsHighLevelOperandUsage, DestMemoryVersionHighLevelOperandUsage }; } // namespace BinaryNinjaCore namespace std { template <> struct hash { typedef BNHighLevelILOperation argument_type; typedef int result_type; result_type operator()(argument_type const& value) const { return (result_type)value; } }; #ifdef BINARYNINJACORE_LIBRARY template <> struct hash #else template <> struct hash #endif { #ifdef BINARYNINJACORE_LIBRARY typedef BinaryNinjaCore::HighLevelILOperandUsage argument_type; #else typedef BinaryNinja::HighLevelILOperandUsage argument_type; #endif typedef int result_type; result_type operator()(argument_type const& value) const { return (result_type)value; } }; } // namespace std #ifdef BINARYNINJACORE_LIBRARY namespace BinaryNinjaCore #else namespace BinaryNinja #endif { #ifdef BINARYNINJACORE_LIBRARY #define _STD_VECTOR vector #define _STD_SET set #define _STD_STACK stack #define _STD_UNORDERED_MAP unordered_map #else #define _STD_VECTOR std::vector #define _STD_SET std::set #define _STD_STACK std::stack #define _STD_UNORDERED_MAP std::unordered_map #endif /*! \ingroup highlevelil */ class HighLevelILInstructionAccessException : public ExceptionWithStackTrace { public: HighLevelILInstructionAccessException() : ExceptionWithStackTrace("invalid access to HLIL instruction") {} }; /*! \ingroup highlevelil */ class HighLevelILIntegerList { struct ListIterator { typedef std::forward_iterator_tag iterator_category; typedef uint64_t value_type; typedef std::ptrdiff_t difference_type; typedef void pointer; typedef value_type reference; #ifdef BINARYNINJACORE_LIBRARY HighLevelILFunction* function; #else Ref function; #endif size_t offset; size_t count; bool operator==(const ListIterator& a) const; bool operator!=(const ListIterator& a) const; bool operator<(const ListIterator& a) const; ListIterator& operator++(); uint64_t operator*(); HighLevelILFunction* GetFunction() const { return function; } }; ListIterator m_start; public: typedef ListIterator const_iterator; HighLevelILIntegerList(HighLevelILFunction* func, size_t offset, size_t count); const_iterator begin() const; const_iterator end() const; size_t size() const; uint64_t operator[](size_t i) const; operator _STD_VECTOR() const; }; /*! \ingroup highlevelil */ class HighLevelILIndexList { struct ListIterator { typedef std::forward_iterator_tag iterator_category; typedef size_t value_type; typedef std::ptrdiff_t difference_type; typedef void pointer; typedef value_type reference; 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, size_t offset, 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; }; /*! \ingroup highlevelil */ class HighLevelILInstructionList { struct ListIterator { typedef std::forward_iterator_tag iterator_category; typedef HighLevelILInstruction value_type; typedef std::ptrdiff_t difference_type; typedef void pointer; typedef value_type reference; 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; } ListIterator& operator++() { ++pos; return *this; } const HighLevelILInstruction operator*(); }; HighLevelILIntegerList m_list; bool m_ast; size_t m_instructionIndex; public: typedef ListIterator const_iterator; HighLevelILInstructionList(HighLevelILFunction* func, size_t offset, size_t count, bool asFullAst, size_t instructionIndex); const_iterator begin() const; const_iterator end() const; size_t size() const; const HighLevelILInstruction operator[](size_t i) const; operator _STD_VECTOR() const; operator _STD_VECTOR() const; }; /*! \ingroup highlevelil */ class HighLevelILSSAVariableList { struct ListIterator { typedef std::forward_iterator_tag iterator_category; typedef SSAVariable value_type; typedef std::ptrdiff_t difference_type; typedef void pointer; typedef value_type reference; 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; ++pos; return *this; } const SSAVariable operator*(); }; HighLevelILIntegerList m_list; public: typedef ListIterator const_iterator; HighLevelILSSAVariableList(HighLevelILFunction* func, size_t offset, size_t count); const_iterator begin() const; const_iterator end() const; size_t size() const; const SSAVariable operator[](size_t i) const; operator _STD_VECTOR() const; }; /*! \ingroup highlevelil */ struct HighLevelILInstructionBase : public BNHighLevelILInstruction { #ifdef BINARYNINJACORE_LIBRARY HighLevelILFunction* function = nullptr; #else Ref function = nullptr; #endif size_t exprIndex, instructionIndex; bool ast; HighLevelILOperandList GetOperands() const; uint64_t GetRawOperandAsInteger(size_t operand) const; ConstantData GetRawOperandAsConstantData(size_t operand) const; size_t GetRawOperandAsIndex(size_t operand) const; HighLevelILInstruction GetRawOperandAsExpr(size_t operand) const; Variable GetRawOperandAsVariable(size_t operand) const; SSAVariable GetRawOperandAsSSAVariable(size_t operand) const; HighLevelILInstructionList GetRawOperandAsExprList(size_t operand) const; HighLevelILSSAVariableList GetRawOperandAsSSAVariableList(size_t operand) const; HighLevelILIndexList GetRawOperandAsIndexList(size_t operand) const; PossibleValueSet GetRawOperandAsPossibleValueSet(size_t operand) const; void UpdateRawOperand(size_t operandIndex, ExprId value); void UpdateRawOperandAsInteger(size_t operandIndex, uint64_t value); void UpdateRawOperandAsSSAVariableList(size_t operandIndex, const _STD_VECTOR& vars); void UpdateRawOperandAsExprList(size_t operandIndex, const _STD_VECTOR& exprs); void UpdateRawOperandAsExprList(size_t operandIndex, const _STD_VECTOR& exprs); RegisterValue GetValue() const; PossibleValueSet GetPossibleValues( const _STD_SET& options = _STD_SET()) const; Confidence> GetType() const; size_t GetSSAExprIndex() const; size_t GetNonSSAExprIndex() const; HighLevelILInstruction GetSSAForm() const; HighLevelILInstruction GetNonSSAForm() const; size_t GetMediumLevelILExprIndex() const; bool HasMediumLevelIL() const; MediumLevelILInstruction GetMediumLevelIL() const; MediumLevelILInstruction GetMediumLevelILSSAForm() const; // Return (and leak) a string describing the instruction for debugger use char* Dump() const; void Replace(ExprId expr); void SetAttributes(uint32_t attributes); void SetAttribute(BNILInstructionAttribute attribute, bool state = true); void ClearAttribute(BNILInstructionAttribute attribute); std::optional GetDerivedStringReference() const; void SetDerivedStringReference(const DerivedString& str); void RemoveDerivedStringReference(); size_t GetInstructionIndex() const; HighLevelILInstruction GetInstruction() const; HighLevelILInstruction AsAST() const; HighLevelILInstruction AsNonAST() const; bool HasParent() const; HighLevelILInstruction GetParent() const; uint64_t GetInstructionHash(size_t discriminator = 0) const { constexpr auto rotl = [](uint64_t value, int shift) { return (value << shift) | (value >> (64 - shift)); }; std::hash hasher; uint64_t hash = hasher(operation); hash ^= rotl(hasher(address), 23); hash ^= rotl(hasher(discriminator), 47); return hash; } template HighLevelILInstructionAccessor& As() { if (operation != N) throw HighLevelILInstructionAccessException(); return *(HighLevelILInstructionAccessor*)this; } HighLevelILOneOperandInstruction& AsOneOperand() { return *(HighLevelILOneOperandInstruction*)this; } HighLevelILTwoOperandInstruction& AsTwoOperand() { return *(HighLevelILTwoOperandInstruction*)this; } HighLevelILTwoOperandWithCarryInstruction& AsTwoOperandWithCarry() { return *(HighLevelILTwoOperandWithCarryInstruction*)this; } template const HighLevelILInstructionAccessor& As() const { if (operation != N) throw HighLevelILInstructionAccessException(); return *(const HighLevelILInstructionAccessor*)this; } const HighLevelILConstantInstruction& AsConstant() const { return *(const HighLevelILConstantInstruction*)this; } const HighLevelILConstantDataInstruction& AsConstantData() const { return *(const HighLevelILConstantDataInstruction*)this; } const HighLevelILOneOperandInstruction& AsOneOperand() const { return *(const HighLevelILOneOperandInstruction*)this; } const HighLevelILTwoOperandInstruction& AsTwoOperand() const { return *(const HighLevelILTwoOperandInstruction*)this; } const HighLevelILTwoOperandWithCarryInstruction& AsTwoOperandWithCarry() const { return *(const HighLevelILTwoOperandWithCarryInstruction*)this; } }; /*! \ingroup highlevelil */ struct HighLevelILInstruction : public HighLevelILInstructionBase { HighLevelILInstruction(); HighLevelILInstruction(HighLevelILFunction* func, const BNHighLevelILInstruction& instr, size_t expr, bool asFullAst, size_t instructionIndex); HighLevelILInstruction(const HighLevelILInstructionBase& instr); void CollectSubExprs(_STD_STACK& toProcess) const; void VisitExprs(bn::base::function_ref func) const; void VisitExprs(bn::base::function_ref preFunc, bn::base::function_ref postFunc) const; ExprId CopyTo(HighLevelILFunction* dest, const ILSourceLocation& sourceLocation = {}) const; ExprId CopyTo(HighLevelILFunction* dest, bn::base::function_ref subExprHandler, const ILSourceLocation& sourceLocation = {}) const; bool operator<(const HighLevelILInstruction& other) const; bool operator==(const HighLevelILInstruction& other) const; bool operator!=(const HighLevelILInstruction& other) const; // Templated accessors for instruction operands, use these for efficient access to a known instruction template HighLevelILInstruction GetSourceExpr() const { return As().GetSourceExpr(); } template Variable GetVariable() const { return As().GetVariable(); } template Variable GetDestVariable() const { return As().GetDestVariable(); } template SSAVariable GetSSAVariable() const { return As().GetSSAVariable(); } template SSAVariable GetDestSSAVariable() const { return As().GetDestSSAVariable(); } template HighLevelILInstruction GetDestExpr() const { return As().GetDestExpr(); } template HighLevelILInstruction GetLeftExpr() const { return As().GetLeftExpr(); } 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(); } template HighLevelILInstruction GetLoopExpr() const { return As().GetLoopExpr(); } template HighLevelILInstruction GetInitExpr() const { return As().GetInitExpr(); } template HighLevelILInstruction GetUpdateExpr() const { return As().GetUpdateExpr(); } template HighLevelILInstruction GetDefaultExpr() const { return As().GetDefaultExpr(); } template HighLevelILInstruction GetHighExpr() const { return As().GetHighExpr(); } template HighLevelILInstruction GetLowExpr() const { return As().GetLowExpr(); } template uint64_t GetOffset() const { return As().GetOffset(); } template size_t GetMemberIndex() const { return As().GetMemberIndex(); } template int64_t GetConstant() const { return As().GetConstant(); } template ConstantData GetConstantData() const { return As().GetConstantData(); } template int64_t GetVector() const { return As().GetVector(); } template uint32_t GetIntrinsic() const { return As().GetIntrinsic(); } template uint64_t GetTarget() const { return As().GetTarget(); } template HighLevelILInstructionList GetParameterExprs() const { return As().GetParameterExprs(); } template HighLevelILInstructionList GetSourceExprs() const { return As().GetSourceExprs(); } template HighLevelILInstructionList GetDestExprs() const { return As().GetDestExprs(); } template HighLevelILInstructionList GetBlockExprs() const { return As().GetBlockExprs(); } template HighLevelILInstructionList GetCases() const { return As().GetCases(); } template HighLevelILInstructionList GetValueExprs() const { return As().GetValueExprs(); } 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 PossibleValueSet GetConstraint() const { return As().GetConstraint(); } 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); } template void SetSourceExprs(const _STD_VECTOR& params) { As().SetSourceExprs(params); } template void SetDestExprs(const _STD_VECTOR& params) { As().SetDestExprs(params); } template void SetDestExprs(const _STD_VECTOR& params) { As().SetDestExprs(params); } template void SetBlockExprs(const _STD_VECTOR& params) { As().SetBlockExprs(params); } template void SetBlockExprs(const _STD_VECTOR& params) { As().SetBlockExprs(params); } 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); } template void SetTarget(uint64_t target) { As().SetTarget(target); } bool GetOperandIndexForUsage(HighLevelILOperandUsage usage, size_t& operandIndex) const; // Generic accessors for instruction operands, these will throw a HighLevelILInstructionAccessException // on type mismatch. These are slower than the templated versions above. HighLevelILInstruction GetSourceExpr() const; Variable GetVariable() const; Variable GetDestVariable() const; SSAVariable GetSSAVariable() const; SSAVariable GetDestSSAVariable() const; HighLevelILInstruction GetDestExpr() const; HighLevelILInstruction GetLeftExpr() const; HighLevelILInstruction GetRightExpr() const; HighLevelILInstruction GetCarryExpr() const; HighLevelILInstruction GetIndexExpr() const; HighLevelILInstruction GetConditionExpr() const; HighLevelILInstruction GetConditionPhiExpr() const; HighLevelILInstruction GetTrueExpr() const; HighLevelILInstruction GetFalseExpr() const; HighLevelILInstruction GetLoopExpr() const; HighLevelILInstruction GetInitExpr() const; HighLevelILInstruction GetUpdateExpr() const; HighLevelILInstruction GetDefaultExpr() const; HighLevelILInstruction GetHighExpr() const; HighLevelILInstruction GetLowExpr() const; uint64_t GetOffset() const; size_t GetMemberIndex() const; int64_t GetConstant() const; ConstantData GetConstantData() const; int64_t GetVector() const; uint32_t GetIntrinsic() const; uint64_t GetTarget() const; HighLevelILInstructionList GetParameterExprs() const; HighLevelILInstructionList GetSourceExprs() const; HighLevelILInstructionList GetDestExprs() const; HighLevelILInstructionList GetBlockExprs() const; HighLevelILInstructionList GetCases() const; HighLevelILInstructionList GetValueExprs() const; HighLevelILSSAVariableList GetSourceSSAVariables() const; size_t GetSourceMemoryVersion() const; HighLevelILIndexList GetSourceMemoryVersions() const; size_t GetDestMemoryVersion() const; static bool CanCollapse(int operand); }; /*! \ingroup highlevelil */ class HighLevelILOperand { HighLevelILInstruction m_instr; HighLevelILOperandUsage m_usage; HighLevelILOperandType m_type; size_t m_operandIndex; public: HighLevelILOperand(const HighLevelILInstruction& instr, HighLevelILOperandUsage usage, size_t operandIndex); HighLevelILOperandType GetType() const { return m_type; } HighLevelILOperandUsage GetUsage() const { return m_usage; } uint64_t GetInteger() const; ConstantData GetConstantData() const; size_t GetIndex() const; uint32_t GetIntrinsic() const; HighLevelILInstruction GetExpr() const; Variable GetVariable() const; SSAVariable GetSSAVariable() const; HighLevelILInstructionList GetExprList() const; HighLevelILSSAVariableList GetSSAVariableList() const; HighLevelILIndexList GetIndexList() const; }; /*! \ingroup highlevelil */ class HighLevelILOperandList { struct ListIterator { typedef std::forward_iterator_tag iterator_category; typedef HighLevelILOperand value_type; typedef std::ptrdiff_t difference_type; typedef void pointer; typedef value_type reference; const HighLevelILOperandList* owner; size_t index; constexpr bool operator==(const ListIterator& a) const { return index == a.index; } constexpr auto operator<=>(const ListIterator& a) const { return index <=> a.index; } ListIterator& operator++() { ++index; return *this; } const HighLevelILOperand operator*(); }; HighLevelILInstruction m_instr; const HighLevelILOperandUsage* m_usages; const uint8_t* m_indices; uint8_t m_count; public: typedef ListIterator const_iterator; HighLevelILOperandList(const HighLevelILInstruction& instr, const HighLevelILOperandUsage* usages, const uint8_t* indices, uint8_t count); const_iterator begin() const; const_iterator end() const; size_t size() const; const HighLevelILOperand operator[](size_t i) const; operator _STD_VECTOR() const; }; /*! \ingroup highlevelil */ struct HighLevelILConstantInstruction : public HighLevelILInstructionBase { int64_t GetConstant() const { return GetRawOperandAsInteger(0); } }; /*! \ingroup highlevelil */ struct HighLevelILConstantDataInstruction : public HighLevelILInstructionBase { ConstantData GetConstantData() const { return GetRawOperandAsConstantData(0); } }; /*! \ingroup highlevelil */ struct HighLevelILOneOperandInstruction : public HighLevelILInstructionBase { HighLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(0); } }; /*! \ingroup highlevelil */ struct HighLevelILTwoOperandInstruction : public HighLevelILInstructionBase { HighLevelILInstruction GetLeftExpr() const { return GetRawOperandAsExpr(0); } HighLevelILInstruction GetRightExpr() const { return GetRawOperandAsExpr(1); } }; /*! \ingroup highlevelil */ struct HighLevelILTwoOperandWithCarryInstruction : public HighLevelILInstructionBase { HighLevelILInstruction GetLeftExpr() const { return GetRawOperandAsExpr(0); } HighLevelILInstruction GetRightExpr() const { return GetRawOperandAsExpr(1); } HighLevelILInstruction GetCarryExpr() const { return GetRawOperandAsExpr(2); } }; // Implementations of each instruction to fetch the correct operand value for the valid operands, these // are derived from HighLevelILInstructionBase so that invalid operand accessor functions will generate // a compiler error. template <> struct HighLevelILInstructionAccessor : public HighLevelILInstructionBase { HighLevelILInstructionList GetBlockExprs() const { return GetRawOperandAsExprList(0); } }; template <> struct HighLevelILInstructionAccessor : public HighLevelILInstructionBase { HighLevelILInstruction GetConditionExpr() const { return GetRawOperandAsExpr(0); } HighLevelILInstruction GetTrueExpr() const { return GetRawOperandAsExpr(1); } HighLevelILInstruction GetFalseExpr() const { return GetRawOperandAsExpr(2); } }; template <> struct HighLevelILInstructionAccessor : public HighLevelILInstructionBase { 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); } HighLevelILInstruction GetConditionExpr() const { return GetRawOperandAsExpr(1); } 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); } HighLevelILInstruction GetDefaultExpr() const { return GetRawOperandAsExpr(1); } HighLevelILInstructionList GetCases() const { return GetRawOperandAsExprList(2); } }; template <> struct HighLevelILInstructionAccessor : public HighLevelILInstructionBase { HighLevelILInstructionList GetValueExprs() const { return GetRawOperandAsExprList(0); } HighLevelILInstruction GetTrueExpr() const { return GetRawOperandAsExpr(2); } }; template <> struct HighLevelILInstructionAccessor : public HighLevelILInstructionBase { uint64_t GetTarget() const { return GetRawOperandAsInteger(0); } void SetTarget(uint64_t target) { UpdateRawOperandAsInteger(0, target); } }; template <> struct HighLevelILInstructionAccessor : public HighLevelILInstructionBase { uint64_t GetTarget() const { return GetRawOperandAsInteger(0); } void SetTarget(uint64_t target) { UpdateRawOperandAsInteger(0, target); } }; template <> struct HighLevelILInstructionAccessor : public HighLevelILInstructionBase { HighLevelILInstructionList GetSourceExprs() const { return GetRawOperandAsExprList(0); } void SetSourceExprs(const _STD_VECTOR& exprs) { UpdateRawOperandAsExprList(0, exprs); } }; template <> struct HighLevelILInstructionAccessor : public HighLevelILInstructionBase { Variable GetVariable() const { return GetRawOperandAsVariable(0); } }; template <> struct HighLevelILInstructionAccessor : public HighLevelILInstructionBase { Variable GetDestVariable() const { return GetRawOperandAsVariable(0); } HighLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(1); } }; template <> struct HighLevelILInstructionAccessor : public HighLevelILInstructionBase { SSAVariable GetDestSSAVariable() const { return GetRawOperandAsSSAVariable(0); } void SetDestSSAVersion(size_t version) { UpdateRawOperand(1, version); } HighLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(2); } }; template <> struct HighLevelILInstructionAccessor : public HighLevelILInstructionBase { 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 { Variable GetDestVariable() const { return GetRawOperandAsVariable(0); } Variable GetVariable() const { return GetRawOperandAsVariable(1); } }; template <> struct HighLevelILInstructionAccessor : public HighLevelILInstructionBase { SSAVariable GetDestSSAVariable() const { return GetRawOperandAsSSAVariable(0); } void SetDestSSAVersion(size_t version) { UpdateRawOperand(1, version); } SSAVariable GetSSAVariable() const { return GetRawOperandAsSSAVariable(2); } void SetSSAVersion(size_t version) { UpdateRawOperand(3, version); } }; template <> struct HighLevelILInstructionAccessor : public HighLevelILInstructionBase { Variable GetVariable() const { return GetRawOperandAsVariable(0); } PossibleValueSet GetConstraint() const { return GetRawOperandAsPossibleValueSet(1); } }; template <> struct HighLevelILInstructionAccessor : public HighLevelILInstructionBase { SSAVariable GetSSAVariable() const { return GetRawOperandAsSSAVariable(0); } void SetSSAVersion(size_t version) { UpdateRawOperand(1, version); } PossibleValueSet GetConstraint() const { return GetRawOperandAsPossibleValueSet(2); } }; template <> struct HighLevelILInstructionAccessor : public HighLevelILInstructionBase { HighLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(0); } uint64_t GetOffset() const { return GetRawOperandAsInteger(1); } size_t GetMemberIndex() const { return GetRawOperandAsIndex(2); } }; template <> struct HighLevelILInstructionAccessor : public HighLevelILInstructionBase { HighLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(0); } uint64_t GetOffset() const { return GetRawOperandAsInteger(1); } size_t GetMemberIndex() const { return GetRawOperandAsIndex(2); } }; 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); } size_t GetMemberIndex() const { return GetRawOperandAsIndex(3); } }; 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); } HighLevelILInstruction GetLowExpr() const { return GetRawOperandAsExpr(1); } }; template <> struct HighLevelILInstructionAccessor : public HighLevelILInstructionBase { Variable GetVariable() const { return GetRawOperandAsVariable(0); } }; template <> struct HighLevelILInstructionAccessor : public HighLevelILInstructionBase { SSAVariable GetSSAVariable() const { return GetRawOperandAsSSAVariable(0); } void SetSSAVersion(size_t version) { UpdateRawOperand(1, version); } }; template <> struct HighLevelILInstructionAccessor : public HighLevelILInstructionBase { SSAVariable GetDestSSAVariable() const { return GetRawOperandAsSSAVariable(0); } 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 { HighLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(0); } }; template <> struct HighLevelILInstructionAccessor : public HighLevelILInstructionBase { HighLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(0); } HighLevelILInstructionList GetParameterExprs() const { return GetRawOperandAsExprList(1); } }; template <> struct HighLevelILInstructionAccessor : public HighLevelILInstructionBase { HighLevelILInstructionList GetParameterExprs() const { return GetRawOperandAsExprList(0); } }; template <> struct HighLevelILInstructionAccessor : public HighLevelILInstructionBase { HighLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(0); } HighLevelILInstructionList GetParameterExprs() const { return GetRawOperandAsExprList(1); } }; template <> struct HighLevelILInstructionAccessor : public HighLevelILInstructionBase { 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(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 { int64_t GetVector() const { return GetRawOperandAsInteger(0); } }; template <> struct HighLevelILInstructionAccessor : public HighLevelILConstantInstruction { int64_t GetConstant() const { return GetRawOperandAsInteger(0); } int64_t GetOffset() const { return GetRawOperandAsInteger(1); } }; template <> struct HighLevelILInstructionAccessor : public HighLevelILInstructionBase {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILInstructionBase {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILInstructionBase {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILInstructionBase {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILInstructionBase {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILInstructionBase {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILInstructionBase {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILInstructionBase {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILConstantInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILConstantInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILConstantInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILConstantInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILConstantDataInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandWithCarryInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandWithCarryInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandWithCarryInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILTwoOperandWithCarryInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILOneOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILOneOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILOneOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILOneOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILOneOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILOneOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILOneOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILOneOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILOneOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILOneOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILOneOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILOneOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILOneOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILOneOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILOneOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILOneOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILOneOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILOneOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILOneOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILOneOperandInstruction {}; template <> struct HighLevelILInstructionAccessor : public HighLevelILOneOperandInstruction {}; #undef _STD_VECTOR #undef _STD_SET #undef _STD_UNORDERED_MAP } // namespace BinaryNinjaCore #ifdef BINARYNINJACORE_LIBRARY #define IL_INS_NS BinaryNinjaCore #else #define IL_INS_NS BinaryNinja #endif template<> struct fmt::formatter { // -> normal, ? -> debug char presentation = ' '; format_context::iterator format(const IL_INS_NS::HighLevelILInstruction& obj, format_context& ctx) const; constexpr auto parse(format_parse_context& ctx) -> format_parse_context::iterator { auto it = ctx.begin(), end = ctx.end(); if (it != end && *it == '?') presentation = *it++; if (it != end && *it != '}') report_error("invalid format"); return it; } }; #undef IL_INS_NS